:root {
  color-scheme: dark;
  --bg: #0b0a2a;
  --ink: #f2f6ff;
  --dim: #9aa6d6;
  --cyan: #3ce8ff;
  --pink: #ff7ae0;
  --yellow: #ffe14d;
  --panel: rgba(10, 10, 38, 0.82);
  --line: rgba(120, 200, 255, 0.35);
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: var(--font); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none; touch-action: none;
}
canvas { position: fixed; inset: 0; display: block; width: 100%; height: 100dvh; touch-action: none; }
#probe { position: fixed; bottom: 0; left: 0; width: 0; height: env(safe-area-inset-bottom, 0px); visibility: hidden; pointer-events: none; }

/* ───── HUD ───── */
#hud {
  position: fixed; top: 0; left: 0; right: 0; height: calc(54px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(10px, env(safe-area-inset-right, 0px)) 0 max(10px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; gap: 10px; pointer-events: none; max-width: 640px; margin: 0 auto;
}
.hud-cell { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.hud-cell.mid { align-items: center; text-align: center; }
.lbl { font-size: 10px; font-weight: 800; letter-spacing: 0.14em; color: var(--dim); white-space: nowrap; }
.num { font-size: 22px; font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums; line-height: 1.1; text-shadow: 0 0 12px rgba(60, 232, 255, 0.7); white-space: nowrap; }
.num.small { font-size: 16px; }
.num.bump { animation: bump 0.18s ease-out; }
@keyframes bump { 50% { transform: scale(1.18); color: var(--yellow); } }
.lives { display: flex; gap: 4px; height: 24px; align-items: center; }
.lives i { width: 11px; height: 11px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff, var(--cyan) 60%); box-shadow: 0 0 8px var(--cyan); }
.lives i.off { background: rgba(255, 255, 255, 0.14); box-shadow: none; }
.hud-btns { display: flex; gap: 6px; pointer-events: auto; }
.icon {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: rgba(10, 10, 38, 0.6);
  color: var(--ink); font: 900 18px var(--font); cursor: pointer; touch-action: manipulation;
}
.icon.off { color: #5a6390; text-decoration: line-through; }
.icon:active { transform: scale(0.94); }
body.side #hud {
  right: auto; width: 150px; height: auto; top: 50%; transform: translateY(-50%); flex-direction: column; align-items: flex-start; gap: 14px;
  padding: 0 0 0 max(14px, env(safe-area-inset-left, 0px));
}
body.side .hud-cell.mid { align-items: flex-start; text-align: left; }

/* ───── overlays ───── */
.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: max(12px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) max(12px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  background: radial-gradient(ellipse at center, rgba(8, 6, 34, 0.72), rgba(4, 3, 18, 0.9));
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade 0.22s ease-out; touch-action: pan-y;
}
.overlay.clear { background: radial-gradient(ellipse at center, rgba(8, 6, 34, 0.55), rgba(4, 3, 18, 0.75)); }
@keyframes fade { from { opacity: 0; } }
.panel {
  width: min(440px, 100%); max-height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 22px 20px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 0 40px rgba(60, 232, 255, 0.18), inset 0 0 30px rgba(120, 80, 255, 0.12);
  display: flex; flex-direction: column; gap: 12px; align-items: stretch; animation: rise 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes rise { from { transform: translateY(18px) scale(0.96); opacity: 0; } }
.title-panel { background: none; border: 0; box-shadow: none; }
#scr-title { background: radial-gradient(ellipse at center, rgba(8, 6, 34, 0.5), rgba(4, 3, 18, 0.8)); backdrop-filter: blur(1.5px); -webkit-backdrop-filter: blur(1.5px); }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 30px; font-weight: 900; font-style: italic; letter-spacing: 0.04em; text-shadow: 0 0 18px var(--cyan); }
h3 { font-size: 12px; letter-spacing: 0.16em; color: var(--dim); text-transform: uppercase; margin-top: 4px; }
.sub { font-size: 14px; line-height: 1.45; color: var(--dim); }
.sub b { color: var(--ink); }
.logo {
  font-size: clamp(36px, 11vw, 60px); font-weight: 900; font-style: italic; letter-spacing: -0.02em; line-height: 1;
  display: flex; align-items: center; justify-content: center; white-space: nowrap;
  filter: drop-shadow(0 0 18px rgba(60, 232, 255, 0.75)) drop-shadow(0 4px 0 rgba(120, 40, 255, 0.55));
}
.logo span { background: linear-gradient(180deg, #fff 10%, var(--cyan) 55%, #7a5cff 100%); -webkit-background-clip: text; background-clip: text; color: transparent; padding: 0 0.06em; }
.logo span:last-child { background-image: linear-gradient(180deg, #fff 10%, var(--pink) 55%, #ff4d6d 100%); }
.logo i { font-style: normal; font-size: 0.62em; color: var(--yellow); margin: 0 -0.08em; animation: zap 1.6s infinite; text-shadow: 0 0 20px var(--yellow); }
@keyframes zap { 0%, 100% { transform: scale(1) rotate(-6deg); } 8% { transform: scale(1.35) rotate(8deg); } 16% { transform: scale(1) rotate(-6deg); } }
.tag { font-size: 13px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.best { font-size: 14px; font-weight: 800; color: var(--yellow); min-height: 18px; }
.who, .tip { font-size: 12px; color: var(--dim); min-height: 15px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.btn {
  min-height: 48px; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--cyan); cursor: pointer; touch-action: manipulation;
  background: linear-gradient(180deg, rgba(60, 232, 255, 0.22), rgba(60, 100, 255, 0.12)); color: var(--ink);
  font: 900 14px var(--font); letter-spacing: 0.08em; box-shadow: 0 0 14px rgba(60, 232, 255, 0.25); transition: transform 0.08s, box-shadow 0.15s;
}
.btn:hover { box-shadow: 0 0 22px rgba(60, 232, 255, 0.55); }
.btn:active { transform: scale(0.96); }
.btn.big {
  min-height: 62px; font-size: 22px; font-style: italic; border-color: #fff; color: #0a0a22;
  background: linear-gradient(180deg, #fff, var(--cyan) 45%, #6a7cff); box-shadow: 0 0 30px rgba(60, 232, 255, 0.6), 0 5px 0 rgba(60, 40, 200, 0.7);
  animation: throb 1.4s ease-in-out infinite;
}
@keyframes throb { 50% { box-shadow: 0 0 44px rgba(255, 122, 224, 0.8), 0 5px 0 rgba(60, 40, 200, 0.7); } }
.btn.ghost { border-color: var(--line); background: rgba(255, 255, 255, 0.04); box-shadow: none; font-size: 12px; letter-spacing: 0.03em; padding: 10px 6px; color: var(--dim); }
.btn.ghost.off { color: #5a6390; }

/* the cover picture (?cover=1): a huge logo over a zoomed-in board */
#cover { position: fixed; inset: 0; pointer-events: none; }
#cover .logo {
  position: absolute; left: 0; right: 0; top: 42%; transform: translateY(-50%); font-size: min(12.6vw, 30vh); padding: 0.32em 0;
  background: radial-gradient(ellipse 60% 70% at center, rgba(4, 3, 20, 0.86), rgba(4, 3, 20, 0.55) 60%, transparent 100%);
}
#cover .logo i { animation: none; transform: rotate(-6deg) scale(1.15); }

/* level select */
#level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
#level-grid .wname { grid-column: 1 / -1; font-size: 11px; font-weight: 800; letter-spacing: 0.16em; text-align: left; margin-top: 4px; }
#level-grid button {
  min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--ink);
  font: 900 16px var(--font); cursor: pointer; touch-action: manipulation;
}
#level-grid button:disabled { color: #4a5280; border-color: rgba(255, 255, 255, 0.08); background: none; cursor: default; }
#level-grid button.done { box-shadow: inset 0 -3px 0 currentColor; }

/* how to play */
.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; text-align: left; }
.chip { display: flex; align-items: center; gap: 8px; font-size: 12px; line-height: 1.25; color: var(--dim); }
.chip b { color: var(--ink); display: block; font-size: 12px; }
.chip .pic { flex: none; width: 34px; height: 17px; border-radius: 9px; display: grid; place-items: center; font-weight: 900; font-size: 11px; color: #0a0a22; border: 1px solid rgba(255, 255, 255, 0.7); }
.chip .pic.brick { border-radius: 4px; }

/* tallies */
.tally { display: flex; flex-direction: column; gap: 5px; }
.tally div { display: flex; justify-content: space-between; font-size: 15px; font-weight: 700; color: var(--dim); animation: slide 0.3s both; }
.tally div b { color: var(--ink); font-variant-numeric: tabular-nums; }
.tally div.gold, .tally div.gold b { color: var(--yellow); }
.tally div:nth-child(2) { animation-delay: 0.15s; } .tally div:nth-child(3) { animation-delay: 0.3s; } .tally div:nth-child(4) { animation-delay: 0.45s; }
@keyframes slide { from { transform: translateX(-16px); opacity: 0; } }
.total { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--line); padding-top: 10px; }
.total span { font-size: 12px; font-weight: 800; letter-spacing: 0.14em; color: var(--dim); }
.total b { font-size: 30px; font-weight: 900; font-style: italic; font-variant-numeric: tabular-nums; text-shadow: 0 0 14px var(--cyan); }
.total.big { flex-direction: column; align-items: center; border: 0; padding: 0; }
.total.big b { font-size: 48px; }
.rank { font-size: 16px; font-weight: 800; color: var(--pink); min-height: 20px; }
.rank.top { font-size: 20px; color: var(--yellow); animation: bump 0.6s ease-out 3; }
.shine { background: linear-gradient(90deg, var(--cyan), #fff, var(--pink), var(--yellow), var(--cyan)); background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; text-shadow: none; animation: sweep 2.2s linear infinite; filter: drop-shadow(0 0 12px rgba(255, 122, 224, 0.6)); }
@keyframes sweep { to { background-position: 300% 0; } }

@media (max-height: 520px) {
  .panel { padding: 12px 16px; gap: 8px; }
  .logo { font-size: clamp(34px, 12vh, 56px); }
  .btn.big { min-height: 50px; font-size: 18px; }
  .tag, .tip { display: none; }
  h2 { font-size: 22px; }
  .total.big b { font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) { .btn.big, .logo i, .shine { animation: none; } }
