:root {
  --bg: #0e0d12;
  --bg2: #17151d;
  --card: #1d1b25;
  --line: #2e2b3a;
  --text: #f3efe6;
  --muted: #9a94a8;
  --gold: #f5b82e;
  --gold-2: #ffd56b;
  --red: #e8504a;
  --green: #3ccf8e;
  --cell: #f7f3ea;
  --cell-text: #15131a;
  --word: #ffe9a8;
  --active: #f5b82e;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background:
    radial-gradient(1200px 500px at 50% -200px, #2a1f3d 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 13px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: rgba(14, 13, 18, 0.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-family: "Bebas Neue", sans-serif; font-size: 28px; letter-spacing: 1px; color: var(--text); text-decoration: none; }
.brand span { color: var(--gold); }
.brand-mark { font-size: 22px; }
.topbar-right { display: flex; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip.rating { color: var(--gold-2); font-weight: 700; cursor: default; }

.screen { max-width: 1180px; margin: 0 auto; padding: 20px 16px 48px; }

/* Home */
.hero { text-align: center; padding: 18px 0 8px; }
.hero h1 { font-family: "Bebas Neue", sans-serif; font-size: clamp(44px, 9vw, 76px); line-height: 0.95; margin: 0 0 12px; letter-spacing: 1px; }
.hero h1 em { color: var(--gold); font-style: normal; }
.hero p { color: var(--muted); max-width: 560px; margin: 0 auto; line-height: 1.55; }
.hero b { color: var(--text); }

.card {
  max-width: 520px; margin: 24px auto 0; background: var(--card);
  border: 1px solid var(--line); border-radius: 20px; padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.field { display: block; margin-bottom: 18px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.field small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.field input, .join-row input {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 16px; outline: none;
}
.field input:focus, .join-row input:focus { border-color: var(--gold); }

.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.cat {
  border: 1px solid var(--line); background: var(--bg); border-radius: 12px;
  padding: 12px 6px; cursor: pointer; text-align: center; transition: 0.15s;
}
.cat .emoji { font-size: 22px; display: block; }
.cat .lbl { font-size: 13px; font-weight: 600; margin-top: 4px; display: block; }
.cat:hover:not(:disabled) { border-color: var(--muted); }
.cat.sel { border-color: var(--gold); background: rgba(245, 184, 46, 0.12); }
.cat:disabled { cursor: default; opacity: 0.55; }
.cat.sel:disabled { opacity: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--bg2); border-radius: 12px;
  padding: 10px 16px; cursor: pointer; text-decoration: none; font-weight: 600; font-size: 14px;
  transition: 0.15s;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--gold); color: #1a1405; border-color: var(--gold); }
.btn.primary:hover { background: var(--gold-2); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.big { width: 100%; padding: 14px; font-size: 16px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); width: 100%; margin-top: 6px; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 20px 0 14px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 0.3em; font-weight: 700; text-align: center; }

.how { max-width: 720px; margin: 28px auto 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.how div { display: flex; gap: 10px; align-items: flex-start; color: var(--muted); font-size: 14px; line-height: 1.4; }
.how b { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--bg2); border: 1px solid var(--line); display: grid; place-items: center; color: var(--gold); font-size: 13px; }

/* Lobby */
.lobby-card { text-align: left; }
.code-label { text-align: center; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; }
.room-code {
  text-align: center; font-family: "Bebas Neue", sans-serif; font-size: 72px; letter-spacing: 0.25em;
  color: var(--gold); line-height: 1; margin: 6px 0 14px; padding-left: 0.25em;
}
.share-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 22px; }
.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.players li {
  display: flex; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px;
}
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #1a1405; flex: none; }
.players .nm { flex: 1; font-weight: 600; }
.players .meta { color: var(--muted); font-size: 13px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: rgba(245, 184, 46, 0.15); color: var(--gold-2); font-weight: 700; }
.tag.off { background: var(--bg2); color: var(--muted); }
#waitMsg { margin: 10px 0 0; }

/* Game */
.race { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.racer {
  flex: 1 1 160px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px;
}
.racer.me { border-color: rgba(245, 184, 46, 0.5); }
.racer .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; gap: 6px; }
.racer .top b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.racer .top span { color: var(--muted); white-space: nowrap; }
.bar { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--gold); border-radius: 99px; transition: width 0.3s; }
.racer.me .bar i { background: var(--muted); }
.racer.solved .bar i { background: var(--green); }

.game-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.pill { font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }
.timer { font-family: "Bebas Neue", sans-serif; font-size: 36px; letter-spacing: 2px; line-height: 1; }
.timer.low { color: var(--red); }

.current-clue {
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; font-size: 15px; min-height: 44px;
  position: sticky; top: 62px; z-index: 5;
}
.current-clue b { color: var(--gold); margin-right: 6px; }
.note { background: rgba(232, 80, 74, 0.12); border: 1px solid rgba(232, 80, 74, 0.4); color: #ffb3ae; border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; font-size: 14px; }
.spectate { margin-top: 12px; text-align: center; color: var(--muted); }

.game-body { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
.grid-wrap { display: flex; justify-content: center; }
.grid {
  --w: 15;
  display: grid; grid-template-columns: repeat(var(--w), 1fr); gap: 2px;
  width: min(100%, calc(var(--w) * 44px)); background: #000; padding: 2px; border-radius: 6px;
}
.cell { position: relative; aspect-ratio: 1; background: var(--cell); }
.cell.block { background: transparent; }
.cell .num { position: absolute; top: 1px; left: 2px; font-size: clamp(7px, 1.3vw, 10px); font-weight: 700; color: #444; pointer-events: none; z-index: 1; }
.cell input {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; outline: 0; background: transparent;
  text-align: center; text-transform: uppercase; font-weight: 700; color: var(--cell-text);
  font-size: clamp(12px, 3.2vw, 22px); padding: 0; padding-top: 4%; caret-color: transparent; cursor: pointer;
  border-radius: 0;
}
.cell.word { background: var(--word); }
.cell.active { background: var(--active); }
.cell.wrong input { color: var(--red); }
.cell.revealed input { color: #2a7a55; }
.grid.locked .cell input { cursor: default; }

.clues { display: grid; gap: 16px; max-height: calc(100vh - 220px); overflow: auto; padding-right: 4px; }
.clues h3 { font-family: "Bebas Neue", sans-serif; font-size: 22px; letter-spacing: 1px; margin: 0 0 6px; color: var(--gold); }
.clues ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.clues li { padding: 7px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; line-height: 1.35; display: flex; gap: 8px; }
.clues li b { min-width: 20px; color: var(--muted); }
.clues li:hover { background: var(--bg2); }
.clues li.active { background: rgba(245, 184, 46, 0.15); }
.clues li.done { color: var(--muted); }

/* Overlays */
.overlay { position: fixed; inset: 0; background: rgba(5, 4, 8, 0.78); display: grid; place-items: center; z-index: 50; padding: 16px; backdrop-filter: blur(4px); }
.count { font-family: "Bebas Neue", sans-serif; font-size: 180px; color: var(--gold); animation: pop 1s ease-out infinite; }
@keyframes pop { 0% { transform: scale(1.4); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { opacity: 0.6; } }
.modal {
  width: min(460px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 24px;
  text-align: center; max-height: 90vh; overflow: auto;
}
.modal h2 { font-family: "Bebas Neue", sans-serif; font-size: 40px; letter-spacing: 1px; margin: 4px 0; }
.trophy { font-size: 56px; }
.res-list { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 6px; text-align: left; }
.res-list li { display: flex; align-items: center; gap: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.res-list .nm { flex: 1; font-weight: 600; }
.delta { font-weight: 700; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.modal-actions { display: flex; gap: 8px; justify-content: center; }
.modal-actions .btn { flex: 1; }
.lb { width: 100%; border-collapse: collapse; margin: 14px 0; font-size: 14px; }
.lb th, .lb td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.lb th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.lb td:nth-child(3) { color: var(--gold-2); font-weight: 700; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-weight: 600; z-index: 100; font-size: 14px; max-width: calc(100% - 32px);
}

@media (max-width: 900px) {
  .game-body { grid-template-columns: 1fr; }
  .clues { max-height: none; grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .screen { padding: 14px 10px 40px; }
  .cats { grid-template-columns: repeat(3, 1fr); }
  .how { grid-template-columns: 1fr; }
  .clues { grid-template-columns: 1fr; }
  .grid { gap: 1px; padding: 1px; }
  .room-code { font-size: 56px; }
  .chip#lbBtn { padding: 6px 10px; }
  .current-clue { top: 58px; font-size: 14px; }
  .timer { font-size: 30px; }
}
