:root {
  --ink: #f4f0ff;
  --dim: rgba(244, 240, 255, 0.62);
  --panel: rgba(12, 5, 30, 0.72);
  --line: rgba(255, 255, 255, 0.14);
  --cyan: #38f2ff;
  --pink: #ff4fd8;
  --gold: #ffe14d;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #0b0420; color: var(--ink);
  font-family: var(--font); -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent; touch-action: none; overscroll-behavior: none;
}
canvas#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; }
.screen {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 16px; pointer-events: auto; overflow-y: auto;
  background: radial-gradient(ellipse at center, rgba(10, 2, 30, 0.25), rgba(5, 1, 15, 0.6));
}
#title.screen { background: linear-gradient(180deg, rgba(5,1,15,0.55), rgba(5,1,15,0.15) 50%, rgba(5,1,15,0.55)); }
.hidden { display: none !important; }
.panel {
  width: min(560px, 100%); margin: auto; padding: 22px 24px; border-radius: 22px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 0 0 1px rgba(56, 242, 255, 0.08), 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 80px rgba(255, 79, 216, 0.12);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); text-align: center;
  animation: pop 0.28s cubic-bezier(.2, 1.4, .4, 1);
}
.panel.small { width: min(360px, 100%); }
@keyframes pop { from { transform: scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }
.logo {
  margin: 0; font-size: clamp(44px, 10vw, 76px); font-weight: 900; letter-spacing: 0.06em; line-height: 1;
  font-style: italic; color: #fff;
  text-shadow: 0 0 12px var(--cyan), 0 0 34px rgba(56, 242, 255, 0.6), 3px 3px 0 var(--pink);
}
.logo-b { color: transparent; -webkit-text-stroke: 2px #fff; text-shadow: 0 0 18px var(--pink), 0 0 40px rgba(255, 79, 216, 0.7); }
.tag { margin: 8px 0 16px; color: var(--dim); font-size: 15px; }
h2 { margin: 4px 0 12px; font-size: 28px; font-weight: 900; letter-spacing: 0.02em; }
h3 { margin: 14px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--dim); }
.kicker { margin: 0; color: var(--gold); text-transform: uppercase; letter-spacing: 0.18em; font-size: 12px; font-weight: 800; }
.hint { color: var(--dim); font-size: 14px; margin: 6px 0 10px; min-height: 1.2em; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.col { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.btn {
  font: 800 16px var(--font); color: var(--ink); padding: 12px 20px; border-radius: 14px; cursor: pointer;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); min-width: 110px;
  transition: transform 0.12s, background 0.12s, box-shadow 0.12s;
}
.btn:hover, .btn:focus-visible { background: rgba(255, 255, 255, 0.16); transform: translateY(-1px); outline: none; }
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--cyan), var(--pink)); color: #12042a; border: 0;
  box-shadow: 0 0 24px rgba(56, 242, 255, 0.45), 0 0 40px rgba(255, 79, 216, 0.3);
}
.btn.primary:disabled { filter: grayscale(1) brightness(0.6); cursor: not-allowed; box-shadow: none; }
.btn.on { border-color: #5dff9a; color: #5dff9a; }
.btn.ghost { background: transparent; }
.howto { margin: 16px 0 0; color: var(--dim); font-size: 13px; line-height: 1.6; }
.howto b { color: var(--ink); }

.level-picker { display: flex; align-items: stretch; gap: 10px; }
.arrow {
  flex: 0 0 44px; font-size: 34px; color: var(--ink); background: rgba(255,255,255,0.06); border: 1px solid var(--line);
  border-radius: 14px; cursor: pointer; font-weight: 300;
}
.arrow:hover { background: rgba(255,255,255,0.14); }
.arrow:disabled { opacity: 0.25; cursor: default; }
.level-card {
  flex: 1; border-radius: 18px; padding: 16px 18px; text-align: left; position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--c0, #2a0a4a), var(--c1, #5a1a6e)); border: 1px solid rgba(255,255,255,0.2);
  min-height: 132px;
}
.level-card::after {
  content: ''; position: absolute; right: -30px; top: -30px; width: 130px; height: 130px; border-radius: 50%;
  background: radial-gradient(circle, var(--sun, #ffd36b), transparent 70%); opacity: 0.55;
}
.level-card .num { font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(255,255,255,0.7); font-weight: 800; }
.level-card .name { font-size: 26px; font-weight: 900; margin: 2px 0 6px; }
.badge { display: inline-block; font-size: 11px; font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; padding: 3px 8px; border-radius: 99px; background: rgba(0,0,0,0.35); }
.bars { margin-top: 10px; display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 70px 1fr 40px; align-items: center; gap: 8px; font-size: 12px; color: rgba(255,255,255,0.8); font-weight: 700; }
.bar i { display: block; height: 7px; border-radius: 4px; background: rgba(0,0,0,0.35); overflow: hidden; }
.bar i b { display: block; height: 100%; background: linear-gradient(90deg, #fff, var(--accent, #38f2ff)); border-radius: 4px; }
.bar.p i b { background: linear-gradient(90deg, #b8ffd0, #5dff9a); }
.meta { margin-top: 8px; font-size: 12px; color: rgba(255,255,255,0.7); }
.lock { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; background: rgba(5,1,15,0.62); font-weight: 800; z-index: 1; }
.lock span { font-size: 30px; }
.dots { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.25); }
.dots i.done { background: #5dff9a; }
.dots i.sel { background: #fff; box-shadow: 0 0 10px #fff; }

.garage-panel canvas { width: 120px; height: 120px; display: block; margin: 0 auto; }
.swatches { display: grid; grid-template-columns: repeat(5, 46px); gap: 8px; justify-content: center; }
.sw {
  width: 46px; height: 46px; border-radius: 12px; border: 2px solid rgba(255,255,255,0.15); cursor: pointer; position: relative;
  background: #222; padding: 0;
}
.sw.sel { border-color: #fff; box-shadow: 0 0 14px rgba(255,255,255,0.6); }
.sw.locked { filter: grayscale(1) brightness(0.45); }
.sw.locked::after { content: '\1F512'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 16px; filter: none; }
.sw canvas { width: 100%; height: 100%; border-radius: 10px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 4px; }
.stats div { background: rgba(255,255,255,0.06); border-radius: 12px; padding: 10px 4px; }
.stats b { display: block; font-size: 22px; font-weight: 900; }
.stats span { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.1em; }

.iconbtn {
  position: absolute; width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(10, 3, 25, 0.5); color: var(--ink); font-size: 16px; cursor: pointer; pointer-events: auto;
}
#muteBtn { right: max(12px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top)); font-size: 20px; }
#muteBtn.off { opacity: 0.45; text-decoration: line-through; }
#hudBtns .iconbtn { right: calc(62px + env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top)); font-size: 13px; letter-spacing: -2px; }
#practiceBtns { position: absolute; left: 0; right: 0; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; justify-content: center; gap: 10px; pointer-events: none; }
.pbtn {
  pointer-events: auto; font: 800 14px var(--font); color: #5dff9a; padding: 10px 14px; border-radius: 12px;
  border: 1px solid rgba(93, 255, 154, 0.4); background: rgba(5, 20, 12, 0.55); cursor: pointer;
}
.pbtn kbd { font: inherit; opacity: 0.6; margin-left: 4px; }
#toast {
  position: absolute; left: 50%; top: 64px; transform: translate(-50%, -20px); opacity: 0; transition: 0.3s;
  background: linear-gradient(135deg, rgba(56,242,255,0.9), rgba(255,79,216,0.9)); color: #12042a;
  font-weight: 900; padding: 10px 18px; border-radius: 99px; white-space: nowrap; max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 720px) {
  .screen { padding-top: 58px; }
}
@media (max-width: 480px) {
  .panel { padding: 18px 14px; }
  .btn { min-width: 0; padding: 11px 16px; }
  .level-card .name { font-size: 21px; }
  .howto { font-size: 12px; }
  .bar { grid-template-columns: 62px 1fr 36px; }
}
@media (max-height: 560px) {
  .tag, .dots { display: none; }
  .howto { margin-top: 8px; }
  .row { margin-top: 10px; }
  .panel { padding: 14px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .panel { animation: none; }
  #toast { transition: none; }
}
#pauseBtn { display: flex; align-items: center; justify-content: center; gap: 5px; }
#pauseBtn .pz { display: block; width: 5px; height: 16px; border-radius: 2px; background: var(--ink); }
