:root {
  --bg: #0b1220;
  --bg2: #131c30;
  --panel: #16203560;
  --panel-solid: #162035;
  --line: #26324e;
  --text: #e7eefc;
  --muted: #93a4c8;
  --accent: #3ee08a;
  --accent-dim: #1f9d55;
  --gold: #ffd479;
  --easy: #14324a;
  --medium: #173a2e;
  --hard: #3a2a12;
  --jackpot: #3a1230;
  --danger: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: linear-gradient(180deg, var(--bg), var(--bg2)); color: var(--text); }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; line-height: 1.45; min-height: 100vh; }
h2, h3 { margin: 0 0 .5rem; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.error { color: var(--danger); min-height: 1.2em; margin: .5rem 0 0; }
.disclaimer { color: #6b7c9e; font-size: .74rem; margin-top: 1.2rem; }

.topbar { padding: 1rem clamp(1rem, 4vw, 3rem); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 1.5rem; letter-spacing: -.02em; }
.brand .logo { font-size: 1.3rem; }
.tagline { color: var(--muted); font-size: .9rem; margin-top: .2rem; }

main { max-width: 1160px; margin: 0 auto; padding: clamp(1rem, 3vw, 2rem); }

/* ---------- Landing ---------- */
.landing { display: grid; grid-template-columns: minmax(0,1.1fr) minmax(0,.9fr); gap: 1.5rem; }
@media (max-width: 820px) { .landing { grid-template-columns: 1fr; } }
.card-panel, .panel, .explain { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; }
.tabs { display: flex; gap: .3rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab { background: transparent; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: .5rem 1rem; cursor: pointer; font-size: .9rem; min-height: 40px; }
.tab.active { background: var(--accent); color: #04231a; border-color: var(--accent); font-weight: 700; }
.fields, .tabpane { display: flex; flex-direction: column; gap: .8rem; }
label { display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; font-weight: 600; }
input, select { background: #0e1626; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; font-size: 1rem; min-height: 44px; }
input:focus, select:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.checkline { flex-direction: row; align-items: flex-start; gap: .6rem; font-weight: 500; }
.checkline input { min-height: auto; width: 20px; height: 20px; margin-top: .15rem; }
.tabpane { margin-top: 1rem; }
.explain ol { padding-left: 1.1rem; }
.explain li { margin-bottom: .6rem; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; background: #1c2740; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: .7rem 1rem; font-size: .95rem; cursor: pointer; min-height: 44px; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04231a; border-color: var(--accent); font-weight: 700; }
.btn.big { font-size: 1.05rem; padding: .85rem 1.2rem; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Game ---------- */
.statusbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; flex-wrap: wrap; }
.room-name { font-weight: 800; font-size: 1.15rem; }
.room-code { color: var(--muted); margin-left: .5rem; font-family: ui-monospace, monospace; }
.chip { background: #0e1626; border: 1px solid var(--line); border-radius: 999px; padding: .35rem .8rem; font-size: .82rem; }
.chip.live { border-color: var(--accent); color: var(--accent); }
.chip.finished { border-color: var(--gold); color: var(--gold); }
.you-score { font-weight: 800; margin-left: .8rem; color: var(--accent); }

.nearmiss { margin: .8rem 0; padding: .8rem 1rem; border-radius: var(--radius); background: linear-gradient(90deg, #3a2f0e, #221a06); border: 1px solid var(--gold); color: var(--gold); font-weight: 700; }

.layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1.2rem; margin-top: 1rem; }
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }

.controls { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.board-title { margin-bottom: .5rem; }

.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.cell { position: relative; aspect-ratio: 1; min-width: 0; min-height: 60px; border-radius: 10px; border: 1px solid var(--line); background: #131d31; color: #c9d6ee; font-size: clamp(.6rem, 1.7vw, .78rem); line-height: 1.15; padding: .3rem; display: flex; align-items: center; justify-content: center; text-align: center; cursor: default; overflow: hidden; word-break: break-word; }
.cell.tier-easy { background: var(--easy); }
.cell.tier-medium { background: var(--medium); }
.cell.tier-hard { background: var(--hard); }
.cell.tier-jackpot { background: var(--jackpot); }
.cell.free { background: #243044; color: var(--muted); font-weight: 700; }
.cell.marked { background: var(--accent-dim); border-color: var(--accent); color: #eafff2; font-weight: 700; }
.cell .glyph { position: absolute; top: 3px; right: 5px; font-size: .8rem; opacity: 0; }
.cell.marked .glyph { opacity: 1; }
.cell .pts { position: absolute; bottom: 3px; left: 5px; font-size: .62rem; font-weight: 700; color: var(--gold); opacity: .85; }
.cell.marked .pts { color: #eafff2; opacity: 1; }
.cell.free .pts { display: none; }
.cell.nearmiss { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset; }
.cell.swappable { cursor: pointer; }
.cell.swappable:hover { border-color: var(--accent); }
.cell.just-marked { animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(.8); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
.cell.nearmiss { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 2px var(--gold) inset; } 50% { box-shadow: 0 0 0 4px var(--gold) inset, 0 0 14px #ffd47955; } }

.share-row { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }

.side-col { display: flex; flex-direction: column; gap: 1rem; }
.leaderboard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.leaderboard li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .5rem .6rem; border-radius: 8px; background: #0e1626; cursor: pointer; min-height: 40px; }
.leaderboard li:hover { background: #16203a; }
.leaderboard li.me { border: 1px solid var(--accent); }
.leaderboard li.viewing { outline: 2px solid var(--gold); }
.lb-name { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.lb-name .rank { color: var(--muted); width: 1.4em; }
.lb-name .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-pts { font-weight: 800; color: var(--accent); white-space: nowrap; }

.feed { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: .25rem; font-size: .86rem; }
.feed li { padding: .35rem .5rem; border-radius: 6px; background: #0e1626; }
.feed li.big { background: #16283a; color: var(--accent); font-weight: 700; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti i { position: absolute; top: -10px; width: 9px; height: 14px; opacity: .9; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: 1; } }

dialog { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); max-width: 560px; width: 92%; }
dialog::backdrop { background: #000a; }
.reveal-body { white-space: pre-wrap; word-break: break-all; background: #0e1626; border-radius: 8px; padding: .8rem; font-size: .78rem; max-height: 50vh; overflow: auto; }

@media (prefers-reduced-motion: reduce) {
  .cell.just-marked, .cell.nearmiss, .confetti i { animation: none !important; }
}
