:root {
--panel: rgba(247, 243, 232, 0.94);
--ink: #1e2933;
--ink-soft: #4d6171;
--accent: #cf6b21;
--accent-2: #2d74a9;
--accent-3: #4f8f2f;
--danger: #b12d2f;
--line: rgba(30, 41, 51, 0.12);
--shadow: 0 20px 50px rgba(22, 33, 42, 0.16);
--page-max: 860px;
--page-pad: 24px;
}

* { box-sizing: border-box; }

html { margin: 0; }

body {
margin: 0;
background: #d9efff;
color: var(--ink);
font-family: system-ui, -apple-system, sans-serif;
}

/* Lock body scroll during active gameplay only */
body.game-active {
overflow: hidden;
height: 100dvh;
}

/* ── Home section ──────────────────────────────────────────────────────────── */

.home-section {
min-height: 100dvh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
padding: 48px var(--page-pad);
max-width: var(--page-max);
margin: 0 auto;
gap: 28px;
}

.home-section h1 {
margin: 0;
font-size: clamp(2.4rem, 6vw, 4rem);
line-height: 1.05;
letter-spacing: -0.01em;
}

.home-section .intro {
margin: 0;
font-size: 1.1rem;
line-height: 1.7;
color: var(--ink-soft);
max-width: 62ch;
}

.home-section button {
font-size: 1.05rem;
padding: 14px 36px;
min-height: 52px;
}

/* ── Settings section ──────────────────────────────────────────────────────── */

.settings-section {
max-width: var(--page-max);
margin: 0 auto;
padding: 32px var(--page-pad) 64px;
display: flex;
flex-direction: column;
gap: 20px;
}

.settings-header {
display: flex;
align-items: center;
gap: 16px;
padding-bottom: 8px;
}

.settings-header h2 {
margin: 0;
font-size: clamp(1.4rem, 3vw, 2rem);
}

.back-btn {
border-radius: 999px;
padding: 8px 16px;
min-height: 40px;
font-size: 0.92rem;
flex-shrink: 0;
}

.settings-body {
display: flex;
flex-direction: column;
gap: 16px;
}

fieldset {
margin: 0;
border: 1px solid rgba(30, 41, 51, 0.1);
border-radius: 18px;
padding: 18px;
background: rgba(255, 255, 255, 0.7);
display: flex;
flex-direction: column;
gap: 14px;
}

legend {
padding: 0 6px;
font-weight: 700;
color: var(--ink);
font-size: 0.92rem;
text-transform: uppercase;
letter-spacing: 0.06em;
}

.field-grid {
display: grid;
gap: 12px;
grid-template-columns: repeat(2, minmax(0, 1fr));
}

label.select-wrap,
.range-wrap {
display: grid;
gap: 6px;
font-weight: 700;
color: var(--ink);
}

select {
min-height: 48px;
border-radius: 12px;
border: 1px solid rgba(30, 41, 51, 0.14);
background: rgba(255, 255, 255, 0.92);
padding: 10px 12px;
color: var(--ink);
font: inherit;
}

input[type="range"] {
width: 100%;
accent-color: var(--accent-2);
font: inherit;
}

.range-meta {
font-size: 0.92rem;
color: var(--ink-soft);
}

.small-note {
margin: 0;
font-size: 0.88rem;
color: var(--ink-soft);
line-height: 1.5;
}

.terrain-grid {
display: grid;
gap: 8px;
grid-template-columns: repeat(3, minmax(0, 1fr));
}

.check-row {
display: grid;
grid-template-columns: auto 1fr;
align-items: center;
gap: 8px;
min-height: 48px;
border-radius: 12px;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.82);
border: 1px solid rgba(30, 41, 51, 0.1);
font-weight: 600;
cursor: pointer;
}

.check-row input {
width: 18px;
height: 18px;
accent-color: var(--accent-2);
}

/* ── Key bindings disclosure ───────────────────────────────────────────────── */

.keybindings {
border-radius: 14px;
border: 1px solid rgba(30, 41, 51, 0.08);
background: rgba(255, 255, 255, 0.5);
}

.keybindings summary {
padding: 12px 16px;
font-weight: 700;
cursor: pointer;
list-style: none;
display: flex;
align-items: center;
gap: 8px;
color: var(--ink-soft);
font-size: 0.92rem;
}

.keybindings summary::before {
content: "▶";
font-size: 0.7rem;
transition: transform 0.15s;
}

.keybindings[open] summary::before {
transform: rotate(90deg);
}

.keybindings .help-table,
.keybindings p {
margin: 0;
padding: 0 16px 14px;
}

/* ── Settings actions bar ──────────────────────────────────────────────────── */

.settings-actions {
display: flex;
gap: 10px;
align-items: center;
flex-wrap: wrap;
padding-top: 4px;
}

.settings-actions #jumpBtn {
margin-left: auto;
font-size: 1.05rem;
padding: 14px 36px;
min-height: 52px;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */

button {
appearance: none;
border: 0;
border-radius: 999px;
padding: 11px 16px;
min-height: 48px;
background: var(--accent);
color: white;
cursor: pointer;
font: inherit;
font-weight: 700;
letter-spacing: 0.02em;
box-shadow: 0 10px 18px rgba(207, 107, 33, 0.18);
}

button.alt {
background: var(--accent-2);
box-shadow: 0 10px 18px rgba(45, 116, 169, 0.18);
}

button.green {
background: var(--accent-3);
box-shadow: 0 10px 18px rgba(79, 143, 47, 0.18);
}

button.ghost {
background: rgba(30, 41, 51, 0.08);
color: var(--ink);
box-shadow: none;
}

button.outline {
background: transparent;
color: var(--ink);
border: 2px solid rgba(30, 41, 51, 0.22);
box-shadow: none;
}

button.outline:hover {
background: rgba(30, 41, 51, 0.06);
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
outline: 3px solid rgba(45, 116, 169, 0.35);
outline-offset: 2px;
}

/* ── Game canvas (full-screen, hidden until play) ──────────────────────────── */

.stage-wrap {
position: fixed;
inset: 0;
overflow: hidden;
background: #dce9f2;
z-index: 1;
}

.stage-wrap[hidden] { display: none; }

canvas {
display: block;
width: 100%;
height: 100%;
background: #d9efff;
touch-action: none;
}

/* ── In-game topbar (fixed, hidden until play) ─────────────────────────────── */

.topbar {
position: fixed;
top: 14px;
left: 14px;
right: 14px;
z-index: 8;
display: grid;
grid-template-columns: minmax(0, 1.25fr) minmax(0, 2fr) auto;
gap: 10px;
align-items: stretch;
pointer-events: none;
}

.topbar[hidden] { display: none; }

.topbar > * {
pointer-events: auto;
}

/* During play: brand is decorative, hide it to give HUD more space */
.app-shell.playing .brand {
display: none;
}

/* HUD and top-actions use the glassmorphism panel style */
.brand,
.hud-row,
.top-actions {
border: 1px solid rgba(255, 255, 255, 0.55);
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
}

.brand {
border-radius: 22px;
padding: 14px 18px;
display: flex;
align-items: center;
}

.brand h1 {
margin: 0;
font-size: clamp(1.1rem, 2vw, 1.5rem);
letter-spacing: 0.03em;
}

.hud-row {
border-radius: 22px;
padding: 10px;
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 8px;
align-items: stretch;
}

.card {
border-radius: 16px;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.55);
border: 1px solid rgba(30, 41, 51, 0.08);
min-height: 72px;
display: flex;
flex-direction: column;
justify-content: center;
gap: 4px;
}

.card[hidden] { display: none; }

.card .label {
font-size: 0.72rem;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--ink-soft);
}

.card strong {
font-size: 1rem;
line-height: 1.2;
font-family: "Consolas", "SFMono-Regular", ui-monospace, monospace;
}

.top-actions {
border-radius: 22px;
padding: 10px;
display: flex;
gap: 8px;
align-items: center;
justify-content: center;
}

/* Pause button: round pill, dark glass */
#pauseBtn {
min-width: 42px;
min-height: 42px;
padding: 0;
font-size: 1.15rem;
line-height: 1;
border-radius: 50%;
background: rgba(20, 28, 34, 0.72);
color: #fff;
box-shadow: none;
}

/* Settings / Help hidden during normal play, visible when paused */
#menuBtn,
#helpBtn {
display: none;
}

.app-shell.paused-view #menuBtn,
.app-shell.paused-view #helpBtn {
display: inline-flex;
}

.app-shell.paused-view .top-actions {
padding: 8px;
border-radius: 18px;
}

/* ── Result overlay (over canvas) ──────────────────────────────────────────── */

.overlay {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 24px;
background: rgba(217, 239, 255, 0.88);
backdrop-filter: blur(8px);
z-index: 4;
}

.overlay[hidden] { display: none; }

.result-card {
width: min(100%, 700px);
border-radius: 28px;
padding: 28px;
display: flex;
flex-direction: column;
gap: 20px;
align-items: center;
background: rgba(247, 243, 232, 0.96);
border: 1px solid rgba(255, 255, 255, 0.62);
box-shadow: 0 36px 80px rgba(8, 18, 26, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.result-badge {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 12px 24px;
border-radius: 999px;
font-weight: 800;
font-size: 1rem;
letter-spacing: 0.05em;
text-transform: uppercase;
background: #4f8f2f;
color: #ffffff;
border: none;
}

.result-badge.fail { background: #b12d2f; }
.result-badge.near { background: #2d74a9; }

.result-card h2 {
margin: 0;
text-align: center;
font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.result-stats {
display: grid;
gap: 10px;
grid-template-columns: repeat(2, minmax(0, 1fr));
width: 100%;
}

.result-stat {
border-radius: 14px;
padding: 14px;
background: rgba(255, 255, 255, 0.72);
border: 1px solid rgba(30, 41, 51, 0.08);
}

.result-stat span {
display: block;
color: var(--ink-soft);
font-size: 0.76rem;
text-transform: uppercase;
letter-spacing: 0.06em;
}

.result-stat strong {
display: block;
margin-top: 6px;
font-size: 1.3rem;
font-family: "Consolas", "SFMono-Regular", ui-monospace, monospace;
}

.result-actions {
display: flex;
gap: 10px;
justify-content: center;
flex-wrap: wrap;
}

#playAgainBtn {
padding: 14px 36px;
min-height: 52px;
font-size: 1.05rem;
}

#resultSettingsBtn {
padding: 14px 24px;
min-height: 52px;
}

/* ── Touch bar (mobile flight controls) ────────────────────────────────────── */

#touchBar { display: none; }

#touchBar.touch-bar--active { display: flex; }

@media (pointer: fine) {
#touchBar { display: none !important; }
}

.touch-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 6;
padding: 10px 10px calc(14px + env(safe-area-inset-bottom, 0px));
background: rgba(14, 20, 26, 0.82);
border-top: 1px solid rgba(255, 255, 255, 0.1);
backdrop-filter: blur(12px);
flex-direction: column;
gap: 6px;
}

.touch-row {
display: flex;
gap: 6px;
width: 100%;
}

.touch-row--primary {
justify-content: center;
gap: 12px;
}

.touch-row--primary button {
min-width: 140px;
height: 52px;
font-size: 1rem;
font-weight: 800;
border-radius: 14px;
}

.touch-row--primary button[data-control="jump"] {
background: #cf6b21;
color: #fff;
box-shadow: 0 8px 20px rgba(207, 107, 33, 0.4);
}

.touch-row--primary button[data-control="deploy"] {
background: #2d74a9;
color: #fff;
box-shadow: 0 8px 20px rgba(45, 116, 169, 0.4);
}

.touch-row--secondary { justify-content: center; }

.touch-row--secondary button {
flex: 1;
max-width: 120px;
height: 44px;
font-size: 0.88rem;
border-radius: 12px;
background: rgba(255, 255, 255, 0.12);
color: #eef5fb;
box-shadow: none;
}

.touch-row--secondary button.is-held {
background: rgba(255, 255, 255, 0.28);
}

.touch-row--secondary button:disabled {
opacity: 0.35;
cursor: default;
}

/* ── Help table ────────────────────────────────────────────────────────────── */

.help-table {
border-collapse: collapse;
width: 100%;
font-size: 0.88rem;
}

.help-table td {
padding: 4px 8px;
border-bottom: 1px solid rgba(30, 41, 51, 0.08);
}

.help-table td:first-child {
font-weight: 700;
white-space: nowrap;
color: var(--accent-2);
width: 130px;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 820px) {
:root { --page-pad: 16px; }

.home-section {
min-height: 100dvh;
padding: 32px var(--page-pad);
}

.field-grid { grid-template-columns: 1fr; }

.terrain-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.result-stats { grid-template-columns: 1fr; }

.topbar { grid-template-columns: minmax(0, 2fr) auto; }

.hud-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.settings-actions { flex-wrap: wrap; }
.settings-actions #jumpBtn { margin-left: 0; width: 100%; }
}
