:root {
  --ink: #f4efff;
  --ink-dim: rgba(244, 239, 255, 0.62);
  --ink-faint: rgba(244, 239, 255, 0.32);
  --glass: rgba(40, 32, 88, 0.38);
  --glass-strong: rgba(34, 27, 78, 0.62);
  --line: rgba(244, 239, 255, 0.16);
  --peach: #ffc4a8;
  --mint: #a8f0d6;
  --lavender: #c9b8ff;
  --gold: #ffe3a3;
  --bg: #16123a;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --ease: cubic-bezier(.4, .0, .2, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Quicksand', 'Nunito', system-ui, -apple-system, sans-serif;
  font-weight: 400;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  touch-action: none;
}

canvas#game {
  position: fixed; inset: 0; width: 100%; height: 100%;
  display: block; touch-action: none;
  cursor: crosshair;
}

button { font: inherit; color: inherit; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-top {
  position: absolute; top: calc(var(--sat) + 12px); left: calc(var(--sal) + 12px); right: calc(var(--sar) + 12px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.level-title {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  font-weight: 300; letter-spacing: .04em; opacity: .85; min-width: 0;
}
#lvl-num { font-size: 11px; letter-spacing: .3em; color: var(--ink-faint); }
#lvl-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 56vw; }

.icon-btn {
  pointer-events: auto; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--glass);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  display: grid; place-items: center; cursor: pointer; padding: 0;
  transition: background .4s var(--ease), transform .4s var(--ease), box-shadow .6s var(--ease);
}
.icon-btn:active { transform: scale(.94); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 1.4; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.icon-btn.pulse { animation: pulse 2.4s var(--ease) infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168, 240, 214, 0); }
  50% { box-shadow: 0 0 0 8px rgba(168, 240, 214, .18); background: rgba(80, 70, 150, .5); }
}

.hud-bottom {
  position: absolute; left: 0; right: 0; bottom: calc(var(--sab) + 18px);
  display: flex; justify-content: center;
}
#fuel { display: flex; gap: 12px; padding: 10px 16px; border-radius: 99px; background: var(--glass); border: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
#fuel i {
  width: 9px; height: 9px; border-radius: 50%; background: var(--peach);
  box-shadow: 0 0 10px rgba(255, 196, 168, .8);
  transition: all .8s var(--ease);
}
#fuel i.used { background: transparent; box-shadow: inset 0 0 0 1px var(--ink-faint); transform: scale(.8); }
#fuel i.par { outline: 1px solid rgba(255,255,255,0); }

#hint {
  position: absolute; left: 50%; bottom: calc(var(--sab) + 72px); transform: translateX(-50%);
  font-weight: 300; font-size: 15px; letter-spacing: .03em; color: var(--ink-dim);
  text-align: center; width: max-content; max-width: calc(100vw - 48px);
  opacity: 0; transition: opacity 1.4s var(--ease);
}
#hint.show { opacity: 1; }

/* ---------- Панели ---------- */
.panel {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 16px) calc(var(--sab) + 16px) calc(var(--sal) + 16px);
  background: radial-gradient(ellipse at center, rgba(22, 18, 58, .35), rgba(12, 10, 34, .72));
  animation: panelIn 1s var(--ease) both;
  overflow-y: auto; touch-action: pan-y;
}
@keyframes panelIn { from { opacity: 0; } to { opacity: 1; } }
.panel-inner {
  width: 100%; max-width: 360px; text-align: center;
  display: flex; flex-direction: column; align-items: stretch; gap: 14px;
  animation: rise 1.1s var(--ease) both;
}
.panel-inner.wide { max-width: 560px; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

h1 {
  font-weight: 300; font-size: clamp(30px, 8vw, 44px); line-height: 1.08; margin: 0 0 4px;
  letter-spacing: .02em;
}
h1 span { background: linear-gradient(90deg, var(--peach), var(--lavender), var(--mint)); -webkit-background-clip: text; background-clip: text; color: transparent; font-weight: 400; }
h2 { font-weight: 300; font-size: 26px; margin: 0 0 6px; letter-spacing: .04em; }
.sub { margin: 0 0 18px; color: var(--ink-dim); font-weight: 300; letter-spacing: .03em; }
.note { margin: 0; font-size: 13px; color: var(--ink-faint); min-height: 1em; }
.stars-total { margin: 8px 0 0; color: var(--ink-faint); font-size: 14px; letter-spacing: .08em; }

.menu-buttons { display: flex; flex-direction: column; gap: 10px; }
.btn {
  height: 52px; border-radius: 26px; border: 1px solid var(--line);
  background: var(--glass); cursor: pointer; font-size: 17px; font-weight: 400; letter-spacing: .04em;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  transition: background .5s var(--ease), transform .3s var(--ease);
}
.btn:hover { background: var(--glass-strong); }
.btn:active { transform: scale(.97); }
.btn.primary {
  background: linear-gradient(100deg, rgba(255, 196, 168, .9), rgba(201, 184, 255, .9));
  color: #2a1f5c; border-color: transparent; font-weight: 500;
  box-shadow: 0 6px 28px rgba(255, 196, 168, .22);
}
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-dim); height: 44px; }

/* Сетка уровней */
#level-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 10px; margin: 6px 0 10px;
}
.lvl {
  aspect-ratio: 1; border-radius: 18px; border: 1px solid var(--line); background: var(--glass);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; font-size: 18px; font-weight: 400;
  transition: background .5s var(--ease), transform .3s var(--ease);
}
.lvl:active { transform: scale(.95); }
.lvl.locked { opacity: .3; cursor: default; }
.lvl.current { border-color: rgba(168, 240, 214, .6); box-shadow: 0 0 18px rgba(168, 240, 214, .18); }
.lvl .mini { display: flex; gap: 3px; }
.lvl .mini b { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-faint); opacity: .5; }
.lvl .mini b.on { background: var(--gold); opacity: 1; box-shadow: 0 0 6px var(--gold); }

/* Переключатели */
.toggle {
  display: flex; align-items: center; justify-content: space-between; height: 52px; padding: 0 18px;
  border-radius: 26px; background: var(--glass); border: 1px solid var(--line); cursor: pointer;
  font-size: 17px; font-weight: 300;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { width: 46px; height: 26px; border-radius: 13px; background: rgba(255,255,255,.12); position: relative; transition: background .5s var(--ease); }
.toggle i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); transition: transform .5s var(--ease); }
.toggle input:checked + i { background: linear-gradient(90deg, var(--mint), var(--lavender)); }
.toggle input:checked + i::after { transform: translateX(20px); }

/* Звёзды доставки */
.star-row { display: flex; justify-content: center; gap: 22px; margin: 6px 0 16px; }
.star-item { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.star-item small { font-size: 12px; color: var(--ink-faint); letter-spacing: .05em; }
.star {
  width: 40px; height: 40px; opacity: .22;
  background: var(--ink);
  clip-path: polygon(50% 2%, 61% 36%, 97% 38%, 68% 59%, 79% 94%, 50% 73%, 21% 94%, 32% 59%, 3% 38%, 39% 36%);
  transform: scale(.8); transition: all 1s var(--ease);
}
.star.on { opacity: 1; background: linear-gradient(135deg, #fff3cf, var(--gold) 50%, var(--peach)); transform: scale(1); filter: drop-shadow(0 0 10px rgba(255, 227, 163, .8)); }

#fade {
  position: fixed; inset: 0; background: #0f0c2c; pointer-events: none;
  opacity: 1; transition: opacity 1.4s var(--ease);
}
#fade.clear { opacity: 0; }

/* Невидимый переключатель для тактильного отклика iOS */
.haptic-proxy { position: fixed; left: -100px; top: -100px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  .panel, .panel-inner { animation-duration: .01s; }
}
