:root {
  --bg: #14161f; --panel: #1e2130; --panel2: #262a3d; --text: #f2f3f7; --muted: #9aa0b8;
  --line: #33384f; --accent: #ff4fa3; --blue: #1d72f3; --lt: #f0d9b5; --dk: #b58863; --r: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
a { color: #8fb6ff; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .6em; }
.muted { color: var(--muted); } .small { font-size: 13px; } .hidden { display: none !important; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; color: var(--text); text-decoration: none; letter-spacing: -.3px; }
.logo-grid { display: grid; grid-template-columns: 1fr 1fr; width: 24px; height: 24px; border-radius: 5px; overflow: hidden; }
.logo-grid i:nth-child(1) { background: #e63946 } .logo-grid i:nth-child(2) { background: var(--lt) }
.logo-grid i:nth-child(3) { background: var(--dk) } .logo-grid i:nth-child(4) { background: #1d72f3 }
.top nav { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.top nav a { color: var(--text); text-decoration: none; opacity: .85; }
.who { color: var(--muted); }

/* buttons + forms */
.btn { display: inline-block; background: var(--blue); color: #fff !important; border: 0; border-radius: 10px; padding: 10px 18px; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; opacity: 1 !important; }
.btn:hover { filter: brightness(1.1); } .btn:disabled { opacity: .5 !important; }
.btn.big { padding: 14px 24px; font-size: 17px; width: 100%; text-align: center; }
.btn.sm { padding: 6px 12px; font-size: 14px; }
.btn.accent { background: var(--accent); }
.link { background: none; border: 0; color: #8fb6ff; cursor: pointer; font: inherit; padding: 0; }
.danger { color: #ff6b7a !important; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
input, select { display: block; width: 100%; margin-top: 5px; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; }
input:focus, select:focus { outline: 2px solid var(--blue); border-color: transparent; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 22px; margin-bottom: 18px; }
.card.narrow { max-width: 420px; margin: 30px auto; }
.links { text-align: center; font-size: 14px; margin: 14px 0 0; }
.flash { padding: 11px 14px; border-radius: 10px; margin: 0 0 14px; background: #1f4d33; }
.flash.err { background: #5a1f2a; }
.code { font-family: ui-monospace, monospace; background: var(--panel2); padding: 2px 10px; border-radius: 8px; letter-spacing: 2px; }

/* landing */
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; align-items: center; padding: 30px 0; }
.hero h1 { font-size: clamp(30px, 5vw, 48px); letter-spacing: -1px; }
.hero-board { display: grid; grid-template-columns: repeat(8, 1fr); aspect-ratio: 1; border-radius: var(--r); overflow: hidden; box-shadow: 0 20px 60px #0008; }
.hero-board i { background: var(--lt); position: relative; }
.hero-board i.dk { background: var(--dk); }
.hero-board i.own { animation: pop 1.6s ease-in-out infinite alternate; }
.hero-board i.dk.own::after, .sq.dk.own::after { content: ''; position: absolute; inset: 0; background: rgba(0,0,0,.13); }
@keyframes pop { from { filter: brightness(.9) } to { filter: brightness(1.15) } }
.join { display: flex; gap: 8px; margin: 22px 0 14px; }
.join input { margin: 0; text-transform: uppercase; letter-spacing: 3px; font-weight: 700; }
.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 20px 0 40px; }
.how div { background: var(--panel); border-radius: var(--r); padding: 20px; border: 1px solid var(--line); }
.how b { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); margin-bottom: 10px; }
.how p { color: var(--muted); margin: 0; }

/* game */
body.game main { max-width: 1200px; padding: 10px; }
.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.room-chip, .me-chip { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.room-chip { cursor: pointer; } .room-chip b { letter-spacing: 2px; } .room-chip span { color: var(--accent); font-weight: 700; }
.timer { font-size: 34px; font-weight: 900; font-variant-numeric: tabular-nums; min-width: 90px; text-align: center; }
.timer.hurry { color: #ff4d5e; animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08) } }
.arena { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.board-box { position: relative; width: min(100%, calc(100vh - 140px)); margin: 0 auto; }
.board { display: grid; grid-template-columns: repeat(var(--n, 8), 1fr); aspect-ratio: 1; border-radius: var(--r); overflow: hidden;
         box-shadow: 0 0 0 6px #3a2a1d, 0 20px 60px #000a; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer; }
.sq { background: var(--lt); position: relative; transition: background-color .12s; }
.sq.dk { background: var(--dk); }
.sq.shield { box-shadow: inset 0 0 0 3px rgba(255,255,255,.85); }
.sq.nope { animation: nope .3s; }
@keyframes nope { 0%,100% { transform: none } 30% { transform: translateX(-3px) } 60% { transform: translateX(3px) } }
.overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; background: rgba(15,17,25,.72); border-radius: var(--r); backdrop-filter: blur(2px); padding: 16px; }
.overlay.count { background: rgba(15,17,25,.35); pointer-events: none; }
.count-num { font-size: min(40vw, 220px); font-weight: 900; color: #fff; text-shadow: 0 10px 40px #000; animation: zoom 1s ease-out infinite; }
@keyframes zoom { from { transform: scale(1.4); opacity: 0 } 25% { opacity: 1 } to { transform: scale(.9); opacity: .9 } }
.ov-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 24px 28px; text-align: center; max-width: 360px; width: 100%; }
.ov-card h2 { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 26px; }
.final { text-align: left; padding-left: 22px; margin: 14px 0; }
.final li { padding: 4px 0; display: flex; align-items: center; gap: 8px; }
.final li b { margin-left: auto; }
.sw { display: inline-block; width: 16px; height: 16px; border-radius: 4px; flex: none; }
.sw.big { width: 26px; height: 26px; border-radius: 6px; }
.side { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.scores { list-style: none; padding: 0; margin: 0 0 16px; }
.scores li { display: grid; grid-template-columns: 16px 1fr auto auto; grid-template-areas: "sw nm n x" "bar bar bar bar"; gap: 4px 8px; align-items: center; padding: 8px 6px; border-radius: 8px; }
.scores li.me { background: var(--panel2); }
.scores .sw { grid-area: sw; } .scores .nm { grid-area: nm; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores b { grid-area: n; font-variant-numeric: tabular-nums; } .scores .x { grid-area: x; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 18px; }
.scores .bar { grid-area: bar; height: 5px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.scores .bar i { display: block; height: 100%; transition: width .25s; }
.controls { border-top: 1px solid var(--line); padding-top: 14px; margin-bottom: 10px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); opacity: 0; background: #000d; padding: 10px 18px; border-radius: 999px; transition: .25s; pointer-events: none; z-index: 9; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* admin */
.tabs { display: flex; gap: 6px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 16px; border-radius: 10px; color: var(--text); text-decoration: none; background: var(--panel); }
.tabs a.on { background: var(--blue); }
.tabs .stats { margin-left: auto; color: var(--muted); font-size: 14px; }
.toolbar { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar form { display: flex; gap: 6px; align-items: center; }
.toolbar input { margin: 0; width: 220px; padding: 7px 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--r); overflow: hidden; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; background: var(--panel2); }
td.act { display: flex; gap: 12px; } td.act form { margin: 0; }
.tag { font-size: 12px; background: var(--panel2); padding: 2px 8px; border-radius: 999px; }
.tag.warn { background: #5a4a1f; } .tag.live { background: #1f4d33; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-form .row, .grid-form .checks { grid-column: 1 / -1; display: flex; gap: 16px; align-items: center; }
.chk { display: flex; align-items: center; gap: 8px; color: var(--text); }
.chk input { width: auto; margin: 0; }
.pager { display: flex; gap: 6px; margin-top: 12px; } .pager a { padding: 4px 10px; background: var(--panel); border-radius: 6px; text-decoration: none; }
.pager a.on { background: var(--blue); color: #fff; }

@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr; gap: 24px; padding: 10px 0; }
  .hero-board { max-width: 340px; width: 100%; margin: 0 auto; order: 2; }
  .how { grid-template-columns: 1fr; }
  .arena { grid-template-columns: 1fr; }
  .board-box { width: 100%; }
  .timer { font-size: 28px; min-width: 70px; }
  .me-chip { font-size: 12px; padding: 6px 10px; }
  .room-chip { font-size: 12px; padding: 6px 10px; }
  .grid-form { grid-template-columns: 1fr; }
  .top nav .who { display: none; }
}

/* ---------- v2: special squares, shrink, invite, result ---------- */
.sq::before { position: absolute; inset: 0; display: grid; place-items: center; line-height: 1; pointer-events: none; z-index: 1; }
.sq.gold { box-shadow: inset 0 0 0 2px #f4c20d; }
.sq.gold::before { content: '★'; color: #d9a400; font-weight: 900; text-shadow: 0 1px 0 #fff8; }
.sq.gold.own::before { color: #fff; text-shadow: 0 1px 3px #0006; }
.sq.bomb::before { content: '💣'; font-size: .8em; animation: tick 1s ease-in-out infinite; }
@keyframes tick { 50% { transform: scale(1.12) rotate(-6deg) } }
.sq.boom { animation: boom .55s ease-out; z-index: 2; }
@keyframes boom { 0% { transform: scale(1); filter: brightness(2.2) } 40% { transform: scale(1.18) } 100% { transform: scale(1); filter: none } }
.sq.warn::after { content: ''; position: absolute; inset: 0; background: rgba(140,200,255,.45); animation: warn .5s infinite alternate; }
@keyframes warn { from { opacity: .15 } to { opacity: .8 } }
.sq.frozen { filter: saturate(.55) brightness(.75); cursor: not-allowed; }
.sq.frozen::after { content: ''; position: absolute; inset: 0;
  background: repeating-linear-gradient(135deg, rgba(200,230,255,.28) 0 4px, transparent 4px 10px); }
.sq.dk.own.frozen::after { background: repeating-linear-gradient(135deg, rgba(200,230,255,.28) 0 4px, rgba(0,0,0,.13) 4px 10px); }

.modes { margin: 4px 0 14px; display: grid; gap: 8px; }
.modes .chk { margin: 0; font-size: 14px; }
.rules { padding-left: 18px; margin: 10px 0 0; }
.rules li { margin-bottom: 4px; }
.btn.ghost { background: var(--panel2); }
.row-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0 4px; }
.qr { background: #fff; border-radius: 12px; padding: 6px; margin: 10px auto; width: min(240px, 70vw); }
.qr.small { width: min(150px, 34vw); }
.qr svg { display: block; width: 100%; height: auto; }
.modal { position: fixed; inset: 0; background: rgba(8,9,14,.75); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 24px; width: 100%; max-width: 380px; text-align: center; }
.modal-x { position: absolute; top: 8px; right: 12px; background: none; border: 0; color: var(--muted); font-size: 28px; cursor: pointer; }
.link-row { display: flex; gap: 6px; margin: 12px 0; }
.link-row input { margin: 0; font-size: 14px; }
.ov-card .code { font-size: 15px; }

/* ---------- v3: bots ---------- */
.bot-row { display: flex; gap: 8px; margin-bottom: 12px; }
.bot-row select { margin: 0; padding: 8px 10px; font-size: 14px; }
.bot-row .btn { white-space: nowrap; }
.lvl { font-size: 11px; color: var(--muted); background: var(--bg); padding: 1px 6px; border-radius: 999px; margin-left: 4px; }

/* ---------- v4: fun + speed ---------- */
.hud-right { display: flex; align-items: center; gap: 8px; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 999px; width: 38px; height: 38px; font-size: 17px; cursor: pointer; padding: 0; }
.board-box { position: relative; }
.floats { position: absolute; inset: 0; pointer-events: none; z-index: 6; overflow: visible; }
.float { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 22px; color: #fff; text-shadow: 0 2px 6px #000a; animation: rise .9s ease-out forwards; white-space: nowrap; }
.float.gold { color: #ffd84d; font-size: 26px; }
.float.big { font-size: 34px; color: #fff; text-shadow: 0 0 18px #ff4fa3, 0 2px 6px #000; }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6) } 20% { opacity: 1; transform: translate(-50%, -60%) scale(1.15) } 100% { opacity: 0; transform: translate(-50%, -170%) scale(1) } }
.sq.stolen { animation: stolen .45s ease-out; }
@keyframes stolen { 0% { box-shadow: inset 0 0 0 4px #fff; filter: brightness(1.6) } 100% { box-shadow: inset 0 0 0 0 #fff; filter: none } }
.banner { position: absolute; left: 50%; top: 12px; transform: translate(-50%, -20px); opacity: 0; z-index: 7; pointer-events: none;
  background: rgba(15,17,25,.88); border: 1px solid var(--line); padding: 8px 16px; border-radius: 999px; font-size: 15px; white-space: nowrap; box-shadow: 0 8px 24px #0008; }
.banner.show { animation: banner 1.6s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -20px) } 12% { opacity: 1; transform: translate(-50%, 0) } 80% { opacity: 1; transform: translate(-50%, 0) } 100% { opacity: 0; transform: translate(-50%, -10px) } }
.react-bar { display: flex; justify-content: center; gap: 6px; margin-top: 14px; }
.react-bar button { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; font-size: 22px; width: 46px; height: 46px; cursor: pointer; padding: 0; transition: transform .1s; }
.react-bar button:active { transform: scale(.85); }
.react-bar button:disabled { opacity: .45; }
.react-float { position: absolute; bottom: 0; display: flex; flex-direction: column; align-items: center; animation: float-up 2.2s ease-out forwards; }
.react-float .e { font-size: 44px; filter: drop-shadow(0 4px 8px #0008); }
.react-float .who { font-size: 11px; font-weight: 700; color: #fff; padding: 1px 8px; border-radius: 999px; margin-top: 2px; text-shadow: 0 1px 2px #0008; }
@keyframes float-up { 0% { opacity: 0; transform: translateY(0) scale(.5) } 15% { opacity: 1; transform: translateY(-40px) scale(1.1) } 100% { opacity: 0; transform: translateY(-320px) scale(1) rotate(-8deg) } }
.count-num.go { color: #4ade80; font-size: min(28vw, 170px); }
.confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 30; }
.scores li.away { opacity: .5; }
.create { display: grid; gap: 10px; margin-bottom: 12px; }
.create input { margin: 0; font-size: 17px; padding: 14px; }
@media (max-width: 820px) {
  .react-bar button { width: 42px; height: 42px; font-size: 20px; }
  .icon-btn { width: 32px; height: 32px; font-size: 14px; }
  .banner { font-size: 13px; }
}
