:root {
  --bg: #05060d;
  --ink: #eef0ff;
  --dim: #8b90b8;
  --faint: #3a3f66;
  --sun: #ffb35c;
  --sun-hi: #ffd9a8;
  --teal: #5cf2d6;
  --magenta: #ff4fa3;
  --panel: rgba(12, 14, 30, 0.72);
  --line: rgba(160, 170, 255, 0.16);
  --display: 'Syne', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: var(--mono); -webkit-font-smoothing: antialiased;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
canvas#c { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; cursor: crosshair; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
  pointer-events: none; gap: 12px;
}
#hud > * { pointer-events: auto; }
.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hud-left { flex: 1; }
.hud-right { flex: 1; justify-content: flex-end; }
#lvl-label { display: flex; gap: 10px; align-items: baseline; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lvl-num { color: var(--sun); font-weight: 600; }
#lvl-name { color: var(--ink); opacity: 0.85; overflow: hidden; text-overflow: ellipsis; }
#shots { font-size: 13px; color: var(--dim); margin-right: 4px; white-space: nowrap; }
#shots b { color: var(--ink); font-weight: 600; }

.icon {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: grid; place-items: center; transition: border-color .2s, background .2s, transform .1s;
}
.icon:hover { border-color: rgba(255, 179, 92, 0.5); }
.icon:active { transform: scale(0.94); }
.icon.active { border-color: var(--sun); background: rgba(255, 179, 92, 0.14); }
.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#btn-ff svg { fill: currentColor; stroke: none; }
#btn-mute .off { display: none; }
#btn-mute.muted .on { display: none; }
#btn-mute.muted .off { display: block; }

.hud-mid { display: flex; gap: 6px; }
.hud-mid i, .big-stars i {
  display: block; width: 18px; height: 18px; background: var(--faint);
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
  transition: background .25s, transform .25s;
}
.hud-mid i.on, .big-stars i.on { background: var(--sun-hi); transform: scale(1.15); filter: drop-shadow(0 0 6px var(--sun)); }

#hint {
  position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px)); text-align: center; font-size: 13px; line-height: 1.5; color: var(--dim);
  pointer-events: none; transition: opacity .6s;
}
#toast {
  position: fixed; left: 50%; top: 72px; transform: translateX(-50%); padding: 8px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-size: 12px; opacity: 0; transition: opacity .3s; pointer-events: none;
}
#toast.show { opacity: 1; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px 16px; overflow-y: auto; touch-action: pan-y; }
#menu { background: radial-gradient(ellipse at 50% 60%, rgba(5, 6, 13, 0.1), rgba(5, 6, 13, 0.75) 70%); }
.menu-inner { width: min(640px, 100%); min-width: 0; text-align: left; }
.kicker { margin: 0 0 8px; font-size: 12px; letter-spacing: 0.3em; text-transform: uppercase; color: var(--sun); }
h1 {
  font-family: var(--display); font-weight: 800; font-size: clamp(34px, 9.6vw, 80px); line-height: 0.95; margin: 0; padding-right: 0.05em; white-space: nowrap;
  letter-spacing: -0.04em;
  background: linear-gradient(100deg, var(--ink) 30%, var(--sun-hi) 60%, var(--sun) 80%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lede { color: var(--dim); font-size: 15px; margin: 18px 0 30px; }
.modes { display: grid; gap: 10px; }
.mode {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px; text-align: left;
  padding: 18px 20px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: border-color .2s, transform .2s, background .2s;
}
.mode:hover, .mode:focus-visible { border-color: rgba(255, 179, 92, 0.6); transform: translateX(4px); background: rgba(24, 20, 30, 0.8); outline: none; }
.mode-name { font-family: var(--display); font-weight: 700; font-size: 22px; letter-spacing: -0.01em; white-space: nowrap; }
.mode-sub { font-size: 12px; color: var(--dim); text-align: right; }
.controls { margin-top: 26px; font-size: 11px; color: var(--dim); line-height: 2; opacity: 0.8; }
kbd { font-family: var(--mono); font-size: 10px; border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; margin: 0 1px; }

#levels { background: rgba(5, 6, 13, 0.82); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.levels-inner { width: min(760px, 100%); }
.levels-head { display: flex; align-items: baseline; gap: 16px; margin-bottom: 22px; }
.levels-head h2 { font-family: var(--display); font-size: 34px; margin: 0; flex: 1; }
#campaign-total { color: var(--sun-hi); font-size: 13px; }
.back { background: none; border: none; color: var(--dim); padding: 6px 0; font-size: 13px; }
.back:hover { color: var(--ink); }
#level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.lvl {
  position: relative; text-align: left; padding: 14px 14px 12px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); min-height: 96px; display: flex; flex-direction: column; justify-content: space-between; transition: border-color .2s, transform .15s;
}
.lvl:hover:not(:disabled) { border-color: rgba(255, 179, 92, 0.6); transform: translateY(-2px); }
.lvl:disabled { opacity: 0.35; cursor: not-allowed; }
.lvl .n { color: var(--sun); font-size: 12px; font-weight: 600; }
.lvl .t { font-family: var(--display); font-weight: 700; font-size: 17px; margin: 4px 0 10px; }
.lvl .s { display: flex; gap: 4px; }
.lvl .s i { width: 12px; height: 12px; display: block; background: var(--faint); clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%); }
.lvl .s i.on { background: var(--sun-hi); }

#modal { background: rgba(5, 6, 13, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.card {
  width: min(400px, 100%); padding: 28px 26px 22px; border-radius: 22px; background: rgba(12, 14, 30, 0.9);
  border: 1px solid var(--line); text-align: center; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  animation: rise .45s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(.96); } }
.card h2 { font-family: var(--display); font-weight: 800; font-size: 38px; margin: 0 0 14px; letter-spacing: -0.02em; }
.big-stars { display: flex; justify-content: center; gap: 14px; margin: 6px 0 16px; }
.big-stars i { width: 38px; height: 38px; }
.big-stars i.on { animation: pop .5s backwards; }
.big-stars i.on:nth-child(2) { animation-delay: .15s; }
.big-stars i.on:nth-child(3) { animation-delay: .3s; }
@keyframes pop { from { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.4); } }
#modal-body { color: var(--dim); font-size: 13px; line-height: 1.6; margin: 0 0 20px; white-space: pre-line; }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn {
  padding: 12px 18px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); font-size: 13px; min-width: 96px;
  transition: border-color .2s, background .2s;
}
.btn:hover { border-color: rgba(255, 179, 92, 0.5); }
.btn.primary { background: var(--sun); color: #1a0f02; border-color: var(--sun); font-weight: 600; }
.btn.primary:hover { background: var(--sun-hi); }

#loading { background: rgba(5, 6, 13, 0.6); color: var(--dim); font-size: 13px; letter-spacing: 0.2em; text-transform: uppercase; }
.dots::after { content: ''; animation: dots 1s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

@media (max-width: 520px) {
  #lvl-name { display: none; }
  .icon { width: 34px; height: 34px; border-radius: 10px; }
  .mode { flex-direction: column; gap: 4px; }
  .mode-sub { text-align: left; }
  .hud-mid { position: fixed; left: 50%; transform: translateX(-50%); top: calc(max(12px, env(safe-area-inset-top)) + 50px); }
  .hud-mid i { width: 14px; height: 14px; }
  .kicker { letter-spacing: 0.2em; }
  .controls { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- hint button ---------- */
#btn-hint.pulse { animation: hintpulse 1.6s ease-in-out infinite; border-color: rgba(255, 211, 107, 0.7); }
@keyframes hintpulse { 50% { box-shadow: 0 0 0 6px rgba(255, 211, 107, 0.12); } }

/* ---------- forge ---------- */
#forge-bar {
  position: fixed; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(1100px, calc(100vw - 20px)); padding: 10px 12px; border-radius: 16px; background: rgba(12, 14, 30, 0.86);
  border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); display: grid; gap: 8px;
}
.fb-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.fb-title { font-family: var(--display); font-weight: 800; font-size: 18px; margin: 0 8px; }
.fb-help { font-size: 11px; color: var(--dim); flex: 1; min-width: 160px; }
.tool {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255,255,255,0.03); font-size: 12px; white-space: nowrap; transition: border-color .15s, background .15s;
}
.tool:hover:not(:disabled) { border-color: rgba(255, 179, 92, 0.5); }
.tool.active { border-color: var(--sun); background: rgba(255, 179, 92, 0.15); }
.tool:disabled { opacity: .35; cursor: default; }
.tool.sm { width: 32px; justify-content: center; font-size: 15px; padding: 5px 0; }
.fb-row .btn { padding: 8px 14px; min-width: 0; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.sw { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.sw.planet { background: radial-gradient(circle at 35% 35%, #ffc59a, #c2531c 60%, #3a1205); }
.sw.giant { background: radial-gradient(circle at 35% 35%, #b9d3ff, #2f5fd0 60%, #0a1640); width: 15px; height: 15px; }
.sw.moon { background: radial-gradient(circle at 35% 35%, #e5e7ef, #7c7f8f 60%, #24252c); width: 8px; height: 8px; }
.sw.repel { background: radial-gradient(circle at 35% 35%, #ffd0e8, #ff4fa3 55%, #5a0a35); }
.sw.hole { background: #000; box-shadow: 0 0 0 2px #ff9a4a; width: 9px; height: 9px; }
.sw.worm { background: #0a0418; box-shadow: 0 0 0 2px #a77bff, 0 0 0 4px rgba(120,230,255,.5); width: 8px; height: 8px; }

body.og .modes, body.og .controls { display: none; }
body.og .lede { font-size: 22px; }

@media (max-width: 720px) {
  .fb-help { display: none; }
  .tool { padding: 6px 8px; font-size: 11px; }
  .sep { display: none; }
}

/* ---------- fine aim ---------- */
#nudge { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); display: grid; justify-items: end; gap: 6px; pointer-events: none; }
#aim-readout { font-size: 11px; color: var(--dim); letter-spacing: .06em; font-variant-numeric: tabular-nums; }
.nudge-pad { display: none; grid-template-columns: repeat(2, 44px); gap: 6px; pointer-events: auto; }
.nudge-pad button { height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 18px; touch-action: none; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.nudge-pad button:active { border-color: var(--sun); background: rgba(255,179,92,.15); }
#nudge-launch { grid-column: span 2; font-size: 12px !important; letter-spacing: .12em; text-transform: uppercase; background: rgba(255,179,92,.16) !important; border-color: rgba(255,179,92,.5) !important; }
@media (pointer: coarse) {
  #nudge { left: 50%; right: auto; transform: translateX(-50%); justify-items: center; }
  .nudge-pad { display: grid; grid-template-columns: repeat(4, 46px) 86px; }
  #nudge-launch { grid-column: auto; }
  #hint { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 74px); }
}

/* ---------- hangar ---------- */
.hangar-wrap { display: flex; align-items: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.hangar-label { font-size: 11px; color: var(--dim); letter-spacing: .2em; text-transform: uppercase; }
#hangar { display: flex; gap: 6px; flex-wrap: wrap; }
.skin { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px 5px 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-size: 11px; color: var(--dim); }
.skin i { width: 22px; height: 8px; border-radius: 99px; display: block; }
.skin.on { border-color: var(--sun); color: var(--ink); }
.skin:disabled { opacity: .45; cursor: default; }
.skin:disabled i { filter: grayscale(1) brightness(.6); }
body.og .hangar-wrap { display: none; }

/* ---------- full screen (touch) ---------- */
#btn-full { display: none; }
#btn-full .off { display: none; }
#btn-full.active .on { display: none; }
#btn-full.active .off { display: block; }
@media (pointer: coarse) { #btn-full { display: grid; } }

body.full #hud { padding-top: max(6px, env(safe-area-inset-top)); padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
body.full .icon { width: 32px; height: 32px; border-radius: 10px; background: rgba(12, 14, 30, 0.45); }
body.full .icon svg { width: 16px; height: 16px; }
body.full #lvl-name, body.full #shots .sl { display: none; }
body.full #shots { margin-right: 0; }
body.full .hud-mid { top: calc(max(6px, env(safe-area-inset-top)) + 40px); }
body.full #hint { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 62px); font-size: 12px; text-shadow: 0 1px 6px #000; }
body.full #nudge { bottom: max(8px, env(safe-area-inset-bottom)); }
body.full .nudge-pad button { height: 40px; background: rgba(12, 14, 30, 0.5); }
body.full #aim-readout { text-shadow: 0 1px 4px #000; }
@media (pointer: coarse) and (orientation: landscape) {
  body.full #nudge { left: auto; right: max(8px, env(safe-area-inset-right)); bottom: 50%; transform: translateY(50%); justify-items: center; }
  body.full .nudge-pad { grid-template-columns: repeat(2, 44px); }
  body.full #nudge-launch { grid-column: span 2; }
  body.full #hint { bottom: max(8px, env(safe-area-inset-bottom)); max-width: 50vw; }
}

/* ---------- cookie consent ---------- */
.cookie-link { margin-top: 14px; font-size: 11px; letter-spacing: 0.06em; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--faint); }
body.og .cookie-link, body.og #consent { display: none !important; }
#consent {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; display: flex; justify-content: center;
  padding: 0 max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  pointer-events: none; touch-action: pan-y; user-select: text; -webkit-user-select: text;
}
.consent-card {
  pointer-events: auto; width: min(620px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 20px 22px 18px; border-radius: 20px; background: rgba(12, 14, 30, 0.94);
  border: 1px solid var(--line); box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  animation: rise .45s cubic-bezier(.2, .9, .3, 1.2);
}
.consent-card .kicker { margin-bottom: 6px; }
.consent-text { margin: 0; font-size: 13px; line-height: 1.6; color: var(--dim); }
.consent-prefs { display: grid; gap: 8px; margin: 16px 0 2px; }
.pref {
  position: relative; display: flex; align-items: center; gap: 16px; padding: 12px 14px;
  border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); cursor: pointer;
}
.pref:has(input:disabled) { cursor: default; }
.pref-text { flex: 1; min-width: 0; display: grid; gap: 3px; }
.pref-name { font-family: var(--display); font-weight: 700; font-size: 15px; color: var(--ink); }
.pref-sub { font-size: 11px; line-height: 1.5; color: var(--dim); }
.pref-sub code { font-family: var(--mono); color: var(--sun-hi); }
.pref input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch {
  flex: none; width: 40px; height: 22px; border-radius: 999px; background: var(--faint); position: relative;
  transition: background .2s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink); transition: transform .2s;
}
.pref input:checked + .switch { background: var(--sun); }
.pref input:checked + .switch::after { transform: translateX(18px); background: #1a0f02; }
.pref input:disabled + .switch { opacity: 0.55; }
.pref input:focus-visible + .switch { outline: 2px solid var(--teal); outline-offset: 2px; }
.consent-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.consent-actions .btn { min-width: 0; }
.consent-actions .btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
@media (max-width: 520px) {
  .consent-card { padding: 18px 16px 16px; }
  .consent-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .consent-actions .btn.primary { grid-column: 1 / -1; order: -1; }
}
