/* Self-hosted fonts (SIL Open Font License, see /fonts/LICENSE-*.txt). Nothing is loaded from third parties. */
@font-face { font-family: 'Bungee'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/bungee-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/inter-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/inter-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('/fonts/inter-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/inter-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 800; font-display: swap; src: url('/fonts/inter-latin-800-normal.woff2') format('woff2'); }

:root {
  --bg: #0d0f17;
  --bg2: #141724;
  --card: #181c2b;
  --card2: #1f2436;
  --line: #2a3048;
  --text: #eef1fb;
  --muted: #8d94b3;
  --accent: #ffd23d;
  --accent2: #ff3d5e;
  --good: #2ee07f;
  --radius: 14px;
  --display: 'Bungee', 'Impact', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, #2a1630 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 10%, #12284a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 700; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }

.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }
.screen.center.active { align-items: center; justify-content: center; padding: 32px 16px; }

/* ---------- home ---------- */
.home { width: min(460px, 100%); text-align: center; }
.logo {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(48px, 12vw, 84px);
  line-height: .9;
  margin-bottom: 18px;
  display: flex; flex-direction: column; align-items: center;
}
.logo span:first-child {
  background: linear-gradient(90deg, #ff3d5e, #ff8a24, #ffd23d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo span:last-child {
  background: linear-gradient(90deg, #25e3f2, #3d8bff, #a95cff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--muted); margin: 0 0 24px; }
.tagline em { color: var(--accent); font-style: normal; font-weight: 700; }
.how { list-style: none; padding: 0; margin: 24px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; text-align: left; }
.how li { background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font-size: 13px; color: var(--muted); counter-increment: step; }
.how li b { display: block; color: var(--text); font-size: 14px; margin-bottom: 2px; }
.how li b::before { content: counter(step) ". "; color: var(--accent); }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ---------- generic ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card.tight { padding: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field span { font-size: 13px; color: var(--muted); font-weight: 600; }
input, textarea {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; outline: none; width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); }
.code-input { flex: 1; width: auto; text-transform: uppercase; letter-spacing: .3em; font-weight: 800; text-align: center; }

.btn {
  border: 1px solid var(--line); background: var(--card2); border-radius: 10px;
  padding: 10px 16px; font-weight: 700; cursor: pointer; transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover { border-color: #3d4566; background: #262c42; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); }
.btn.primary:hover { background: #ffdc63; }
.btn.primary.on { background: var(--good); border-color: var(--good); }
.btn.ghost { background: transparent; }
.btn.big { padding: 14px 18px; font-size: 16px; width: 100%; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.tiny { padding: 4px 10px; font-size: 12px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 6px; border-radius: 999px; background: var(--card2); font-weight: 700; font-size: 13px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; box-shadow: 0 0 10px currentColor; }

.toast {
  position: fixed; left: 50%; top: 16px; transform: translateX(-50%) translateY(-200%); visibility: hidden;
  background: #2b1520; border: 1px solid var(--accent2); color: #ffd7de; padding: 10px 16px; border-radius: 10px;
  z-index: 50; transition: transform .25s; max-width: calc(100% - 32px);
}
.toast.show { transform: translateX(-50%) translateY(0); visibility: visible; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: rgba(13, 15, 23, .7); backdrop-filter: blur(6px); position: sticky; top: 0; z-index: 5; }
.brand.small { font-family: var(--display); font-size: 18px; background: linear-gradient(90deg, #ff3d5e, #ffd23d, #25e3f2); -webkit-background-clip: text; background-clip: text; color: transparent; }
.room-code { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.room-code b { color: var(--text); font-family: var(--display); font-size: 20px; letter-spacing: .12em; font-weight: 400; }
.phase-title { font-weight: 800; }
.timer { font-family: var(--display); font-size: 26px; min-width: 64px; text-align: right; color: var(--accent); }
.timer.urgent { color: var(--accent2); animation: pulse .6s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }

/* ---------- lobby ---------- */
.lobby-grid, .prompt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 20px; max-width: 1100px; width: 100%; margin: 0 auto; }
.prompt-grid { grid-template-columns: 1.4fr 1fr; }
.players { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.players li { display: flex; align-items: center; gap: 10px; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.players.compact li { padding: 7px 10px; font-size: 14px; }
.players .name { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .tag { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 2px 8px; border-radius: 6px; background: var(--card2); color: var(--muted); }
.players .tag.ok { background: rgba(46, 224, 127, .15); color: var(--good); }
.players .tag.host { background: rgba(255, 210, 61, .15); color: var(--accent); }
.players li.me { border-color: #4a5480; }
.setting { margin-bottom: 14px; }
.setting > span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 1px solid var(--line); background: var(--bg2); padding: 8px 12px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg button:disabled { cursor: default; }
body:not(.is-host) .host-only { display: none !important; }
body.is-host .guest-only { display: none !important; }

/* ---------- prompt ---------- */
.prompt-card { display: flex; flex-direction: column; gap: 12px; }
.you-are { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
textarea { min-height: 190px; resize: vertical; font-size: 17px; line-height: 1.5; }
textarea:disabled { opacity: .7; }
.locked { background: rgba(46, 224, 127, .1); border: 1px dashed var(--good); color: var(--good); padding: 10px 12px; border-radius: 10px; font-weight: 700; }
.note { background: rgba(61, 139, 255, .12); border: 1px solid #335; padding: 10px 12px; border-radius: 10px; }
.ideas { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.idea { border: 1px dashed var(--line); background: transparent; border-radius: 999px; padding: 5px 11px; cursor: pointer; color: var(--muted); }
.idea:hover { color: var(--text); border-color: var(--muted); }
.rules { margin: 0 0 18px; padding-left: 18px; color: var(--muted); font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.rules b { color: var(--text); }

/* ---------- arena ---------- */
.arena-grid { display: grid; grid-template-columns: 1fr 300px; gap: 14px; padding: 14px; flex: 1; min-height: 0; }
.stage { position: relative; display: flex; align-items: flex-start; justify-content: center; min-width: 0; }
#canvas { width: 100%; aspect-ratio: 16 / 10; max-height: calc(100vh - 100px); object-fit: contain; border-radius: 14px; background: #10131d; box-shadow: 0 20px 60px rgba(0, 0, 0, .45), inset 0 0 0 1px var(--line); }
.overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; text-align: center; padding: 20px; }
.overlay-big { font-family: var(--display); font-size: clamp(40px, 9vw, 120px); line-height: 1; text-shadow: 0 6px 30px rgba(0, 0, 0, .6); }
.overlay-small { margin-top: 12px; font-weight: 700; font-size: 18px; background: rgba(13, 15, 23, .75); padding: 8px 16px; border-radius: 10px; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; max-height: calc(100vh - 90px); overflow: auto; }
.scores { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.scores li { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; font-size: 14px; }
.scores .label { display: flex; align-items: center; gap: 8px; font-weight: 700; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.scores .pct { font-variant-numeric: tabular-nums; font-weight: 800; }
.scores .bar { grid-column: 1 / -1; height: 6px; border-radius: 4px; background: var(--bg2); overflow: hidden; }
.scores .bar i { display: block; height: 100%; border-radius: 4px; transition: width .3s; }
.scores.big li { font-size: 16px; }
.scores.big .bar { height: 10px; }
.plans { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.plans li { background: var(--bg2); border: 1px solid var(--line); border-left: 4px solid var(--c, #888); border-radius: 10px; padding: 10px; font-size: 13px; }
.plans .who { font-weight: 800; display: flex; justify-content: space-between; gap: 6px; }
.plans .src { font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.plans .src.ai { color: var(--accent); }
.plans .quote { color: var(--muted); font-style: italic; margin: 4px 0 6px; word-break: break-word; }
.plans .tank { height: 4px; background: var(--card2); border-radius: 3px; margin-top: 8px; overflow: hidden; }
.plans .tank i { display: block; height: 100%; background: var(--c); transition: width .2s; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips span { background: var(--card2); border-radius: 6px; padding: 2px 7px; font-size: 11.5px; }
.chips span b { color: var(--muted); font-weight: 600; margin-right: 3px; }

/* countdown plan reveal */
.reveal { font-family: var(--body); line-height: 1.4; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; width: min(900px, 100%); margin-top: 16px; pointer-events: none; }
.reveal .plan { background: rgba(20, 23, 36, .92); border: 1px solid var(--line); border-top: 4px solid var(--c); border-radius: 12px; padding: 12px; text-align: left; font-size: 13px; animation: pop .35s both; }
.reveal .plan .who { font-weight: 800; font-size: 15px; margin-bottom: 4px; }
.reveal .plan .sum { color: #cdd3ea; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.96); } }

/* ---------- results ---------- */
.results-wrap { padding: 20px; max-width: 1150px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.winner { text-align: center; font-family: var(--display); font-size: clamp(28px, 6vw, 56px); line-height: 1.1; padding: 8px 0; }
.winner small { display: block; font-family: var(--body); font-size: 16px; color: var(--muted); font-weight: 600; margin-top: 6px; }
.results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.final-canvas { width: 100%; aspect-ratio: 16 / 10; border-radius: 10px; background: #10131d; margin-bottom: 14px; }
.final-players { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.final-players li { background: var(--bg2); border: 1px solid var(--line); border-left: 4px solid var(--c); border-radius: 10px; padding: 12px; }
.final-players .who { font-weight: 800; display: flex; justify-content: space-between; }
.final-players .quote { font-style: italic; color: #cdd3ea; margin: 6px 0; word-break: break-word; }
.final-players .stats { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; }
.final-players .stats b { color: var(--text); }
.rematch-bar { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }
.rematch-bar .btn.big { width: auto; min-width: 260px; }

@media (max-width: 900px) {
  .lobby-grid, .prompt-grid, .results-grid { grid-template-columns: 1fr; padding: 16px; }
  .arena-grid { grid-template-columns: 1fr; padding: 10px; }
  .side { max-height: none; }
  .how { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
  .phase-title { display: none; }
}

/* ---------- login & model picker ---------- */
.form-error { margin: 0; color: #ffb3c0; background: rgba(255, 61, 94, .12); border: 1px solid rgba(255, 61, 94, .5); border-radius: 10px; padding: 10px 12px; text-align: left; }
.logout { margin-top: 14px; }
.model-select {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-weight: 600; cursor: pointer;
}
.model-select:focus { outline: none; border-color: var(--accent); }
.model-select:disabled { opacity: .65; cursor: default; }
.model-pick { display: flex; align-items: center; gap: 8px; color: var(--muted); font-weight: 600; font-size: 14px; }
.model-pick .model-select { width: auto; }
#model-note { margin: 6px 0 0; }
.model-select option { background: var(--card); color: var(--text); }
.model-select option:disabled { color: var(--muted); }
