/* Waits Trainer minigame (#waits-trainer) — see static/js/waits-trainer.js.
   Self-contained visual scope: a full-height stage of falling hands plus a
   nine-tile arsenal, sized to work on a phone in portrait. */

.wt-wrap {
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  user-select: none;
  -webkit-user-select: none;
}

/* --- HUD --- */

.wt-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex: 0 0 auto;
}

.wt-lives { display: flex; gap: 4px; font-size: 22px; line-height: 1; }
.wt-heart { color: var(--sev-major); text-shadow: 0 0 8px rgba(239, 83, 80, 0.45); }
.wt-heart.lost { color: var(--border); text-shadow: none; }

.wt-score-box { text-align: center; }
.wt-score {
  font-family: 'Outfit', sans-serif;
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.wt-score-box .wt-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.wt-combo {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  transition: color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.wt-combo .wt-combo-n {
  font-family: 'Outfit', sans-serif;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.wt-combo .wt-combo-l { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
/* Lit from combo 5 — the threshold that unlocks the bigger hands. */
.wt-combo.hot {
  color: var(--sev-light);
  border-color: var(--sev-light);
  box-shadow: 0 0 12px rgba(253, 216, 53, 0.25);
}

.wt-hud-right { display: flex; align-items: center; gap: 8px; }

/* Sound toggle. Muted state is remembered in localStorage, so it also
   reflects a choice made in an earlier session. */
.wt-mute {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  line-height: 0;
  padding: 6px 8px;
  cursor: pointer;
  transition: border-color 0.15s, opacity 0.15s;
}
.wt-mute:hover { border-color: var(--text-dim); }
.wt-mute.muted { opacity: 0.45; }

/* --- Stage --- */

.wt-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 220px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(79, 195, 247, 0.08), transparent 70%),
    var(--bg-card);
  touch-action: manipulation;
}
/* The floor: crossing it costs a life. */
.wt-stage::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--sev-major), transparent);
  opacity: 0.5;
}

.wt-hands, .wt-fx { position: absolute; inset: 0; }
.wt-fx { pointer-events: none; }

.wt-stage.wt-shake { animation: wt-shake 0.35s cubic-bezier(.36,.07,.19,.97); }
@keyframes wt-shake {
  10%, 90% { transform: translateX(-3px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}
/* Life lost — the stage is wiped and flashes red for the grace pause. */
.wt-stage.wt-cleared { box-shadow: inset 0 0 60px rgba(239, 83, 80, 0.35); }

/* --- Falling hands --- */

.wt-hand {
  position: absolute;
  top: 0; left: 0;
  padding: 6px 7px 5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(15, 26, 46, 0.92);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  will-change: transform;
}
.wt-hand-tiles { display: flex; gap: 1px; }
/* --wt-tile-h is written on .wt-wrap by wtSyncTileSize() so a falling tile is
   the same width as the arsenal tile that shoots it; the value here is only
   the pre-mount fallback. */
.wt-hand .tile.wt-tile {
  --tile-size: var(--wt-tile-h, 34px);
  border-width: 1px;
  border-radius: 2px;
}

/* Every tile in the minigame states its aspect (the SVGs are 300x400), so a
   tile occupies its final box the instant it's in the DOM. Without this the
   `.tile` base rule's `width: auto` measures 0 until the SVG decodes, and a
   hand laid out from that measurement hangs off the edge of the stage. */
.wt-hand .tile.wt-tile,
.wt-slot .tile.wt-slot-tile,
.wt-shot .tile.wt-shot-tile,
.wt-killer .tile.wt-killer-tile,
.wt-ammo .tile.wt-ammo-tile { aspect-ratio: 3 / 4; }
.wt-hand-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.wt-hand-pts {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.wt-slots { display: flex; gap: 3px; align-items: center; }
/* One slot per wait: how many tiles this hand still needs. Filled slots show
   the wait you already landed. */
.wt-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 13px;
  height: 17px;
  padding: 0 2px;
  border: 1px dashed var(--text-dim);
  border-radius: 3px;
  font-size: 10px;
  color: var(--text-dim);
}
.wt-slot.filled { border: 1px solid var(--success); border-style: solid; padding: 0; }
.wt-slot .tile.wt-slot-tile { --tile-size: 15px; border: 0; border-radius: 2px; }

/* The hand your shots go to. */
.wt-hand.wt-targeted {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 16px rgba(79, 195, 247, 0.35);
}
/* 4+ waits — a shape worth slowing down for. */
.wt-hand.wt-hand-multi { border-color: var(--sev-flag); }
.wt-hand.wt-hand-multi .wt-hand-pts { color: var(--sev-flag); }

.wt-hand.wt-flash-ok { animation: wt-flash-ok 0.3s ease-out; }
@keyframes wt-flash-ok {
  0% { box-shadow: 0 0 0 2px var(--success), 0 0 22px rgba(102, 187, 106, 0.6); }
  100% { box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35); }
}

.wt-hand.wt-dissolve {
  animation: wt-dissolve 0.3s ease-in forwards;
  pointer-events: none;
}
@keyframes wt-dissolve {
  0% { opacity: 1; filter: none; }
  100% { opacity: 0; filter: blur(4px); transform-origin: center; }
}

/* --- Effects --- */

.wt-shot { position: absolute; top: 0; left: 0; will-change: transform; }
.wt-shot .tile.wt-shot-tile {
  --tile-size: 30px;
  border-width: 1px;
  box-shadow: 0 0 12px rgba(79, 195, 247, 0.6);
}
.wt-shot.bad .tile.wt-shot-tile { box-shadow: 0 0 12px rgba(239, 83, 80, 0.7); }

.wt-float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: 'Outfit', sans-serif;
  font-size: 20px;
  font-weight: 700;
  animation: wt-float 0.85s ease-out forwards;
}
.wt-float-ok { color: var(--success); text-shadow: 0 0 10px rgba(102, 187, 106, 0.5); }
@keyframes wt-float {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0.8); }
  100% { opacity: 0; transform: translate(-50%, -180%) scale(1.15); }
}

.wt-banner {
  position: absolute;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border: 1px solid var(--sev-light);
  border-radius: 999px;
  background: rgba(26, 26, 46, 0.9);
  color: var(--sev-light);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  animation: wt-banner 1.4s ease-out forwards;
}
@keyframes wt-banner {
  0% { opacity: 0; transform: translateX(-50%) translateY(8px); }
  15%, 75% { opacity: 1; transform: translateX(-50%) translateY(0); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-8px); }
}

/* --- Overlay (intro / paused / game over) --- */

.wt-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 14, 28, 0.86);
  backdrop-filter: blur(2px);
}
.wt-overlay.show { display: flex; }
.wt-panel {
  max-width: 460px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
}
.wt-panel h3 {
  font-family: 'Outfit', sans-serif;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 10px;
}
.wt-panel .wt-hint { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
/* The hand that ended the run, on the game-over panel: the shape, then one
   slot per wait — green for a wait that was already shot, red for one that
   was still open when the hand hit the floor. */
.wt-killer {
  margin: 4px 0 2px;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(15, 26, 46, 0.7);
}
.wt-killer-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 7px;
}
.wt-killer-tiles {
  display: flex;
  justify-content: center;
  gap: 1px;
  flex-wrap: wrap;
}
.wt-killer .tile.wt-killer-tile {
  --tile-size: 26px;
  border-width: 1px;
  border-radius: 2px;
}
.wt-killer-waits {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-top: 9px;
}
.wt-killer-waits-l {
  font-size: 11px;
  color: var(--text-dim);
  margin-right: 2px;
}
.wt-killer-wait {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.wt-killer-wait.hit { border-color: var(--success); }
.wt-killer-wait.missed { border-color: var(--sev-major); box-shadow: 0 0 0 1px var(--sev-major); }

.wt-result { display: flex; justify-content: center; gap: 22px; margin: 14px 0 6px; }
.wt-result > div { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-dim); }
.wt-result .wt-result-n {
  font-family: 'Outfit', sans-serif;
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* Leaderboard, shown on both the intro and game-over panels. */
.wt-lb {
  margin-top: 18px;
  text-align: left;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.wt-lb-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.wt-lb-head span { font-weight: 400; letter-spacing: 0; text-transform: none; }
.wt-lb table { width: 100%; border-collapse: collapse; font-size: 13px; }
.wt-lb th {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  text-align: right;
  padding-bottom: 3px;
}
.wt-lb th:nth-child(2) { text-align: left; }
/* Match the body cells' gutter so the two right-hand headers don't collide. */
.wt-lb th:nth-child(3),
.wt-lb th:nth-child(4) { padding-left: 10px; }
.wt-lb td { padding: 3px 0; color: var(--text-dim); }
.wt-lb .wt-lb-rank { width: 2em; text-align: right; padding-right: 8px; font-variant-numeric: tabular-nums; }
.wt-lb .wt-lb-name {
  color: var(--text);
  max-width: 0;          /* let the cell shrink so the ellipsis engages */
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wt-lb .wt-lb-combo,
.wt-lb .wt-lb-score { text-align: right; padding-left: 10px; font-variant-numeric: tabular-nums; }
.wt-lb .wt-lb-score { color: var(--text); font-weight: 700; }
/* Your row, wherever it sits. */
.wt-lb .wt-lb-you td { color: var(--accent); }
.wt-lb .wt-lb-you .wt-lb-name,
.wt-lb .wt-lb-you .wt-lb-score { color: var(--accent); }
/* Your row when you're outside the top slice — divided off from the board. */
.wt-lb .wt-lb-outside td { border-top: 1px dashed var(--border); padding-top: 6px; }

/* --- Arsenal --- */

.wt-arsenal {
  flex: 0 0 auto;
  width: 100%;
  max-width: 470px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 5px;
  transition: opacity 0.1s, filter 0.1s;
  touch-action: manipulation;
}
/* Hitstun: the arsenal is inert until the stun expires. */
.wt-arsenal.wt-stunned {
  opacity: 0.4;
  filter: grayscale(1);
  pointer-events: none;
}

.wt-ammo {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 5px 3px 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  cursor: pointer;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.wt-ammo:active { transform: translateY(1px); border-color: var(--accent); }
@media (hover: hover) {
  .wt-ammo:hover { border-color: var(--accent); background: var(--bg-card-hover); }
}
.wt-ammo .tile.wt-ammo-tile {
  width: 100%;
  height: auto;
  border-width: 1px;
  border-radius: 3px;
}
.wt-ammo-key { font-size: 9px; color: var(--text-dim); line-height: 1; }

/* The Buy-me-a-coffee widget is fixed bottom-right, exactly where the 9p
   button lands on a phone. Hide it while the minigame is mounted. */
body:has(.wt-wrap) #bmc-wbtn { display: none !important; }

/* --- Small screens --- */

@media (max-width: 700px) {
  .wt-score { font-size: 26px; }
}
@media (max-width: 640px) {
  /* Claw back the .content padding — the stage wants the whole viewport. */
  .wt-wrap { margin: -10px -12px; }
  .wt-arsenal { gap: 3px; }
  .wt-ammo { padding: 4px 2px 2px; border-radius: 6px; }
  .wt-ammo-key { display: none; }
}
@media (max-width: 420px) {
  .wt-hand { padding: 4px 5px 4px; }
  .wt-slot { height: 15px; min-width: 11px; }
  .wt-slot .tile.wt-slot-tile { --tile-size: 13px; }
}
/* Landscape phone: the stage is short, so shed HUD height. */
@media (max-height: 520px) {
  .wt-wrap { gap: 6px; }
  .wt-score { font-size: 22px; }
  .wt-lives { font-size: 18px; }
  .wt-mute { padding: 4px 6px; }
  .wt-stage { min-height: 140px; }
}
