:root {
  --bg: #06111d;
  --panel: #0a1828;
  --panel-2: #0c1d30;
  --line: #163049;
  --line-2: #1f4060;
  --text: #eaf4fb;
  --muted: #8ea3b8;
  --soft: #b9cad9;
  --accent: #0ee6f5;
  --accent-2: #22d3ee;
  --accent-ink: #032a33;
  --board: #0a1a29;
  --radius: 14px;
  --reserve: 420px;
  font-family: "Segoe UI", "Segoe UI Variable", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 700px at 50% -10%, #0b2236 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body { min-height: 100dvh; display: flex; flex-direction: column; }

svg { width: 20px; height: 20px; flex: none; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

h1, h2, h3, p { margin: 0; }

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 clamp(16px, 3vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(6, 17, 29, .6);
  backdrop-filter: blur(8px);
}

.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: var(--text); min-width: 0; }
.brand a { display: flex; }
.brand-logo-link { transition: opacity .2s; }
.brand-logo-link:hover { opacity: .8; }
.brand-icon { width: 40px; height: 40px; }
.brand-logo { width: 110px; height: auto; }
.brand-sep { width: 1px; height: 28px; background: var(--line-2); margin: 0 10px 0 6px; }
.brand-title {
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .5em;
  text-transform: uppercase;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 16px; }
.divider { width: 1px; height: 24px; background: var(--line-2); }

.link-btn, .icon-btn {
  display: inline-flex; align-items: center; gap: 10px;
  background: none; border: 0; padding: 6px; border-radius: 8px;
  color: #c6d6e4; font-size: 16px;
}
.link-btn svg, .icon-btn svg { width: 24px; height: 24px; color: var(--accent-2); }
.icon-btn svg { color: inherit; }
.link-btn:hover, .icon-btn:hover { color: var(--accent); }
.icon-btn[hidden] { display: none; }
.icon-btn[aria-pressed="false"] { color: var(--muted); }
.link-btn:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--accent); }

/* ---------- Main ---------- */
.main {
  flex: 1;
  width: 100%;
  max-width: 1520px;
  margin: 0 auto;
  padding: 20px clamp(16px, 3.4vw, 60px) 0;
  display: flex; flex-direction: column;
  gap: 14px;
}

.card {
  background: linear-gradient(180deg, rgba(12, 29, 48, .92) 0%, rgba(9, 22, 37, .92) 100%);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: 1.6fr 1.4fr 1.1fr auto;
  align-items: center;
  padding: 14px 0;
}
.stat { padding: 2px clamp(16px, 5.5vw, 82px); min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line-2); }
.stat-label { display: block; font-size: 14px; letter-spacing: .06em; text-transform: uppercase; color: var(--soft); }
.stat-value { display: block; font-size: 30px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }

.stat--level { display: flex; flex-direction: column; align-items: center; }
.level-row { display: flex; align-items: baseline; gap: 14px; }
.level-row .stat-label { display: inline; }
.level-bar {
  width: min(210px, 100%); height: 8px; margin-top: 8px;
  border-radius: 999px; background: var(--line-2); overflow: hidden;
}
.level-bar i {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: var(--accent); box-shadow: 0 0 10px rgba(14, 230, 245, .6);
  transition: width .25s ease;
}

.stat--lives { display: flex; gap: 16px; padding-left: clamp(16px, 3vw, 44px); padding-right: clamp(16px, 3vw, 44px); }
.stat--lives svg { width: 36px; height: 36px; color: var(--accent); filter: drop-shadow(0 0 8px rgba(14, 230, 245, .45)); transition: color .3s; }
.stat--lives svg.is-lost { color: var(--line-2); filter: none; }
.stat--lives svg.is-pop { animation: pop .5s ease; }
@keyframes pop { 40% { transform: scale(1.35); } }

/* ---------- Board ---------- */
.board-frame {
  --ar: 2.381;
  --glow: 14, 230, 245;
  position: relative;
  width: min(100%, calc((100dvh - var(--reserve)) * var(--ar)));
  min-width: min(100%, 280px);
  aspect-ratio: var(--ar);
  margin: 0 auto;
  border: 2px solid rgb(var(--glow));
  border-radius: 12px;
  background: var(--board);
  box-shadow: 0 0 22px rgba(var(--glow), .28), inset 0 0 18px rgba(var(--glow), .06);
  overflow: hidden;
  touch-action: none;
  transition: border-color .3s, box-shadow .3s;
}
.board-frame.is-dead { --glow: 239, 68, 68; }
.board-frame canvas { display: block; width: 100%; height: 100%; cursor: none; }
.board-frame.show-cursor canvas { cursor: default; }

.board-hint {
  position: absolute; left: 50%; top: 58%;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(14, 230, 245, .12);
  border: 1px solid rgba(14, 230, 245, .35);
  color: #d8f9fc; font-size: 15px;
  white-space: nowrap;
  pointer-events: none;
  animation: hint 1.6s ease-in-out infinite;
}
.board-hint[hidden] { display: none; }
@keyframes hint { 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { .board-hint { animation: none; } }

.board-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 20px; text-align: center;
  background: rgba(5, 13, 22, .76);
  backdrop-filter: blur(3px);
}
.board-overlay[hidden] { display: none; }
.board-overlay h3 { font-size: 34px; font-weight: 800; }
.board-overlay p { color: var(--muted); margin-bottom: 8px; line-height: 1.5; font-size: 17px; }
.board-overlay p b { color: var(--accent); font-size: 1.15em; }
.board-overlay .primary-btn { padding: 0 34px; min-width: 0; }

/* ---------- Controls ---------- */
.controls {
  display: flex; align-items: center; justify-content: space-between;
  gap: clamp(14px, 2vw, 34px);
  padding: 18px clamp(16px, 2.8vw, 40px);
}
.controls-buttons { display: flex; gap: 18px; }
.vsep { width: 1px; height: 54px; background: var(--line-2); flex: none; }

.primary-btn, .outline-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 14px;
  min-height: 56px; padding: 0 30px;
  border-radius: 8px;
  font-size: 18px; font-weight: 600;
  white-space: nowrap;
}
.primary-btn svg, .outline-btn svg { width: 24px; height: 24px; }
.primary-btn {
  background: var(--accent); color: var(--accent-ink); border: 0; min-width: 180px;
  box-shadow: 0 6px 24px rgba(14, 230, 245, .22);
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: .45; cursor: default; filter: none; box-shadow: none; }
.outline-btn { background: transparent; border: 1px solid var(--soft); color: #fff; }
.outline-btn:hover { border-color: var(--accent); color: var(--accent); }
.primary-btn:focus-visible, .outline-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.seg {
  display: grid; grid-template-columns: repeat(3, 1fr);
  width: min(380px, 100%);
  border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden;
  background: rgba(6, 17, 29, .5);
}
.controls .seg { flex: none; min-width: 300px; }
.seg button {
  padding: 12px 8px;
  background: transparent; border: 0;
  font-size: 17px; color: var(--text);
}
.seg button:hover { background: rgba(34, 211, 238, .08); }
.seg button[aria-checked="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg button:focus-visible { outline: 2px solid #fff; outline-offset: -3px; }

.powers { display: flex; }
.power {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 0 clamp(12px, 2vw, 30px);
  font-size: 15px; color: #c6d6e4; white-space: nowrap;
}
.power + .power { border-left: 1px solid var(--line); }
.power-icon {
  position: relative;
  display: grid; place-items: center;
  width: 70px; height: 44px;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: rgba(6, 17, 29, .5);
  color: var(--accent-2);
  overflow: hidden;
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.power-icon svg { width: 26px; height: 26px; }
.power-icon svg.i-wide { width: 52px; height: 26px; }
.power-icon i {
  position: absolute; left: 0; bottom: 0; height: 3px;
  width: calc(var(--p, 0) * 100%);
  background: var(--accent);
}
.power--life .power-icon { color: #f472b6; }
.power--life.is-ready .power-icon { border-color: rgba(244, 114, 182, .6); box-shadow: 0 0 12px rgba(244, 114, 182, .25); }
.power.is-active .power-icon { border-color: var(--accent); background: rgba(14, 230, 245, .12); box-shadow: 0 0 14px rgba(14, 230, 245, .3); }
.power.is-hit .power-icon { animation: hit .6s ease; }
@keyframes hit { 30% { transform: scale(1.1); border-color: var(--accent); background: rgba(14, 230, 245, .2); } }

/* ---------- Hints ---------- */
.hints {
  display: flex; align-items: center; justify-content: center; flex-wrap: wrap;
  gap: 12px 28px;
  padding: 12px 0 0;
  color: #9fb6cc; font-size: 15px;
}
.hint { display: inline-flex; align-items: center; gap: 12px; }
.hint .mouse { width: 30px; height: 30px; color: var(--accent-2); }
.hsep { width: 1px; height: 28px; background: var(--line-2); }
.key {
  display: inline-grid; place-items: center;
  min-width: 38px; height: 36px; padding: 0 10px;
  background: rgba(14, 230, 245, .04);
  border: 1px solid var(--line-2); border-radius: 6px;
  color: var(--text);
  font-size: 13px; font-weight: 600;
  transition: background .08s, border-color .08s, transform .08s;
}
.key + .key { margin-left: -4px; }
.key svg { width: 15px; height: 15px; }
.key-space { min-width: 96px; }
.key.is-down { background: rgba(14, 230, 245, .2); border-color: var(--accent); transform: translateY(1px); }

.credit {
  text-align: center; color: #9fb6cc;
  font-size: 13px; letter-spacing: .22em;
  padding: 18px 0 20px;
}
.credit a { color: var(--accent); font-weight: 700; text-decoration: none; }
.credit a:hover { text-decoration: underline; }

/* ---------- How to play ---------- */
.howto {
  width: min(540px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 24px 26px;
  border: 1px solid var(--line-2); border-radius: var(--radius);
  background: linear-gradient(180deg, #0c1d30 0%, #091625 100%);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.howto::backdrop { background: rgba(3, 9, 16, .7); backdrop-filter: blur(3px); }
.howto-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.howto h2 { font-size: 27px; font-weight: 600; }
.howto h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .14em; color: var(--accent); margin: 20px 0 10px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 16px; line-height: 1.45; color: #d2e0ec; }
.steps li { display: flex; align-items: flex-start; gap: 14px; }
.steps li > span:first-child {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  background: #12416a; color: #fff;
  font-size: 15px; font-weight: 600;
}
.howto-powers { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.howto-powers li { display: flex; align-items: center; gap: 14px; font-size: 15px; color: var(--muted); }
.howto-powers b { display: block; color: var(--text); font-size: 16px; }
.howto-powers .power-icon { width: 60px; height: 38px; flex: none; }
.howto-controls { color: var(--muted); line-height: 1.6; font-size: 15px; }
.howto-controls b { color: var(--text); }
.howto-ok { width: 100%; margin-top: 22px; min-height: 50px; }

input[type="checkbox"] { position: absolute; opacity: 0; pointer-events: none; }
.toggle-field { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; cursor: pointer; margin-top: 18px; }
.toggle-field .field-label { display: block; font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.toggle-field small { color: var(--muted); font-size: 14px; line-height: 1.4; }
.switch {
  position: relative;
  width: 56px; height: 30px;
  border-radius: 999px;
  background: var(--line-2);
  transition: background .2s;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute; top: 4px; left: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}
input:checked + .switch { background: var(--accent); }
input:checked + .switch::after { transform: translateX(26px); }
input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Full screen ---------- */
body.is-fullscreen { --reserve: 330px; }
body.is-fullscreen .hints, body.is-fullscreen .credit { display: none; }

/* ---------- Medium screens ---------- */
@media (max-width: 1280px) {
  .controls { flex-wrap: wrap; justify-content: center; row-gap: 16px; }
  .controls .vsep:last-of-type { display: none; }
  .primary-btn, .outline-btn { min-height: 52px; padding: 0 24px; font-size: 17px; }
  .primary-btn { min-width: 150px; }
}

@media (max-height: 860px) and (min-width: 961px) {
  :root { --reserve: 340px; }
  .main { padding-top: 12px; gap: 10px; }
  .stats { padding: 8px 0; }
  .stat-value { font-size: 25px; }
  .stat-label { font-size: 13px; }
  .stat--lives svg { width: 30px; height: 30px; }
  .controls { padding: 10px 24px; }
  .primary-btn, .outline-btn { min-height: 46px; }
  .seg button { padding: 9px 8px; }
  .power-icon { height: 38px; }
  .hints { padding-top: 4px; }
  .credit { padding: 10px 0 14px; }
}

/* ---------- Tablet / mobile ---------- */
@media (max-width: 960px) {
  :root { --reserve: 300px; }
  .topbar { height: 56px; }
  .brand { gap: 10px; }
  .brand-icon { width: 32px; height: 32px; }
  .brand-logo { width: 84px; }
  .brand-sep { margin: 0 2px; height: 22px; }
  .brand-title { font-size: 12px; letter-spacing: .3em; }
  .topbar-actions { gap: 8px; }
  .link-btn span { display: none; }

  .main { padding-top: 12px; gap: 10px; }
  .stats { padding: 8px 0; }
  .stat { padding: 2px 14px; }
  .stat-label { font-size: 12px; }
  .stat-value { font-size: 22px; }
  .level-row { gap: 8px; }
  .level-bar { height: 6px; margin-top: 5px; }
  .stat--lives { gap: 6px; padding: 0 12px; }
  .stat--lives svg { width: 22px; height: 22px; }

  .controls { padding: 12px; gap: 12px; }
  .controls .vsep { display: none; }
  .controls-buttons { width: 100%; gap: 12px; }
  .controls-buttons > * { flex: 1; min-width: 0; }
  .seg { width: 100%; }
  .seg button { padding: 10px 6px; font-size: 16px; }
  .powers { width: 100%; justify-content: space-around; }
  .power { padding: 0 8px; font-size: 13px; }
  .power-icon { width: 60px; height: 38px; }
}

@media (max-width: 960px), (pointer: coarse) {
  .hints, #capture-field { display: none; }
}

@media (max-width: 560px) {
  .brand .brand-logo-link, .brand-sep { display: none; }
  .stats { grid-template-columns: 1.15fr 1fr 1fr auto; }
  .stat { padding: 2px 10px; }
  .stat-label { font-size: 11px; letter-spacing: .05em; }
  .stat-value { font-size: 19px; }
  .level-row { gap: 5px; }
  .level-bar { width: 100%; }
  .stat--lives { gap: 3px; padding: 0 8px; }
  .stat--lives svg { width: 17px; height: 17px; }
  .primary-btn, .outline-btn { min-height: 46px; font-size: 16px; gap: 10px; }
  .primary-btn svg, .outline-btn svg { width: 20px; height: 20px; }
  .primary-btn { min-width: 0; }
  .board-overlay h3 { font-size: 28px; }
  .credit { letter-spacing: .12em; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}

/* ---------- Side panels (wide screens only) ---------- */
.stage { display: flex; flex-direction: column; gap: 14px; min-width: 0; container-type: inline-size; }
.side { display: none; container-type: inline-size; }

/* Desktop: side panels on both sides of the game */
@media (min-width: 961px) {
  .main {
    max-width: 2240px;
    display: grid;
    grid-template-columns: clamp(190px, 16vw, 300px) minmax(0, 1fr) clamp(190px, 16vw, 300px);
    column-gap: clamp(14px, 1.6vw, 36px);
    align-items: start;
  }
  .side { display: flex; flex-direction: column; gap: 14px; }
  .credit { grid-column: 1 / -1; }
}
@media (min-width: 961px) {
  @container (max-width: 1240px) { .board-frame { --reserve: 470px; } }
}

/* The game column gets narrower with the side panels, so size its parts by the column, not the window */
@container (max-width: 1240px) {
  .controls { flex-wrap: wrap; justify-content: center; row-gap: 14px; padding: 14px 18px; }
  .controls .vsep:last-of-type { display: none; }
  .primary-btn, .outline-btn { min-height: 50px; padding: 0 22px; font-size: 17px; }
  .primary-btn { min-width: 140px; }
  .stat { padding: 2px 28px; }
  .stat-value { font-size: 26px; }
  .stat--lives { gap: 10px; padding: 0 22px; }
  .stat--lives svg { width: 30px; height: 30px; }
  .hints { gap: 10px 18px; font-size: 14px; }
}
@container (max-width: 760px) {
  .controls .vsep { display: none; }
  .stat { padding: 2px 16px; }
  .stat-label { font-size: 12px; }
  .stat-value { font-size: 22px; }
  .stat--lives { gap: 6px; padding: 0 14px; }
  .stat--lives svg { width: 24px; height: 24px; }
  .power { padding: 0 12px; font-size: 14px; }
  .power-icon { width: 60px; height: 38px; }
  .hsep { display: none; }
}

/* Narrow side panels on smaller desktops */
@container (max-width: 250px) {
  .side-card { padding: 14px; }
  .side-card h2 { margin-bottom: 10px; }
  .run-stats div { padding: 6px 0; }
  .run-stats dt { font-size: 13px; }
  .run-stats dd { font-size: 16px; }
  .level-map { gap: 6px; }
  .level-map li { height: 34px; font-size: 14px; }
  .best-list li { padding: 8px 10px; font-size: 14px; }
  .best-list b { font-size: 16px; }
  .brick-guide li { gap: 10px; font-size: 12px; }
  .brick-guide b { font-size: 14px; }
  .mini-brick { width: 40px; height: 18px; }
  .score-guide li { font-size: 12.5px; }
}

.side-card { padding: 18px 20px; }
.side-card h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .14em; color: var(--accent); margin-bottom: 14px; }
.side-note { color: var(--muted); font-size: 13px; margin-top: 12px; line-height: 1.4; }

.run-stats { margin: 0; display: grid; gap: 2px; }
.run-stats div { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); }
.run-stats div:last-child { border-bottom: 0; }
.run-stats dt { color: var(--soft); font-size: 15px; }
.run-stats dd { margin: 0; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.run-stats dd.is-bump { animation: bump .35s ease; color: var(--accent); }
@keyframes bump { 40% { transform: scale(1.25); } }

.level-map { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.level-map li {
  display: grid; place-items: center;
  height: 44px;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: rgba(6, 17, 29, .5);
  color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums;
}
.level-map li.is-done { color: var(--accent); border-color: rgba(14, 230, 245, .35); background: rgba(14, 230, 245, .06); }
.level-map li.is-current { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); box-shadow: 0 0 14px rgba(14, 230, 245, .35); }

.best-list, .brick-guide, .score-guide { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.best-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  border: 1px solid var(--line-2); border-radius: 8px;
  background: rgba(6, 17, 29, .5);
}
.best-list span { color: var(--soft); }
.best-list b { font-size: 20px; font-variant-numeric: tabular-nums; }
.best-list li.is-current { border-color: var(--accent); background: rgba(14, 230, 245, .08); }
.best-list li.is-current span { color: var(--accent); }

.brick-guide li { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--muted); }
.brick-guide b { display: block; color: var(--text); font-size: 15px; font-weight: 600; }
.mini-brick {
  position: relative; flex: none;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  width: 54px; height: 22px; border-radius: 3px;
  background: linear-gradient(#3fe4ff, #08d0f2);
  box-shadow: inset 0 2px rgba(255, 255, 255, .25), inset 0 -6px rgba(0, 20, 50, .14);
}
.mini-brick i { width: 4px; height: 4px; border-radius: 50%; background: #fff; }
.mini-brick--tough { background: linear-gradient(#25b4d1, #07abc8); outline: 1.5px solid rgba(255, 255, 255, .55); outline-offset: -4px; }
.mini-brick--strong { background: linear-gradient(#f5f8fb, #dbe4ee); outline: 1.5px solid rgba(255, 255, 255, .7); outline-offset: -4px; }
.mini-brick--strong i { background: #0f2241; }
.mini-brick--steel { background: repeating-linear-gradient(135deg, #51637d 0 6px, #5b6d87 6px 9px); }

.score-guide li { display: flex; justify-content: space-between; font-size: 14px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.score-guide li:last-child { border-bottom: 0; }
.score-guide span { color: var(--soft); }
.score-guide b { color: var(--text); font-weight: 600; }
