:root {
  color-scheme: light dark;
  --bg: #eef1f6; --fg: #111827; --panel: #ffffff; --border: #d3d8e2; --accent: #2563eb; --accent-2: #22c55e;
  --muted: #5b6472; --btn: #e6eaf1; --danger: #dc2626; --shadow: 0 10px 30px rgba(15, 23, 42, .12);
  /* in-game chrome is always dark, like a game panel */
  --game-bg: #0f1420; --game-panel: #161c2c; --game-border: #2a3348; --game-fg: #e8ecf5; --game-muted: #95a0b8;
  /* skill accents */
  --c-climber: #f59e0b; --c-floater: #22d3ee; --c-bomber: #ef4444; --c-blocker: #a855f7;
  --c-builder: #eab308; --c-basher: #14b8a6; --c-miner: #c2703a; --c-digger: #22c55e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17; --fg: #e5e7eb; --panel: #151a24; --border: #2a3140; --accent: #60a5fa;
    --muted: #9ca3af; --btn: #1f2735; --danger: #ef4444; --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.4;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
#app { min-height: 100dvh; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
button { font: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ================================================================ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .6rem 1.1rem; border-radius: .8rem; border: 1px solid var(--border); background: var(--btn); color: var(--fg);
  cursor: pointer; font-weight: 600; transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.primary {
  background: linear-gradient(135deg, #3b82f6, #2563eb 55%, #1d4ed8); color: #fff; border-color: transparent;
  box-shadow: 0 6px 18px rgba(37, 99, 235, .35), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.btn.big { padding: .85rem 1.4rem; font-size: 1.05rem; border-radius: 1rem; }
.btn svg { width: 20px; height: 20px; }

/* ================================================================ menu */
#menu { padding-bottom: 4rem; overflow-x: clip; max-width: 100vw; }
.hero canvas { max-width: 100%; }
.hero {
  position: relative; height: clamp(200px, 32vh, 300px); overflow: hidden;
  background: linear-gradient(#7fbcff, #e9f4ff);
  box-shadow: inset 0 -30px 40px -30px rgba(0, 0, 0, .35);
}
@media (prefers-color-scheme: dark) { .hero { background: linear-gradient(#0a1430, #22386a); } }
#hero { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.hero-text {
  position: absolute; left: 0; right: 0; top: 10%; text-align: center; pointer-events: none; padding: 0 1rem;
}
.hero-text h1 {
  margin: 0; font-size: clamp(2.6rem, 9vw, 4.5rem); font-weight: 900; letter-spacing: .04em; line-height: 1;
  color: #fff; text-transform: uppercase;
  text-shadow: 0 2px 0 #1d4ed8, 0 4px 0 #1e3a8a, 0 8px 22px rgba(0, 0, 0, .35);
}
.hero-text .tag {
  margin: .5rem auto 0; display: inline-block; font-weight: 600; color: #fff;
  background: rgba(15, 23, 42, .45); backdrop-filter: blur(6px); padding: .3rem .8rem; border-radius: 999px; font-size: .95rem;
}
.menu-body { max-width: 780px; margin: 0 auto; padding: 1rem 1rem 0; }
#btn-play { width: 100%; max-width: 100%; margin: -1.6rem 0 1.2rem; position: relative; z-index: 1; font-size: 1.1rem; overflow: hidden; }
#btn-play span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-title { font-size: .85rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 0 .6rem .2rem; }
.levels { display: grid; gap: .7rem; grid-template-columns: 1fr; margin: 0 0 1.4rem; }
@media (min-width: 620px) { .levels { grid-template-columns: 1fr 1fr; } }
.level {
  text-align: left; display: flex; gap: .8rem; align-items: stretch; padding: .55rem; border-radius: 1rem;
  border: 1px solid var(--border); background: var(--panel); color: var(--fg); cursor: pointer; box-shadow: var(--shadow);
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
  animation: rise .45s ease both;
}
.level:hover, .level:focus-visible { transform: translateY(-2px); border-color: var(--accent); outline: none; }
.level:active { transform: translateY(0) scale(.99); }
.level .thumb { width: 112px; height: 63px; border-radius: .6rem; flex: 0 0 auto; object-fit: cover; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
@media (min-width: 420px) { .level .thumb { width: 128px; height: 72px; } }
.level .body { display: flex; flex-direction: column; gap: .2rem; min-width: 0; flex: 1; }
.lvl-top { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.lvl-top strong { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .98rem; }
.level .num {
  display: inline-grid; place-items: center; width: 1.7em; height: 1.7em; border-radius: .5em; font-weight: 800; font-size: .85rem;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; flex: 0 0 auto;
}
.level.done .num { background: linear-gradient(135deg, #34d399, #059669); }
.stars { display: inline-flex; gap: 1px; font-size: .9rem; line-height: 1; color: color-mix(in srgb, var(--muted) 45%, transparent); }
.stars .on { color: #f59e0b; text-shadow: 0 0 6px rgba(245, 158, 11, .5); }
.level .meta { font-size: .76rem; color: var(--muted); }
.skill-icons { display: flex; gap: .3rem; flex-wrap: wrap; margin: .2rem 0 0; }
.chip {
  display: inline-flex; align-items: center; gap: .25rem; font-size: .74rem; padding: .12rem .45rem .12rem .3rem; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--c, var(--border)) 45%, transparent); background: color-mix(in srgb, var(--c, var(--border)) 14%, transparent); color: var(--fg);
}
.chip svg { width: 14px; height: 14px; color: var(--c, currentColor); }
.chip-climber { --c: var(--c-climber); } .chip-floater { --c: var(--c-floater); } .chip-bomber { --c: var(--c-bomber); } .chip-blocker { --c: var(--c-blocker); }
.chip-builder { --c: var(--c-builder); } .chip-basher { --c: var(--c-basher); } .chip-miner { --c: var(--c-miner); } .chip-digger { --c: var(--c-digger); }
.help { border: 1px solid var(--border); border-radius: 1rem; background: var(--panel); padding: .2rem 1rem; box-shadow: var(--shadow); }
.help summary { cursor: pointer; font-weight: 700; padding: .7rem 0; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.help summary::after { content: "+"; font-size: 1.3rem; color: var(--muted); }
.help[open] summary::after { content: "–"; }
.help ul { padding-left: 1.2rem; margin: 0 0 .8rem; }
.help li { margin: .35rem 0; }
.help .skill-icons { margin: 0 0 .9rem; }
kbd { font: .8em ui-monospace, monospace; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 .35em; }
.credits { text-align: center; color: var(--muted); font-size: .78rem; margin: 1.4rem 0 0; }
.error { background: color-mix(in srgb, var(--danger) 15%, transparent); border: 1px solid var(--danger); padding: .7rem 1rem; border-radius: .8rem; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ================================================================ game */
#game { display: flex; flex-direction: column; height: 100dvh; background: var(--game-bg); color: var(--game-fg); }
#stage { position: relative; flex: 1; min-height: 0; background: #000; }
#c { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; user-select: none; }

/* glassy HUD floating over the top of the playfield */
#hud {
  position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: .5rem; padding: .4rem .5rem;
  font-size: .8rem; color: #fff; pointer-events: none;
  background: linear-gradient(rgba(5, 10, 20, .55), rgba(5, 10, 20, 0));
}
#hud > * { pointer-events: auto; }
.hud-btn {
  width: 36px; height: 36px; border: 0; border-radius: .7rem; display: grid; place-items: center; cursor: pointer; padding: 0;
  background: rgba(15, 23, 42, .55); color: #fff; backdrop-filter: blur(8px); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}
.hud-btn svg { width: 20px; height: 20px; }
#hud .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 0 1 auto; text-shadow: 0 1px 2px rgba(0, 0, 0, .6); }
@media (max-width: 560px) { #hud .name { display: none; } }
.pills { display: flex; gap: .35rem; flex: 0 0 auto; }
.pill {
  display: inline-flex; align-items: center; gap: .35rem; padding: .3rem .6rem; border-radius: 999px; white-space: nowrap;
  background: rgba(15, 23, 42, .55); backdrop-filter: blur(8px); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
  font-variant-numeric: tabular-nums; position: relative; overflow: hidden;
}
.pill b { font-weight: 800; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.pill .dot.out { background: #60a5fa; box-shadow: 0 0 6px #60a5fa; }
.pill .dot.home { background: #34d399; box-shadow: 0 0 6px #34d399; }
.pill .bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255, 255, 255, .12); }
.pill .bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #34d399, #a7f3d0); transition: width .3s ease; }
.pill.goal { box-shadow: inset 0 0 0 1px #34d399; }
.pill.time.low { background: rgba(220, 38, 38, .75); animation: pulse 1s ease-in-out infinite; }
#hud-info { margin-left: auto; min-width: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: rgba(255, 255, 255, .85); text-shadow: 0 1px 2px rgba(0, 0, 0, .7); }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }

/* bottom panel */
#bar {
  background: linear-gradient(var(--game-panel), var(--game-bg)); border-top: 1px solid var(--game-border);
  padding: .45rem .5rem calc(.45rem + env(safe-area-inset-bottom));
  display: flex; flex-wrap: wrap; gap: .45rem .8rem; justify-content: center; align-items: center;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .35);
}
#skills { display: grid; grid-template-columns: repeat(8, minmax(38px, 1fr)); gap: .3rem; flex: 1 1 320px; max-width: 560px; }
.skill {
  --c: #94a3b8; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: .35rem .1rem .3rem; min-height: 54px; border-radius: .8rem; cursor: pointer; line-height: 1; font-size: .62rem;
  color: var(--game-fg); border: 1px solid var(--game-border);
  background: linear-gradient(#232b3f, #171d2d); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 2px 4px rgba(0, 0, 0, .3);
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease;
}
.skill svg { width: 24px; height: 24px; color: var(--c); filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .4)); }
.skill .count {
  position: absolute; top: -6px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; display: grid; place-items: center;
  font-size: .72rem; font-weight: 800; color: #fff; background: var(--c); box-shadow: 0 2px 6px rgba(0, 0, 0, .4), inset 0 1px 0 rgba(255, 255, 255, .3);
}
.skill .name { display: none; color: var(--game-muted); }
@media (min-width: 760px) { .skill .name { display: block; } .skill { min-height: 62px; } }
.skill:active { transform: translateY(1px) scale(.97); }
.skill.on {
  background: linear-gradient(color-mix(in srgb, var(--c) 70%, #fff 0%), color-mix(in srgb, var(--c) 55%, #000)); border-color: color-mix(in srgb, var(--c) 80%, #fff);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 45%, transparent), 0 0 18px color-mix(in srgb, var(--c) 55%, transparent), inset 0 1px 0 rgba(255, 255, 255, .35);
  transform: translateY(-2px);
}
.skill.on svg, .skill.on .name { color: #fff; }
.skill.on .count { background: #fff; color: #111; }
.skill.empty:not(.on) { opacity: .45; }
.skill.empty:not(.on) .count { background: #475569; }
.skill:disabled { opacity: .2; cursor: default; }
.skill-climber { --c: var(--c-climber); } .skill-floater { --c: var(--c-floater); } .skill-bomber { --c: var(--c-bomber); } .skill-blocker { --c: var(--c-blocker); }
.skill-builder { --c: var(--c-builder); } .skill-basher { --c: var(--c-basher); } .skill-miner { --c: var(--c-miner); } .skill-digger { --c: var(--c-digger); }

#controls { display: flex; gap: .4rem; align-items: center; }
.ctl-group {
  display: flex; align-items: center; gap: .15rem; padding: .15rem; border-radius: 999px;
  background: #0d1220; border: 1px solid var(--game-border); box-shadow: inset 0 2px 6px rgba(0, 0, 0, .5);
}
.ctl {
  width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--game-border); color: var(--game-fg);
  background: linear-gradient(#232b3f, #171d2d); display: grid; place-items: center; cursor: pointer; padding: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 2px 4px rgba(0, 0, 0, .3); transition: transform .12s ease, box-shadow .15s ease;
}
.ctl-group .ctl { width: 34px; height: 34px; border: 0; background: transparent; box-shadow: none; }
.ctl-group .ctl:active { background: rgba(255, 255, 255, .1); }
.ctl svg { width: 20px; height: 20px; }
.ctl.round { width: 44px; height: 44px; }
.ctl:active { transform: scale(.94); }
.ctl.on { background: linear-gradient(#3b82f6, #1d4ed8); border-color: #60a5fa; box-shadow: 0 0 14px rgba(59, 130, 246, .55); color: #fff; }
.ctl.danger { color: #fca5a5; }
.ctl.armed { background: linear-gradient(#ef4444, #b91c1c); border-color: #fca5a5; color: #fff; box-shadow: 0 0 16px rgba(239, 68, 68, .7); animation: pulse .6s ease-in-out infinite; }
.ctl:disabled { opacity: .35; cursor: default; }
.rate { display: flex; flex-direction: column; align-items: center; min-width: 2.4em; line-height: 1; }
.rate b { font-size: .95rem; font-variant-numeric: tabular-nums; }
.rate small { font-size: .55rem; text-transform: uppercase; letter-spacing: .08em; color: var(--game-muted); }

/* ================================================================ overlays */
#overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 10, 20, .55); backdrop-filter: blur(3px); padding: .8rem; overflow: auto; animation: fade .25s ease; }
.card {
  background: var(--panel); color: var(--fg); border-radius: 1.2rem; padding: 0 1.2rem 1.2rem; max-width: 440px; width: 100%;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .5); overflow: hidden; animation: pop .3s cubic-bezier(.2, .9, .3, 1.2);
}
.card-thumb { display: block; width: calc(100% + 2.4rem); margin: 0 -1.2rem .9rem; aspect-ratio: 16 / 9; height: auto; }
.card .eyebrow { margin: .9rem 0 0; font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 700; }
.card h2 { margin: .1rem 0 .5rem; font-size: 1.6rem; letter-spacing: -.01em; }
.card .hint { margin: 0 0 .8rem; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: .4rem 0 .8rem; }
.tile { background: var(--btn); border-radius: .8rem; padding: .5rem .3rem; text-align: center; display: flex; flex-direction: column; gap: .1rem; }
.tile b { font-size: 1.15rem; font-weight: 800; line-height: 1.1; }
.tile span { font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.tile.ok { background: color-mix(in srgb, #22c55e 18%, transparent); } .tile.ok b { color: #16a34a; }
.tile.bad { background: color-mix(in srgb, #ef4444 16%, transparent); } .tile.bad b { color: #dc2626; }
.card .skill-icons { margin: 0 0 .4rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; }
.row .btn.big { flex: 1 1 auto; }
.result-stars { display: flex; justify-content: center; gap: .3rem; font-size: 2.6rem; line-height: 1; margin: .2rem 0 .6rem; color: color-mix(in srgb, var(--muted) 35%, transparent); }
.result-stars .star.on { color: #f59e0b; text-shadow: 0 0 14px rgba(245, 158, 11, .7); animation: star .5s cubic-bezier(.2, .9, .3, 1.4) both; }
.card.won .eyebrow { color: #16a34a; }
.card.lost .eyebrow { color: #dc2626; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes star { from { transform: scale(0) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* keep the feedback button clear of the game chrome */
body.playing > .mf-fab { bottom: auto; top: 48px; width: 34px; height: 34px; font-size: 16px; }
body.playing > .mf-panel { bottom: auto; top: 90px; }

/* ================================================================ rating tabs */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: .35rem; margin: 0 0 .5rem; }
.tab {
  display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .5rem .2rem; border-radius: .8rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel); color: var(--fg); line-height: 1.1;
}
.tab b { font-size: .95rem; }
.tab small { font-size: .7rem; color: var(--muted); }
.tab.on { background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; border-color: transparent; box-shadow: 0 6px 16px rgba(37, 99, 235, .35); }
.tab.on small { color: rgba(255, 255, 255, .85); }
.tier-blurb { margin: 0 0 .7rem .2rem; font-size: .85rem; color: var(--muted); }

/* ================================================================ small screens */
@media (max-width: 480px) {
  .hero { height: clamp(170px, 28vh, 240px); }
  .hero-text { top: 8%; }
  .hero-text .tag { font-size: .8rem; padding: .25rem .6rem; }
  .pill { padding: .25rem .45rem; gap: .25rem; font-size: .74rem; }
  .pill .label { display: none; }
  #hud { gap: .35rem; padding: .35rem .4rem; }
  #hud-info { display: none; }
  #skills { grid-template-columns: repeat(8, minmax(32px, 1fr)); gap: .22rem; }
  .skill { min-height: 48px; padding: .3rem .05rem .25rem; }
  .skill svg { width: 21px; height: 21px; }
  .skill .count { min-width: 17px; height: 17px; font-size: .66rem; top: -5px; right: -3px; }
  .ctl.round { width: 40px; height: 40px; }
  .ctl-group .ctl { width: 30px; height: 30px; }
  .rate b { font-size: .85rem; }
}
/* phones in landscape: keep the whole panel on one short row */
@media (max-height: 520px) and (orientation: landscape) {
  #bar { flex-wrap: nowrap; gap: .4rem; padding: .3rem .5rem calc(.3rem + env(safe-area-inset-bottom)); }
  #skills { flex: 1 1 auto; min-width: 0; max-width: none; grid-template-columns: repeat(8, minmax(30px, 1fr)); gap: .2rem; }
  .skill { min-height: 40px; padding: .2rem .05rem; }
  .skill svg { width: 20px; height: 20px; }
  .skill .name { display: none !important; }
  .skill .count { min-width: 16px; height: 16px; font-size: .62rem; }
  #controls { gap: .3rem; }
  .ctl.round { width: 36px; height: 36px; }
  .ctl-group .ctl { width: 28px; height: 28px; }
  .rate small { display: none; }
  .card-thumb { display: none; }
  .card { padding-top: .2rem; }
  .card h2 { font-size: 1.2rem; }
  .tiles { margin: .3rem 0 .5rem; }
  .hero { height: 150px; }
}
/* overlay: centre when it fits, scroll when it does not */
#overlay { display: flex; align-items: flex-start; justify-content: center; }
#overlay .card { margin: auto; }
