:root {
  --bg: #16112a;
  --bg-2: #1e1736;
  --surface: #261d44;
  --surface-2: #33285a;
  --line: #43376f;
  --ink: #f7f3ff;
  --muted: #b3a9d4;
  --accent: #ffd23f;
  --accent-ink: #2a1d00;
  --pink: #ff5fa2;
  --ok: #3ddc97;
  --bad: #ff6b6b;
  --radius: 18px;
  --font: 'Bricolage Grotesque', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 10% -10%, #3a2470 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #5b1f4f 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.1; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.hidden { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  border: 2px solid var(--line); background: var(--surface-2); color: var(--ink);
  border-radius: 999px; padding: 0.6em 1.1em; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.pink { background: var(--pink); color: #2b0016; border-color: var(--pink); }
.btn.ghost { background: transparent; }
.btn.big { font-size: 1.15rem; padding: 0.8em 1.5em; }
.btn.sm { padding: 0.35em 0.8em; font-size: 0.875rem; }
.btn.icon { width: 2.1em; height: 2.1em; padding: 0; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #002515; }
.btn.bad { background: transparent; border-color: var(--bad); color: var(--bad); }

.field {
  width: 100%; background: var(--bg-2); border: 2px solid var(--line); border-radius: 12px;
  padding: 0.7em 0.9em; outline: none; transition: border-color 0.15s;
}
.field:focus { border-color: var(--accent); }
textarea.field { resize: vertical; min-height: 3.2em; }
label.lbl { display: block; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 0.4em; }
.row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: 0.9rem; }

.panel {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 2px solid var(--line); border-radius: var(--radius); padding: 1.2rem;
  backdrop-filter: blur(6px);
}

/* ---------- home ---------- */
.home { max-width: 980px; margin: 0 auto; padding: 48px 16px 64px; }
.logo {
  font-size: clamp(2.6rem, 8vw, 5rem); font-weight: 800; line-height: 0.95; letter-spacing: -0.03em;
}
.logo .q { color: var(--accent); display: inline-block; transform: rotate(8deg); }
.tagline { font-size: 1.15rem; color: var(--muted); margin: 0.8rem 0 2.2rem; max-width: 46ch; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.home-grid .panel { padding: 1.6rem; }
.home-grid h2 { font-size: 1.5rem; margin-bottom: 0.4rem; }
.how { margin-top: 2.2rem; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.how div { padding: 1rem; border-radius: 14px; background: color-mix(in srgb, var(--bg-2) 70%, transparent); border: 1px dashed var(--line); }
.how b { display: block; font-size: 1.05rem; margin-bottom: 0.2rem; }
.code-input { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 800; font-size: 1.3rem; text-align: center; }

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; gap: 1rem; padding: 12px 20px; flex-wrap: wrap;
  border-bottom: 2px solid var(--line); background: color-mix(in srgb, var(--bg) 80%, transparent);
  position: sticky; top: 0; z-index: 10; backdrop-filter: blur(8px);
}
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--ink); }
.brand span { color: var(--accent); }
.roomcode { display: flex; align-items: center; gap: 0.5rem; color: var(--muted); }
.roomcode b { font-size: 1.5rem; letter-spacing: 0.18em; color: var(--accent); }
.bar .spacer { flex: 1; }

/* ---------- GM layout ---------- */
.gm { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.2rem; padding: 1.2rem 20px 3rem; max-width: 1500px; margin: 0 auto; }
.gm-search { position: sticky; top: 84px; align-self: start; max-height: calc(100dvh - 100px); display: flex; flex-direction: column; }
.round-head { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 1rem; }
.round-head h2 { font-size: 1.6rem; }
.phase { font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; padding: 0.3em 0.8em; border-radius: 999px; }
.phase.setup { background: var(--surface-2); color: var(--muted); }
.phase.live { background: var(--ok); color: #002515; animation: pulse 1.6s ease-in-out infinite; }
.phase.reveal { background: var(--pink); color: #2b0016; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--ok) 25%, transparent); } }

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 0.25em 0.75em; font-size: 0.85rem; color: var(--muted); cursor: pointer; }
.chip:hover { color: var(--ink); border-color: var(--muted); }

.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 0.9rem; margin: 1.2rem 0; }
.slot {
  border: 2px solid var(--line); border-radius: 16px; padding: 0.8rem; background: var(--bg-2);
  cursor: pointer; transition: border-color 0.15s, transform 0.15s; position: relative;
}
.slot:hover { border-color: var(--muted); }
.slot.active { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }
.slot-top { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.6rem; }
.pname { font-weight: 800; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bad); flex: none; }
.dot.on { background: var(--ok); }
.score { margin-left: auto; display: flex; align-items: center; gap: 0.3rem; }
.score b { min-width: 1.6em; text-align: center; font-size: 1.1rem; }
.score .btn { width: 1.7em; height: 1.7em; padding: 0; font-size: 0.9rem; }
.slot-empty { border: 2px dashed var(--line); border-radius: 12px; aspect-ratio: 3 / 4; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 1rem; font-size: 0.9rem; }
.slot.active .slot-empty { border-color: var(--accent); color: var(--ink); }
.slot-actions { display: flex; gap: 0.35rem; margin-top: 0.6rem; flex-wrap: wrap; align-items: center; }
.slot-more { margin-left: auto; display: flex; gap: 0.1rem; }
.slot-actions .kick { padding: 0.3em 0.6em; font-size: 0.78rem; opacity: 0.6; border-color: transparent; }
.slot-actions .kick:hover { opacity: 1; border-color: var(--bad); color: var(--bad); }
.badge { font-size: 0.7rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; padding: 0.2em 0.6em; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok); color: #002515; }

.controls { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }

.guesses { margin-top: 1.4rem; }
.guesses h3 { font-size: 1.1rem; margin-bottom: 0.6rem; }
.guess { display: flex; align-items: center; gap: 0.6rem; padding: 0.55rem 0.8rem; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line); }
.guess + .guess { margin-top: 0.4rem; }
.guess .who { font-weight: 800; }
.guess .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.guess.right { border-color: var(--ok); }
.guess.right .st { color: var(--ok); }
.guess.wrong .txt { text-decoration: line-through; color: var(--muted); }
.guess.wrong .st { color: var(--bad); }

details.settings { margin-top: 1.4rem; border-top: 1px solid var(--line); padding-top: 1rem; }
details.settings summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.opt { display: flex; gap: 0.7rem; align-items: flex-start; padding: 0.6rem 0; cursor: pointer; }
.opt input { margin-top: 0.3em; accent-color: var(--accent); width: 1.1em; height: 1.1em; flex: none; }
.opt b { display: block; }

/* ---------- search ---------- */
.gm-search h2 { font-size: 1.3rem; }
.assigning { margin: 0.4rem 0 0.9rem; color: var(--muted); }
.assigning b { color: var(--accent); }
.results { overflow-y: auto; margin: 0.9rem -0.4rem 0; padding: 0 0.4rem 0.4rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.7rem; align-content: start; min-height: 120px; }
.result { border: 2px solid var(--line); background: var(--bg-2); border-radius: 14px; padding: 0.5rem; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 0.35rem; transition: border-color 0.12s, transform 0.12s; }
.result:hover { border-color: var(--accent); transform: translateY(-2px); }
.result .thumb { aspect-ratio: 1; border-radius: 10px; }
.result .nm { font-weight: 800; font-size: 0.95rem; line-height: 1.15; }
.result .sub { font-size: 0.75rem; color: var(--muted); line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.src { align-self: flex-start; font-size: 0.65rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; padding: 0.1em 0.5em; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.src.Wikipedia { color: #cfd8ff; }
.src.Fandom { color: #ffb3d6; }
.src.AniList { color: #9fe3ff; }
.src.TV { color: #b8f5c8; }
.src.Custom { color: var(--accent); }
.empty-state { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 2rem 1rem; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; margin: 0 auto 0.6rem; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs { display: flex; gap: 0.3rem; margin-top: 0.9rem; border-bottom: 2px solid var(--line); }
.tab { background: none; border: none; padding: 0.5em 0.9em; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tab.on { color: var(--ink); border-color: var(--accent); }
.paste-zone { border: 2px dashed var(--line); border-radius: 14px; padding: 1rem; text-align: center; color: var(--muted); cursor: pointer; }
.paste-zone.has { border-style: solid; border-color: var(--accent); }
.paste-zone img { max-height: 160px; max-width: 100%; border-radius: 10px; display: block; margin: 0 auto 0.5rem; }

/* ---------- character cards ---------- */
.thumb { width: 100%; background: var(--surface-2); overflow: hidden; position: relative; display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top center; display: block; }
.thumb .initial { font-size: 3rem; font-weight: 800; color: var(--muted); }
.ccard { border-radius: 14px; overflow: hidden; background: var(--surface); border: 2px solid var(--line); position: relative; }
.ccard .thumb { aspect-ratio: 3 / 4; }
.ccard .meta { padding: 0.55rem 0.7rem 0.7rem; }
.ccard .nm { font-weight: 800; font-size: 1.1rem; line-height: 1.1; }
.ccard .sub { font-size: 0.78rem; color: var(--muted); margin-top: 0.15rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ccard .x { position: absolute; top: 6px; right: 6px; z-index: 2; background: rgba(10, 6, 20, 0.75); border-color: transparent; }
.ccard.mystery {
  aspect-ratio: 3 / 4; display: grid; place-items: center; border: 2px solid var(--accent);
  background: repeating-linear-gradient(-45deg, #2d2152 0 14px, #261d44 14px 28px);
}
.ccard.mystery span { font-size: 5rem; font-weight: 800; color: var(--accent); transform: rotate(-6deg); text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35); }
.ccard.none { aspect-ratio: 3 / 4; display: grid; place-items: center; color: var(--muted); border-style: dashed; padding: 1rem; text-align: center; font-size: 0.9rem; }
.ccard.flip { animation: flip 0.55s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes flip { from { transform: rotateY(90deg) scale(0.9); opacity: 0.3; } to { transform: none; opacity: 1; } }
.ccard.solved { border-color: var(--ok); }

/* ---------- player & tv ---------- */
.play { max-width: 760px; margin: 0 auto; padding: 1rem 16px 3rem; }
.prompt-card {
  background: var(--accent); color: var(--accent-ink); border-radius: 22px; padding: 1.4rem 1.5rem;
  box-shadow: 0 8px 0 #b8921a; margin: 0.5rem 0 1.6rem; transform: rotate(-1deg);
}
.prompt-card .lbl2 { font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.12em; opacity: 0.7; }
.prompt-card .text { font-size: clamp(1.4rem, 5vw, 2.2rem); font-weight: 800; line-height: 1.1; margin-top: 0.3rem; overflow-wrap: anywhere; }
.prompt-card.waiting { background: var(--surface); color: var(--muted); box-shadow: 0 8px 0 #120c24; transform: none; border: 2px solid var(--line); }
.prompt-card.waiting .text { color: var(--ink); font-size: 1.4rem; }
.table { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 1rem; }
.seat .seat-name { display: flex; align-items: center; gap: 0.4rem; font-weight: 800; margin-bottom: 0.45rem; }
.seat .seat-name .pts { margin-left: auto; color: var(--accent); }
.seat.me .seat-name { color: var(--accent); }
.guess-box { margin: 1.6rem 0 1rem; }
.status-line { text-align: center; padding: 1rem; border-radius: 14px; background: var(--surface); border: 2px solid var(--line); }
.status-line.win { background: var(--ok); color: #002515; border-color: var(--ok); font-weight: 800; font-size: 1.2rem; }

.tv { padding: 2rem 3vw; min-height: 100dvh; display: flex; flex-direction: column; gap: 2rem; }
.tv-top { display: flex; align-items: center; gap: 2rem; flex-wrap: wrap; }
.tv-join { margin-left: auto; text-align: right; color: var(--muted); font-size: 1.1rem; }
.tv-join b { display: block; font-size: 3rem; letter-spacing: 0.2em; color: var(--accent); line-height: 1; }
.tv .prompt-card { margin: 0; max-width: 1100px; }
.tv .prompt-card .text { font-size: clamp(2rem, 4.5vw, 4rem); }
.tv .table { grid-template-columns: repeat(auto-fit, minmax(170px, min(240px, 28vh))); justify-content: center; gap: 2rem; }
.tv .seat .seat-name { font-size: 1.5rem; }
.tv .ccard .nm { font-size: 1.5rem; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.5rem; z-index: 100; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 0.75em 1.1em; border-radius: 12px; font-weight: 600; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); animation: tin 0.2s ease-out; }
.toast.err { background: var(--bad); color: #2a0000; }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

.center-msg { max-width: 480px; margin: 15vh auto; padding: 0 16px; text-align: center; }
.center-msg h2 { font-size: 1.8rem; margin-bottom: 0.6rem; }

@media (max-width: 960px) {
  .gm { grid-template-columns: minmax(0, 1fr); padding: 1rem 16px 3rem; }
  .gm > .panel { min-width: 0; }
  .gm-search { position: static; max-height: none; }
  .results { max-height: 70vh; }
}
@media (max-width: 720px) {
  .home { padding-top: 32px; }
  .home-grid, .how { grid-template-columns: 1fr; }
  .bar { padding: 10px 16px; gap: 0.6rem; }
  .table { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
  .slots { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.6rem; }
  .slot { padding: 0.6rem; }
  .slot-top { flex-wrap: wrap; }
  .slot .score { margin-left: 0; width: 100%; justify-content: space-between; }
  .slot-actions .kick { padding: 0.3em 0.4em; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 0.3rem; scrollbar-width: none; }
  .chip { flex: none; }
  .tv-join { margin-left: 0; text-align: left; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* GM slots: compact card crop so several players fit on screen */
.slot .ccard .thumb, .slot .slot-empty { aspect-ratio: 4 / 3; }

.gm-tag { text-transform: none; letter-spacing: 0; font-weight: 600; }
