/*
 * Couchcade base styles, shared by the hub and the games. Games link it with
 * <link rel="stylesheet" href="../../lib/base.css"> and build on the tokens below, so the whole
 * site feels like one place. Everything is optional: a game can restyle as much as it likes.
 *
 * Classes: .btn (+ .btn-primary, .btn-ghost, .btn-big), .card, .chip, .dot, .muted, .stack, .row
 * On TVs (html.is-tv, set by lib/tv.js) the base font grows and the focus ring is always visible.
 */
:root {
  --bg: #0e0c1f;
  --bg-2: #15122c;
  --surface: #1d1a38;
  --surface-2: #282449;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f7f5ff;
  --muted: #a49fc8;
  --accent: #ffb627;
  --accent-ink: #1f1500;
  --pink: #ff5d8f;
  --good: #3fd68f;
  --bad: #ff5d5d;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  --focus: 0 0 0 3px var(--bg), 0 0 0 6px var(--accent);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
html.is-tv { font-size: clamp(18px, 1.15vw, 28px); }
html.is-tv.text-small { font-size: clamp(15px, 0.95vw, 23px); }
html.is-tv.text-large { font-size: clamp(22px, 1.45vw, 34px); }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.4;
}

button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}
.btn:hover { background: #332e5a; }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: #ffc552; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface); }
.btn-big { min-height: 58px; padding: 14px 26px; font-size: 1.1rem; }
.btn-icon { width: 46px; padding: 0; }

/* Surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  background: var(--c, var(--muted));
  flex: none;
}

input[type="text"] {
  width: 100%;
  min-height: 50px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-2);
  outline: none;
}
input[type="text"]:focus { border-color: var(--accent); }

/* Focus: keyboards and TV remotes always see where they are */
:focus-visible { outline: none; box-shadow: var(--focus); }
html.is-tv :focus { outline: none; box-shadow: var(--focus); }

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

/* lib/ui.js: the "I'm ready" button and hidden answers */
.ready-btn { width: 100%; flex-direction: column; gap: 2px; }
.ready-btn small { font-size: 0.8rem; font-weight: 600; opacity: 0.8; }
.ready-btn.on { background: color-mix(in srgb, var(--good) 22%, var(--surface)); border-color: var(--good); color: var(--text); }
.ready-line { color: var(--muted); }
.ready-line b { color: var(--text); }

.secret-field { display: flex; align-items: center; gap: 8px; width: 100%; }
.secret-field > input { flex: 1; min-width: 0; }
.secret-input, .secret-field > input { -webkit-text-security: disc; text-security: disc; }
.secret-field.revealed > input, .revealed .secret-input { -webkit-text-security: none; text-security: none; }
.secret-toggle { flex: none; min-height: 40px; padding: 6px 12px; font-size: 0.9rem; white-space: nowrap; }
.secret-text { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.secret-text .secret-value { display: none; }
.secret-text .secret-mask { letter-spacing: 0.3em; color: var(--muted); }
.secret-text .secret-mask::before { content: "•••• "; letter-spacing: 0.1em; }
.secret-text.revealed .secret-value { display: inline; }
.secret-text.revealed .secret-mask { display: none; }
.shake-hint { display: block; margin: 6px auto 0; font-size: 0.9rem; text-align: center; }

/* lib/shell.js: the shared game frame (top bar, sheets, setup, turn alerts, waiting lines) */
.cs-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(6px + var(--safe-top)) calc(8px + env(safe-area-inset-right, 0px)) 6px calc(8px + env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.cs-bar .cs-btn { flex: none; width: 40px; min-height: 40px; padding: 0; font-size: 1.1rem; }
.cs-bar .cs-back { font-size: 1.3rem; }
.cs-bar .cs-help { font-weight: 800; }
.cs-title { flex: 1 1 0; display: flex; align-items: center; gap: 8px; min-width: 0; }
.cs-title .cs-icon { flex: none; font-size: 1.25rem; }
.cs-title .cs-icon:empty { display: none; }
.cs-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1.05rem; font-weight: 800; letter-spacing: -0.01em; }
.cs-extra { flex: 0 1 auto; display: flex; align-items: center; gap: 6px; min-width: 0; }
.cs-extra:empty { display: none; }
/* Long chips shrink and end in … on narrow phones instead of running into the buttons */
.cs-extra { overflow: hidden; }
.cs-extra > * { min-width: 0; flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html.is-tv .cs-bar { gap: 0.6rem; padding: calc(0.6rem + var(--safe-top)) 1.6rem 0.6rem; }
html.is-tv .cs-bar .cs-btn { width: 2.6rem; min-height: 2.6rem; font-size: 1.2rem; }
html.is-tv .cs-name { font-size: 1.35rem; }
html.is-tv .cs-title .cs-icon { font-size: 1.6rem; }
@media (min-width: 720px) and (hover: hover) { .cs-bar { padding-left: 14px; padding-right: 14px; } .cs-bar .cs-btn { width: 44px; min-height: 44px; } }

/* Sheets: modal cards over the game (How to play, pause menu, leave) */
.cs-sheet {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: rgba(8, 6, 20, 0.72);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: cs-fade 0.18s ease both;
}
.cs-card {
  width: min(100%, 34rem);
  max-height: calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom));
  overflow: auto;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: cs-rise 0.22s ease both;
}
.cs-card h2 { font-size: 1.45rem; margin: 2px 0 12px; }
.cs-card > p { margin-bottom: 14px; }
.cs-card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.cs-card-icon { font-size: 2.4rem; line-height: 1; }
.cs-card-icon:empty { display: none; }
.cs-card-head h2 { margin: 0; }
.cs-kicker { font-size: 0.82rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.cs-kicker:empty { display: none; }
.cs-steps { margin: 6px 0 18px; padding: 0; list-style: none; counter-reset: cs-step; display: grid; gap: 10px; }
.cs-steps li { counter-increment: cs-step; position: relative; padding-left: 2.3em; line-height: 1.45; }
.cs-steps li::before {
  content: counter(cs-step);
  position: absolute; left: 0; top: -0.05em;
  width: 1.6em; height: 1.6em; display: grid; place-items: center;
  border-radius: 50%; background: var(--surface-2); color: var(--accent); font-weight: 800; font-size: 0.9em;
}
.cs-menu { display: grid; gap: 10px; }
.cs-menu .btn { width: 100%; justify-content: flex-start; padding-left: 22px; }
.cs-menu .cs-snd { color: var(--muted); font-weight: 600; }
.cs-menu .cs-end { color: var(--muted); }
.cs-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.cs-actions .btn { flex: 1 1 10rem; }
@media (max-width: 560px) {
  /* Phones: a bottom sheet within thumb reach */
  .cs-sheet { place-items: end center; padding-bottom: calc(10px + var(--safe-bottom)); }
  .cs-card { border-radius: var(--radius) var(--radius) calc(var(--radius) - 6px) calc(var(--radius) - 6px); }
}
html.is-tv .cs-card { width: min(100%, 40rem); padding: 1.6rem 1.8rem; }
html.is-tv .cs-card h2 { font-size: 1.8rem; }
@keyframes cs-fade { from { opacity: 0; } }
@keyframes cs-rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } }

/* "Your turn!" banner */
.cs-toast {
  position: fixed;
  left: 50%;
  top: calc(var(--cs-bar-h, 0px) + 12px + var(--safe-top));
  z-index: 900;
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 1.05rem;
  width: max-content;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -12px) scale(0.96);
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.cs-toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* Waiting line: "Ana is choosing…" */
.cs-waiting { display: inline-block; margin: 0; color: var(--muted); font-weight: 600; }
.cs-waiting .dot { width: 0.7em; height: 0.7em; margin-right: 6px; vertical-align: -0.05em; background: var(--c); }
.cs-dots { display: inline-flex; gap: 4px; margin-right: 10px; vertical-align: middle; }
.cs-dots i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.35; animation: cs-dot 1.2s ease-in-out infinite; }
.cs-dots i:nth-child(2) { animation-delay: 0.15s; }
.cs-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes cs-dot { 0%, 60%, 100% { opacity: 0.35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

/* Setup screen */
.cs-setup { width: min(100%, 60rem); margin: 0 auto; padding: 18px 16px calc(24px + var(--safe-bottom)); display: grid; gap: 18px; }
.cs-setup-head { display: flex; align-items: center; gap: 14px; }
.cs-setup-head h1 { font-size: 1.9rem; }
.cs-logo { font-size: 2.8rem; line-height: 1; }
.cs-setup-grid { display: grid; gap: 18px; align-items: start; }
.cs-setup.has-aside .cs-setup-grid { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 760px) { .cs-setup.has-aside .cs-setup-grid { grid-template-columns: minmax(0, 1.7fr) minmax(14rem, 1fr); } }
.cs-setup-main { display: grid; gap: 18px; }
.cs-setup-body { color: var(--muted); }
.cs-label { font-size: 0.82rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.cs-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.cs-opts.cs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); }
.cs-opt {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 8px 18px;
  border: 2px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--text); font-weight: 700; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}
.cs-opt:hover { background: var(--surface-2); }
.cs-opt:active { transform: scale(0.97); }
.cs-opt[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--surface)); }
.cs-opt-icon { font-size: 1.15em; }
.cs-start { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.cs-start .btn { min-width: 12rem; }
.cs-note { font-size: 0.92rem; }
.cs-aside { display: grid; gap: 8px; }
.cs-players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.cs-players li { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.cs-players .dot { background: var(--c); }
.cs-players li.away { opacity: 0.45; }
html.is-tv .cs-setup { padding-top: 1.6rem; }
html.is-tv .cs-setup-head h1 { font-size: 2.4rem; }
.cs-foot { font-size: 0.85rem; margin-top: -6px; }
.cs-grid .cs-opt { justify-content: flex-start; border-radius: var(--radius-sm); padding: 8px 14px; text-align: left; line-height: 1.15; }
.cs-bar .couch-audio-btn { width: auto; min-width: 40px; padding: 0 8px; white-space: nowrap; }
html.is-tv .cs-bar .couch-audio-btn { min-width: 2.6rem; }

/* Shell on a TV: every size in rem, so it follows the TV text size (html.text-small / text-large) */
html.is-tv .cs-sheet { padding: 1rem; }
html.is-tv .cs-menu { gap: 0.6rem; }
html.is-tv .cs-sheet .btn { min-height: 3rem; padding: 0.5rem 1.4rem; font-size: 1.1rem; }
html.is-tv .cs-steps { gap: 0.6rem; margin-bottom: 1.1rem; }
html.is-tv .cs-opt { min-height: 2.6rem; padding: 0.4rem 1.1rem; }
html.is-tv .cs-opts { gap: 0.5rem; }
html.is-tv .cs-setup .btn-big { min-height: 3.2rem; padding: 0.7rem 1.6rem; font-size: 1.1rem; }
html.is-tv .cs-dots { gap: 0.25rem; }
html.is-tv .cs-dots i { width: 0.35rem; height: 0.35rem; }
html.is-tv .cs-toast { padding: 0.6rem 1.3rem; }
