:root {
  --bg: #070b1c; --panel: rgba(16, 22, 44, .78); --fg: #f2f4fa; --muted: #8e98b8; --border: rgba(110, 160, 255, .22);
  --gold: #ffb52e; --gold-hi: #ffe39a; --cyan: #58b4ff; --n: 5;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; color: var(--fg); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
html { background: var(--bg); }
body { display: flex; flex-direction: column; min-height: 100dvh; background: url(/bg.webp) center / cover no-repeat fixed, radial-gradient(ellipse at 50% 110%, #3a2208 0%, transparent 55%), var(--bg); user-select: none; }
button { font: inherit; color: inherit; cursor: pointer; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }

.top { position: relative; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 12px; min-height: 56px; }
.top .left, .top .right { display: flex; gap: 8px; align-items: center; }
.top .right { justify-content: flex-end; }
.top h1 { margin: 0; font-size: clamp(18px, 4.6vw, 26px); letter-spacing: .32em; font-weight: 300; color: var(--gold-hi); white-space: nowrap;
  text-shadow: 0 0 6px var(--gold), 0 0 18px rgba(255, 170, 40, .55); display: flex; align-items: center; }
.top h1 .o { display: inline-block; width: .78em; height: .78em; border: .12em solid var(--gold-hi); border-radius: .16em; margin: 0 .32em 0 .5em;
  box-shadow: 0 0 6px var(--gold), 0 0 16px rgba(255, 170, 40, .6), inset 0 0 8px rgba(255, 170, 40, .5); animation: breathe 3.2s ease-in-out infinite; }
.icon { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border); background: var(--panel); font-weight: 700; display: grid; place-items: center; padding: 0; backdrop-filter: blur(6px); }
.icon.off { opacity: .45; }
.chip { border: 1px solid var(--border); background: var(--panel); border-radius: 999px; padding: 7px 14px; font-size: 13px; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; backdrop-filter: blur(6px); }
.chip.active, .chip.primary { border-color: var(--gold); color: var(--gold-hi); background: rgba(255, 181, 46, .14); box-shadow: 0 0 12px rgba(255, 181, 46, .25); }

.sizes { position: relative; z-index: 2; display: flex; justify-content: center; gap: 6px; padding: 4px 6px; flex-wrap: wrap; }
.sizes .chip { color: var(--muted); font-variant-numeric: tabular-nums; }
.sizes .chip.active { color: var(--gold-hi); }
.sizes .chip small { margin-left: 4px; color: var(--gold); letter-spacing: -.1em; }
.diffs { padding-top: 2px; }
.diffs .chip { display: inline-flex; align-items: baseline; gap: 6px; }
.diffs .chip small { letter-spacing: 0; color: var(--muted); font-size: 11px; margin: 0; }
.diffs .chip.easy.active { border-color: #5fd39a; color: #b9f5d6; background: rgba(95, 211, 154, .12); box-shadow: 0 0 12px rgba(95, 211, 154, .25); }
.diffs .chip.hard.active { border-color: #ff6b5a; color: #ffc4bb; background: rgba(255, 107, 90, .12); box-shadow: 0 0 12px rgba(255, 107, 90, .3); }
.diffs .chip.active small { color: inherit; opacity: .8; }

main { position: relative; z-index: 2; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px 8px max(12px, env(safe-area-inset-bottom)); gap: 14px; min-height: 0; }
.hud { display: flex; gap: 16px; justify-content: center; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; flex-wrap: wrap; text-transform: uppercase; letter-spacing: .08em; }
.hud b { color: var(--fg); font-size: 17px; margin-left: 4px; letter-spacing: 0; }
.hud b.under { color: var(--gold-hi); }

.board { --size: min(calc(100vw - 24px), calc(100dvh - 310px), 540px); --gap: calc(var(--size) * .022);
  width: var(--size); height: var(--size); display: grid; grid-template-columns: repeat(var(--n), 1fr); grid-template-rows: repeat(var(--n), 1fr); gap: var(--gap);
  padding: var(--gap); border-radius: calc(var(--size) * .045); background: rgba(6, 10, 26, .55); border: 1px solid var(--border);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .55), inset 0 0 40px rgba(60, 120, 255, .06); perspective: 900px; touch-action: manipulation; }
.board.won { animation: boardwin 1.2s ease; }
.tile { position: relative; border: 0; padding: 0; border-radius: 18%; outline: none; touch-action: manipulation;
  background: linear-gradient(160deg, #1b2747 0%, #0b1226 70%);
  box-shadow: inset 0 0 0 1px rgba(88, 180, 255, .45), inset 0 1px 0 rgba(255, 255, 255, .12), inset 0 -6px 14px rgba(0, 0, 0, .45), 0 4px 10px rgba(0, 0, 0, .35);
  transition: background .22s ease, box-shadow .22s ease, transform .12s ease; }
.tile::after { content: ""; position: absolute; inset: 9%; border-radius: 14%; background: linear-gradient(170deg, rgba(255, 255, 255, .10), transparent 45%); pointer-events: none; }
.tile.on { background: radial-gradient(circle at 50% 45%, var(--gold-hi) 0%, var(--gold) 45%, #e07a10 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 236, 170, .9), inset 0 -6px 14px rgba(170, 70, 0, .45), 0 0 14px rgba(255, 170, 40, .75), 0 0 36px rgba(255, 150, 20, .45); }
.tile:hover { transform: translateY(-2px); }
.tile:active, .tile.press { transform: scale(.9); }
.tile.ripple { animation: ripple .38s ease; }
.tile.cur { box-shadow: inset 0 0 0 2px #fff, 0 0 0 3px rgba(88, 180, 255, .7); }
.tile.on.cur { box-shadow: inset 0 0 0 2px #fff, 0 0 0 3px rgba(88, 180, 255, .7), 0 0 30px rgba(255, 150, 20, .55); }
.tile.hint::before { content: ""; position: absolute; inset: -6%; border-radius: 22%; border: 2px solid var(--cyan); box-shadow: 0 0 16px var(--cyan); animation: hintpulse 1s ease-in-out infinite; pointer-events: none; }
.board.won .tile { transition-duration: .5s; }

.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(calc(100vw - 24px), 540px); }
.tools button { height: 46px; border-radius: 12px; border: 1px solid var(--border); background: var(--panel); font-weight: 600; font-size: 14px; white-space: nowrap; padding: 0 4px; touch-action: manipulation; backdrop-filter: blur(6px); }
.tools button:active { background: rgba(255, 181, 46, .18); }
.tools button:disabled { opacity: .35; cursor: default; }

.toast { position: fixed; top: 120px; left: 50%; transform: translateX(-50%); background: rgba(255, 227, 154, .95); color: #1a1205; font-weight: 700; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 5; box-shadow: 0 0 24px rgba(255, 170, 40, .5); }
.toast.show { opacity: 1; }

.dlg { background: rgba(12, 17, 36, .96); color: var(--fg); border: 1px solid var(--border); border-radius: 16px; padding: 22px 24px; width: min(92vw, 420px); box-shadow: 0 30px 90px rgba(0, 0, 0, .6), 0 0 40px rgba(88, 180, 255, .08); }
.dlg::backdrop { background: rgba(2, 4, 12, .65); backdrop-filter: blur(3px); }
.dlg h2 { margin: 0 0 10px; font-weight: 600; letter-spacing: .02em; }
.dlg p, .dlg li { color: #cdd3e6; font-size: 15px; line-height: 1.45; }
.dlg .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.result { text-align: center; }
.result h2 { color: var(--gold-hi); font-size: 30px; letter-spacing: .12em; text-transform: uppercase; text-shadow: 0 0 14px rgba(255, 170, 40, .7); }
.result .actions { justify-content: center; }
.stars { display: flex; justify-content: center; gap: 10px; font-size: 44px; margin: 6px 0; }
.stars span { color: #2a3352; transform: scale(.4); opacity: 0; animation: starpop .45s cubic-bezier(.2, 1.6, .4, 1) forwards; }
.stars span.got { color: var(--gold-hi); text-shadow: 0 0 10px var(--gold), 0 0 26px rgba(255, 150, 20, .7); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin: 8px 0 14px; }
.stats b { display: block; font-size: 24px; color: var(--gold-hi); }
.stats span { color: var(--muted); font-size: 12px; }
.stats-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
.stats-table th, .stats-table td { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--border); }
.stats-table th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; }
.stats-table td small { margin-left: 6px; color: var(--muted); }
.stats-table td:not(:first-child) { color: var(--gold-hi); }
.dlg .note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

@keyframes breathe { 50% { box-shadow: 0 0 10px var(--gold), 0 0 26px rgba(255, 170, 40, .8), inset 0 0 12px rgba(255, 170, 40, .7); } }
@keyframes ripple { 0% { transform: scale(1); } 40% { transform: scale(.94); filter: brightness(1.5); } 100% { transform: scale(1); } }
@keyframes hintpulse { 50% { opacity: .35; transform: scale(1.04); } }
@keyframes starpop { to { transform: scale(1); opacity: 1; } }
@keyframes boardwin { 0% { box-shadow: 0 30px 80px rgba(0, 0, 0, .55); } 30% { box-shadow: 0 0 60px rgba(255, 170, 40, .55), 0 0 140px rgba(255, 140, 20, .35); } 100% { box-shadow: 0 30px 80px rgba(0, 0, 0, .55); } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } .stars span { opacity: 1; transform: none; } }
@media (min-width: 700px) { main { gap: 18px; } }
@media (max-width: 480px) { .top { padding: 8px; gap: 6px; } .top h1 { font-size: 16px; letter-spacing: .2em; } .tools button { font-size: 13px; } }
