:root {
  color-scheme: dark;
  --ink: #07151b;
  --navy: #102733;
  --navy-2: #183b49;
  --cream: #fff4d6;
  --cyan: #49e6e2;
  --yellow: #ffd447;
  --orange: #ff8a3d;
  --coral: #ff5e67;
  --magenta: #cf4cff;
  --green: #58e18b;
  --white: #fff;
  --panel: rgba(7, 21, 27, .88);
  --panel-edge: rgba(142, 238, 238, .33);
  --shadow: 0 18px 60px rgba(0, 0, 0, .45);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overflow: hidden; background: var(--ink); }
body { min-height: 100dvh; color: var(--cream); }
button, select, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.skip-link { position: fixed; left: 12px; top: -80px; z-index: 1000; padding: 10px 14px; color: var(--ink); background: var(--yellow); font-weight: 900; border-radius: 8px; }
.skip-link:focus { top: 12px; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

.incident-header {
  height: 58px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: linear-gradient(180deg, #153744, #091b23);
  border-bottom: 2px solid rgba(73, 230, 226, .42);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .4);
  position: relative;
  z-index: 100;
}
.back-link { color: var(--cream); text-decoration: none; font-weight: 900; letter-spacing: .04em; justify-self: start; }
.back-link:hover, .back-link:focus-visible { color: var(--cyan); }
.incident-brand { display: flex; align-items: center; gap: 10px; justify-self: center; text-align: left; }
.incident-brand strong, .incident-brand small { display: block; }
.incident-brand strong { font-family: "Arial Black", sans-serif; font-size: 13px; letter-spacing: .12em; }
.incident-brand small { color: #a8c7cf; font-size: 10px; letter-spacing: .12em; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--yellow); color: var(--ink); border: 3px solid var(--ink); box-shadow: 0 0 0 2px var(--yellow); font-size: 20px; }
.header-actions { display: flex; justify-content: flex-end; gap: 8px; }
.header-actions button { border: 1px solid rgba(255,255,255,.22); background: rgba(255,255,255,.07); color: var(--cream); border-radius: 8px; padding: 8px 12px; font-weight: 800; cursor: pointer; }
.header-actions button:hover, .header-actions button:focus-visible { border-color: var(--cyan); color: var(--cyan); }

.game-shell { position: relative; height: calc(100dvh - 58px); min-height: 360px; background: radial-gradient(circle at center, #244a55, #07151b 75%); overflow: hidden; isolation: isolate; }
.game-canvas { position: absolute; inset: 0; display: grid; place-items: center; }
.game-canvas canvas { max-width: 100%; max-height: 100%; outline: none; box-shadow: inset 0 0 70px rgba(0,0,0,.35); }
.game-shell[data-state="briefing"] .game-canvas,
.game-shell[data-state="paused"] .game-canvas { filter: saturate(.7) brightness(.62) blur(1px); }

.hud { position: absolute; z-index: 50; pointer-events: none; }
.hud-primary { top: 12px; left: 12px; right: 12px; display: grid; grid-template-columns: minmax(300px, 1fr) repeat(3, minmax(120px, 160px)); gap: 9px; }
.objective-card, .metric-card, .tool-card, .tool-meter {
  background: linear-gradient(145deg, rgba(8, 27, 35, .94), rgba(18, 51, 62, .86));
  border: 1px solid var(--panel-edge);
  box-shadow: 0 8px 24px rgba(0,0,0,.3), inset 0 1px rgba(255,255,255,.08);
  backdrop-filter: blur(12px);
}
.objective-card { padding: 10px 14px; border-left: 5px solid var(--cyan); border-radius: 8px; min-width: 0; }
.objective-card span, .metric-card span, .tool-card span, .tool-meter span { display: block; color: #a9cdd2; font-size: 10px; font-weight: 900; letter-spacing: .13em; }
.objective-card strong { display: block; margin-top: 3px; color: var(--white); font-size: clamp(12px, 1.2vw, 16px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-card { border-radius: 8px; padding: 9px 12px; text-align: center; }
.metric-card strong { display: block; margin-top: 2px; font-family: "Arial Black", sans-serif; font-size: clamp(18px, 2vw, 27px); color: var(--white); }
.rescue-card { border-bottom: 4px solid var(--green); }
.timer-card { border-bottom: 4px solid var(--yellow); }
.property-card { border-bottom: 4px solid var(--orange); }

.meter { position: relative; height: 7px; margin-top: 5px; overflow: hidden; border-radius: 999px; background: rgba(0, 0, 0, .48); box-shadow: inset 0 1px 3px rgba(0,0,0,.75); }
.meter i { display: block; width: 100%; height: 100%; transform-origin: left center; background: linear-gradient(90deg, var(--cyan), var(--green)); border-radius: inherit; transition: width .16s linear, transform .16s linear; }
#property-fill[data-level="warning"] { background: linear-gradient(90deg, var(--yellow), var(--orange)); }
#property-fill[data-level="critical"] { background: linear-gradient(90deg, var(--coral), #ff213f); animation: critical-pulse .55s ease-in-out infinite alternate; }
#heat-fill { background: linear-gradient(90deg, var(--cyan), var(--magenta), var(--coral)); }
#dash-fill { background: linear-gradient(90deg, var(--yellow), var(--green)); }

.hud-tools { left: 12px; bottom: 12px; display: grid; grid-template-columns: repeat(3, minmax(86px, 122px)) repeat(2, minmax(105px, 150px)); gap: 8px; align-items: stretch; }
.tool-card { position: relative; min-height: 58px; padding: 8px 10px 8px 42px; border-radius: 9px; }
.tool-card kbd { position: absolute; left: 8px; top: 10px; display: grid; place-items: center; width: 27px; height: 27px; border-radius: 6px; background: var(--cream); color: var(--ink); border: 2px solid var(--ink); box-shadow: 0 0 0 1px var(--cream); font-family: "Arial Black", sans-serif; }
.tool-card strong { display: block; font-family: "Arial Black", sans-serif; font-size: 22px; line-height: 1; margin-top: 6px; color: var(--white); }
.tool-meter { min-width: 115px; padding: 9px 11px; border-radius: 9px; }

.status-callout { position: absolute; z-index: 70; left: 50%; top: 92px; transform: translate(-50%, -12px); opacity: 0; pointer-events: none; border-radius: 999px; padding: 9px 18px; background: rgba(7, 21, 27, .93); border: 2px solid var(--cyan); color: var(--cream); font-weight: 900; letter-spacing: .04em; box-shadow: var(--shadow); transition: .18s ease; }
.status-callout.is-visible { opacity: 1; transform: translate(-50%, 0); }
.status-callout[data-tone="good"] { border-color: var(--green); color: #c8ffdc; }
.status-callout[data-tone="bad"] { border-color: var(--coral); color: #ffd9de; }
.repair-progress { position: absolute; z-index: 52; left: 50%; bottom: 98px; transform: translateX(-50%); width: min(390px, 75vw); padding: 10px 14px; border-radius: 10px; background: var(--panel); border: 2px solid var(--yellow); box-shadow: var(--shadow); text-align: center; }
.repair-progress span { font-size: 11px; font-weight: 900; letter-spacing: .12em; color: var(--yellow); }
.repair-progress .meter { height: 10px; }
.repair-progress .meter i { background: linear-gradient(90deg, var(--yellow), var(--green)); }
.extraction-countdown { position: absolute; z-index: 51; left: 50%; top: 105px; transform: translateX(-50%); padding: 8px 16px; border-radius: 8px; background: var(--green); color: var(--ink); border: 3px solid var(--ink); box-shadow: 0 0 0 2px var(--green), var(--shadow); font-family: "Arial Black", sans-serif; letter-spacing: .08em; }

.modal { position: absolute; z-index: 90; inset: 0; display: grid; place-items: center; padding: clamp(14px, 3vw, 42px); background: radial-gradient(circle at center, rgba(15, 50, 60, .46), rgba(3, 10, 14, .84)); backdrop-filter: blur(8px); overflow: auto; }
.briefing-panel { grid-template-columns: minmax(0, 1.2fr) minmax(300px, .6fr); gap: clamp(18px, 4vw, 56px); align-items: center; }
.briefing-copy, .dispatch-card, .modal-card, .results-card { width: 100%; max-width: 900px; }
.dispatch-label { display: inline-flex; padding: 6px 10px; border-radius: 6px; background: var(--yellow); color: var(--ink); font-family: "Arial Black", sans-serif; font-size: 11px; letter-spacing: .12em; }
.briefing-copy h1, .modal-card h2, .results-card h2 { margin: 12px 0 12px; font-family: "Arial Black", sans-serif; font-size: clamp(34px, 5vw, 76px); line-height: .98; letter-spacing: -.04em; text-transform: uppercase; text-shadow: 0 4px 0 rgba(0,0,0,.25); }
.briefing-copy > p { max-width: 760px; color: #d6e8e8; font-size: clamp(16px, 1.6vw, 22px); line-height: 1.5; }
.mission-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 24px 0; }
.mission-grid article { min-height: 105px; padding: 14px; border-radius: 10px; background: linear-gradient(145deg, rgba(255,255,255,.1), rgba(255,255,255,.045)); border: 1px solid rgba(255,255,255,.18); }
.mission-grid span { display: block; color: var(--cyan); font-size: 10px; font-weight: 900; letter-spacing: .15em; }
.mission-grid strong { display: block; margin-top: 8px; line-height: 1.3; }
.briefing-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.action-button { display: inline-flex; justify-content: center; align-items: center; min-height: 48px; padding: 11px 20px; border: 0; border-radius: 9px; text-decoration: none; cursor: pointer; font-weight: 950; letter-spacing: .03em; transition: transform .14s ease, box-shadow .14s ease, background .14s ease; }
.action-button:hover, .action-button:focus-visible { transform: translateY(-2px); }
.action-button.primary { color: var(--ink); background: var(--yellow); border: 3px solid var(--ink); box-shadow: 0 0 0 2px var(--yellow), 0 10px 24px rgba(0,0,0,.35); }
.action-button.secondary { color: var(--cream); background: rgba(255,255,255,.08); border: 2px solid rgba(255,255,255,.3); }
.action-button.text-action { color: var(--cyan); background: transparent; }

.dispatch-card { align-self: center; max-width: 430px; justify-self: end; padding: 18px; border-radius: 16px; background: linear-gradient(160deg, #f5e7bd, #cdbf94); color: var(--ink); border: 6px solid #162b34; box-shadow: 16px 18px 0 rgba(0,0,0,.26), var(--shadow); transform: rotate(1.2deg); }
.dispatch-card h2 { margin: 16px 0 8px; font-family: "Arial Black", sans-serif; text-transform: uppercase; }
.dispatch-card ul { list-style: none; padding: 0; margin: 0; }
.dispatch-card li { display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px dashed rgba(7,21,27,.32); }
kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 900; }
.dispatch-note { margin: 13px 0 0; padding: 10px; border-left: 5px solid var(--coral); background: rgba(255,255,255,.38); font-weight: 750; }
.dispatch-map { position: relative; height: 165px; overflow: hidden; border-radius: 10px; background: #173943; border: 4px solid var(--ink); }
.map-room { position: absolute; display: block; border: 3px solid #87bec2; background: rgba(73,230,226,.14); }
.room-one { left: 14px; top: 18px; width: 38%; height: 58%; }
.room-two { left: 46%; top: 14px; width: 25%; height: 38%; }
.room-three { right: 15px; bottom: 17px; width: 25%; height: 42%; }
.map-route { position: absolute; left: 24%; top: 62%; width: 58%; height: 4px; background: var(--cyan); transform: rotate(6deg); box-shadow: 0 0 12px var(--cyan); }
.map-route::after { content: ""; position: absolute; right: -4px; top: -7px; border-left: 13px solid var(--cyan); border-top: 8px solid transparent; border-bottom: 8px solid transparent; }
.map-exit, .map-you { position: absolute; padding: 3px 6px; font-family: "Arial Black", sans-serif; font-size: 9px; border-radius: 4px; }
.map-exit { right: 8px; bottom: 8px; color: var(--ink); background: var(--green); }
.map-you { left: 28px; bottom: 19px; color: var(--ink); background: var(--yellow); }

.compact-modal .modal-card { max-width: 560px; padding: clamp(22px, 4vw, 42px); border-radius: 18px; background: linear-gradient(145deg, rgba(11, 38, 48, .98), rgba(5, 19, 25, .98)); border: 2px solid var(--panel-edge); box-shadow: var(--shadow); text-align: center; }
.compact-modal .modal-card h2, .results-card h2 { font-size: clamp(30px, 4vw, 52px); }
.compact-modal .modal-card > p { color: #bcd6db; }
.compact-modal .action-button { width: 100%; margin-top: 10px; }
.settings-card { text-align: left !important; max-width: 720px !important; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 20px 0; }
.settings-grid label { display: grid; gap: 7px; color: #dcebed; font-weight: 800; }
.settings-grid select, .settings-grid input[type="range"] { width: 100%; accent-color: var(--cyan); border-radius: 8px; background: #eafafa; color: var(--ink); padding: 9px; border: 0; }
.settings-grid .check-row { grid-template-columns: auto 1fr; align-items: center; padding: 10px 12px; background: rgba(255,255,255,.06); border-radius: 8px; }
.settings-grid .check-row input { width: 20px; height: 20px; accent-color: var(--yellow); }
.settings-note { color: #a9cbd0; font-size: 13px; line-height: 1.45; }
.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; margin: 20px 0; }
.controls-grid div { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px; border-radius: 8px; background: rgba(255,255,255,.06); }
.controls-grid kbd { color: var(--yellow); }

.results-card { max-width: 760px; padding: clamp(24px, 4vw, 48px); border-radius: 20px; background: linear-gradient(150deg, #153b48, #07151b 72%); border: 3px solid var(--yellow); box-shadow: 0 0 0 5px var(--ink), 0 0 0 7px var(--yellow), var(--shadow); text-align: center; }
.results-card > p { color: #c7dfe1; font-size: 17px; }
.score-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 24px 0; }
.score-grid article { padding: 18px 10px; border-radius: 12px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.15); }
.score-grid small { display: block; color: #b9d1d5; letter-spacing: .13em; font-weight: 900; }
.score-grid strong { display: block; margin-top: 8px; font-family: "Arial Black", sans-serif; font-size: clamp(22px, 4vw, 38px); }
.report-star { display: block; margin: -35px auto 9px; color: #52646a; font-size: 42px; filter: drop-shadow(0 4px 0 #07151b); }
.report-star.earned { color: var(--yellow); animation: star-in .55s cubic-bezier(.2,1.7,.4,1) both; }
.total-score { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 18px; border-radius: 10px; background: var(--yellow); color: var(--ink); }
.total-score span { font-weight: 950; letter-spacing: .08em; }
.total-score strong { font-family: "Arial Black", sans-serif; font-size: 34px; }
.best-result { margin: 15px 0 20px; }
.results-card .briefing-actions { justify-content: center; }

.touch-controls { display: none; position: absolute; z-index: 60; inset: 0; pointer-events: none; }
.touch-controls button { pointer-events: auto; user-select: none; touch-action: none; border: 2px solid rgba(255,255,255,.38); background: rgba(6, 26, 34, .7); color: var(--white); box-shadow: 0 6px 18px rgba(0,0,0,.35); backdrop-filter: blur(8px); font-family: "Arial Black", sans-serif; }
.touch-controls button.is-active, .touch-controls button:active { background: var(--cyan); color: var(--ink); }
.touch-dpad { position: absolute; left: max(14px, env(safe-area-inset-left)); bottom: max(16px, env(safe-area-inset-bottom)); width: 150px; height: 150px; }
.touch-dpad button { position: absolute; width: 54px; height: 54px; border-radius: 14px; }
.touch-dpad [data-touch-move="up"] { left: 48px; top: 0; }
.touch-dpad [data-touch-move="left"] { left: 0; top: 48px; }
.touch-dpad [data-touch-move="down"] { left: 48px; top: 96px; }
.touch-dpad [data-touch-move="right"] { left: 96px; top: 48px; }
.touch-actions { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(15px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 52px); gap: 7px; align-items: end; }
.touch-actions button { height: 45px; border-radius: 12px; font-size: 11px; }
.touch-actions .pulse-touch { grid-column: span 2; height: 58px; background: rgba(73,230,226,.78); color: var(--ink); }
.noscript { position: fixed; inset: 70px 20px auto; z-index: 1000; background: var(--coral); color: var(--ink); padding: 16px; font-weight: 900; }

.high-contrast-game .objective-card, .high-contrast-game .metric-card, .high-contrast-game .tool-card, .high-contrast-game .tool-meter { background: #000; border-color: #fff; }
.high-contrast-game .hud { filter: contrast(1.25); }
.reduced-motion *, .reduced-motion *::before, .reduced-motion *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }

@keyframes critical-pulse { to { filter: brightness(1.6); } }
@keyframes star-in { from { transform: scale(.2) rotate(-120deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }

@media (pointer: coarse), (max-width: 960px) {
  .touch-controls { display: block; }
  .hud-tools { display: none; }
  .incident-header { height: 48px; grid-template-columns: auto 1fr auto; }
  .game-shell { height: calc(100dvh - 48px); }
  .incident-brand small, .back-link span, #controls-button { display: none; }
  .brand-mark { width: 30px; height: 30px; font-size: 15px; }
  .incident-brand strong { font-size: 10px; }
  .header-actions button { padding: 6px 8px; font-size: 11px; }
  .hud-primary { top: 7px; left: 7px; right: 7px; grid-template-columns: minmax(0, 1fr) repeat(3, 82px); gap: 5px; }
  .objective-card { padding: 6px 9px; border-left-width: 3px; }
  .objective-card span { font-size: 8px; }
  .objective-card strong { font-size: 10px; }
  .metric-card { padding: 5px; }
  .metric-card span { font-size: 7px; }
  .metric-card strong { font-size: 15px; }
  .metric-card .meter { height: 4px; }
  .status-callout { top: 64px; font-size: 11px; padding: 7px 11px; }
  .repair-progress { bottom: 82px; }
  .extraction-countdown { top: 72px; font-size: 11px; }
  .briefing-panel { grid-template-columns: 1fr; display: block; padding: 14px; }
  .briefing-copy { max-width: 760px; margin: auto; }
  .briefing-copy h1 { font-size: clamp(34px, 8vw, 55px); }
  .briefing-copy > p { font-size: 14px; }
  .dispatch-card { display: none; }
  .mission-grid { margin: 13px 0; }
  .mission-grid article { min-height: 75px; padding: 9px; font-size: 11px; }
  .briefing-actions .action-button { min-height: 40px; padding: 8px 13px; }
  .modal { align-items: start; }
  .compact-modal .modal-card, .results-card { margin: auto; padding: 18px; }
  .settings-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .settings-grid label { font-size: 12px; }
  .controls-grid { grid-template-columns: 1fr 1fr; font-size: 11px; }
}

@media (max-width: 620px) {
  .hud-primary { grid-template-columns: 1fr repeat(3, 67px); }
  .objective-card strong { max-width: 42vw; }
  .mission-grid { grid-template-columns: 1fr; }
  .mission-grid article { min-height: 0; }
  .settings-grid, .controls-grid, .score-grid { grid-template-columns: 1fr; }
  .score-grid article { padding: 10px; }
  .report-star { margin: 0; }
}

/* Civic incident campaign */
.incident-board { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 18px 0 12px; }
.incident-card { position: relative; display: grid; gap: 5px; min-height: 108px; padding: 13px; border: 2px solid rgba(255,255,255,.18); border-radius: 12px; background: rgba(4,22,29,.74); box-shadow: inset 0 0 0 1px rgba(255,255,255,.04); }
.incident-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; border-radius: 10px 0 0 10px; background: #48636c; }
.incident-card.is-selected { border-color: var(--yellow); background: linear-gradient(145deg, rgba(21,59,72,.96), rgba(8,30,38,.96)); box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--yellow), 0 12px 28px rgba(0,0,0,.22); }
.incident-card.is-selected::before { background: var(--yellow); }
.incident-card > span { color: var(--cyan); font-size: 10px; font-weight: 950; letter-spacing: .12em; }
.incident-card > strong { font-family: "Arial Black", sans-serif; font-size: 18px; line-height: 1.05; text-transform: uppercase; }
.incident-card > small { color: #aecbd0; font-weight: 900; letter-spacing: .06em; }
.incident-card button { justify-self: start; margin-top: 2px; padding: 6px 9px; border: 1px solid rgba(255,255,255,.3); border-radius: 7px; background: rgba(255,255,255,.08); color: var(--white); font-weight: 900; cursor: pointer; }
.incident-card.is-selected button { color: var(--ink); background: var(--yellow); border-color: var(--yellow); }
.game-shell[data-incident="last-train-out"] .objective-card { border-left-color: #ffb72b; }
.game-shell[data-incident="last-train-out"] .dispatch-label { color: #ffd66b; }
.game-shell[data-incident="last-train-out"] .dispatch-map { background: linear-gradient(145deg, #173943, #24384d); }
@media (pointer: coarse), (max-width: 960px) {
  .incident-board { margin: 9px 0; }
  .incident-card { min-height: 77px; padding: 8px 10px; }
  .incident-card > strong { font-size: 14px; }
  .incident-card button { font-size: 10px; padding: 4px 7px; }
}
@media (max-width: 620px) { .incident-board { grid-template-columns: 1fr; } }
