:root {
  color-scheme: dark;
  --ink: #102b3d;
  --panel: rgba(13, 42, 61, .94);
  --panel-soft: rgba(17, 54, 77, .86);
  --cream: #fff4d7;
  --yellow: #ffd45a;
  --coral: #ff7163;
  --cyan: #50d2ff;
  --green: #69df79;
  --shadow: 0 18px 55px rgba(7, 27, 40, .35);
  font-family: Inter, ui-rounded, "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #0f3147; overflow: hidden; }
body { color: white; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.game-shell { min-height: 100dvh; display: grid; grid-template-rows: 74px minmax(0, 1fr) 38px; background: radial-gradient(circle at 50% -30%, #4ea6c8, #102f45 65%); }
.topbar { display: grid; grid-template-columns: 170px minmax(0, 1fr) 48px; align-items: center; gap: 16px; padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); background: linear-gradient(180deg, rgba(9, 34, 50, .98), rgba(12, 47, 68, .96)); border-bottom: 1px solid rgba(255,255,255,.12); box-shadow: 0 8px 30px rgba(0,0,0,.24); z-index: 10; }
.brand-link { width: 160px; height: 58px; overflow: hidden; border-radius: 15px; display: block; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.brand-link img { width: 100%; height: 100%; object-fit: cover; }
.topbar-copy { min-width: 0; display: flex; align-items: baseline; gap: 12px; }
.topbar-copy strong { color: var(--yellow); letter-spacing: .05em; text-transform: uppercase; font-size: .83rem; white-space: nowrap; }
.topbar-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; font-size: clamp(.92rem, 2vw, 1.12rem); }
.icon-button { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.2); border-radius: 14px; background: rgba(255,255,255,.08); color: white; font-size: 1.35rem; cursor: pointer; }
.icon-button:hover, .icon-button:focus-visible { background: rgba(255,255,255,.18); outline: 3px solid rgba(80,210,255,.45); }

.playfield { position: relative; min-height: 0; overflow: hidden; isolation: isolate; }
#game { width: 100%; height: 100%; }
#game canvas { display: block; width: 100% !important; height: 100% !important; object-fit: contain; }

.hud { position: absolute; inset: 14px 14px auto auto; display: grid; grid-template-columns: repeat(2, minmax(118px, auto)); gap: 8px; pointer-events: none; z-index: 4; }
.hud-card { min-height: 58px; padding: 9px 12px; border-radius: 15px; background: var(--panel-soft); border: 1px solid rgba(255,255,255,.14); box-shadow: 0 8px 22px rgba(0,0,0,.22); backdrop-filter: blur(10px); }
.hud-card span { display: block; color: #bde6f2; font-size: .72rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.hud-card strong { display: block; margin-top: 2px; font-size: 1.08rem; }
.hud-tension, .hud-method { grid-column: 1 / -1; }
.hud-tension > div { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.hud-tension strong { font-size: .88rem; color: var(--yellow); }
progress { width: 100%; height: 11px; appearance: none; border: 0; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,.12); }
progress::-webkit-progress-bar { background: rgba(255,255,255,.12); }
progress::-webkit-progress-value { background: linear-gradient(90deg, var(--green) 0 48%, var(--yellow) 62%, var(--coral) 100%); border-radius: 999px; }
progress::-moz-progress-bar { background: linear-gradient(90deg, var(--green) 0 48%, var(--yellow) 62%, var(--coral) 100%); border-radius: 999px; }
.hud-method strong { font-size: .85rem; color: #eafaff; }
.damage-immune .hud-damage strong::after { content: " shielded"; color: var(--green); font-size: .7rem; text-transform: uppercase; }

.modal-card { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); z-index: 8; background: linear-gradient(145deg, rgba(255,250,230,.985), rgba(255,228,171,.985)); color: var(--ink); border: 5px solid #123d57; border-radius: 28px; box-shadow: var(--shadow); }
.eyebrow { margin: 0 0 7px; color: #28759c; font-size: .74rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
h1, h2 { margin: 0; font-family: "Trebuchet MS", system-ui, sans-serif; letter-spacing: -.035em; }
h1 { font-size: clamp(2.15rem, 5vw, 4rem); line-height: .96; color: #184d70; }

.dispatch-board { width: min(1030px, calc(100% - 32px)); padding: 26px; }
.dispatch-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.dispatch-header p:not(.eyebrow) { margin: 10px 0 0; color: #405968; font-weight: 720; }
.dispatch-stamp { flex: 0 0 auto; min-width: 82px; padding: 10px 12px; border: 4px double #d05b52; border-radius: 12px; color: #bb514b; font-size: 1.1rem; font-weight: 950; line-height: .95; text-align: center; transform: rotate(4deg); }
.call-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; }
.call-card { position: relative; min-width: 0; min-height: 305px; display: flex; flex-direction: column; align-items: flex-start; overflow: hidden; padding: 15px; border: 3px solid #245b79; border-radius: 20px; background: linear-gradient(180deg, #f8fbf7, #f9dca6); color: #173b51; text-align: left; cursor: pointer; box-shadow: 0 10px 20px rgba(30,66,81,.14); transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.call-card::after { content: ""; position: absolute; inset: auto -22px -28px auto; width: 112px; height: 112px; border: 18px solid rgba(255,255,255,.25); border-radius: 50%; }
.call-card img { align-self: center; width: 148px; height: 132px; object-fit: contain; margin: -5px 0 4px; filter: drop-shadow(0 8px 10px rgba(33,55,63,.16)); }
.call-number { color: #d15d53; font-size: .72rem; font-weight: 950; letter-spacing: .1em; text-transform: uppercase; }
.call-card strong { margin-top: 5px; font-size: 1.28rem; line-height: 1.04; }
.call-card small { margin-top: 7px; color: #4f6470; font-weight: 720; line-height: 1.35; }
.call-status { position: relative; z-index: 1; margin-top: auto; width: 100%; padding-top: 12px; border-top: 1px solid rgba(23,59,81,.17); color: #246846; font-size: .75rem; font-weight: 900; }
.call-card:not(:disabled):hover, .call-card:not(:disabled):focus-visible { transform: translateY(-3px); border-color: #eb6c5f; box-shadow: 0 16px 28px rgba(35,72,89,.22); outline: 4px solid rgba(80,210,255,.36); }
.call-card:disabled { cursor: not-allowed; filter: saturate(.35); opacity: .66; }
.call-card:disabled::before { content: "LOCKED"; position: absolute; z-index: 2; top: 14px; right: -31px; width: 128px; padding: 6px 0; background: #173b51; color: #fff4d7; font-size: .68rem; font-weight: 950; letter-spacing: .12em; text-align: center; transform: rotate(38deg); }
.call-card:disabled .call-status { color: #7a5860; }
.dispatch-note { display: flex; justify-content: space-between; gap: 18px; margin-top: 15px; padding: 11px 14px; border-radius: 13px; background: rgba(24,77,112,.08); color: #365564; font-size: .78rem; font-weight: 800; }

.mission-card { width: min(900px, calc(100% - 32px)); display: grid; grid-template-columns: 245px minmax(0, 1fr); overflow: hidden; }
.mission-portrait { display: grid; place-items: end center; padding: 24px 18px 0; background: radial-gradient(circle at 50% 25%, #fff7c7, #ff9f9b); }
.mission-portrait img { width: 220px; max-width: 100%; max-height: 420px; object-fit: contain; filter: drop-shadow(0 12px 16px rgba(75,34,54,.18)); }
.mission-copy { padding: 28px 32px 30px; }
.mission-copy > p:not(.eyebrow) { margin: 15px 0; font-size: 1rem; line-height: 1.5; color: #2d4657; }
.mission-facts { display: grid; grid-template-columns: .9fr 1.25fr; gap: 9px; margin: 14px 0; }
.mission-facts span { min-width: 0; padding: 9px 11px; border-radius: 11px; background: rgba(20,65,91,.08); }
.mission-facts small, .mission-facts strong { display: block; }
.mission-facts small { color: #55707d; font-size: .64rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.mission-facts strong { margin-top: 3px; color: #1c4962; font-size: .82rem; line-height: 1.25; }
blockquote { margin: 14px 0 18px; padding: 12px 15px; border-left: 5px solid var(--coral); background: rgba(255,255,255,.58); border-radius: 0 14px 14px 0; font-weight: 800; color: #683d4d; }
.control-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 20px; }
.control-grid span { display: flex; align-items: center; gap: 7px; min-width: 0; padding: 8px; background: rgba(20,65,91,.08); border-radius: 10px; font-size: .72rem; }
.control-grid small { white-space: nowrap; color: #415b69; font-weight: 700; }
kbd { min-width: 34px; padding: 3px 6px; border-radius: 6px; background: #133d57; box-shadow: inset 0 -2px 0 rgba(0,0,0,.25); color: white; font-weight: 900; text-align: center; }

.primary-button, .secondary-button { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; padding: 0 21px; border-radius: 15px; font-weight: 900; text-decoration: none; cursor: pointer; }
.primary-button { border: 0; background: linear-gradient(180deg, #ffdd68, #f5af2d); color: #173447; box-shadow: inset 0 -4px 0 rgba(127,72,11,.26), 0 8px 20px rgba(190,107,15,.25); }
.primary-button:hover, .primary-button:focus-visible { transform: translateY(-1px); outline: 4px solid rgba(80,210,255,.45); }
.secondary-button { border: 2px solid #245b79; color: #245b79; background: rgba(255,255,255,.46); }
.secondary-button:hover, .secondary-button:focus-visible { outline: 4px solid rgba(80,210,255,.35); }
.next-button { background: linear-gradient(180deg, #82e48b, #4dbd67); }

.result-card { width: min(660px, calc(100% - 32px)); padding: 34px; text-align: center; }
.result-card h2 { color: #194f70; font-size: clamp(2rem, 5vw, 3.35rem); }
.score-lockup { margin: 18px auto 9px; display: flex; align-items: baseline; justify-content: center; gap: 10px; }
.score-lockup strong { font-size: clamp(3rem, 8vw, 5.2rem); line-height: 1; color: #db5e51; }
.score-lockup span { font-weight: 900; color: #315064; }
.result-card > p { color: #365364; }
.unlock { padding: 13px; border-radius: 13px; background: #dff7df; color: #25663b !important; font-weight: 850; }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 20px; }

.toast { position: absolute; left: 50%; bottom: 24px; z-index: 7; max-width: min(650px, calc(100% - 36px)); padding: 12px 17px; border: 1px solid rgba(255,255,255,.18); border-radius: 14px; background: rgba(10,38,55,.94); box-shadow: 0 9px 25px rgba(0,0,0,.3); color: white; font-weight: 800; text-align: center; transform: translate(-50%, 18px); opacity: 0; transition: .22s ease; pointer-events: none; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.touch-controls { position: absolute; inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); z-index: 6; display: flex; align-items: flex-end; justify-content: space-between; pointer-events: none; }
.touch-controls button { pointer-events: auto; touch-action: none; user-select: none; border: 2px solid rgba(255,255,255,.28); background: rgba(11,48,69,.82); color: white; box-shadow: 0 7px 18px rgba(0,0,0,.25); font-weight: 900; }
.touch-controls button:active { background: #ffb63b; color: #173447; transform: scale(.97); }
.touch-steer { display: grid; grid-template-columns: repeat(2, 76px); gap: 8px; }
.touch-steer button { height: 76px; border-radius: 24px; font-size: 1.6rem; }
.touch-actions { display: grid; grid-template-columns: repeat(2, 72px); gap: 8px; }
.touch-actions button { height: 58px; border-radius: 18px; font-size: .7rem; }
.touch-actions .throttle { height: 72px; background: rgba(36,151,93,.9); }

.footer-strip { display: flex; align-items: center; justify-content: center; gap: 28px; overflow: hidden; padding: 0 18px; background: #0a2739; border-top: 1px solid rgba(255,255,255,.1); color: #aad6e5; font-size: .75rem; font-weight: 750; white-space: nowrap; }
.footer-strip span::before { content: "•"; margin-right: 9px; color: var(--yellow); }

.settings-dialog { width: min(580px, calc(100% - 28px)); padding: 0; border: 2px solid rgba(255,255,255,.16); border-radius: 24px; color: white; background: linear-gradient(160deg, #123c57, #0b2a3f); box-shadow: var(--shadow); }
.settings-dialog::backdrop { background: rgba(5,19,28,.7); backdrop-filter: blur(7px); }
.settings-dialog form { padding: 24px; }
.settings-dialog header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 15px; }
.settings-dialog h2 { font-size: 1.85rem; }
.settings-dialog label { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 13px 4px; border-top: 1px solid rgba(255,255,255,.12); }
.settings-dialog label span { min-width: 0; }
.settings-dialog label strong, .settings-dialog label small { display: block; }
.settings-dialog label small { margin-top: 3px; color: #aed5e3; line-height: 1.3; }
.settings-dialog input { width: 48px; height: 26px; accent-color: #55d979; flex: 0 0 auto; }
.settings-note { margin: 13px 0 0; color: #9fc6d5; font-size: .8rem; }

[hidden] { display: none !important; }

@media (max-width: 820px) {
  .game-shell { grid-template-rows: 60px minmax(0, 1fr); }
  .topbar { grid-template-columns: 122px minmax(0, 1fr) 42px; gap: 9px; padding-block: 6px; }
  .brand-link { width: 118px; height: 45px; border-radius: 11px; }
  .topbar-copy { display: block; }
  .topbar-copy strong, .topbar-copy span { display: block; }
  .topbar-copy strong { font-size: .65rem; }
  .topbar-copy span { font-size: .82rem; }
  .icon-button { width: 39px; height: 39px; }
  .footer-strip { display: none; }
  .hud { inset: 8px 8px auto auto; grid-template-columns: repeat(2, 102px); gap: 5px; }
  .hud-card { min-height: 48px; padding: 7px 9px; border-radius: 12px; }
  .hud-card span { font-size: .58rem; }
  .hud-card strong { font-size: .88rem; }
  .hud-method { display: none; }
  .dispatch-board { max-height: calc(100% - 20px); overflow: auto; padding: 20px; }
  .dispatch-header { margin-bottom: 14px; }
  .dispatch-stamp { display: none; }
  .call-grid { grid-template-columns: 1fr; }
  .call-card { min-height: 136px; display: grid; grid-template-columns: 106px 1fr; grid-template-rows: auto auto auto 1fr; column-gap: 12px; }
  .call-card img { grid-row: 1 / 5; width: 104px; height: 104px; margin: 0; align-self: center; }
  .call-card .call-status { padding-top: 7px; }
  .dispatch-note { display: none; }
  .mission-card { grid-template-columns: 1fr; max-height: calc(100% - 20px); overflow: auto; }
  .mission-portrait { display: none; }
  .mission-copy { padding: 22px; }
  .mission-facts { grid-template-columns: 1fr; }
  .control-grid { grid-template-columns: repeat(2, 1fr); }
  .result-card { padding: 24px 18px; }
  .toast { bottom: 100px; font-size: .82rem; }
}

@media (max-height: 680px) and (min-width: 821px) {
  .dispatch-board { transform: translate(-50%, -50%) scale(.84); }
  .mission-card { transform: translate(-50%, -50%) scale(.82); }
  .result-card { transform: translate(-50%, -50%) scale(.88); }
  .hud { transform: scale(.86); transform-origin: top right; }
}

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