:root {
  --ink: #1f2420;
  --panel: #2b312c;
  --panel-2: #353c36;
  --rule: #4a5249;
  --text: #ece7d8;
  --muted: #a9ad9d;
  --nomex: #f2c230;
  --fire: #ff6a1a;
  --retardant: #ff6f9c;
  --engine: #e0503f;
  --dozer: #c98a3c;
  --air: #7fc4e8;
  --go: #8fd36b;
  --display: "Barlow Semi Condensed", "Arial Narrow", sans-serif;
  --body: Barlow, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--ink); color: var(--text); font: 14px/1.4 var(--body); overflow: hidden; }
button { font: inherit; color: inherit; background: var(--panel-2); border: 1px solid var(--rule); border-radius: 3px; padding: 5px 10px; cursor: pointer; }
button:hover { border-color: var(--muted); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--nomex); outline-offset: 1px; }
button.primary { background: var(--nomex); color: var(--ink); border-color: var(--nomex); font-weight: 500; }
button.on { background: var(--nomex); color: var(--ink); border-color: var(--nomex); }
input, select { font: inherit; color: var(--text); background: var(--ink); border: 1px solid var(--rule); border-radius: 3px; padding: 5px 8px; width: 100%; }
h1, h2, h3, h4 { font-family: var(--display); font-weight: 600; margin: 0; }
.hidden { display: none !important; }
.bad { color: var(--engine); }
small { color: var(--muted); }

/* ---------------- start screen */
#start { height: 100%; overflow: auto; padding: 48px 24px; }
.start-inner { max-width: 1040px; margin: 0 auto; }
.start-head h1 { font-size: 56px; line-height: 1; letter-spacing: -0.01em; }
.tagline { max-width: 62ch; font-size: 17px; color: var(--muted); margin: 14px 0 36px; }
.start-cols { display: grid; grid-template-columns: 1.6fr 1fr; gap: 36px; }
.start-cols h2 { font-size: 20px; margin-bottom: 12px; padding-bottom: 6px; border-bottom: 2px solid var(--nomex); display: inline-block; }
#scenario-list { display: grid; gap: 10px; }
.scenario { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "name region" "brief brief" "meta meta"; text-align: left; padding: 12px 14px; background: var(--panel); border-left: 4px solid var(--rule); border-radius: 0 3px 3px 0; gap: 2px 12px; }
.scenario:hover { border-left-color: var(--nomex); background: var(--panel-2); }
.sc-name { grid-area: name; font: 600 22px var(--display); }
.sc-region { grid-area: region; color: var(--muted); align-self: center; }
.sc-brief { grid-area: brief; color: var(--text); opacity: 0.85; max-width: 70ch; margin-top: 4px; }
.sc-meta { grid-area: meta; color: var(--muted); font-size: 13px; margin-top: 4px; }
.custom { background: var(--panel); padding: 16px; border-radius: 3px; align-self: start; }
.custom p { color: var(--muted); margin: 0 0 12px; font-size: 13px; }
.custom label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.custom input, .custom select { margin-top: 4px; }
.custom button { width: 100%; margin-top: 4px; }
#load-status { min-height: 1.4em; color: var(--nomex); margin: 18px 0 0; }
#start.loading .start-cols { opacity: 0.4; pointer-events: none; }
.how { margin-top: 40px; max-width: 70ch; color: var(--muted); }
.how h2 { font-size: 18px; color: var(--text); margin-bottom: 8px; }

/* ---------------- app layout */
#app { height: 100%; display: grid; grid-template-columns: 96px 1fr 320px; grid-template-rows: 56px 1fr 64px; grid-template-areas: "hud hud hud" "tools map panel" "strip strip strip"; }
#hud { grid-area: hud; display: flex; align-items: stretch; gap: 0; background: var(--panel); border-bottom: 1px solid var(--rule); padding: 0 12px; }
.hud-block { display: flex; flex-direction: column; justify-content: center; padding: 0 16px; border-right: 1px solid var(--rule); font-family: var(--display); font-size: 17px; font-weight: 600; white-space: nowrap; }
.hud-block .sub { font: 12px var(--body); color: var(--muted); }
.hud-block.name { padding-left: 0; }
.hud-block.name #hud-name { font-size: 20px; }
.hud-block.clock #hud-clock { font-size: 28px; line-height: 1; letter-spacing: 0.02em; }
#hud-danger[data-level="low"] { color: var(--go); }
#hud-danger[data-level="moderate"] { color: #d9d36b; }
#hud-danger[data-level="high"] { color: var(--nomex); }
#hud-danger[data-level="extreme"] { color: var(--fire); }
#hud-danger[data-level="critical"] { color: var(--engine); }
#hud-air.bad { color: var(--engine); }
#speeds { flex-direction: row; gap: 4px; align-items: center; }
#speeds button { padding: 4px 9px; font-family: var(--display); font-weight: 600; }
.hud-block.right { margin-left: auto; border-right: 0; flex-direction: row; align-items: center; gap: 8px; padding-right: 0; }
.layer { font: 13px var(--body); color: var(--muted); display: flex; align-items: center; gap: 6px; }
.layer select { width: auto; }

#tools { grid-area: tools; background: var(--panel); border-right: 1px solid var(--rule); display: flex; flex-direction: column; padding: 8px 6px; gap: 4px; }
#tools button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; font-size: 12px; background: transparent; border-color: transparent; }
#tools button:hover { background: var(--panel-2); }
#tools button.on { background: var(--panel-2); border-color: var(--nomex); color: var(--text); }
.ico { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font: 700 13px var(--display); color: var(--ink); background: var(--text); }
.ico.crew { background: var(--nomex); }
.ico.dozer { background: var(--dozer); border-radius: 3px; }
.ico.engine { background: var(--engine); }
.ico.air { background: var(--air); }
.ico.fire { background: var(--fire); }

#map-wrap { grid-area: map; position: relative; overflow: hidden; background: #1c201d; cursor: grab; }
#map-wrap[data-tool="handline"], #map-wrap[data-tool="dozerline"], #map-wrap[data-tool="retardant"], #map-wrap[data-tool="bucket"], #map-wrap[data-tool="burnout"], #map-wrap[data-tool="protect"] { cursor: crosshair; }
#map, #overlay { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#tool-hint { position: absolute; bottom: 36px; left: 14px; right: 12px; color: var(--text); font-size: 13px; background: rgba(31,36,32,0.72); padding: 6px 10px; border-radius: 3px; border-left: 3px solid var(--nomex); width: fit-content; max-width: calc(100% - 100px); }
#hover-info { position: absolute; left: 14px; bottom: 10px; margin-left: 60px; font-size: 12px; color: var(--muted); background: rgba(31,36,32,0.72); padding: 4px 8px; border-radius: 3px; }
#hover-info:empty { display: none; }
#toast { position: absolute; left: 50%; bottom: 40px; transform: translate(-50%, 20px); background: var(--ink); color: var(--text); border-left: 4px solid var(--engine); padding: 10px 14px; border-radius: 3px; opacity: 0; transition: opacity .2s, transform .2s; max-width: 70%; pointer-events: none; font-size: 14px; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#panel { grid-area: panel; background: var(--panel); border-left: 1px solid var(--rule); display: flex; flex-direction: column; min-height: 0; }
#stats { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--rule); }
#stats div { padding: 8px 12px; display: flex; flex-direction: column; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
#stats div:nth-child(3n) { border-right: 0; }
#stats div:nth-child(n+4) { border-bottom: 0; }
#stats span { font: 600 20px/1 var(--display); }
#stats small { font-size: 11px; margin-top: 3px; }
.tabs { display: flex; border-bottom: 1px solid var(--rule); }
.tab { flex: 1; background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 9px 4px; color: var(--muted); font-family: var(--display); font-weight: 600; font-size: 14px; }
.tab.on { color: var(--text); border-bottom-color: var(--nomex); }
.pane { overflow: auto; flex: 1; padding: 10px 12px; }

.res-group { margin-bottom: 12px; }
.res-group h4 { display: flex; align-items: center; gap: 8px; font-size: 15px; margin-bottom: 4px; }
.res-group h4 small { margin-left: auto; font-weight: 400; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.res { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 3px; cursor: pointer; border-left: 3px solid transparent; }
.res:hover { background: var(--panel-2); }
.res.selected { border-left-color: var(--nomex); background: var(--panel-2); }
.res-status { color: var(--muted); font-size: 12px; text-align: right; }
.res.st-working .res-status { color: var(--go); }
.res.st-retreat .res-status, .res.st-lost .res-status, .res.st-grounded .res-status { color: var(--engine); }
.res.st-enroute .res-status { color: var(--air); }
.res.st-lost { opacity: 0.5; cursor: default; }
button.mini { padding: 2px 7px; font-size: 11px; }

.comm { padding: 10px 10px; margin-bottom: 8px; background: var(--panel-2); border-radius: 3px; border-left: 3px solid var(--rule); }
.comm.alerted { border-left-color: var(--nomex); }
.comm.ordered { border-left-color: var(--go); }
.comm.hit { border-left-color: var(--engine); }
.comm-head { display: flex; justify-content: space-between; align-items: baseline; }
.comm-name { font: 600 17px var(--display); }
.comm-pop { color: var(--muted); font-size: 12px; }
.comm-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-top: 3px; }
.comm-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.comm-actions button { font-size: 12px; padding: 4px 8px; }

#weather .brief { color: var(--text); margin: 0 0 12px; }
.wx-day { border-top: 1px solid var(--rule); padding: 8px 0; }
.wx-day h4 { font-size: 15px; margin-bottom: 4px; }
.wx-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); }
.wx-row span:last-child { text-align: right; color: var(--text); }
.wx-row.front span:last-child { color: var(--retardant); }
#weather .note { font-size: 12px; color: var(--muted); }

.log { display: grid; grid-template-columns: 62px 1fr; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--rule); font-size: 13px; }
.log-t { color: var(--muted); font-family: var(--display); font-weight: 600; }
.log.warn span:last-child { color: var(--nomex); }
.log.alert span:last-child { color: var(--engine); }

#strip { grid-area: strip; background: var(--panel); border-top: 1px solid var(--rule); display: grid; grid-template-columns: 1fr auto; align-items: center; padding: 0 12px; gap: 12px; }
#timeline { width: 100%; height: 56px; display: block; }
#source-note { font-size: 11px; color: var(--muted); max-width: 320px; text-align: right; }

/* ---------------- end screen */
#end { position: fixed; inset: 0; background: rgba(31,36,32,0.82); display: grid; place-items: center; padding: 24px; }
.end-card { display: grid; grid-template-columns: 160px 1fr; gap: 24px; background: var(--panel); border-radius: 4px; padding: 28px; max-width: 640px; width: 100%; }
.end-grade { font: 700 140px/1 var(--display); color: var(--nomex); text-align: center; align-self: center; }
.end-text p { margin: 0 0 6px; }
.end-score { font: 600 24px var(--display); }
.end-row { display: grid; grid-template-columns: 1fr auto 60px; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--rule); font-size: 13px; }
.end-row span:last-child { text-align: right; color: var(--muted); }
.end-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }

@media (max-width: 1000px) {
  #app { grid-template-columns: 72px 1fr 260px; }
  .hud-block { padding: 0 10px; font-size: 15px; }
  .hud-block.name { display: none; }
  .start-cols { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  #app { grid-template-columns: 64px 1fr; grid-template-rows: 56px 1fr 220px 64px; grid-template-areas: "hud hud" "tools map" "panel panel" "strip strip"; }
  #panel { border-left: 0; border-top: 1px solid var(--rule); }
  #hud { overflow-x: auto; }
  .hud-block { padding: 0 8px; }
  .hud-block.right .layer, #fit { display: none; }
  #strip { grid-template-columns: 1fr; }
  #source-note { display: none; }
  #timeline { height: 48px; }
  .start-head h1 { font-size: 40px; }
  .end-card { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
