/* ============================================================
   铁履与星翼 · interface
   Pixel HUD is drawn on a 320×180 canvas; all chrome around it is
   deliberately crisp, low-noise HTML/CSS.
   ============================================================ */
:root {
  --bg: #070b14;
  --bg-soft: #0b1120;
  --panel: #0f1728;
  --panel-2: #121d32;
  --line: #22314d;
  --line-bright: #354a70;
  --pale: #e8f2ff;
  --muted: #8fa2c1;
  --muted-2: #657796;
  --orange: #ff7a2f;
  --orange-soft: #ffb15c;
  --orange-dim: #b34c20;
  --cyan: #4fd8ff;
  --cyan-soft: #aef4ff;
  --cyan-dim: #227d9e;
  --gold: #ffc857;
  --danger: #ff5849;
  --green: #8cd493;
  --font: "Noto Sans CJK SC", "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  --radius: 4px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1000px 620px at 12% -10%, rgba(255, 122, 47, 0.13), transparent 62%),
    radial-gradient(900px 620px at 88% 0%, rgba(79, 216, 255, 0.12), transparent 58%),
    radial-gradient(900px 800px at 50% 120%, rgba(32, 72, 118, 0.16), transparent 60%),
    var(--bg);
  color: var(--pale);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(88, 124, 174, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(88, 124, 174, 0.055) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.9), transparent 78%);
  opacity: 0.55;
}
.page-noise {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.018) 0,
    rgba(255, 255, 255, 0.018) 1px,
    transparent 1px,
    transparent 3px
  );
  opacity: 0.5;
  mix-blend-mode: screen;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.site-head {
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 22px 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.brand { display: inline-flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 38px;
  height: 38px;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 12px rgba(255, 122, 47, 0.25));
}
.brand b { font-size: 18px; letter-spacing: 0.14em; font-weight: 900; }
.site-nav { display: flex; align-items: center; gap: 4px; }
.nav-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
  font-size: 13px;
  letter-spacing: 0.04em;
  transition: 160ms ease;
}
.nav-btn:hover { color: var(--pale); background: rgba(255,255,255,0.045); border-color: var(--line); }
.icon-btn {
  width: 38px; height: 38px;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line);
  background: rgba(15, 23, 40, 0.7);
  border-radius: 3px;
  margin-left: 6px;
  transition: 160ms ease;
}
.icon-btn:hover { border-color: var(--line-bright); background: var(--panel); }
.sound-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; }
.sound-bars i { display: block; width: 3px; background: var(--cyan); }
.sound-bars i:nth-child(1) { height: 5px; }
.sound-bars i:nth-child(2) { height: 9px; }
.sound-bars i:nth-child(3) { height: 13px; }
body.sound-off .sound-bars i { background: var(--muted-2); height: 2px; }
body.sound-off .sound-bars i:nth-child(2) { height: 4px; }
body.sound-off .sound-bars i:nth-child(3) { height: 6px; }
body.modal-open { overflow: hidden; }

/* ---------- main / home ---------- */
.main { flex: 1; width: 100%; }
.view { width: 100%; }
.view-home {
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 30px 0 60px;
}
.home-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(380px, 0.78fr);
  gap: 48px;
  align-items: start;
}
.hero { position: relative; padding-top: 12px; }
.hero-title {
  margin: 0;
  font-size: clamp(60px, 8.4vw, 116px);
  line-height: 0.98;
  letter-spacing: 0.035em;
  font-weight: 900;
  color: #f4f8ff;
  text-shadow:
    3px 3px 0 #16243a,
    6px 6px 0 rgba(0, 0, 0, 0.24);
}
.hero-title span {
  font-size: 0.45em;
  margin: 0 0.12em 0 0.04em;
  vertical-align: 0.45em;
  color: var(--orange);
  text-shadow: 2px 2px 0 #5b2611;
}
.hero-lead {
  max-width: 660px;
  margin: 24px 0 0;
  font-size: 16px;
  line-height: 1.9;
  color: #b4c4de;
}

.duo-stage {
  margin-top: 34px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 14px;
}
.duo-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 126px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(255,255,255,0.035), transparent 48%),
    rgba(13, 21, 37, 0.78);
  overflow: hidden;
}
.duo-card::before {
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(135deg, rgba(255,255,255,0.02) 0 1px, transparent 1px 9px);
  pointer-events: none;
}
.duo-card--tank { border-left: 2px solid var(--orange); }
.duo-card--plane { border-right: 2px solid var(--cyan); }
.duo-card--tank::after,
.duo-card--plane::after {
  content: "";
  position: absolute; width: 80px; height: 80px;
  border-radius: 50%;
  filter: blur(26px);
  opacity: 0.2;
  pointer-events: none;
}
.duo-card--tank::after { background: var(--orange); left: -30px; bottom: -30px; }
.duo-card--plane::after { background: var(--cyan); right: -30px; bottom: -30px; }
.sprite-crop {
  flex: 0 0 auto;
  width: 82px; height: 82px;
  background-image: url("../images/sprites.png");
  background-repeat: no-repeat;
  background-size: 1536px 1536px; /* 16px cell × 6 */
  image-rendering: pixelated;
  filter: drop-shadow(0 10px 14px rgba(0,0,0,0.42));
  animation: floatY 4.8s ease-in-out infinite;
}
.sprite-tank { background-position: 0 -96px; }
.sprite-plane { background-position: -384px -96px; animation-delay: -2.4s; }
.duo-meta { min-width: 0; }
.duo-meta b { display: block; font-size: 22px; line-height: 1.2; letter-spacing: 0.08em; }
.duo-meta p { margin: 8px 0 0; font-size: 13px; line-height: 1.65; color: var(--muted); }

.hero-stats {
  margin-top: 26px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.hero-stats div { padding: 14px 16px; border-right: 1px solid var(--line); }
.hero-stats div:last-child { border-right: 0; }
.hero-stats span { display: block; font: 12px/1.4 var(--font); color: var(--muted); letter-spacing: 0.08em; }
.hero-stats b { display: block; margin-top: 4px; font: 21px/1.2 var(--mono); color: var(--pale); }
.accent-orange { color: var(--orange) !important; }
.accent-cyan { color: var(--cyan) !important; }
.accent-gold { color: var(--gold) !important; }
.accent-danger { color: var(--danger) !important; }
.accent-info { color: #7bc8ff !important; }

/* ---------- launch panel ---------- */
.launch-panel {
  position: relative;
  border: 1px solid var(--line-bright);
  background:
    linear-gradient(160deg, rgba(24, 37, 60, 0.94), rgba(10, 17, 30, 0.97) 58%),
    var(--panel);
  box-shadow: var(--shadow);
  padding: 24px;
}
.launch-panel::before,
.launch-panel::after {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  border: 1px solid var(--orange);
  pointer-events: none;
}
.launch-panel::before { left: -1px; top: -1px; border-right: 0; border-bottom: 0; }
.launch-panel::after { right: -1px; bottom: -1px; border-left: 0; border-top: 0; border-color: var(--cyan); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.panel-head h2,
.strip-head h2 { margin: 0; font-size: 24px; letter-spacing: 0.07em; }
.field-label { margin: 18px 0 9px; font: 12px/1.3 var(--font); letter-spacing: 0.08em; color: var(--muted); }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg-btn {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(7, 11, 20, 0.54);
  padding: 12px 13px;
  transition: 150ms ease;
  position: relative;
}
.seg-btn b { display: block; font-size: 15px; letter-spacing: 0.05em; }
.seg-btn:hover { border-color: var(--line-bright); background: rgba(21, 34, 55, 0.7); }
.seg-btn.is-active { border-color: rgba(255,122,47,0.6); background: rgba(255,122,47,0.08); box-shadow: inset 0 -2px 0 var(--orange); }
.seg-btn.is-active b { color: var(--orange-soft); }
.seg-btn[data-mode="solo"].is-active { border-color: rgba(79,216,255,0.6); background: rgba(79,216,255,0.07); box-shadow: inset 0 -2px 0 var(--cyan); }
.seg-btn[data-mode="solo"].is-active b { color: var(--cyan-soft); }

.char-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 9px; }
.char-btn {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--line);
  background: rgba(7, 11, 20, 0.44);
  padding: 10px;
  text-align: left;
  color: var(--muted);
  transition: 150ms ease;
}
.char-btn > span:last-child { min-width: 0; }
.char-btn b { display: block; font-size: 14px; color: var(--pale); }
.char-swatch { width: 8px; height: 24px; flex: 0 0 auto; }
.swatch-orange { background: linear-gradient(var(--orange-soft), var(--orange-dim)); }
.swatch-cyan { background: linear-gradient(var(--cyan-soft), var(--cyan-dim)); }
.char-btn.is-active { border-color: var(--line-bright); background: rgba(255,255,255,0.055); }
.char-btn[data-character="tank"].is-active { border-color: rgba(255,122,47,0.5); }
.char-btn[data-character="plane"].is-active { border-color: rgba(79,216,255,0.5); }

.level-list {
  display: grid;
  gap: 4px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-bright) transparent;
}
.level-list::-webkit-scrollbar { width: 6px; }
.level-list::-webkit-scrollbar-track { background: transparent; }
.level-list::-webkit-scrollbar-thumb { background: var(--line-bright); border-radius: 999px; }
.level-btn {
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0,1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  background: rgba(7, 11, 20, 0.4);
  padding: 6px 10px;
  text-align: left;
  transition: 150ms ease;
}
.level-btn:hover { border-color: var(--line-bright); background: rgba(255,255,255,0.035); }
.level-btn.is-active { border-color: rgba(255,122,47,0.58); background: linear-gradient(90deg, rgba(255,122,47,0.09), rgba(79,216,255,0.03)); }
.level-no { font: 16px/1 var(--mono); color: var(--muted-2); text-align: center; }
.level-btn.is-active .level-no { color: var(--orange-soft); }
.level-copy b { display: block; font-size: 13px; letter-spacing: 0.06em; }
.level-tags { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.level-rank { font: 12px/1 var(--mono); color: var(--gold); }
.level-rank.empty { color: var(--muted-2); }
.level-btn.is-cleared .level-no { color: var(--green); }

.start-btn {
  width: 100%;
  margin-top: 16px;
  display: grid;
  grid-template-columns: 34px 1fr 22px;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid #ff9c5a;
  background:
    linear-gradient(180deg, #ff8d43, #ea641e);
  color: #1a1009;
  box-shadow: 0 5px 0 #8f3b14, 0 16px 30px rgba(255, 122, 47, 0.18);
  transition: transform 100ms ease, box-shadow 100ms ease, filter 150ms ease;
}
.start-btn:hover { filter: brightness(1.06); }
.start-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #8f3b14; }
.start-icon { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid rgba(26,16,9,0.4); font-size: 12px; }
.start-copy { text-align: left; }
.start-copy b { display: block; font-size: 17px; line-height: 1.2; letter-spacing: 0.08em; }
.start-arrow { font-size: 18px; text-align: right; }
.launch-note { margin: 12px 0 0; font-size: 13px; line-height: 1.65; color: var(--muted); }

/* ---------- chapters ---------- */
.chapter-strip {
  margin-top: 58px;
  border-top: 1px solid var(--line);
  padding-top: 28px;
}
.strip-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 36px; }
.chapter-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 1px;
}
.chapter-card {
  position: relative;
  min-height: 170px;
  padding: 20px;
  border-top: 2px solid var(--line);
  background: linear-gradient(155deg, #121c30, #0a101c);
  box-shadow: 0 0 0 1px var(--line);
  overflow: hidden;
  transition: 180ms ease;
}
.chapter-card:hover { background: #182640; }
.chapter-card::after {
  content: attr(data-no);
  position: absolute; right: 12px; bottom: -18px;
  font: 900 72px/1 var(--mono);
  color: rgba(255,255,255,0.035);
  pointer-events: none;
}
.chapter-card h3 { margin: 0; font-size: 19px; letter-spacing: 0.08em; }
.chapter-card p { margin: 9px 0 0; font-size: 13px; line-height: 1.7; color: var(--muted); }
.chapter-card[data-theme="0"] { border-top-color: var(--orange); }
.chapter-card[data-theme="1"] { border-top-color: #54a5c6; }
.chapter-card[data-theme="2"] { border-top-color: #e0a355; }
.chapter-card[data-theme="3"] { border-top-color: #8b7dff; }
.chapter-card:last-child { grid-column: span 3; }

/* ---------- game view ---------- */
body.in-game { overflow: hidden; }
body.in-game .site-head,
body.in-game .site-foot { display: none; }
.view-game {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 10px 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background:
    radial-gradient(900px 520px at 50% 50%, rgba(20, 39, 67, 0.35), transparent 70%),
    rgba(4, 7, 13, 0.25);
}
.game-toolbar {
  width: min(1280px, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 36px;
}
.toolbar-mid { display: flex; align-items: center; gap: 10px; font: 12px/1.4 var(--mono); letter-spacing: 0.06em; color: var(--muted); }
.toolbar-mid b { color: var(--pale); font-weight: 500; }
.toolbar-mid i { color: var(--line-bright); font-style: normal; }
.toolbar-actions { display: flex; align-items: center; gap: 6px; }
.ghost-btn {
  border: 1px solid var(--line);
  background: rgba(15, 23, 40, 0.64);
  color: var(--muted);
  padding: 7px 11px;
  font-size: 12px;
  letter-spacing: 0.05em;
  transition: 150ms ease;
}
.ghost-btn:hover { color: var(--pale); border-color: var(--line-bright); background: var(--panel); }
.primary-btn {
  border: 1px solid #ff9c5a;
  background: linear-gradient(180deg, #ff8d43, #e7601b);
  color: #1b1008;
  padding: 8px 16px;
  font-weight: 700;
  letter-spacing: 0.06em;
  box-shadow: 0 3px 0 #8f3b14;
  transition: 120ms ease;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #8f3b14; }

.game-shell { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; min-height: 0; width: 100%; }
.game-frame {
  --s: 4;
  position: relative;
  flex: 0 0 auto;
  background: #05080f;
  border: 1px solid #3a4b6b;
  box-shadow:
    0 0 0 1px rgba(0,0,0,0.8),
    0 0 0 4px #0c1320,
    0 0 0 5px #253554,
    0 28px 90px rgba(0,0,0,0.6);
  overflow: hidden;
  touch-action: none;
  container-type: inline-size;
  font-size: calc(var(--s) * 3.4px + 1px);
}
.game-frame::before {
  content: "";
  position: absolute; inset: 0;
  z-index: 30;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255,122,47,0.16), transparent 8%, transparent 92%, rgba(79,216,255,0.16)),
    repeating-linear-gradient(to bottom, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px);
  mix-blend-mode: screen;
  opacity: 0.5;
}
.game-frame::after {
  content: "";
  position: absolute; inset: 0;
  z-index: 31;
  pointer-events: none;
  box-shadow: inset 0 0 80px rgba(0,0,0,0.44);
}
#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: -moz-crisp-edges;
  image-rendering: pixelated;
  background: #070b15;
}
.game-frame canvas { position: relative; z-index: 1; }

/* HUD */
.hud { position: absolute; inset: 0; z-index: 8; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; }
.hud-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
  padding: calc(var(--s) * 2px + 1px) calc(var(--s) * 2.5px + 1px);
  background: linear-gradient(to bottom, rgba(3,6,12,0.86), rgba(3,6,12,0.35) 62%, transparent);
}
.hud-stage { min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 7px; line-height: 1.2; text-shadow: 0 1px 2px #000; }
.hud-mode { font: 600 calc(var(--s) * 2.2px + 1px)/1.2 var(--mono); letter-spacing: 0.1em; color: var(--orange-soft); border: 1px solid rgba(255,177,92,0.35); background: rgba(255,122,47,0.12); padding: 2px 4px; }
.hud-stage b { font-size: calc(var(--s) * 3.2px + 1px); letter-spacing: 0.08em; color: var(--pale); flex-basis: 100%; }
.hud-timer { display: flex; flex-direction: column; align-items: center; min-width: calc(var(--s) * 34px); }
.hud-timer span { font: calc(var(--s) * 2px + 1px)/1.1 var(--mono); letter-spacing: 0.18em; color: var(--muted-2); }
.hud-timer b { font: 500 calc(var(--s) * 5.6px + 2px)/1.15 var(--mono); letter-spacing: 0.08em; color: var(--pale); text-shadow: 0 1px 4px #000; }
.hud-timer.is-low b { color: var(--danger); animation: pulseText 900ms ease-in-out infinite; }
.timer-track { display: block; width: 100%; height: 2px; margin-top: 3px; background: rgba(255,255,255,0.12); overflow: hidden; }
.timer-track em { display: block; height: 100%; width: 100%; background: var(--cyan); transition: width 200ms linear, background 200ms linear; }
.hud-timer.is-low .timer-track em { background: var(--danger); }
.hud-score { justify-self: end; display: flex; align-items: center; gap: 7px; }
.hud-score > span { font: calc(var(--s) * 2px + 1px)/1.1 var(--mono); letter-spacing: 0.1em; color: var(--muted-2); }
.hud-score > b { font: 500 calc(var(--s) * 4.2px + 1px)/1.1 var(--mono); color: var(--gold); text-shadow: 0 1px 3px #000; }
.hud-pause {
  pointer-events: auto;
  width: calc(var(--s) * 8px);
  height: calc(var(--s) * 8px);
  min-width: 24px;
  min-height: 24px;
  display: grid; place-items: center;
  border: 1px solid rgba(232,242,255,0.25);
  background: rgba(8,13,23,0.75);
  color: var(--pale);
  font: calc(var(--s) * 3px)/1 var(--mono);
}
.hud-pause:hover { border-color: var(--cyan); color: var(--cyan); }
.hud-bottom {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: calc(var(--s) * 2px + 1px) calc(var(--s) * 3px + 1px);
  background: linear-gradient(to top, rgba(3,6,12,0.86), rgba(3,6,12,0.28) 62%, transparent);
}
.hud-pickups { display: flex; flex-wrap: wrap; gap: 5px; }
.pickup-chip {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(7,11,20,0.7);
  padding: calc(var(--s) * 1.2px) calc(var(--s) * 2px);
  font: calc(var(--s) * 2.2px + 1px)/1 var(--mono);
  color: var(--muted);
}
.pickup-chip b { color: var(--pale); font-weight: 500; }
.pickup-chip i { display: block; width: calc(var(--s) * 2.4px); height: calc(var(--s) * 2.4px); }
.pickup-gear i { background: var(--orange); transform: rotate(45deg); }
.pickup-star i { background: var(--cyan); clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 94%, 50% 72%, 21% 94%, 32% 57%, 2% 35%, 39% 35%); }
.pickup-death { color: var(--muted-2); }
.hud-energy { min-width: calc(var(--s) * 36px); display: flex; align-items: center; gap: 5px; }
.hud-energy > span { font: calc(var(--s) * 2px + 1px)/1 var(--mono); letter-spacing: 0.08em; color: var(--muted-2); }
.energy-track { display: block; flex: 1; min-width: calc(var(--s) * 20px); height: calc(var(--s) * 2px + 1px); border: 1px solid rgba(79,216,255,0.24); background: rgba(4,8,15,0.7); overflow: hidden; }
.energy-track em { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--cyan-dim), var(--cyan), var(--orange)); transition: width 160ms ease; }
.hud-energy > b { font: calc(var(--s) * 2px + 1px)/1 var(--mono); color: var(--cyan-soft); min-width: 18px; text-align: right; }
.hud-energy.is-full .energy-track em { background: var(--gold); }
.hud-energy.is-boost > b { color: var(--gold); animation: pulseText 700ms ease-in-out infinite; }

/* Canvas overlays */
.canvas-overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--s) * 6px);
  background: rgba(3, 6, 12, 0.78);
  backdrop-filter: blur(2px);
}
.pause-card {
  width: min(330px, 92%);
  border: 1px solid var(--line-bright);
  background: linear-gradient(155deg, #142039, #0b1220);
  padding: 22px;
  box-shadow: var(--shadow);
  text-align: left;
}
.pause-card h2 { margin: 0 0 14px; font-size: 26px; letter-spacing: 0.12em; }
.pause-actions { display: grid; gap: 6px; }
.pause-actions .primary-btn, .pause-actions .ghost-btn { width: 100%; padding: 9px; }
.portrait-mask { z-index: 40; background: #070b14; }
body.touch-mode .portrait-mask {
  position: fixed;
  inset: 0;
  z-index: 70;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
}
.portrait-card { text-align: center; max-width: 280px; }
.rotate-glyph { font-size: 54px; line-height: 1; color: var(--orange); transform: rotate(90deg); animation: rotateHint 2.2s ease-in-out infinite; }
.portrait-card h2 { margin: 18px 0 6px; font-size: 24px; letter-spacing: 0.15em; }
.portrait-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.level-intro {
  position: absolute; z-index: 15;
  left: 50%; top: 46%;
  transform: translate(-50%, -50%);
  width: min(430px, 88%);
  text-align: center;
  padding: 16px 18px;
  border-top: 1px solid rgba(255,177,92,0.7);
  border-bottom: 1px solid rgba(79,216,255,0.45);
  background: linear-gradient(90deg, transparent, rgba(4,8,15,0.82) 18%, rgba(4,8,15,0.82) 82%, transparent);
  animation: introIn 260ms ease-out both;
  pointer-events: none;
}
.level-intro h2 { margin: 0; font-size: 30px; letter-spacing: 0.14em; }
.level-intro p { margin: 6px 0 0; font-size: 13px; line-height: 1.65; color: var(--muted); }

/* underbar */
.underbar {
  width: min(1280px, 100%);
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  min-height: 34px;
  font: 12px/1.5 var(--font);
  color: var(--muted);
}
.hint-box { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hint-icon {
  flex: 0 0 auto; width: 16px; height: 16px; display: grid; place-items: center;
  border: 1px solid var(--orange-dim); color: var(--orange-soft);
  font: 11px/1 var(--mono);
}
#hintText { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.key-legend { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px 16px; }
.key-legend b { color: var(--pale); font-weight: 500; }
.key-legend kbd { font: inherit; color: var(--orange-soft); }

/* touch controls */
.touch-controls {
  --tb: clamp(38px, calc(var(--s) * 22px), 58px);
  --tg: clamp(4px, calc(var(--s) * 2px), 8px);
  position: absolute; inset: 0; z-index: 12; pointer-events: none; display: none;
}
body.touch-mode .touch-controls { display: block; }
.touch-cluster { position: absolute; bottom: max(8px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: var(--tg); pointer-events: none; }
.touch-cluster.p1 { left: max(8px, env(safe-area-inset-left)); }
.touch-cluster.p2 { right: max(8px, env(safe-area-inset-right)); flex-direction: row-reverse; }
.tbtn {
  pointer-events: auto;
  -webkit-user-select: none; user-select: none;
  touch-action: none;
  width: var(--tb);
  height: var(--tb);
  display: grid; place-items: center;
  border: 1px solid rgba(232,242,255,0.33);
  border-radius: 50%;
  background: rgba(10, 17, 30, 0.58);
  color: var(--pale);
  font: 600 clamp(14px, calc(var(--s) * 4.6px), 22px)/1 var(--font);
  text-shadow: 0 1px 2px #000;
  transition: transform 80ms ease, background 80ms ease, border-color 80ms ease;
}
.tbtn::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
}
.tbtn { position: relative; }
.tbtn-move { border-color: rgba(174,244,255,0.4); }
.tbtn.is-down { background: rgba(79,216,255,0.25); border-color: var(--cyan); transform: scale(0.93); }
.p1 .tbtn-action.is-down { background: rgba(255,122,47,0.25); border-color: var(--orange); }
.tbtn-dash.is-down { background: rgba(255,201,87,0.25); border-color: var(--gold); }
.touch-dpad, .touch-actions { display: flex; align-items: flex-end; gap: var(--tg); }
.touch-actions { flex-wrap: wrap-reverse; width: calc(var(--tb) * 2 + var(--tg)); justify-content: flex-end; }
.p2 .touch-actions { justify-content: flex-start; }
.touch-side-label {
  position: absolute; top: -16px; left: 0;
  font: calc(var(--s) * 2.2px + 1px)/1 var(--mono);
  letter-spacing: 0.12em; color: var(--muted-2);
}
.p1 .touch-side-label { color: var(--orange-soft); }
.p2 .touch-side-label { right: 0; left: auto; color: var(--cyan-soft); }
.touch-solo { position: absolute; inset: 0; pointer-events: none; }
.touch-solo .touch-dpad { position: absolute; left: max(10px, env(safe-area-inset-left)); bottom: max(10px, env(safe-area-inset-bottom)); }
.touch-solo .touch-actions { position: absolute; right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom)); }
.touch-solo .tbtn { width: calc(var(--tb) * 1.08); height: calc(var(--tb) * 1.08); }

/* site footer */
.site-foot {
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 18px 0 26px;
  border-top: 1px solid rgba(34,49,77,0.7);
  font: 12px/1.7 var(--font);
  color: var(--muted);
  text-align: center;
}

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(2,5,10,0.84); backdrop-filter: blur(3px); }
.modal-card {
  position: relative;
  z-index: 1;
  width: min(620px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--line-bright);
  background:
    linear-gradient(155deg, rgba(24,36,59,0.98), rgba(9,15,26,0.99) 62%),
    var(--panel);
  box-shadow: var(--shadow);
  padding: 24px;
  animation: modalIn 180ms ease-out both;
  scrollbar-width: thin;
  scrollbar-color: var(--line-bright) transparent;
}
.modal-wide { width: min(980px, 100%); }
.modal-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 3px 0 0; font-size: 28px; letter-spacing: 0.1em; }
.modal-close {
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 20px; line-height: 1;
}
.modal-close:hover { color: var(--pale); border-color: var(--line-bright); }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: 20px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.manual-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 36px; padding-top: 20px; }
.manual-grid h3 { margin: 20px 0 9px; font-size: 15px; color: var(--orange-soft); letter-spacing: 0.08em; }
.manual-grid h3:first-child { margin-top: 0; }
.key-row { display: flex; gap: 12px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid rgba(34,49,77,0.55); }
.key-row b { flex: 0 0 64px; font-size: 13px; color: var(--pale); }
.key-row span { font-size: 13px; color: var(--muted); line-height: 1.7; }
.key-row kbd { display: inline-block; min-width: 18px; padding: 0 4px; margin: 0 1px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); font: 12px/1.5 var(--mono); color: var(--orange-soft); text-align: center; }
.manual-list p { margin: 0 0 9px; font-size: 13px; line-height: 1.75; color: var(--muted); }
.manual-list p b { display: inline-block; min-width: 84px; font-size: 13px; }
.modal-foot .primary-btn, .modal-foot .ghost-btn { flex: 0 0 auto; }

.rank-controls { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; padding: 16px 0 12px; }
.mini-tabs { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); }
.mini-tabs button { border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted-2); padding: 6px 11px; font: 12px/1.4 var(--font); }
.mini-tabs button:last-child { border-right: 0; }
.mini-tabs button:hover { color: var(--pale); background: rgba(255,255,255,0.04); }
.mini-tabs button.is-active { color: var(--orange-soft); background: rgba(255,122,47,0.1); }
.rank-table-wrap { overflow: auto; border: 1px solid var(--line); }
.rank-table { width: 100%; border-collapse: collapse; font: 12px/1.5 var(--mono); }
.rank-table th { text-align: left; padding: 8px 10px; color: var(--muted-2); font-weight: 400; border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.025); }
.rank-table td { padding: 8px 10px; border-bottom: 1px solid rgba(34,49,77,0.6); color: var(--muted); }
.rank-table tr:last-child td { border-bottom: 0; }
.rank-table .rank-pos { color: var(--muted-2); }
.rank-table .rank-name { color: var(--pale); }
.rank-table .rank-score { color: var(--gold); text-align: right; }
.rank-table .rank-letter { color: var(--orange-soft); font-weight: 700; }
.rank-empty { text-align: center; color: var(--muted-2) !important; padding: 26px !important; }
.rank-note { margin: 10px 0 0; font-size: 12px; line-height: 1.6; color: var(--muted); }

.settings-form { padding-top: 8px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 14px 0; border-bottom: 1px solid rgba(34,49,77,0.65); }
.setting-row b { display: block; font-size: 14px; color: var(--pale); }
.setting-row input[type="checkbox"] { width: 38px; height: 20px; accent-color: var(--orange); }
.setting-row select, .setting-row input[type="text"] {
  min-width: 150px;
  border: 1px solid var(--line);
  background: rgba(5,9,16,0.7);
  color: var(--pale);
  padding: 7px 9px;
  font-size: 13px;
}
.setting-stack { align-items: flex-start; flex-direction: column; gap: 8px; }
.setting-stack input { width: 100%; }
.setting-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 14px; }
.setting-status { font: 12px/1.5 var(--font); color: var(--green); }

/* result */
.result-card { width: min(780px, 100%); }
.result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.result-head h2 { margin: 0; font-size: 30px; letter-spacing: 0.08em; }
.result-head p { margin: 5px 0 0; font: 12px/1.6 var(--font); color: var(--muted); }
.rank-badge {
  width: 96px; height: 96px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border: 1px solid rgba(255,201,87,0.45);
  background:
    radial-gradient(circle at 50% 45%, rgba(255,201,87,0.18), transparent 60%),
    rgba(7,11,20,0.64);
  font: 900 56px/1 var(--mono);
  color: var(--gold);
  text-shadow: 0 3px 0 #5b3e11, 0 0 24px rgba(255,201,87,0.3);
}
.rank-badge.rank-a { color: var(--cyan-soft); border-color: rgba(79,216,255,0.44); text-shadow: 0 3px 0 #0e3c54, 0 0 24px rgba(79,216,255,0.25); }
.rank-badge.rank-b { color: #b8c7de; border-color: var(--line-bright); text-shadow: 0 3px 0 #1d2639; }
.result-stats { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.result-stats div { padding: 14px 16px; border-right: 1px solid var(--line); }
.result-stats div:last-child { border-right: 0; }
.result-stats span, .result-score span { display: block; font: 12px/1.4 var(--font); color: var(--muted); letter-spacing: 0.06em; }
.result-stats b { display: block; margin-top: 3px; font: 19px/1.2 var(--mono); color: var(--pale); }
.result-score { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; border-bottom: 1px solid var(--line); }
.result-score > div { flex: 1; }
.result-score > div:last-child { text-align: right; }
.result-score b { display: block; margin-top: 2px; font: 26px/1.2 var(--mono); color: var(--gold); }
.result-board { padding: 14px 0 0; }
.result-board-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.result-board-head h3 { margin: 0; font-size: 15px; letter-spacing: 0.07em; }
.result-board-head span { font: 12px/1.4 var(--font); color: var(--muted); }
.board-rows { margin-top: 8px; border: 1px solid var(--line); }
.board-row { display: grid; grid-template-columns: 32px 1fr auto auto; gap: 10px; align-items: center; padding: 7px 10px; border-bottom: 1px solid rgba(34,49,77,0.55); font: 12px/1.5 var(--mono); color: var(--muted); }
.board-row:last-child { border-bottom: 0; }
.board-row .br-pos { color: var(--muted-2); }
.board-row .br-name { color: var(--pale); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board-row .br-letter { color: var(--orange-soft); font-weight: 700; }
.board-row .br-score { color: var(--gold); text-align: right; }
.board-empty { padding: 18px; text-align: center; font: 12px/1.5 var(--font); color: var(--muted); }
.result-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }

/* toast */
.toast-root { position: fixed; z-index: 130; left: 50%; bottom: 28px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(520px, calc(100vw - 32px)); }
body.in-game .toast-root { bottom: 76px; }
.toast {
  max-width: 100%;
  border: 1px solid var(--line-bright);
  background: rgba(9, 16, 28, 0.94);
  color: var(--pale);
  padding: 8px 13px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 12px 36px rgba(0,0,0,0.45);
  animation: toastIn 160ms ease-out both;
}
.toast.good { border-color: rgba(140,212,147,0.4); color: #c9f3cd; }
.toast.warn { border-color: rgba(255,88,73,0.45); color: #ffd1cb; }
.toast.boost { border-color: rgba(255,201,87,0.55); color: #ffe1a3; }
.toast.out { animation: toastOut 180ms ease-in both; }

/* fatal */
.fatal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: rgba(2,5,10,0.92); padding: 24px; }
.fatal-card { max-width: 520px; border: 1px solid var(--danger); background: var(--panel); padding: 24px; }
.fatal-card h2 { margin: 0 0 8px; }
.fatal-card p { color: var(--muted); font-size: 13px; }
.fatal-card button { margin-top: 12px; }

/* ---------- animations ---------- */
@keyframes floatY { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes pulseText { 0%,100% { opacity: 1; } 50% { opacity: 0.62; } }
@keyframes rotateHint { 0%,20% { transform: rotate(90deg); } 70%,100% { transform: rotate(0deg); } }
@keyframes introIn { from { opacity: 0; transform: translate(-50%, -44%); } to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-4px); } }

/* ---------- responsive ---------- */
/* touch layout: keep a central playfield clear; compact the HUD to the top */
body.touch-mode .hud { justify-content: flex-start; }
body.touch-mode .hud-bottom {
  justify-content: center;
  padding-top: 2px;
  background: none;
}
body.touch-mode .hud-pickups,
body.touch-mode .hud-energy { background: rgba(4,8,15,0.4); }
@media (orientation: landscape) and (max-height: 520px) {
  body.touch-mode .game-toolbar { display: none; }
  body.touch-mode .view-game { padding: 3px 4px 0; gap: 0; }
  body.touch-mode .underbar {
    min-height: 18px;
    height: auto;
    font-size: 11px;
    padding: 0 6px max(1px, env(safe-area-inset-bottom));
    gap: 10px;
  }
  body.touch-mode .hint-icon { width: 14px; height: 14px; font-size: 10px; }
  body.touch-mode .hint-box { max-width: 100%; }
  body.touch-mode .hud-top { padding-top: 2px; }
  body.touch-mode .hud-stage b { display: none; }
  body.touch-mode .hud-bottom { padding-bottom: 0; }
}

@media (max-width: 1080px) {
  .home-grid { grid-template-columns: minmax(0, 1fr) 370px; gap: 28px; }
  .duo-card { padding: 13px; gap: 10px; }
  .sprite-crop { width: 80px; height: 80px; background-size: 1280px 1280px; background-position: 0 -80px; }
  .sprite-plane { background-position: -320px -80px; }
  .chapter-grid { grid-template-columns: repeat(2, 1fr); }
  .chapter-card:last-child { grid-column: span 2; }
}
@media (max-width: 860px) {
  .site-head, .view-home, .site-foot { width: calc(100% - 28px); }
  .site-head { padding-top: 14px; }
  .brand b { font-size: 16px; }
  .site-nav .nav-btn { padding: 8px; font-size: 12px; }
  .home-grid { grid-template-columns: 1fr; }
  .hero-title { font-size: clamp(52px, 15vw, 90px); }
  .hero-lead { font-size: 14px; }
  .launch-panel { margin-top: 10px; }
  .duo-stage { grid-template-columns: 1fr; }
  .strip-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  .view-game { padding: 6px; }
  .game-toolbar { padding: 0 4px; }
  .toolbar-mid { display: none; }
  .underbar { padding: 0 2px; }
  .key-legend { display: none; }
  .hint-box { width: 100%; }
  .manual-grid { grid-template-columns: 1fr; gap: 8px; }
  .result-stats { grid-template-columns: repeat(2, 1fr); }
  .result-stats div:nth-child(2) { border-right: 0; }
  .result-stats div:nth-child(1), .result-stats div:nth-child(2) { border-bottom: 1px solid var(--line); }
  .modal { padding: 10px; }
  .modal-card { padding: 18px; max-height: calc(100dvh - 20px); }
  .result-head h2 { font-size: 23px; }
  .rank-badge { width: 72px; height: 72px; font-size: 42px; }
}
@media (max-width: 560px) {
  .site-head { flex-wrap: wrap; gap: 10px; }
  .site-nav { width: 100%; justify-content: space-between; }
  .site-nav .nav-btn { flex: 1; text-align: center; }
  .hero-stats b { font-size: 17px; }
  .duo-stage { display: none; }
  .chapter-strip { display: none; }
  .launch-panel { padding: 16px; }
  .segmented { grid-template-columns: 1fr; }
  .char-picker { grid-template-columns: 1fr; }
  .game-toolbar .ghost-btn { padding: 6px 8px; }
  .modal-foot { flex-direction: column; align-items: stretch; }
  .modal-foot .primary-btn { width: 100%; }
  .result-actions { flex-wrap: wrap; }
  .result-actions button { flex: 1 1 100%; }
  .result-score { flex-direction: column; align-items: flex-start; gap: 10px; }
  .result-score > div:last-child { text-align: left; }
  .toast-root { bottom: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* Readability floor for the 640×360 virtual-key layout. */
body.touch-mode .hud-mode { font-size: max(9px, calc(var(--s) * 2.2px + 1px)); }
body.touch-mode .hud-timer span,
body.touch-mode .hud-score > span,
body.touch-mode .hud-energy > span { font-size: max(9px, calc(var(--s) * 2px + 1px)); }
body.touch-mode .hud-timer b { font-size: max(16px, calc(var(--s) * 5.6px + 2px)); }
body.touch-mode .hud-score > b { font-size: max(12px, calc(var(--s) * 4.2px + 1px)); }
body.touch-mode .pickup-chip { font-size: max(9px, calc(var(--s) * 2.2px + 1px)); }
body.touch-mode .hud-energy > b { font-size: max(9px, calc(var(--s) * 2px + 1px)); }
body.touch-mode .touch-side-label { font-size: max(9px, calc(var(--s) * 2.2px + 1px)); }
body.touch-mode .hud-stage b { font-size: max(11px, calc(var(--s) * 3.2px + 1px)); }
