:root {
  color-scheme: dark;
  --bg: #100d22;
  --panel: #1d1937;
  --panel2: #272145;
  --line: #3c3563;
  --text: #f7f4ff;
  --muted: #b8b1d4;
  --purple: #9c78ff;
  --pink: #ff6db3;
  --cyan: #4ddfd4;
  --green: #56df88;
  --yellow: #ffc85c;
  --red: #ff6b73;
  --shadow: 0 22px 55px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at 10% 0%, rgba(156, 120, 255, .22), transparent 32rem),
    radial-gradient(circle at 90% 15%, rgba(255, 109, 179, .13), transparent 30rem),
    var(--bg);
}
button, input, textarea { font: inherit; }
button { touch-action: manipulation; }

.shell { width: min(1120px, 100%); margin: 0 auto; padding: 22px clamp(16px, 4vw, 44px) 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.account-chip { padding: 8px 11px; border-radius: 999px; color: var(--cyan); background: rgba(77,223,212,.08); border: 1px solid rgba(77,223,212,.28); font-size: .82rem; font-weight: 850; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 900; letter-spacing: -.02em; }
.logo { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 15px; background: linear-gradient(145deg, var(--purple), var(--pink)); box-shadow: 0 10px 30px rgba(156,120,255,.3); }
.status { color: var(--muted); font-size: .86rem; display: flex; align-items: center; gap: 8px; }
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 14px var(--green); }
.status.off { color: #ffb0b5; }
.status.off::before { background: var(--red); box-shadow: 0 0 14px var(--red); }

.hero { min-height: calc(100vh - 150px); display: grid; grid-template-columns: 1.15fr .85fr; align-items: center; gap: clamp(28px, 6vw, 84px); }
.auth-layout { min-height: calc(100vh - 150px); display: grid; grid-template-columns: 1.1fr .9fr; align-items: center; gap: clamp(28px, 6vw, 78px); }
.auth-copy h1 { max-width: 720px; }
.auth-panel { max-width: 470px; width: 100%; justify-self: end; }
.eyebrow { color: var(--cyan); font-weight: 800; text-transform: uppercase; letter-spacing: .12em; font-size: .78rem; }
h1 { margin: 12px 0 18px; font-size: clamp(2.7rem, 8vw, 5.8rem); line-height: .94; letter-spacing: -.065em; }
.gradient { background: linear-gradient(100deg, #fff 5%, #bda8ff 48%, #ff91c7); -webkit-background-clip: text; color: transparent; }
.lead { max-width: 620px; color: var(--muted); font-size: clamp(1rem, 2vw, 1.25rem); line-height: 1.65; }
.mini-list { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 25px; }
.chip { padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; color: #d9d3ec; font-size: .82rem; background: rgba(255,255,255,.025); }
.chip-button { font: inherit; cursor: pointer; }

.panel { background: linear-gradient(160deg, rgba(39,33,69,.96), rgba(25,21,49,.96)); border: 1px solid var(--line); border-radius: 26px; padding: clamp(20px, 4vw, 30px); box-shadow: var(--shadow); }
.panel h2, .panel h3 { margin-top: 0; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: rgba(0,0,0,.2); padding: 5px; border-radius: 14px; margin-bottom: 20px; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 10px; border-radius: 10px; cursor: pointer; }
.tab.active { background: var(--panel2); color: var(--text); font-weight: 800; }
.stack { display: grid; gap: 13px; }
label { color: var(--muted); font-size: .86rem; font-weight: 700; }
input, textarea {
  width: 100%; margin-top: 7px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 13px;
  color: var(--text); background: #131027; outline: none; transition: .2s border, .2s box-shadow;
}
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(156,120,255,.14); }
.code-input { text-transform: uppercase; letter-spacing: .18em; font-size: 1.15rem; font-weight: 900; }
.btn { border: 0; border-radius: 13px; padding: 12px 17px; font-weight: 850; color: #171125; background: var(--text); cursor: pointer; transition: transform .15s, opacity .15s; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(135deg, var(--purple), #c497ff); }
.btn.pink { background: linear-gradient(135deg, var(--pink), #ff9acb); }
.btn.green { background: var(--green); }
.btn.yellow { background: var(--yellow); }
.btn.red { background: var(--red); }
.btn.ghost { color: var(--text); background: transparent; border: 1px solid var(--line); }
.btn.small { padding: 8px 11px; border-radius: 10px; font-size: .82rem; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.member-card { display: flex; align-items: center; gap: 12px; padding: 13px; border: 1px solid var(--line); border-radius: 15px; background: #15122c; }
.member-card small, .member-card strong { display: block; }
.member-card small { color: var(--muted); margin-bottom: 3px; }
.member-avatar { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; color: #171125; background: linear-gradient(135deg, var(--cyan), var(--green)); font-weight: 950; }
.hint { color: var(--muted); font-size: .84rem; line-height: 1.55; }
.error { color: #ff9ea4; }

.room-head { display: grid; grid-template-columns: 1fr auto; gap: 18px; align-items: center; margin-bottom: 24px; }
.room-code { display: inline-flex; align-items: center; gap: 10px; padding: 9px 14px; border-radius: 13px; border: 1px solid var(--line); background: var(--panel); }
.room-code b { letter-spacing: .16em; color: var(--cyan); }
.players { display: flex; flex-wrap: wrap; gap: 8px; }
.room-tools { display: grid; justify-items: end; gap: 10px; }
.player { padding: 8px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: .86rem; }
.player.me { border-color: var(--purple); }
.player.host::after { content: " ★"; color: var(--yellow); }

.section-title { margin: 26px 0 14px; display: flex; justify-content: space-between; align-items: end; gap: 16px; }
.section-title h2 { margin: 0; font-size: clamp(1.5rem, 4vw, 2.25rem); }
.invite-panel { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 18px; margin: 0 0 18px; padding: 18px; border-radius: 18px; border: 1px solid rgba(86,223,136,.35); background: rgba(86,223,136,.08); }
.invite-panel p { margin: 6px 0 10px; color: var(--muted); font-size: .88rem; }
.invite-panel code { display: inline-block; max-width: 100%; color: var(--cyan); overflow-wrap: anywhere; }
.game-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.game-card { position: relative; min-height: 180px; text-align: left; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 20px; cursor: pointer; }
.game-card:hover { border-color: #655b96; }
.game-card.selected { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(156,120,255,.14); background: linear-gradient(150deg, #302657, #1d1937); }
.game-card .icon { font-size: 2rem; }
.game-card h3 { margin: 12px 0 7px; font-size: 1.05rem; }
.game-card p { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.5; }
.game-card small { position: absolute; top: 17px; right: 17px; color: var(--cyan); font-weight: 800; }
.start-dock { position: sticky; bottom: 14px; margin-top: 22px; padding: 13px; border: 1px solid var(--line); border-radius: 18px; background: rgba(23, 19, 46, .9); backdrop-filter: blur(14px); display: flex; justify-content: space-between; align-items: center; gap: 15px; box-shadow: var(--shadow); }
.settings-panel { margin-top: 20px; padding: 19px; border: 1px solid var(--line); border-radius: 19px; background: linear-gradient(145deg, rgba(39,33,69,.9), rgba(24,20,47,.9)); display: grid; grid-template-columns: minmax(220px,.8fr) minmax(360px,1.2fr); align-items: end; gap: 24px; }
.settings-panel h3 { margin: 5px 0; font-size: 1.3rem; }
.settings-panel p { margin: 0; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 10px; }
.settings-grid input { margin-top: 6px; }
.setting-readonly { min-height: 70px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 13px; background: #15122c; display: grid; align-content: center; }
.setting-readonly small { color: var(--muted); }
.setting-readonly strong { margin-top: 5px; }
.settings-summary { display: flex; justify-content: end; flex-wrap: wrap; gap: 10px; }
.settings-summary span, .goal-chip { padding: 7px 10px; border-radius: 999px; border: 1px solid rgba(77,223,212,.28); color: var(--cyan); background: rgba(77,223,212,.07); font-size: .8rem; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 16px; align-items: start; }
.game-main, .side { background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: clamp(18px, 4vw, 28px); }
.side { position: sticky; top: 16px; }
.game-title { display: flex; align-items: center; gap: 13px; margin-bottom: 20px; }
.game-title span { font-size: 2rem; }
.game-title h1 { margin: 0; font-size: clamp(1.7rem, 5vw, 2.6rem); letter-spacing: -.04em; }
.goal-chip { display: inline-block; margin-top: 7px; }
.early-confirm { margin-top: 20px; padding: 14px; border-radius: 16px; border: 1px solid rgba(255,200,92,.35); background: rgba(255,200,92,.07); display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.early-confirm p { margin: 4px 0 0; color: var(--muted); font-size: .82rem; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 10px; margin: 15px 0; }
.stat { background: #15122c; border: 1px solid var(--line); border-radius: 15px; padding: 14px; }
.stat small { display: block; color: var(--muted); margin-bottom: 6px; }
.stat strong { font-size: 1.2rem; }
.callout { padding: 16px; border-radius: 16px; background: rgba(77,223,212,.08); border: 1px solid rgba(77,223,212,.32); margin: 15px 0; }
.auction-item { display: grid; place-items: center; min-height: 190px; border: 1px dashed #5b507f; border-radius: 20px; background: radial-gradient(circle, rgba(156,120,255,.17), transparent 65%); text-align: center; }
.auction-item .emoji { font-size: 3rem; }
.auction-item h2 { margin: 8px 0; font-size: clamp(1.7rem, 5vw, 2.7rem); }
.bid-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 15px; }
.bid-row input { margin: 0; }
.list { display: grid; gap: 9px; margin: 12px 0; }
.row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 11px 12px; background: #15122c; border: 1px solid var(--line); border-radius: 13px; }
.row.correct { border-color: rgba(86,223,136,.55); }
.row.wrong { border-color: rgba(255,107,115,.42); }
.answer { display: inline-flex; gap: 6px; align-items: center; font-weight: 850; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.yes { background: var(--green); }.no { background: var(--red); }.maybe { background: var(--yellow); }
.team { padding: 13px; border-radius: 15px; border: 1px solid var(--line); background: #15122c; }
.team.active { border-color: var(--purple); }
.team h3 { margin: 0 0 8px; }
.team-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; margin: 14px 0; }
.chain { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin: 16px 0; }
.word { padding: 9px 12px; border-radius: 11px; background: var(--panel2); border: 1px solid var(--line); font-weight: 800; }
.arrow { color: var(--muted); }
.letter { display: grid; place-items: center; width: 112px; height: 112px; margin: 5px auto 20px; border-radius: 30px; font-size: 4.7rem; font-weight: 950; background: linear-gradient(145deg, var(--purple), var(--pink)); box-shadow: 0 18px 50px rgba(156,120,255,.25); }
.category-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.pattern { font: 900 clamp(1.45rem, 6vw, 2.4rem)/1 ui-monospace, monospace; letter-spacing: .17em; color: var(--cyan); }
.big-timer { display: grid; place-items: center; width: min(270px, 70vw); aspect-ratio: 1; margin: 20px auto; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #332a63, #17132f 65%); border: 8px solid var(--purple); box-shadow: 0 0 0 12px rgba(156,120,255,.12), var(--shadow); text-align: center; }
.big-timer strong { display: block; font-size: 3.5rem; }
.stop-button { width: 100%; min-height: 90px; font-size: 1.35rem; }
.word-board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0; }
.word-slot { min-height: 64px; display: grid; place-items: center; padding: 9px; border-radius: 13px; border: 1px solid var(--line); background: #15122c; font-weight: 900; text-align: center; }
.word-slot.open { border-color: var(--cyan); color: var(--cyan); }
.question-box { min-height: 170px; display: grid; place-items: center; padding: 24px; margin: 15px 0; border-radius: 21px; text-align: center; background: linear-gradient(145deg, #302657, #17132f); border: 1px solid #594d86; }
.question-box h2 { margin: 0; font-size: clamp(1.5rem, 5vw, 2.5rem); }
.lives { color: var(--red); letter-spacing: .12em; }
.math-problem { display: grid; place-items: center; min-height: 190px; margin: 14px 0; border-radius: 22px; border: 1px solid var(--line); background: radial-gradient(circle, rgba(77,223,212,.13), transparent 70%); font: 950 clamp(2.6rem, 10vw, 5.5rem)/1 ui-monospace, monospace; }
.age-photo { width: 100%; max-height: 480px; object-fit: contain; border-radius: 20px; background: #0b0918; border: 1px solid var(--line); }
.memory-grid { display: grid; grid-template-columns: repeat(5, minmax(42px, 1fr)); gap: 7px; width: min(520px, 100%); margin: 18px auto; }
.memory-cell { aspect-ratio: 1; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: #15122c; color: var(--text); font-size: clamp(1.2rem, 5vw, 2rem); font-weight: 900; }
button.memory-cell { cursor: pointer; }
.card-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin: 15px 0; }
.match-card { min-height: 92px; padding: 9px; border-radius: 15px; border: 1px solid var(--line); color: var(--text); background: linear-gradient(145deg, #2d2554, #1a1633); font-weight: 900; cursor: pointer; overflow-wrap: anywhere; }
.match-card small { display: block; margin-bottom: 5px; color: var(--cyan); font-size: .64rem; line-height: 1.1; }
.match-card span { display: block; font-size: .82rem; line-height: 1.15; }
.match-card.closed { color: transparent; background: linear-gradient(135deg, var(--purple), #513e91); }
.match-card.closed::after { content: "?"; color: white; font-size: 1.8rem; }
.match-card.matched { border-color: var(--green); background: rgba(86,223,136,.12); }
.color-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; margin: 18px 0; }
.color-room { min-height: 92px; padding: 10px; border: 2px solid transparent; border-radius: 16px; color: #111; font-weight: 950; cursor: pointer; }
.color-room.selected { border-color: white; box-shadow: 0 0 0 3px var(--purple); }
.score-table { width: 100%; border-collapse: collapse; }
.score-table th, .score-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.leader-hero { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 18px; }
.leader-hero div { padding: 17px; border-radius: 17px; border: 1px solid var(--line); background: var(--panel); }
.leader-hero small, .leader-hero strong { display: block; }
.leader-hero small { color: var(--muted); margin-bottom: 6px; }
.leader-hero strong { color: var(--cyan); font-size: 1.7rem; }
.leaderboard-wrap { overflow-x: auto; }
.leader-table { width: 100%; min-width: 650px; border-collapse: collapse; }
.leader-table th, .leader-table td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.leader-table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.leader-table tr:last-child td { border-bottom: 0; }
.leader-table .leader-me td { background: rgba(77,223,212,.08); color: var(--cyan); }
.rank { counter-reset: rank; }
.rank .row::before { counter-increment: rank; content: counter(rank) "."; color: var(--yellow); font-weight: 900; }
.muted { color: var(--muted); }
.center { text-align: center; }
.empty { padding: 28px; border: 1px dashed var(--line); color: var(--muted); border-radius: 16px; text-align: center; }
#toast { position: fixed; z-index: 50; left: 50%; bottom: 22px; transform: translate(-50%, 120px); opacity: 0; max-width: min(92vw, 520px); padding: 12px 17px; border-radius: 13px; color: white; background: #3b1830; border: 1px solid var(--pink); box-shadow: var(--shadow); transition: .25s; }
#toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 820px) {
  .hero, .auth-layout { grid-template-columns: 1fr; padding-top: 24px; }
  .auth-panel { justify-self: stretch; max-width: none; }
  .game-grid { grid-template-columns: repeat(2, 1fr); }
  .game-layout { grid-template-columns: 1fr; }
  .side { position: static; }
  .settings-panel { grid-template-columns: 1fr; }
}
@media (max-width: 540px) {
  .shell { padding: 15px 13px 48px; }
  .topbar { margin-bottom: 12px; }
  .brand span:last-child { display: none; }
  .status { display: none; }
  .top-actions { gap: 5px; }
  .account-chip { display: none; }
  .room-head { grid-template-columns: 1fr; }
  .room-tools { justify-items: start; }
  .invite-panel { grid-template-columns: 1fr; }
  .invite-panel .btn { width: 100%; }
  .game-grid, .category-grid, .team-grid { grid-template-columns: 1fr; }
  .game-card { min-height: 150px; }
  .start-dock { align-items: stretch; flex-direction: column; }
  .start-dock .btn { width: 100%; }
  .settings-grid { grid-template-columns: 1fr; }
  .early-confirm { align-items: stretch; flex-direction: column; }
  .early-confirm .btn { width: 100%; }
  .word-board { grid-template-columns: repeat(2, 1fr); }
  .card-grid { grid-template-columns: repeat(3, 1fr); }
  .match-card { min-height: 82px; padding: 7px; }
  .match-card span { font-size: .74rem; }
  .color-grid { grid-template-columns: repeat(2, 1fr); }
  .leader-hero { grid-template-columns: 1fr; }
}
