/* Time's Down - mobile-first stylesheet.
   Everything is sized for a thumb: big targets, no hover-only affordances. */

:root {
  --bg: #0b0d16;
  --bg-glow: #1b2140;
  --surface: #151a2b;
  --surface-2: #1d2438;
  --line: #2a3350;
  --text: #f2f4fb;
  --muted: #8e96b3;
  --accent: #ffb44d;
  --accent-dim: #7a5a24;
  --ok: #34d97a;
  --ok-deep: #0f7a3d;
  --warn: #ffcf5c;
  --danger: #ff6b6b;
  --radius: 18px;
  --tap: 56px;
  --pad: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  background-image:
    radial-gradient(120% 70% at 50% -10%, var(--bg-glow) 0%, transparent 60%),
    radial-gradient(80% 50% at 100% 100%, #16203a 0%, transparent 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, "Helvetica Neue", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Text is never selectable during play: a long-press must reveal a card,
   not pop the browser's copy menu. Inputs opt back in below. */
body, button {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 16px) var(--pad) calc(var(--safe-bottom) + 16px);
  max-width: 560px;
  margin: 0 auto;
  width: 100%;
}

/* ------------------------------------------------------------- typography */

h1, h2, h3 { margin: 0; font-weight: 750; letter-spacing: -0.02em; }
h1 { font-size: 2rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
.mono-code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.32em;
  text-indent: 0.32em; /* balance the trailing letter-spacing */
}

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 10px; align-items: center; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }

/* ---------------------------------------------------------------- surfaces */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.panel-tight { padding: 12px 14px; }

/* ----------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  min-height: var(--tap);
  padding: 14px 18px;
  border-radius: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.975); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:active { transform: none; }
.btn-block { width: 100%; }

.btn-primary {
  background: linear-gradient(180deg, #ffc571, var(--accent));
  border-color: #ffd08a;
  color: #2a1a02;
  font-weight: 800;
}
.btn-ok {
  background: linear-gradient(180deg, #46e88a, var(--ok));
  border-color: #6cf0a5;
  color: #04301a;
  font-weight: 800;
}
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #4a2a35; background: #24151d; }
.btn-lg { min-height: 68px; font-size: 1.15rem; }
.btn-sm { min-height: 40px; padding: 8px 12px; font-size: 0.88rem; border-radius: 11px; }

/* ------------------------------------------------------------------ inputs */

.field {
  width: 100%;
  min-height: var(--tap);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  font: inherit;
  padding: 12px 16px;
}
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field::placeholder { color: #5d668a; }

.field-code {
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  text-transform: uppercase;
  padding: 16px;
  min-height: 72px;
}

/* Segmented control, used for team count and turn length. */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg .btn { flex: 1; min-width: 56px; min-height: 46px; padding: 8px; }
.seg .btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #2a1a02;
  font-weight: 800;
}

/* -------------------------------------------------------------- home / brand */

.brand { text-align: center; padding: 8px 0 4px; }
.brand-mark { font-size: 3rem; line-height: 1; }
.brand h1 {
  font-size: 2.6rem;
  background: linear-gradient(180deg, #fff, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand .tag { color: var(--muted); font-size: 0.95rem; margin-top: 2px; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* --------------------------------------------------------------- room code */

.codebox {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
}
.codebox .label {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.codebox .code {
  font-size: 2.7rem;
  font-weight: 850;
  color: var(--accent);
  line-height: 1.15;
}
.codebox .url { color: var(--muted); font-size: 0.85rem; word-break: break-all; }

/* ------------------------------------------------------------------ counts */

.counts { display: flex; gap: 10px; }
.count {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  text-align: center;
}
.count .n { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.count .n.accent { color: var(--accent); }
.count .k {
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

/* -------------------------------------------------------------- word chips */

.wordlist { display: flex; flex-direction: column; gap: 8px; }

.wordchip {
  appearance: none;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 11px 14px;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.wordchip .idx {
  color: var(--muted);
  font-size: 0.8rem;
  min-width: 22px;
  font-variant-numeric: tabular-nums;
}
.wordchip .masked { letter-spacing: 0.16em; color: #5d668a; }
.wordchip .revealed-text { font-weight: 650; }
.wordchip .hint { margin-left: auto; color: var(--muted); font-size: 0.75rem; }
.wordchip.open { border-color: var(--accent-dim); background: #221e18; }

.chip-actions { display: flex; gap: 8px; padding: 0 0 2px 34px; }

.notice {
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.86rem;
  border: 1px solid;
}
.notice-warn { background: #2a2412; border-color: #4d4120; color: var(--warn); }
.notice-info { background: #16203a; border-color: #2a3a63; color: #a8c2ff; }

/* ------------------------------------------------------------- game screen */

.game { flex: 1; display: flex; flex-direction: column; gap: 14px; }

.game-head { display: flex; flex-direction: column; gap: 4px; text-align: center; }
.round-pill {
  align-self: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: var(--muted);
}
.team-name { font-size: 1.35rem; font-weight: 800; }

.timer {
  font-size: 3.6rem;
  font-weight: 850;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.timer.low { color: var(--danger); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

.timer-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.timer-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s linear;
}
.timer-bar.low span { background: var(--danger); }

/* The card itself: text is fully covered until a finger is held on it. */
.card {
  position: relative;
  flex: 1;
  min-height: 190px;
  border-radius: 24px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  cursor: pointer;
}
.card-word {
  font-size: clamp(1.8rem, 9vw, 3rem);
  font-weight: 850;
  text-align: center;
  line-height: 1.15;
  word-break: break-word;
  color: transparent;
  text-shadow: 0 0 26px rgba(242, 244, 251, 0.55);
  transition: color 0.06s ease, text-shadow 0.06s ease;
}
.card-veil {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(180deg, #1d2438, #151a2b);
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  transition: opacity 0.08s ease;
}
.card-veil .finger { font-size: 2.2rem; letter-spacing: normal; }
.card.revealed .card-veil { opacity: 0; }
.card.revealed .card-word { color: var(--text); text-shadow: none; }

.card-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
}

.actions { display: flex; gap: 12px; }
.actions .btn { flex: 1; }

/* --------------------------------------------------------------- scoreboard */

.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scores th, .scores td {
  padding: 10px 8px;
  text-align: right;
  border-bottom: 1px solid var(--line);
}
.scores th:first-child, .scores td:first-child { text-align: left; }
.scores thead th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 600;
}
.scores tbody tr:last-child td { border-bottom: none; }
.scores .total { font-weight: 850; color: var(--accent); font-size: 1.05rem; }
.scores .leader td:first-child::after { content: " 👑"; }

.podium { display: flex; flex-direction: column; gap: 8px; }
.podium-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.podium-row.first { border-color: var(--accent); background: #241d0f; }
.podium-row .rank { font-size: 1.3rem; min-width: 28px; }
.podium-row .pname { font-weight: 700; flex: 1; }
.podium-row .pscore { font-weight: 850; font-size: 1.3rem; color: var(--accent); }

/* ------------------------------------------------------------ review list */

.review-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.review-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 8px 10px;
  min-height: 54px;
}
.review-row.ok { border-color: #235c3d; background: #10241a; }
.review-row.skip { border-color: var(--line); }

.review-word {
  flex: 1;
  min-width: 0;
  padding: 8px 6px;
  border-radius: 9px;
  background: transparent;
  border: none;
  font: inherit;
  text-align: left;
  color: transparent;
  text-shadow: 0 0 12px rgba(242, 244, 251, 0.6);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.review-word.revealed { color: var(--text); text-shadow: none; }

.toggle {
  min-width: 52px;
  min-height: 40px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
}
.review-row.ok .toggle { background: var(--ok-deep); border-color: var(--ok); color: #eafff2; }

/* --------------------------------------------------------------- overlays */

#flash {
  position: fixed;
  inset: 0;
  background: var(--ok);
  opacity: 0;
  pointer-events: none;
  z-index: 90;
}
#flash.on { opacity: 1; }
#flash.on.skip { background: var(--warn); opacity: 0.6; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 22px);
  transform: translate(-50%, 20px);
  background: #2b3350;
  border: 1px solid #3d4870;
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  max-width: 88vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: #45202a; border-color: #6d3040; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.topbar .title { font-weight: 800; letter-spacing: -0.01em; }
.topbar .code-tag {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.1em;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  margin-right: 6px;
  vertical-align: middle;
}
.dot.off { background: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
