/* ── Reset & Tokens ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b27;
  --surface2:  #1f2535;
  --border:    #2a3050;

  /* ── Accent — Fire Extinguisher Simulator (extinguisher red) ── */
  --accent:    #e5372b;
  --accent-lo: rgba(229,55,43,.24);

  /* ── Semantic colours — DO NOT CHANGE ── */
  --green:     #3ddc84;
  --red:       #ff5555;
  --gold:      #f5c842;

  --text:      #dde3f0;
  --text-dim:  #6b7a99;
  --font:      'Segoe UI', system-ui, sans-serif;
  --mono:      'Courier New', monospace;
  --radius:    12px;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); min-height: 100vh; padding: 0 16px; }
#app { max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ── Header ─── */
header { text-align: center; padding: 4px 0; }
header h1 {
  font-size: 1.8rem; font-weight: 700;
  background: linear-gradient(120deg, #ff5a36 0%, #ffb02e 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.subtitle { color: var(--text-dim); font-size: 0.85rem; margin-top: 3px; }

/* ── Controls bar ─── */
.controls-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.ctrl-group { display: flex; align-items: center; gap: 8px; }
.ctrl-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); white-space: nowrap; }

/* ── Pills ─── */
.pill-tabs { display: flex; flex-wrap: wrap; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px; }
.pill {
  padding: 5px 13px; border: none; background: transparent; color: var(--text-dim);
  border-radius: 6px; cursor: pointer; font-size: 0.81rem; min-height: 28px;
  transition: background .18s, color .18s, box-shadow .18s;
}
.pill.active { background: var(--accent); color: #fff; box-shadow: 0 0 12px var(--accent-lo); }
.pill:hover:not(.active) { background: var(--surface2); color: var(--text); }

/* ── Buttons ─── */
.btn { padding: 8px 18px; border: none; border-radius: 8px; cursor: pointer; font-size: 0.84rem; font-weight: 600; transition: filter .18s, box-shadow .18s, opacity .18s; }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { filter: brightness(1.12); box-shadow: 0 0 12px var(--accent-lo); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }
.btn-big { width: 100%; padding: 13px 18px; font-size: 0.98rem; }

/* ── Layout: canvas first, rail beside it ─── */
.sim-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; align-items: start; }
.sim-left { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.canvas-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; overflow-x: clip; position: relative; }
.stage-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 8px; }
.scen-pick { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; }
.scen-pick select {
  max-width: 360px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 0.82rem;
}
.stage { position: relative; width: 100%; aspect-ratio: 1100 / 640; border-radius: 8px; overflow: hidden; background: #0a0d14; }
.stage > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage > canvas[hidden] { display: none; }
#fe-gl { touch-action: pan-y; }
#fe-hud { pointer-events: none; }
#fe-hud[hidden], #fe-gl[hidden] { display: none; }
.stage-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; color: var(--text); font-size: 0.95rem; line-height: 1.5; }
.stage-fallback[hidden] { display: none; }
.cam-bar [hidden] { display: none; }
.stage-note {
  position: absolute; left: 50%; top: 66px; transform: translateX(-50%); max-width: 90%; z-index: 4;   /* below the camera bar, never over it */
  padding: 8px 14px; border-radius: 8px; background: rgba(13,17,23,.92); border: 1px solid var(--border);
  font-size: 0.82rem; color: var(--text); text-align: center;
}
.cam-bar { position: absolute; right: 10px; top: 10px; z-index: 3; display: flex; gap: 2px; padding: 3px; border-radius: 8px; background: rgba(13,17,23,.82); border: 1px solid var(--border); }
.cam-bar[hidden] { display: none; }
.status-line { margin-top: 8px; padding: 8px 12px; border-radius: 8px; background: var(--bg); font-size: 0.88rem; color: var(--text); min-height: 36px; }

/* ── Display controls panel (in-canvas) ─── */
.canvas-toggles {
  position: absolute; left: 10px; bottom: 10px; z-index: 3;
  background: rgba(13,17,23,.88); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 0.78rem;
}
.canvas-toggles summary { cursor: pointer; color: var(--text); font-weight: 600; min-height: 24px; line-height: 24px; list-style: none; display: flex; align-items: center; gap: 6px; }
.canvas-toggles summary::-webkit-details-marker { display: none; }
.canvas-toggles .dc-gear { font-size: 1.05rem; line-height: 1; transition: transform .25s; }
.canvas-toggles[open] .dc-gear { transform: rotate(60deg); }
.canvas-toggles label { display: block; margin: 4px 0; color: var(--text); cursor: pointer; }

/* ── Readouts ─── */
.readout-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.readout-cell { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; display: flex; flex-direction: column; gap: 3px; }
.readout-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.readout-value { font-size: 1.05rem; font-weight: 700; color: var(--text); font-family: var(--mono); }
.agent-bar { display: block; height: 5px; border-radius: 3px; background: var(--surface2); overflow: hidden; }
.agent-bar span { display: block; height: 100%; width: 0; background: var(--gold); transition: width .15s; }

/* ── Rail ─── */
.sim-rail { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.rail-title { font-size: 0.95rem; color: var(--gold); }
.guide-steps { list-style: none; display: flex; flex-direction: column; gap: 4px; counter-reset: st; }
.guide-steps li { counter-increment: st; display: flex; gap: 8px; align-items: baseline; font-size: 0.84rem; color: var(--text-dim); padding: 4px 6px; border-radius: 6px; }
.guide-steps li::before { content: counter(st); flex: 0 0 20px; height: 20px; border-radius: 50%; background: var(--surface2); color: var(--text-dim); font-size: 0.72rem; display: inline-flex; align-items: center; justify-content: center; }
.guide-steps li.now { background: var(--accent-lo); color: var(--text); }
.guide-steps li.now::before { background: var(--accent); color: #fff; }
.guide-steps li.done { color: var(--green); }
.guide-steps li.done::before { background: var(--green); color: #0d1117; content: '✓'; }
.guide-steps li.bad { color: var(--red); }
.rail-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.rail-actions .btn { flex: 1 1 auto; }

/* ── Article ─── */
.seo-article { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 22px; line-height: 1.6; font-size: 0.92rem; }
.seo-article h2 { font-size: 1.2rem; margin-bottom: 8px; color: var(--gold); }
.seo-article h3 { font-size: 1rem; margin: 18px 0 6px; color: var(--accent); }
.seo-article a { color: #7cc4ff; }

/* ── Responsive ─── */
@media (max-width: 960px) {
  .sim-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .scen-pick { margin-left: 0; width: 100%; }
  .scen-pick select { max-width: none; flex: 1; }
  .pill { min-height: 36px; }
}
@media (max-width: 500px) {
  body { padding: 0 10px; }
  header h1 { font-size: 1.4rem; }
  .stage { aspect-ratio: 375 / 420; }
  .readout-panel { grid-template-columns: 1fr 1fr; }
}
@media (pointer: coarse) {
  .pill, .btn { min-height: 44px; min-width: 44px; }
  .stage-strip select, .scen-pick select, #ext-select, #how-ext { min-height: 44px; }
  .head-actions .btn-link { min-height: 44px; min-width: 44px; justify-content: center; }
  .canvas-toggles summary { min-height: 44px; line-height: 44px; }
  .canvas-toggles label { min-height: 44px; display: flex; align-items: center; gap: 8px; margin: 0; }
}

/* ── Drill controls ─── */
.squeeze-lever {
  position: absolute; right: 14px; bottom: 14px; z-index: 3; width: 92px; height: 92px; border-radius: 50%;
  border: 3px solid #fff; background: radial-gradient(circle at 35% 30%, #ff6a5a, #b8160f); color: #fff; font-weight: 800; font-size: 0.85rem;
  box-shadow: 0 6px 18px rgba(0,0,0,.45); cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none;
}
.squeeze-lever:active { transform: scale(0.95); filter: brightness(1.15); }
.squeeze-lever[hidden] { display: none; }
.ext-pick { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.ext-pick select { padding: 7px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface2); color: var(--text); }
.score-list { list-style: none; display: flex; flex-direction: column; gap: 3px; font-size: 0.82rem; width: 100%; }
.score-list li.ok::before { content: '✓ '; color: var(--green); }
.score-list li.bad { color: var(--red); }
.score-list li.bad::before { content: '✗ '; }

.debrief p { font-size: 0.84rem; line-height: 1.45; margin: 0 0 6px; color: var(--text); }
.print-only { display: none; }
@media print {
  body * { visibility: hidden; }
  #print-summary, #print-summary * { visibility: visible; }
  #print-summary { display: block; position: absolute; left: 0; top: 0; color: #000; font: 12pt/1.5 serif; padding: 24px; }
}

/* Show me how: the caption and the transport under the stage */
.show-bar { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.show-caption { margin: 0 0 8px; min-height: 2.6em; font-size: 0.95rem; line-height: 1.4; color: var(--text); }
.show-transport { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.show-transport .btn { min-height: 36px; }
.show-scrub { flex: 1 1 180px; min-width: 120px; accent-color: var(--accent); }
.show-time { font-variant-numeric: tabular-nums; font-size: 0.82rem; color: var(--text-dim); min-width: 92px; }
.show-mistake { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--text); cursor: pointer; }
@media (max-width: 500px) { .show-scrub { flex-basis: 100%; order: 5; } }

/* How it works: its controls in the stage strip, the step being explained, the summary */
.how-ctl { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }
.how-ctl[hidden], .how-ctl .pill-tabs[hidden], .scen-pick[hidden] { display: none; }
.how-ctl .scen-pick { margin-left: 0; }
.guide-steps li { flex-wrap: wrap; }
.guide-steps li .how-text { flex-basis: 100%; margin: 4px 0 2px 28px; font-size: 0.84rem; line-height: 1.5; color: var(--text); }
.rail-actions .how-text, .how-sum p { font-size: 0.86rem; line-height: 1.5; color: var(--text); margin: 4px 0 8px; }
.how-sum { padding: 10px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); margin-bottom: 8px; font-size: 0.88rem; }
#fe-gl.aim-touch { touch-action: none; }
/* Explore: the selection chart as a table */
.chart-card { grid-column: 1 / -1; }
.fe-chart { border-collapse: collapse; font-size: 0.8rem; }
.fe-chart th { padding: 4px 6px; text-align: left; font-weight: 600; color: var(--text); white-space: nowrap; }
.fe-chart thead th { text-align: center; }
.fe-chart td { padding: 2px; }
.fe-chart .cell { width: 100%; min-width: 34px; min-height: 30px; border: 1px solid transparent; border-radius: 6px; font-size: 0.95rem; cursor: pointer; }
.fe-chart .cell-yes { background: #1f6b3c; color: #bff5cf; }
.fe-chart .cell-limited { background: #6e5512; color: #ffe39a; }
.fe-chart .cell-no { background: #343a46; color: #aeb6c4; }
.fe-chart .cell-danger { background: #7a1a20; color: #ffd2d2; }
.fe-chart .cell.sel { border-color: #ffffff; }
.chart-reason { margin: 8px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); font-size: 0.9rem; line-height: 1.45; color: var(--text); }
.canvas-toggles[hidden], .canvas-toggles label[hidden] { display: none; }

/* Choose */
.choose-q { margin: 0 0 8px; font-size: 0.9rem; color: var(--text); line-height: 1.4; }
.choose-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.choose-grid .btn { min-height: 40px; text-align: left; white-space: normal; line-height: 1.25; }
.choose-verdict { padding: 10px 12px; border-radius: 8px; margin-bottom: 8px; font-size: 0.88rem; line-height: 1.45; }
.choose-verdict.ok, .prac-fb.ok { background: rgba(31,107,60,0.25); border: 1px solid #2f9a4a; }
.choose-verdict.bad, .prac-fb.bad { background: rgba(122,26,32,0.28); border: 1px solid #c4161c; }
.prac-fb.note { background: var(--surface); border: 1px solid var(--border); }
.choose-verdict p, .prac-fb p { margin: 6px 0 0; }
.choose-score { margin: 8px 0 0; font-size: 0.8rem; color: var(--text-dim); }
/* Explore */
.concepts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.concept-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; font-size: 0.9rem; line-height: 1.5; color: var(--text); }
.concept-card h3 { margin: 0 0 8px; font-size: 1.02rem; color: var(--accent); }
.concept-card ul, .concept-card ol { padding-left: 1.2em; margin: 6px 0; }
.concept-src { margin: 10px 0 0; font-size: 0.75rem; color: var(--text-dim); }
.concept-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.concept-table th, .concept-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.concept-card:has(.concept-table) { grid-column: 1 / -1; overflow-x: auto; }
/* Practice and Quiz */
#sec-practice .pill-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.prac-card, .quiz-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; max-width: 820px; color: var(--text); }
.prac-q, .quiz-q { font-size: 1rem; line-height: 1.5; margin: 0 0 12px; }
.prac-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.prac-row input { width: 140px; min-height: 40px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 1rem; }
.prac-fb { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; font-size: 0.9rem; line-height: 1.45; }
.quiz-prog { font-size: 0.8rem; color: var(--text-dim); margin: 0 0 6px; }
.quiz-opts { display: grid; gap: 8px; margin-bottom: 12px; }
.quiz-opt { text-align: left; white-space: normal; min-height: 44px; line-height: 1.3; }
.quiz-opt.ok { border-color: #2f9a4a; background: rgba(31,107,60,0.25); }
.quiz-opt.bad { border-color: #c4161c; background: rgba(122,26,32,0.28); }
.quiz-score { font-size: 1.2rem; font-weight: 700; margin: 0 0 12px; }

/* header related-tool links (base style; site.css only tunes them) */
.head-actions{display:flex;align-items:center;gap:8px;margin-left:auto;flex-wrap:wrap;justify-content:flex-end;}
.btn-link{display:inline-flex;align-items:center;gap:7px;padding:5px 12px;border-radius:8px;font-size:.82rem;font-weight:700;text-decoration:none;cursor:pointer;background:var(--surface2,#1f2535);color:var(--text,#dde3f0);border:1.5px solid var(--border,#2a3050);white-space:nowrap;transition:border-color .18s,background .18s,color .18s;}
.btn-link:hover{border-color:var(--accent,#4fc3f7);background:var(--accent-lo,rgba(79,195,247,.18));color:#fff;}
.btn-link img{width:20px;height:20px;border-radius:4px;flex:none;}
.btn-link .lbl{line-height:1;}
@media(max-width:560px){.btn-link .lbl{display:none;}.btn-link{padding:5px 9px;}}

/* article tables scroll inside their own box on a phone */
.seo-article .table-wrap{overflow-x:auto;margin:8px 0 12px;-webkit-overflow-scrolling:touch;}
.seo-article table{border-collapse:collapse;width:100%;font-size:.84rem;}
.seo-article th,.seo-article td{border:1px solid var(--border);padding:5px 8px;text-align:left;vertical-align:top;}
.seo-article th{background:var(--surface2,#1f2535);color:var(--text);font-weight:700;}
.seo-article h4{font-size:.95rem;margin:12px 0 4px;}
.seo-article .sources-list{font-size:.8rem;padding-left:18px;overflow-wrap:anywhere;}

/* Train's coach: what to do now and why, inside the step being done */
.guide-steps li .coach { flex-basis: 100%; margin: 4px 0 2px 28px; }
.coach-do { margin: 0 0 4px; font-size: 0.86rem; line-height: 1.5; color: var(--text); font-weight: 600; }
.coach-why { margin: 0; font-size: 0.8rem; line-height: 1.45; color: var(--text-dim); }
.sizeup { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; }
.sizeup li { font-size: 0.8rem; line-height: 1.45; padding: 6px 8px 6px 26px; border-radius: 6px; background: var(--surface2); position: relative; color: var(--text); }
.sizeup li::before { content: '✓'; position: absolute; left: 8px; top: 6px; color: var(--green); font-weight: 700; }
.sizeup li.bad::before { content: '✗'; color: var(--red); }
.btn-chart { width: 100%; background: #1f3a5c; color: #fff; border: 1px solid #3f74b3; font-weight: 700; margin-bottom: 6px; }
.btn-chart:hover { filter: brightness(1.15); }
.btn-reach { width: 100%; background: #1d5a3a; color: #fff; border: 1px solid #3ddc84; font-weight: 700; }
.choose-hint { font-size: 0.82rem; color: var(--text-dim); margin: 0 0 8px; }

/* the selection chart, over the page */
.chart-dlg { position: fixed; inset: 0; z-index: 1000; background: rgba(5,7,12,0.72); display: flex; align-items: center; justify-content: center; padding: 16px; }
.chart-dlg[hidden] { display: none; }
.chart-box { background: var(--surface); border: 1px solid var(--border, #2a3140); border-radius: 12px; max-width: 980px; width: 100%; max-height: calc(100vh - 32px); overflow: auto; padding: 16px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.chart-head h2 { font-size: 1.05rem; margin: 0; }
.chart-now { font-size: 0.86rem; margin: 6px 0 10px; color: var(--text); }
.fe-chart .col-now { background: rgba(255,200,90,0.16); outline: 1px solid rgba(255,200,90,0.5); }

/* the quiz: three kinds */
.quiz-kinds { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-top: 10px; }
.quiz-kind { text-align: left; background: var(--surface2); border: 1px solid var(--border, #2a3140); border-radius: 10px; padding: 12px; color: var(--text); cursor: pointer; display: grid; gap: 4px; font: inherit; }
.quiz-kind:hover, .quiz-kind:focus-visible { border-color: var(--accent); box-shadow: 0 0 10px var(--accent-lo); }
.quiz-kind b { font-size: 1rem; }
.quiz-kind span { font-size: 0.82rem; color: var(--text-dim); line-height: 1.45; }
.rail-actions .choose-q, .rail-actions .choose-hint, .rail-actions .sizeup, .rail-actions .choose-verdict, .rail-actions .debrief { flex-basis: 100%; width: 100%; }
/* the chart in its overlay scrolls sideways on a narrow screen, names pinned; the fire's column is scrolled into view on open */
.chart-box .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chart-box .fe-chart tbody th, .chart-box .fe-chart thead th:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
