:root {
  color-scheme: dark;
  --ink: #f3fbff;
  --muted: #a6c2cc;
  --panel: rgba(5, 20, 30, .88);
  --panel-soft: rgba(8, 30, 42, .72);
  --line: rgba(167, 226, 234, .32);
  --cyan: #8ee8ef;
  --teal: #69dfc7;
  --amber: #ffc857;
  --coral: #ff6b5f;
  --deep: #07141f;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: #07141f; color: var(--ink); }
body { overflow: hidden; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }

.skip-link { position: fixed; top: -100px; left: 18px; z-index: 200; padding: 12px 16px; border-radius: 10px; background: #fff; color: #07141f; font-weight: 800; }
.skip-link:focus { top: 18px; }

.game-shell { position: fixed; inset: 0; display: grid; grid-template-rows: 72px 1fr; background: #102b39; }
.topbar { z-index: 40; display: grid; grid-template-columns: minmax(170px, 1fr) auto minmax(170px, 1fr); align-items: center; min-height: 72px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, rgba(4, 17, 26, .98), rgba(7, 25, 36, .94)); box-shadow: 0 8px 30px rgba(0, 0, 0, .28); }
.brand { justify-self: start; display: inline-flex; align-items: center; }
.brand img { display: block; width: min(190px, 34vw); height: auto; }
.mission-id { text-align: center; letter-spacing: .14em; text-transform: uppercase; }
.mission-id span { display: block; color: var(--amber); font-size: 11px; font-weight: 850; }
.mission-id strong { display: block; margin-top: 3px; font-size: clamp(14px, 1.7vw, 20px); }
.icon-button { justify-self: end; width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 14px; background: rgba(13, 44, 58, .85); color: #fff; font-weight: 900; cursor: pointer; }
.icon-button:hover { background: rgba(31, 77, 91, .95); }

.playfield-wrap { position: relative; min-height: 0; overflow: hidden; isolation: isolate; }
.game-canvas, .game-canvas canvas { width: 100% !important; height: 100% !important; display: block; }
.hud { pointer-events: none; position: absolute; inset: 0; z-index: 25; }

.hud-panel, .message-panel, .objective-panel, .tutorial-card, .controls-panel {
  border: 1px solid var(--line);
  background: linear-gradient(150deg, rgba(4, 18, 28, .93), rgba(8, 34, 46, .78));
  box-shadow: 0 14px 38px rgba(0, 0, 0, .28), inset 0 1px rgba(255, 255, 255, .04);
  backdrop-filter: blur(12px);
}
.flight-panel { position: absolute; top: 18px; left: 18px; width: min(250px, 26vw); padding: 13px 15px; border-radius: 16px; }
.readout { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 8px; }
.readout:first-child { margin-top: 0; }
.readout span, .score span, .objective-panel span, .message-panel span, .tutorial-card span { color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
.readout strong { font-size: 14px; }
.meter { height: 6px; margin-top: 6px; overflow: hidden; border-radius: 999px; background: rgba(255, 255, 255, .1); }
.meter i { display: block; width: 100%; height: 100%; transform-origin: left; background: linear-gradient(90deg, #6fe5cf, #cffff2); transition: transform .12s linear; }
.meter.danger i { background: linear-gradient(90deg, #ff6b5f, #ffd278); }
.meter.lift i { background: linear-gradient(90deg, #62b5ff, #c6f9ff); }

.rescue-panel { position: absolute; top: 18px; right: 18px; width: min(235px, 25vw); padding: 14px 16px; border-radius: 16px; text-align: right; }
.rescue-count { display: flex; align-items: baseline; justify-content: flex-end; gap: 8px; }
.rescue-count strong { color: var(--amber); font-size: clamp(19px, 2.4vw, 30px); }
.rescue-count span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; }
.cabin { min-height: 20px; margin-top: 5px; color: #d8f9fb; font-size: 12px; }
.score { display: flex; justify-content: space-between; align-items: baseline; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.score strong { font-variant-numeric: tabular-nums; letter-spacing: .08em; }

.objective-panel { position: absolute; top: 132px; right: 18px; width: min(310px, 35vw); padding: 10px 14px; border-radius: 12px; text-align: right; }
.objective-panel span { color: var(--amber); }
.objective-panel strong { display: block; margin-top: 3px; font-size: 13px; }

.message-panel { position: absolute; left: 50%; bottom: 30px; width: min(680px, calc(100vw - 430px)); padding: 12px 18px; border-radius: 14px; transform: translateX(-50%); text-align: center; }
.message-panel span { color: var(--amber); }
.message-panel strong { display: block; margin-top: 4px; font-size: clamp(13px, 1.4vw, 18px); }

.tutorial-card { position: absolute; left: 50%; top: 22px; width: min(430px, 42vw); padding: 12px 18px 13px; border-radius: 15px; transform: translateX(-50%); text-align: center; transition: opacity .25s ease, transform .25s ease; }
.tutorial-card.is-hidden { opacity: 0; transform: translate(-50%, -14px); }
.tutorial-card span { color: var(--teal); }
.tutorial-card strong { display: block; margin-top: 2px; font-size: 17px; }
.tutorial-card p { margin: 4px 0 0; color: #c9e3e9; font-size: 13px; }

.controls-panel { position: absolute; left: 18px; bottom: 30px; display: flex; flex-wrap: wrap; gap: 8px 12px; max-width: 360px; padding: 10px 13px; border-radius: 13px; color: #c7dfe5; font-size: 11px; }
kbd { display: inline-block; min-width: 25px; margin-right: 3px; padding: 3px 6px; border: 1px solid rgba(255,255,255,.28); border-bottom-width: 3px; border-radius: 6px; background: rgba(255,255,255,.1); color: #fff; font: 800 10px/1 system-ui; text-align: center; }

.touch-controls { display: none; pointer-events: none; position: absolute; z-index: 35; inset: auto 0 max(8px, env(safe-area-inset-bottom)) 0; justify-content: space-between; align-items: end; gap: 10px; padding: 0 max(10px, env(safe-area-inset-left)) 0 max(10px, env(safe-area-inset-right)); }
.touch-bank { pointer-events: auto; display: flex; gap: 8px; }
.touch-button { position: relative; display: grid; place-items: center; width: 76px; height: 76px; padding: 0; overflow: hidden; border: 0; border-radius: 22px; background: transparent; color: #fff; box-shadow: 0 12px 28px rgba(0,0,0,.36); touch-action: none; user-select: none; }
.touch-button img { width: 100%; height: 100%; display: block; }
.touch-button span { position: absolute; bottom: 8px; padding: 2px 6px; border-radius: 6px; background: rgba(3,14,22,.8); font-size: 9px; font-weight: 900; letter-spacing: .1em; }
.touch-button.is-active { transform: translateY(2px) scale(.96); filter: brightness(1.2); }
.touch-button-down img { transform: rotate(180deg); }
.touch-action { width: 70px; height: 70px; }

.game-dialog { width: min(760px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 0; overflow: visible; background: transparent; color: var(--ink); }
.game-dialog::backdrop { background: radial-gradient(circle at 50% 40%, rgba(14, 53, 69, .42), rgba(2, 9, 15, .92)); backdrop-filter: blur(8px); }
.dialog-card { max-height: calc(100vh - 28px); overflow: auto; padding: clamp(24px, 4vw, 44px); border: 1px solid rgba(179, 235, 240, .32); border-radius: 26px; background: linear-gradient(145deg, rgba(5, 21, 31, .98), rgba(8, 43, 53, .97)); box-shadow: 0 30px 100px rgba(0, 0, 0, .62); }
.dialog-card h1, .dialog-card h2 { margin: 5px 0 12px; line-height: .98; letter-spacing: -.03em; }
.dialog-card h1 { font-size: clamp(42px, 8vw, 78px); }
.dialog-card h2 { font-size: clamp(30px, 5vw, 48px); }
.dialog-card p { color: #c3dde3; line-height: 1.55; }
.eyebrow { margin: 0; color: var(--amber) !important; font-size: 11px; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }
.briefing-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 24px 0; }
.briefing-grid div { padding: 13px 15px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.035); }
.briefing-grid span { display: block; color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.briefing-grid strong { display: block; margin-top: 5px; }
.assist-toggle { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: #d9edf1; }
.assist-toggle input { width: 20px; height: 20px; accent-color: var(--teal); }
.dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 28px; }
.dialog-card button, .dialog-card a { min-height: 46px; border-radius: 12px; font-weight: 850; }
.dialog-card button { padding: 12px 20px; border: 0; background: linear-gradient(135deg, #ffc857, #ff9864); color: #23160b; cursor: pointer; box-shadow: 0 12px 26px rgba(255, 164, 74, .2); }
.dialog-card button.secondary { background: rgba(255,255,255,.09); color: #fff; box-shadow: none; }
.dialog-card a { display: inline-flex; align-items: center; color: #bfeaf0; }
.compact-card { display: grid; gap: 12px; width: min(430px, 100%); margin: auto; text-align: center; }
.result-card { text-align: center; }
.grade { display: grid; place-items: center; width: 112px; height: 112px; margin: 18px auto; border: 5px solid var(--amber); border-radius: 50%; color: var(--amber); font-size: 64px; font-weight: 950; box-shadow: 0 0 36px rgba(255, 200, 87, .22); }
.result-card dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 20px 0; }
.result-card dl div { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.035); }
.result-card dt { color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.result-card dd { margin: 5px 0 0; font-size: 18px; font-weight: 850; }
.result-note { margin: 0 auto 18px; max-width: 520px; font-size: 13px; }

@media (pointer: coarse), (max-width: 980px) {
  .touch-controls { display: flex; }
  .controls-panel { display: none; }
  .message-panel { bottom: 100px; width: min(620px, calc(100vw - 28px)); }
  .flight-panel { width: 210px; }
  .rescue-panel { width: 205px; }
}

@media (max-width: 760px) {
  .game-shell { grid-template-rows: 54px 1fr; }
  .topbar { min-height: 54px; padding: 5px 10px; grid-template-columns: 120px 1fr 45px; }
  .brand img { width: 116px; }
  .mission-id span { font-size: 8px; }
  .mission-id strong { font-size: 11px; }
  .icon-button { width: 40px; height: 40px; border-radius: 11px; }
  .flight-panel { top: 8px; left: 8px; width: 168px; padding: 8px 10px; border-radius: 12px; }
  .readout { margin-top: 4px; }
  .readout span { font-size: 8px; }
  .readout strong { font-size: 11px; }
  .meter { height: 4px; margin-top: 3px; }
  .rescue-panel { top: 8px; right: 8px; width: 156px; padding: 8px 10px; border-radius: 12px; }
  .rescue-count strong { font-size: 17px; }
  .rescue-count span, .cabin { font-size: 8px; }
  .score { margin-top: 5px; padding-top: 5px; font-size: 10px; }
  .objective-panel { top: 76px; right: 8px; width: 210px; padding: 7px 9px; }
  .objective-panel strong { font-size: 10px; }
  .tutorial-card { top: 8px; width: min(330px, 48vw); padding: 7px 10px; }
  .tutorial-card strong { font-size: 12px; }
  .tutorial-card p { display: none; }
  .message-panel { bottom: 86px; width: min(520px, calc(100vw - 18px)); padding: 8px 10px; }
  .message-panel strong { font-size: 11px; }
  .touch-button { width: 62px; height: 62px; border-radius: 18px; }
  .touch-action { width: 58px; height: 58px; }
  .touch-button span { bottom: 5px; font-size: 7px; }
  .briefing-grid, .result-card dl { grid-template-columns: repeat(2, 1fr); }
}

@media (max-height: 500px) and (orientation: landscape) {
  .game-shell { grid-template-rows: 48px 1fr; }
  .topbar { min-height: 48px; }
  .brand img { width: 104px; }
  .flight-panel { transform: scale(.86); transform-origin: top left; }
  .rescue-panel { transform: scale(.86); transform-origin: top right; }
  .objective-panel { top: 66px; }
  .tutorial-card { top: 5px; }
  .message-panel { bottom: 72px; }
  .touch-button { width: 56px; height: 56px; }
  .touch-action { width: 52px; height: 52px; }
  .dialog-card { padding: 20px 26px; }
  .dialog-card h1 { font-size: 42px; }
  .briefing-grid { margin: 14px 0; }
  .assist-toggle { display: inline-flex; margin-right: 18px; font-size: 12px; }
  .dialog-actions { margin-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
