:root {
  --bg: #090e17; --panel: rgba(15, 23, 38, 0.95); --line: #26344f; --text: #eef3fb; --muted: #94a3bb;
  --accent: #ffd24a; --flame: #ff9a3c; --dock: #4ff0a0; --bad: #ff6b7f;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%; }
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after { animation-duration: 0s !important; transition-duration: 0s !important; }

button { font: inherit; font-weight: 600; color: var(--text); background: #18233a; border: 1px solid var(--line); border-radius: 14px; padding: 13px 16px; min-height: 52px; cursor: pointer; touch-action: manipulation; }
button:active { transform: scale(0.97); filter: brightness(1.2); }
button:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary { background: linear-gradient(#ffb25c, #f0862a); color: #2a1300; border-color: #ffc98f; font-weight: 800; font-size: 19px; }
button.danger { background: #3a1820; border-color: #7a3040; color: #ffd6dc; }
button.icon { min-width: 44px; min-height: 44px; padding: 0 10px; border-radius: 12px; font-weight: 800; }
button:disabled { opacity: 0.4; cursor: default; }
button .sub { display: block; font-size: 12px; font-weight: 500; color: var(--muted); }
button.primary .sub { color: #5a2c00; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; gap: 10px; max-width: 560px; margin: 0 auto;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 18px) calc(var(--safe-b) + 16px) calc(var(--safe-l) + 18px);
  background: rgba(9, 14, 23, 0.82); overflow-y: auto; touch-action: pan-y; animation: fade 0.2s ease-out; }
.screen.center { justify-content: center; text-align: center; }
.screen.dim { background: rgba(6, 10, 18, 0.72); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); max-width: none; padding-left: max(18px, calc(50vw - 200px)); padding-right: max(18px, calc(50vw - 200px)); }
#screen-home { background: linear-gradient(rgba(9, 14, 23, 0.2), rgba(9, 14, 23, 0.75)); }
@keyframes fade { from { opacity: 0; } }

#logo { width: 240px; height: 170px; align-self: center; }
h1 { margin: 0; font-size: 44px; line-height: 0.98; letter-spacing: 0.04em; font-weight: 900; background: linear-gradient(180deg, #fff, #9cc3ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
h2 { margin: 0; font-size: 22px; }
.tagline { margin: 4px 0 0; color: var(--muted); }
.home-stars { margin: 2px 0 6px; color: var(--accent); font-weight: 700; min-height: 1.4em; }
.menu { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 360px; align-self: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.foot { color: var(--muted); font-size: 12px; margin-top: 8px; }

header.bar { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 10px; position: sticky; z-index: 2;
  top: calc(-16px - var(--safe-t)); margin: calc(-16px - var(--safe-t)) -18px 0; padding: calc(var(--safe-t) + 12px) 18px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line); }
header.bar h2 { text-align: center; }
.bar-right { text-align: right; color: var(--accent); font-weight: 700; white-space: nowrap; }
.list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }

.sector h3 { margin: 10px 0 8px; font-size: 18px; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lvl { aspect-ratio: 1 / 1.05; min-height: 0; padding: 4px 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.lvl b { font-size: 20px; }
.lvl.current { border-color: var(--flame); box-shadow: 0 0 0 2px rgba(255, 154, 60, 0.35) inset; }

.stars { display: flex; gap: 2px; color: #3a465e; }
.stars .on { color: var(--accent); }
.stars.small { font-size: 13px; letter-spacing: 1px; }
.lvl .stars { font-size: 11px; }
.stars.big { justify-content: center; font-size: 46px; gap: 8px; margin: 2px 0; }
.stars.big .on { animation: star 0.45s backwards; text-shadow: 0 0 14px rgba(255, 210, 74, 0.55); }
.stars.big span:nth-child(2) { animation-delay: 0.12s; }
.stars.big span:nth-child(3) { animation-delay: 0.24s; }
@keyframes star { from { transform: scale(0) rotate(-90deg); } }

.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-height: 54px; font-size: 17px; }
.row input[type=range] { width: 50%; accent-color: var(--flame); }
.row input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--flame); }
.note { color: var(--muted); font-size: 13px; margin: 0; }
.prose p { margin: 0; color: #d6dfee; }
#btn-start { position: sticky; bottom: 0; box-shadow: 0 -10px 18px 6px rgba(9, 14, 23, 0.9); }
.cards { display: grid; grid-template-columns: 1fr; gap: 8px; }
.card { display: grid; grid-template-columns: 48px 1fr; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 14px; color: #d6dfee; }
.card canvas { width: 48px; height: 48px; }
.card b { display: block; font-size: 15px; color: var(--text); }

#hud { position: fixed; left: 0; right: 0; top: 0; max-width: 560px; margin: 0 auto; display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 14px) 0 calc(var(--safe-l) + 14px); pointer-events: none; }
.hud-left { min-width: 0; }
#level-title { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 3px #000; }
#level-best { margin-top: 2px; }
#hud button, #bar button { pointer-events: auto; }
#btn-pause { background: rgba(24, 35, 58, 0.85); }
#bar { position: fixed; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 0 calc(var(--safe-r) + 14px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 14px); pointer-events: none; }
#bar button { background: rgba(24, 35, 58, 0.9); }
#btn-hint.on { border-color: var(--accent); color: var(--accent); }
#tip { position: fixed; z-index: 1; pointer-events: none; background: rgba(15, 23, 38, 0.86); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 14px; padding: 12px 16px; text-align: center; }
#tip p { margin: 0; font-size: 17px; }
#screen-game.paused #tip { display: none; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 5; padding: 24px; background: rgba(5, 8, 15, 0.45); }
.dialog { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; background: var(--panel); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 18px; padding: 20px 16px 16px; text-align: center; animation: pop 0.2s ease-out; }
.dialog p { margin: 0; color: #d6dfee; white-space: pre-line; }
@keyframes pop { from { opacity: 0; transform: scale(0.94); } }
@media (max-height: 700px) { #logo { width: 190px; height: 135px; } h1 { font-size: 38px; } }
@media (prefers-reduced-motion: reduce) { button:active { transform: none; } }
