/* play — hand-rolled, no framework, no build step.
   Self-hosted fonts because the Caddy CSP is default-src 'self'. */

@font-face {
  font-family: 'Space Grotesk';
  src: url('/fonts/SpaceGrotesk-300-700.woff2') format('woff2-variations');
  font-weight: 300 700; font-display: swap; font-style: normal;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/IBMPlexMono-500.woff2') format('woff2');
  font-weight: 500; font-display: swap; font-style: normal;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/IBMPlexMono-600.woff2') format('woff2');
  font-weight: 600; font-display: swap; font-style: normal;
}

:root {
  --bg: #0A0B0F;
  --surface: #12141B;
  --surface-2: #1A1D26;
  --line: #262A36;
  --text: #EDEFF5;
  --muted: #9AA1B4;
  --faint: #656C80;

  /* Her — soft velvet purple */
  --her-deep: #2A1633;
  --her-mid: #6D4C93;
  --her: #A879D6;
  --her-text: #EBDCFA;

  /* Him — deep blue */
  --him-deep: #0F1A38;
  --him-mid: #264C9E;
  --him: #5B93E8;
  --him-text: #D8E6FB;

  /* Break — warm amber */
  --brk-deep: #2A1D0B;
  --brk-mid: #8A5A20;
  --brk: #E0A44E;

  --danger: #E5606B;
  --ok: #57C98A;

  --font: 'Space Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --r-sm: 8px; --r-md: 14px; --r-lg: 22px;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --turn-ms: 520ms;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #1B1430 0%, var(--bg) 62%);
}
.login-card {
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 14px;
}
.login-mark {
  width: 54px; height: 54px; margin: 0 auto 6px; border-radius: 16px;
  background: linear-gradient(135deg, var(--her) 0%, var(--him) 100%);
  box-shadow: 0 0 40px -6px rgba(168, 121, 214, .5);
}
.login-card h1 {
  margin: 0 0 6px; text-align: center; font-size: 26px; font-weight: 600; letter-spacing: -.02em;
}
.login-card label { display: flex; flex-direction: column; gap: 6px; }
.login-card label span { font-size: 12px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.login-card input {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--r-md); padding: 13px 14px; min-height: 48px; outline: none;
}
.login-card input:focus { border-color: var(--her-mid); }
.login-error { min-height: 18px; margin: 0; text-align: center; font-size: 13px; color: var(--danger); }

.btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  border-radius: var(--r-md); padding: 13px 18px; min-height: 48px;
  cursor: pointer; touch-action: manipulation; font-weight: 500;
  transition: filter 140ms var(--ease), transform 140ms var(--ease);
}
.btn:active { transform: scale(.98); }
.btn-primary { background: linear-gradient(135deg, var(--her-mid), var(--him-mid)); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: #40272C; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 8px 0; text-decoration: underline; }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.shell { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-t) + 8px) 8px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 11, 15, .82); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 20; flex: 0 0 auto;
}
.topbar-title {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; letter-spacing: -.01em;
}
.conn { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); transition: background 300ms; }
.conn[data-state="live"] { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.conn[data-state="lost"] { background: var(--danger); }
.icon-btn {
  display: grid; place-items: center; width: 44px; height: 44px;
  background: none; border: 0; border-radius: var(--r-md); color: var(--muted);
  cursor: pointer; touch-action: manipulation;
}
.icon-btn:active { background: var(--surface-2); }

.view { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
/* The play view holds TWO children — the split surface and the action bar.
   #view must be a flex column here, or .race (height:100%) eats the whole
   viewport and pushes the action bar below the fold where `overflow:hidden`
   clips it. That silently hid Pause/End game entirely. */
.view.is-play { overflow: hidden; display: flex; flex-direction: column; }

/* ── Drawer ────────────────────────────────────────────────────────────── */
.scrim {
  position: fixed; inset: 0; z-index: 28; background: rgba(0, 0, 0, .55);
  opacity: 0; transition: opacity 260ms var(--ease);
}
.scrim.open { opacity: 1; }
.drawer {
  position: fixed; z-index: 30; top: 0; left: 0; bottom: 0; width: min(300px, 84vw);
  background: var(--surface); border-right: 1px solid var(--line);
  padding: calc(var(--safe-t) + 18px) 0 calc(var(--safe-b) + 18px);
  display: flex; flex-direction: column;
  transform: translateX(-102%); transition: transform 300ms var(--ease);
  overflow-y: auto;
}
.drawer.open { transform: none; }
.drawer-head { padding: 0 18px 14px; display: flex; align-items: baseline; justify-content: space-between; }
.drawer-title { font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.drawer-who { font-size: 12px; color: var(--faint); }
.drawer-section {
  padding: 14px 18px 6px; font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--faint);
}
.game-list { list-style: none; margin: 0; padding: 0; }
.game-link {
  display: flex; align-items: center; gap: 12px; padding: 13px 18px; min-height: 50px;
  color: var(--text); text-decoration: none;
}
/* The drawer's End-game entry is a <button>, styled to match the links. */
button.game-link { width: 100%; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
button.game-link:active { background: var(--surface-2); }
.game-link[aria-current="page"] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--her); }
.game-icon { font-size: 18px; width: 24px; text-align: center; }
.game-name { flex: 1; }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 8px var(--ok); animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }
.drawer-foot { margin-top: auto; padding: 12px 18px 0; border-top: 1px solid var(--line); }

/* ── Generic page furniture ────────────────────────────────────────────── */
.page { padding: 20px 16px calc(var(--safe-b) + 32px); max-width: 720px; margin: 0 auto; }
.page h2 { margin: 0 0 4px; font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.page .sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px; margin-bottom: 14px;
}
.empty { text-align: center; color: var(--faint); padding: 48px 16px; }

.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field > span { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.field input, .field select {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--r-md); padding: 12px 13px; min-height: 48px; outline: none; width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--her-mid); }
.field .hint { font-size: 12px; color: var(--faint); }

.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: var(--r-md); padding: 12px 8px; min-height: 48px; cursor: pointer;
  transition: all 180ms var(--ease);
}
.seg button[aria-pressed="true"] { color: var(--text); border-color: var(--her-mid); background: #241a33; }
.seg button[aria-pressed="true"][data-p="him"] { border-color: var(--him-mid); background: #16233f; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; }
.tile .label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.tile .value { font-family: var(--mono); font-size: 24px; font-weight: 600; margin-top: 6px; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chip { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.chip.her { background: var(--her-deep); color: var(--her-text); }
.chip.him { background: var(--him-deep); color: var(--him-text); }

.hrow {
  display: flex; align-items: center; gap: 12px; padding: 13px 4px;
  border-bottom: 1px solid var(--line);
}
.hrow:last-child { border-bottom: 0; }
.hrow .hmain { flex: 1; min-width: 0; }
.hrow .hwhen { font-size: 12px; color: var(--faint); }
.hrow .hdetail { font-size: 13px; color: var(--muted); margin-top: 3px; }
.hrow .hdel { color: var(--faint); background: none; border: 0; cursor: pointer; padding: 8px; }

/* Bottom action bar — results on top, game controls below, all labelled. */
.actions {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px calc(var(--safe-b) + 12px);
  background: var(--bg); border-top: 1px solid var(--line); z-index: 2;
}
.actions-row { display: flex; gap: 8px; }
.actions-row .btn { flex: 1; }
/* The controls row is secondary to the two result buttons. */
.actions-row:last-child .btn { min-height: 44px; font-size: 14px; }
.btn-her { background: linear-gradient(135deg, var(--her-mid), var(--her-deep)); border-color: var(--her-mid); }
.btn-him { background: linear-gradient(135deg, var(--him-mid), var(--him-deep)); border-color: var(--him-mid); }

/* Lobby / setup */
.lobby { padding: 26px 18px calc(var(--safe-b) + 26px); max-width: 480px; margin: 0 auto; }
.lobby h2 { margin: 0 0 6px; font-size: 24px; font-weight: 600; letter-spacing: -.02em; }
.lobby .sub { color: var(--muted); font-size: 14px; margin: 0 0 22px; }
.mode-card {
  display: block; width: 100%; text-align: left; margin-bottom: 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px;
  transition: border-color 180ms var(--ease), background 180ms var(--ease);
}
.mode-card[aria-pressed="true"] { border-color: var(--her-mid); background: #1A1426; }
.mode-card .mt { font-weight: 600; margin-bottom: 4px; }
.mode-card .md { font-size: 13px; color: var(--muted); line-height: 1.5; }
.mode-card .mw { font-size: 12px; color: var(--her); margin-top: 8px; letter-spacing: .06em; text-transform: uppercase; }

/* Finish overlay */
.finish {
  position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; text-align: center;
  padding: 30px; animation: flood 620ms var(--ease) both;
}
.finish[data-w="her"] { background: radial-gradient(90% 70% at 50% 45%, var(--her-mid), var(--her-deep) 70%, #0C0710); }
.finish[data-w="him"] { background: radial-gradient(90% 70% at 50% 45%, var(--him-mid), var(--him-deep) 70%, #060A16); }
/* A called-off game has no winner, so it gets neither colour. */
.finish[data-w="none"] { background: radial-gradient(90% 70% at 50% 45%, #262A36, #14161D 70%, var(--bg)); }
@keyframes flood { from { opacity: 0; transform: scale(1.06) } to { opacity: 1; transform: none } }
.finish .fw { font-size: 13px; letter-spacing: .26em; text-transform: uppercase; opacity: .8; }
.finish .fn { font-size: clamp(38px, 15vw, 68px); font-weight: 700; letter-spacing: -.03em; margin: 6px 0 10px; }
.finish .fd { color: rgba(255,255,255,.78); font-size: 14px; margin-bottom: 26px; }

/* ── Toasts + modal ────────────────────────────────────────────────────── */
.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 84px); z-index: 90;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: 0 10px 30px -10px #000; animation: rise 260ms var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: none } }

.modal-back {
  position: fixed; inset: 0; z-index: 95; background: rgba(0,0,0,.62);
  display: grid; place-items: center; padding: 24px;
}
.modal {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 22px; width: 100%; max-width: 360px;
  animation: rise 220ms var(--ease);
}
.modal h3 { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.modal p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.modal-row { display: flex; gap: 8px; }
.modal-row .btn { flex: 1; }
/* Stacked, because these labels are sentences rather than one-word verbs. */
.modal-col { display: flex; flex-direction: column; gap: 8px; }
.modal-col .btn { width: 100%; }
.modal-form { display: flex; flex-direction: column; }
.modal-form .field:last-child { margin-bottom: 20px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
