/* Hub, shared button feel, tabs and shop. Loaded after base.css. */

/* ---------- Layout ---------- */

button { touch-action: manipulation; }

/* Game screens fill the window: as wide as the screen allows while the canvas, its HUD and
   controls still fit the height (the px figures are the space taken by everything but the canvas). */
body[data-screen="game"] main,
body[data-screen="quest"] main,
body[data-screen="shooter"] main,
body[data-screen="td"] main { margin-top: 0; padding: 12px 0 8px; }
body[data-screen="game"] main { width: min(100% - 24px, 100dvh - 330px, 640px); min-width: min(100% - 24px, 340px); }
body[data-screen="quest"] main,
body[data-screen="shooter"] main,
body[data-screen="td"] main { width: min(100% - 24px, (100dvh - 200px) * 1.6); min-width: min(100% - 24px, 320px); }

/* Phone on its side: Trailblades takes the whole height and the buttons float over the bottom corners. */
@media (orientation: landscape) and (max-height: 520px) {
  body[data-screen="quest"] main,
  body[data-screen="shooter"] main { width: min(100% - 16px, (100dvh - 70px) * 1.6); padding-top: 6px; }
  .quest { gap: 6px; }
  .quest .pad {
    position: fixed;
    inset: auto 10px 10px;
    pointer-events: none;
    padding: 0;
  }
  .quest .pad-group { pointer-events: auto; opacity: 0.85; }
  .quest .keys-hint { display: none; }
}

/* ---------- Screen entrances ---------- */

.screen.enter { animation: screen-in 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.item { animation: rise-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3) backwards; animation-delay: calc(var(--i, 0) * 0.04s); }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(14px) scale(0.94); }
}

/* ---------- Extra-satisfying 3D buttons ---------- */

/* Every chunky button: a coloured ledge (--depth deep) plus a soft drop shadow.
   Hover lifts it, press squashes it flat onto the ledge, release springs back (.boing). */
:is(.primary, .secondary, .play-btn, .back, .hud-btn, .act-btn, .class-card) {
  --depth: 5px;
  box-shadow: 0 var(--depth) 0 var(--ledge), 0 calc(var(--depth) + 6px) 14px -6px rgb(0 0 0 / 0.35);
  transition: transform 0.12s cubic-bezier(0.3, 1.6, 0.6, 1), box-shadow 0.12s ease-out, filter 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
:is(.primary, .secondary, .play-btn, .back, .hud-btn, .act-btn, .class-card):hover:not(:disabled) {
  filter: brightness(1.07) saturate(1.05);
  transform: translateY(-2px);
  box-shadow: 0 calc(var(--depth) + 2px) 0 var(--ledge), 0 calc(var(--depth) + 12px) 18px -6px rgb(0 0 0 / 0.35);
}
:is(.primary, .secondary, .play-btn, .back, .hud-btn, .act-btn, .class-card):active:not(:disabled) {
  transform: translateY(var(--depth)) scale(0.97, 0.94);
  box-shadow: 0 0 0 var(--ledge), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  filter: brightness(0.96);
  transition-duration: 0.04s;
}
.play-btn { --depth: 8px; }
.act-btn, .class-card { --depth: 6px; }
.back, .hud-btn { --depth: 4px; }

.boing { animation: boing 0.42s cubic-bezier(0.3, 1.8, 0.5, 1); }
@keyframes boing {
  0% { transform: translateY(var(--depth, 4px)) scale(0.97, 0.94); }
  35% { transform: translateY(-4px) scale(1.04, 1.06); }
  65% { transform: translateY(1px) scale(0.99, 0.98); }
  100% { transform: none; }
}

/* Choice chips squash too. */
.seg button:active { transform: translateY(5px) scale(0.96, 0.92); }

/* Shine sweep across big buttons on hover. */
.play-btn { position: relative; overflow: hidden; }
.play-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgb(255 255 255 / 0.35) 50%, transparent 65%);
  transform: translateX(-120%);
  pointer-events: none;
}
.play-btn:hover::after { transform: translateX(120%); transition: transform 0.6s ease-out; }

/* Press bursts */
.burst-ring,
.burst-spark {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  border-radius: 50%;
}
.burst-ring {
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border: 3px solid var(--c);
  animation: ring 0.45s ease-out forwards;
}
.burst-spark {
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  background: var(--c);
  animation: spark 0.5s cubic-bezier(0.2, 0.8, 0.4, 1) forwards;
}
@keyframes ring {
  to { transform: scale(5); opacity: 0; border-width: 1px; }
}
@keyframes spark {
  70% { opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; }
}

/* ---------- Top bar ---------- */

.back {
  --ledge: color-mix(in srgb, var(--line), #000 25%);
  padding: 6px 14px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  outline: 1px solid var(--line);
  outline-offset: -1px;
  font-family: "Fredoka", system-ui, sans-serif;
  font-weight: 600;
}

.title-sm { font-size: clamp(1.75rem, 9vw, 2.5rem); margin-top: -4px; }

/* ---------- Tabs ---------- */

.tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--line);
}
.tabs button {
  padding: 9px 2px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, transform 0.08s;
}
.tabs button:active { transform: scale(0.95); }
.tabs button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 2px 0 color-mix(in srgb, var(--line), #000 20%);
}

/* ---------- Shop ---------- */

details.earn { text-align: left; }
details.earn summary { cursor: pointer; list-style: none; padding: 4px 0; justify-content: flex-start; gap: 4px; }
details.earn summary::-webkit-details-marker { display: none; }
details.earn summary::before { content: "▸ "; }
details.earn[open] summary::before { content: "▾ "; }
details.earn .earn-row { margin-top: 8px; }


.item-sub { display: block; font-size: 0.75rem; font-weight: 500; color: var(--muted); }

/* The equipped item in each shop section. */
.item.equipped { outline: 2px solid var(--accent); outline-offset: -2px; }

.icon-btn { padding: 6px 9px; font-size: 1rem; line-height: 1; }

/* Settings */
.settings { gap: 4px; padding: 6px 14px; }
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.setting:last-child { border-bottom: 0; }
.setting-text { display: flex; flex-direction: column; }
.setting input[type="range"] { width: 45%; accent-color: var(--accent); }
.setting input[type="text"] {
  width: 48%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.switch {
  position: relative;
  flex: none;
  width: 52px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: var(--line);
  transition: background 0.2s;
}
.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.25);
  transition: transform 0.22s cubic-bezier(0.3, 1.6, 0.6, 1);
}
.switch[aria-checked="true"] { background: #16a34a; }
.switch[aria-checked="true"] span { transform: translateX(22px); }
.switch:active span { width: 28px; }
.danger { color: #dc2626 !important; }

/* ---------- Online lobby ---------- */

.online-btn {
  --ledge: color-mix(in srgb, #0891b2, #000 35%);
  --depth: 5px;
  padding: 12px;
  border: 0;
  border-radius: 14px;
  background: #0891b2;
  color: #fff;
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  box-shadow: 0 var(--depth) 0 var(--ledge);
  transition: transform 0.12s cubic-bezier(0.3, 1.6, 0.6, 1), box-shadow 0.12s;
}
.online-btn:hover { transform: translateY(-2px); box-shadow: 0 calc(var(--depth) + 2px) 0 var(--ledge); }
.online-btn:active { transform: translateY(var(--depth)); box-shadow: 0 0 0 var(--ledge); }

.lobby-entry, .lobby-room { display: flex; flex-direction: column; gap: 14px; }
.lobby-entry.busy { opacity: 0.6; pointer-events: none; }
.join-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.8125rem; }
.join-or::before, .join-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 8px; }
.join-row input {
  flex: 1;
  min-width: 0;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-align: center;
  text-transform: uppercase;
}
.join-row input:focus { outline: none; border-color: var(--accent); }
.join-row .primary { padding: 0 22px; font-size: 1.05rem; }

.room-code-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
.room-code { font-family: "Fredoka", system-ui, sans-serif; font-size: 2.6rem; letter-spacing: 0.25em; line-height: 1; padding-left: 0.25em; }

.room-players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.room-player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface);
  outline: 1px solid var(--line);
  outline-offset: -1px;
  text-align: left;
  animation: rise-in 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.room-player.me { outline: 2px solid var(--accent); outline-offset: -2px; }
.room-player.empty { opacity: 0.45; animation: none; }
.rp-icon { font-size: 1.3rem; width: 1.6em; text-align: center; }
.rp-name { font-weight: 600; }
.rp-tag { margin-left: 4px; padding: 1px 6px; border-radius: 999px; background: var(--line); font-size: 0.6875rem; font-weight: 700; text-transform: uppercase; }
.rp-tag.you { background: var(--accent); color: var(--on-accent); }
.lobby-error { margin: 0; padding: 10px 12px; border-radius: 12px; background: #fee2e2; color: #991b1b; font-weight: 600; }

/* ---------- Leaderboard ---------- */
.lb { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface);
  outline: 1px solid var(--line);
  outline-offset: -1px;
  text-align: left;
}
.lb-row.me { outline: 2px solid var(--accent); outline-offset: -2px; }
.lb-rank { width: 1.8em; text-align: center; font-family: "Fredoka", system-ui, sans-serif; font-weight: 700; }
.lb-name { flex: 1; display: flex; flex-direction: column; font-weight: 600; min-width: 0; }
.lb-score { font-family: "Fredoka", system-ui, sans-serif; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-empty { padding: 14px; color: var(--muted); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  top: 12px;
  left: 50%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(420px, 100% - 24px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-family: "Fredoka", system-ui, sans-serif;
  font-weight: 600;
  box-shadow: 0 8px 24px -8px rgb(0 0 0 / 0.45);
  animation: toast-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.4);
}
.toast.leaving { animation: toast-out 0.3s ease-in forwards; }
.toast.toast-bump { animation: bump 0.35s ease-out; }
.toast-icon { font-size: 1.15rem; display: inline-flex; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-16px) scale(0.9); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-12px) scale(0.95); } }

.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.8125rem;
  line-height: 24px;
  box-shadow: 0 2px 0 #991b1b;
  animation: bump 0.45s ease-out;
}

/* ---------- Resume countdown ---------- */
.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-family: "Fredoka", system-ui, sans-serif;
  font-size: clamp(4rem, 18vw, 9rem);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 6px 0 rgb(0 0 0 / 0.3), 0 0 40px rgb(0 0 0 / 0.4);
}
.countdown.count-pop { animation: count-pop 0.55s ease-out; }
@keyframes count-pop {
  0% { transform: scale(1.8); opacity: 0; }
  30% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.2; }
}
