@import url('https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@400;600;700;800;900&family=Press+Start+2P&display=swap');

:root {
  color-scheme: dark;
  --bg: #0d1518;
  --panel: #142126;
  --panel-raised: #19292f;
  --line: #33444a;
  --ink: #f4f3eb;
  --muted: #87979b;
  --lime: #5ce1c6;
  --coral: #ed6254;
  --pixel: "Press Start 2P", "Courier New", monospace;
  --body: "Nunito Sans", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(#263438 .8px, transparent .8px);
  background-size: 14px 14px;
  color: var(--ink);
  font-family: var(--body);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
button, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
select { color-scheme: dark; }

.app-shell { width: min(1440px, calc(100% - 48px)); margin: 0 auto; padding-bottom: 18px; container-type: inline-size; container-name: app; }
body[data-layout-mode="phone"] .app-shell { width: 390px; }
body[data-layout-mode="tablet"] .app-shell { width: 820px; }
body[data-layout-mode="desktop"] .app-shell { width: 1200px; }
body[data-layout-mode]:not([data-layout-mode="auto"]) { overflow-x: auto; }
.topbar { min-height: 92px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.device-switch { display: flex; justify-content: flex-end; align-items: center; gap: 5px; padding: 10px 0 0; }
.device-switch > span { margin-right: 5px; color: var(--muted); font-size: 11px; }
.device-switch button { min-height: 30px; padding: 4px 10px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 11px; }
.device-switch button[aria-pressed="true"] { border-color: var(--lime); background: #0d3a37; color: var(--lime); }
.brand { display: flex; align-items: center; gap: 15px; color: inherit; text-decoration: none; flex: none; }
.brand-mark { width: 48px; height: 48px; display: grid; place-items: center; border: 3px solid var(--lime); color: var(--lime); font: 900 25px var(--body); transform: rotate(-5deg); }
.brand-copy strong, .brand-copy small { display: block; }
.brand-copy strong { font: 900 17px var(--body); white-space: nowrap; }
.brand-copy i { color: var(--coral); font-style: normal; }
.brand-copy small { margin-top: 6px; color: var(--muted); font: 7px var(--pixel); }
.header-tools { display: flex; align-items: center; gap: 10px; }
.choice-field { height: 48px; min-width: 192px; padding: 6px 10px; display: flex; flex-direction: column; justify-content: center; gap: 4px; background: var(--panel); border: 1px solid var(--line); }
.choice-field > span { color: var(--muted); font: 7px var(--pixel); }
.choice-field select, .choice-field button { width: 100%; padding: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; font-weight: 700; text-align: center; }
.choice-field option { background: #162328; color: var(--ink); }
.hero-field { min-width: 110px; }
.sound-toggle { width: 48px; height: 48px; border: 1px solid var(--line); background: var(--panel); font: 22px var(--pixel); color: var(--ink); }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 292px; gap: 22px; padding: 26px 0 18px; align-items: stretch; }
.stage-column { min-width: 0; }
.stage-frame { position: relative; overflow: hidden; aspect-ratio: 1066 / 600; border: 5px solid #48585d; background: #000; box-shadow: 0 0 0 1px #080d0f, 7px 7px 0 #080d0f; }
.stage-frame canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.stage-hud { position: absolute; inset: 4.5% 3.5% auto; z-index: 2; display: flex; justify-content: space-between; pointer-events: none; color: #fff; text-shadow: 2px 2px #000; }
.hud-block { display: flex; flex-direction: column; gap: 5px; min-width: 86px; font-family: var(--pixel); }
.hud-block span { font-size: 8px; }
.hud-block strong { font-size: 10px; font-weight: 400; }
.hud-block i { font-style: normal; }
.hud-block.centered { text-align: center; }
.hud-block.align-right { text-align: right; }
.screen-overlay { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; padding: 20px; background: rgba(5, 11, 13, .66); text-align: center; }
.screen-overlay[hidden] { display: none; }
.overlay-content { max-width: 560px; }
.overlay-kicker { margin: 0 0 18px; color: var(--lime); font: 8px var(--pixel); }
.overlay-content h1 { margin: 0; color: #fff; font: 900 clamp(32px, 5vw, 58px)/.98 var(--body); text-shadow: 4px 5px 0 var(--coral); }
.overlay-content h1 em { font-style: normal; }
.overlay-copy { margin: 18px 0 22px; font-size: 14px; color: #e0e4db; }
.start-button { min-width: 220px; padding: 15px 22px; border: 0; background: var(--lime); box-shadow: 0 5px 0 #1f7f72; color: #0a1c1a; font-size: 17px; font-weight: 900; }
.start-button span { margin-right: 8px; }
.pause-overlay { position: absolute; z-index: 4; inset: 0; display: grid; place-items: center; background: #0d1518b8; color: var(--lime); font: 14px var(--pixel); }
.pause-overlay[hidden] { display: none; }

.stage-toolbar { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid #33444a; }
.world-progress { display: flex; align-items: center; gap: 9px; color: var(--muted); font: 8px var(--pixel); white-space: nowrap; }
.world-progress strong { color: var(--lime); font-weight: 400; }
.status-lamp { width: 8px; height: 8px; background: var(--lime); box-shadow: 0 0 0 3px #5ce1c622; }
.toolbar-divider { color: #607176; }
.keyboard-help { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.keyboard-help kbd { display: grid; min-width: 24px; height: 24px; place-items: center; border: 1px solid #46575c; border-bottom-width: 3px; background: var(--panel-raised); color: var(--ink); font: 8px var(--pixel); }
.restart-button { display: flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 12px; white-space: nowrap; }
.restart-button span:first-child { font-size: 18px; color: var(--ink); }

.status-panel { min-height: 100%; padding: 20px 21px; display: flex; flex-direction: column; border: 1px solid var(--line); background: rgba(20, 33, 38, .94); }
.panel-title { display: flex; align-items: center; gap: 9px; min-height: 26px; }
.panel-mark { width: 9px; height: 9px; background: var(--lime); box-shadow: 0 0 0 4px #5ce1c619; }
.panel-title strong { font-size: 15px; }
.panel-world { margin-left: auto; color: var(--lime); font: 7px var(--pixel); }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 14px; padding: 23px 0 19px; }
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat strong { font-size: 15px; font-weight: 900; }
.panel-rule { height: 1px; background: var(--line); }
.chapter-heading { display: flex; align-items: center; gap: 11px; padding: 20px 0 13px; }
.chapter-heading span { color: var(--muted); font-size: 13px; }
.chapter-heading strong { font-size: 18px; }
.chapter-heading b { margin-left: auto; color: var(--lime); font: 10px var(--pixel); white-space: nowrap; }
.progress-track { height: 7px; background: #34454a; }
.progress-track span { display: block; width: 1%; height: 100%; background: var(--lime); transition: width .2s linear; }
.progress-labels { display: flex; justify-content: space-between; margin-top: 7px; color: var(--muted); font-size: 12px; }
.panel-bottom { display: flex; justify-content: space-between; gap: 10px; margin-top: auto; padding-top: 18px; color: #77888d; font: 7px var(--pixel); }
.touch-controls { display: none; }
.page-footer { min-height: 42px; display: flex; justify-content: space-between; align-items: center; gap: 12px; border-top: 1px solid var(--line); color: #869599; font: 7px var(--pixel); }
.touch-controls button { flex: 1; min-width: 0; height: 62px; border: 1px solid #34464b; border-bottom: 5px solid #435459; background: #18272c; color: var(--ink); font-size: 26px; touch-action: none; }
.touch-controls .run-control { background: #0d3a37; border-color: #3aa58f; border-bottom-color: #2b7a69; color: var(--lime); font: 700 16px var(--body); }
.touch-controls .jump-control { background: var(--coral); border-color: #f07e71; border-bottom-color: #b6443a; color: #fff; font-weight: 900; }

@container app (max-width: 1000px) {
  .app-shell { width: min(800px, calc(100% - 36px)); }
  .game-layout { grid-template-columns: 1fr; gap: 14px; }
  .stage-column { grid-row: 1; }
  .touch-controls { grid-row: 2; display: flex; gap: 12px; }
  .status-panel { grid-row: 3; min-height: 0; padding: 17px 19px; }
  .stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 16px 0; }
  .chapter-heading { padding-top: 15px; }
  .panel-bottom { display: none; }
}

@container app (max-width: 600px) {
  .app-shell { width: calc(100% - 22px); padding-bottom: 12px; }
  .topbar { min-height: 0; display: flex; flex-wrap: wrap; gap: 12px; padding: 13px 0; }
  .brand { gap: 11px; }
  .brand-mark { width: 43px; height: 43px; font-size: 22px; }
  .brand-copy strong { font-size: 16px; }
  .brand-copy small { font-size: 6px; }
  .header-tools { width: 100%; gap: 7px; }
  .device-switch { justify-content: flex-start; padding-top: 8px; }
  .device-switch button { flex: 1; padding-inline: 5px; }
  .choice-field { height: 45px; flex: 1; min-width: 0; padding: 5px 8px; }
  .choice-field > span { font-size: 6px; }
  .choice-field select, .choice-field button { font-size: 11px; }
  .hero-field { flex: 0 0 76px; }
  .sound-toggle { width: 45px; height: 45px; flex: none; font-size: 17px; }
  .game-layout { gap: 11px; padding: 14px 0 13px; }
  .stage-frame { border-width: 3px; aspect-ratio: 16 / 9; }
  .stage-hud { inset: 4% 2.5% auto; }
  .hud-block { min-width: 0; gap: 4px; }
  .hud-block span { font-size: 6px; }
  .hud-block strong { font-size: 7px; }
  .screen-overlay { padding: 13px; }
  .overlay-kicker { font-size: 6px; margin-bottom: 11px; }
  .overlay-content h1 { font-size: 34px; }
  .overlay-copy { font-size: 11px; margin: 11px 0 14px; }
  .start-button { min-width: 0; width: min(230px, 72%); padding: 12px; font-size: 15px; }
  .stage-toolbar { min-height: 42px; gap: 5px; }
  .world-progress { font-size: 6px; gap: 5px; }
  .status-lamp { width: 6px; height: 6px; }
  .toolbar-divider, .world-progress > span:last-child, .keyboard-help { display: none; }
  .restart-button { padding: 5px 7px; font-size: 10px; }
  .restart-button span:first-child { font-size: 15px; }
  .touch-controls { gap: 8px; }
  .touch-controls button { height: 58px; font-size: 24px; }
  .touch-controls .run-control { font-size: 14px; }
  .status-panel { padding: 14px; }
  .panel-title strong { font-size: 13px; }
  .panel-world { font-size: 6px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 13px 8px; padding: 14px 0; }
  .stat span { font-size: 10px; }
  .stat strong { font-size: 13px; }
  .chapter-heading { gap: 8px; padding: 13px 0 10px; }
  .chapter-heading span { font-size: 11px; }
  .chapter-heading strong { font-size: 16px; }
  .chapter-heading b { font-size: 8px; }
  .progress-labels { font-size: 10px; }
  .page-footer { align-items: flex-start; justify-content: center; flex-direction: column; gap: 7px; padding: 10px 0; font-size: 6px; }
}

@container app (max-width: 340px) {
  .brand-copy strong { font-size: 13px; }
  .choice-field select, .choice-field button { font-size: 9px; }
  .hero-field { flex-basis: 64px; }
  .overlay-content h1 { font-size: 29px; }
  .touch-controls { gap: 5px; }
  .touch-controls button { height: 52px; font-size: 20px; }
  .touch-controls .run-control { font-size: 12px; }
  .stats-grid { gap: 10px 6px; }
}
