/*
 * Layout and components. Colors and fonts come from theme.css variables.
 * Touch-first: every control is at least 44px, nothing depends on hover,
 * and the layout works from 360px phones (portrait or landscape) up to desktop.
 */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* Notches and home indicators: keep content clear of the screen edges. */
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 .4em; text-wrap: balance; }
code { font-family: var(--font-mono); font-size: .9em; }
button, input { font: inherit; color: inherit; touch-action: manipulation; }
.muted { color: var(--c-muted); font-weight: 400; font-size: .85em; }
.good { color: var(--c-good); }
.bad { color: var(--c-bad); }
.print-only { display: none; }
small { color: var(--c-muted); }

/* ---------- buttons */
.btn {
  border: 2px solid transparent; border-radius: 999px; padding: .65em 1.3em;
  font-weight: 700; cursor: pointer; min-height: 48px; transition: transform .08s, background .15s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .card-option:focus-visible, .step-tab:focus-visible, .nudge:focus-visible, .lang-btn:focus-visible, input:focus-visible {
  outline: 3px solid var(--c-accent); outline-offset: 2px;
}
.btn[disabled] { opacity: .4; cursor: default; }
.btn-primary { background: var(--c-primary); color: var(--c-primary-ink); box-shadow: 0 3px 0 var(--c-primary-dark); }
.btn-secondary { background: var(--c-secondary); color: var(--c-secondary-ink); }
.btn-ghost { background: transparent; border-color: var(--c-border); }
.btn-big { font-size: 1.1em; padding: .8em 1.6em; min-height: 56px; }
.btn-small { min-height: 44px; padding: .4em 1em; font-size: .9em; }
.btn-icon { min-height: 44px; min-width: 44px; padding: .4em .9em; font-size: .9em; }
.btn-option {
  display: block; width: 100%; text-align: left; background: var(--c-surface-2); border: 2px solid var(--c-border);
  border-radius: var(--radius-small); padding: .9em 1.1em; margin: .5em 0; min-height: 56px; cursor: pointer;
}
.row-buttons { display: flex; gap: .6em; flex-wrap: wrap; margin: .4em 0 .8em; }
/* Hover feedback only on devices that really hover, so taps don't leave "stuck" highlights. */
@media (hover: hover) {
  .btn-primary:hover { background: var(--c-primary-dark); }
  .btn-ghost:hover { background: var(--c-surface-2); }
  .btn-option:hover, .card-option:hover, .nudge:hover { border-color: var(--c-primary); }
}

/* ---------- language switch */
.lang-switch { display: inline-flex; border: 2px solid var(--c-border); border-radius: 999px; overflow: hidden; background: var(--c-surface-2); }
.lang-btn { min-width: 48px; min-height: 44px; border: 0; background: transparent; font-weight: 800; font-size: .85em; letter-spacing: .04em; cursor: pointer; padding: 0 .8em; }
.deltas .flat { color: var(--c-muted); font-weight: 700; }
.lang-btn.on { background: var(--c-secondary); color: var(--c-secondary-ink); }
/* Join form: one big button per language. */
.lang-choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(8em, 1fr)); gap: .5em; }
.lang-option { min-height: 52px; padding: .5em .8em; border: 2px solid var(--c-border); border-radius: var(--radius-small); background: var(--c-surface); color: var(--c-ink); font: 700 1.05em var(--font-body); cursor: pointer; }
.lang-option.on { background: var(--c-secondary); border-color: var(--c-secondary); color: var(--c-secondary-ink); }
.lang-option:focus-visible { outline: 3px solid var(--c-accent); outline-offset: 2px; }

/* ---------- title */
.title-screen { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px 24px;
  background: radial-gradient(circle at 20% 10%, var(--c-bg-2), var(--c-bg) 60%); }
.title-card { background: var(--c-surface); border-radius: 24px; box-shadow: var(--shadow); padding: clamp(18px, 5vw, 36px) clamp(16px, 5vw, 32px); max-width: 680px; width: 100%; text-align: center; }
.title-top { display: flex; justify-content: flex-end; min-height: 44px; }
.title-logo { font-size: clamp(52px, 14vw, 72px); animation: bob 2.6s ease-in-out infinite; }
.title { font-size: clamp(2em, 8vw, 2.8em); color: var(--c-primary); margin: .1em 0 .1em; }
.tagline { color: var(--c-muted); font-size: 1.1em; margin-top: 0; }
.setup { text-align: left; margin-top: 1.2em; display: grid; gap: .7em; }
.field { display: grid; gap: .2em; margin-top: .4em; }
.text-input { font: inherit; padding: .6em .8em; border: 2px solid var(--c-border); border-radius: var(--radius-small); width: 100%; min-height: 48px; background: var(--c-surface); color: var(--c-ink); }
.text-input.mono { font-family: var(--font-mono); text-transform: uppercase; max-width: 260px; }
.text-input.mono::placeholder { text-transform: none; }
.toggle { display: flex; gap: .8em; align-items: flex-start; cursor: pointer; margin: .5em 0; min-height: 44px; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-ui { flex: none; width: 52px; height: 32px; border-radius: 999px; background: var(--c-border); position: relative; transition: background .2s; margin-top: 2px; }
.toggle-ui::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--c-surface); box-shadow: var(--shadow-small); transition: left .2s; }
.toggle input:checked + .toggle-ui { background: var(--c-secondary); }
.toggle input:checked + .toggle-ui::after { left: 24px; }
.toggle input:focus-visible + .toggle-ui { outline: 3px solid var(--c-accent); outline-offset: 2px; }
.setup .btn-big { margin-top: .6em; }
.saved-box { background: var(--c-surface-2); border: 2px dashed var(--c-border); border-radius: var(--radius); padding: 1em; margin-top: 1em; }
.saved-box .row-buttons { justify-content: center; margin-top: .6em; }
.privacy { color: var(--c-muted); font-size: .9em; margin-top: 1.6em; }

/* ---------- HUD */
.hud { display: flex; align-items: center; gap: 10px 18px; flex-wrap: wrap;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 20px 8px;
  background: var(--c-surface); box-shadow: var(--shadow-small); position: sticky; top: 0; z-index: 5; }
.hud-brand { display: flex; align-items: center; gap: 10px; flex: 1 1 280px; min-width: 0; }
.hud-id { min-width: 0; flex: 1; }
.hud-logo { font-size: 34px; flex: none; }
.hud-name { font-family: var(--font-display); font-size: 1.2em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-sub { font-size: .8em; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-actions { display: flex; gap: 8px; align-items: center; flex: none; }
.hud-stats { display: flex; gap: 18px; align-items: center; flex: 0 1 auto; }
.badge { background: var(--c-secondary); color: var(--c-secondary-ink); border-radius: 999px; padding: 1px 8px; font-weight: 700; }
.hud-label { font-size: .75em; text-transform: uppercase; letter-spacing: .05em; color: var(--c-muted); font-weight: 700; white-space: nowrap; }
.hud-big { font-family: var(--font-display); font-size: 1.5em; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hud-big small { font-size: .55em; color: var(--c-muted); }
.hud-stat { min-width: 120px; }
.meter { position: relative; height: 22px; background: var(--c-bg-2); border-radius: 999px; overflow: hidden; min-width: 120px; }
.meter-fill { height: 100%; border-radius: 999px; transition: width .8s ease; background: var(--c-cash); }
.meter.rep .meter-fill, .part-reputation { background: var(--c-rep); }
.meter.mor .meter-fill, .part-morale { background: var(--c-mor); }
.part-cash { background: var(--c-cash); }
.meter-num { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: .85em; }

/* ---------- layout */
.layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 20px; padding: 20px; max-width: 1400px; margin: 0 auto; align-items: start; }
.scene-card { position: sticky; top: 100px; }
.panel { background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0; }

/* ---------- scene */
.scene { position: relative; aspect-ratio: 4 / 3; max-width: 100%; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: var(--scene-floor-a); user-select: none; -webkit-user-select: none; }
.scene-wall { position: absolute; left: 0; right: 0; top: 0; height: 30%; background: var(--scene-wall); border-bottom: 8px solid var(--scene-wall-trim); }
.scene-sign { position: absolute; left: 50%; top: 10%; transform: translateX(-50%); background: var(--scene-sign); color: var(--scene-sign-ink); border-radius: 10px; padding: 4px 16px; text-align: center; box-shadow: var(--shadow-small); max-width: 56%; }
.sign-name { display: block; font-family: var(--font-display); font-size: clamp(12px, 1.5vw, 18px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sign-stars { color: var(--c-accent); letter-spacing: 2px; font-size: clamp(11px, 1.2vw, 15px); }
.scene-window { position: absolute; top: 18%; width: 14%; height: 58%; background: var(--scene-window); border: 5px solid var(--scene-wall-trim); border-radius: 8px 8px 2px 2px; }
.scene-window.w1 { left: 4%; } .scene-window.w2 { right: 4%; }
.scene-decor { position: absolute; left: 3%; bottom: 3%; width: 26%; display: flex; flex-wrap: wrap; gap: 2px 6px; font-size: clamp(14px, 2vw, 24px); line-height: 1.1; }
.scene-decor span { animation: pop .5s ease both; }
.scene-lights { display: none; position: absolute; left: 0; right: 0; top: 4px; height: 12px;
  background: radial-gradient(circle, var(--scene-lights) 35%, transparent 40%) 0 0 / 22px 12px repeat-x; filter: drop-shadow(0 0 4px var(--scene-lights)); }
.tier-3 .scene-lights, .tier-4 .scene-lights { display: block; animation: twinkle 2s ease-in-out infinite; }
.tier-4 .scene-sign { box-shadow: 0 0 0 3px var(--c-accent), var(--shadow-small); }
.scene-floor { position: absolute; left: 0; right: 0; bottom: 0; top: 30%;
  background: repeating-conic-gradient(var(--scene-floor-a) 0 25%, var(--scene-floor-b) 0 50%) 0 0 / 40px 40px; }
.scene-work { position: absolute; left: 3%; top: 6%; width: 24%; height: 52%; background: var(--scene-work); border: 4px solid var(--scene-work-edge); border-radius: 10px; padding: 4px; }
.work-label { font-size: clamp(9px, 1vw, 13px); font-weight: 800; text-transform: uppercase; color: var(--c-muted); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work-staff { display: flex; flex-wrap: wrap; gap: 2px; justify-content: center; font-size: clamp(14px, 2vw, 26px); }
.staff { animation: bob 1.8s ease-in-out infinite; display: inline-block; }
.staff:nth-child(2n) { animation-delay: .5s; }
.seat { position: absolute; width: 13%; aspect-ratio: 1; transform: translate(-50%, -50%); background: var(--scene-seat); border-radius: 50%; display: grid; place-items: center; box-shadow: inset 0 -4px 0 rgba(0,0,0,.18), var(--shadow-small); }
.seat span { font-size: clamp(12px, 1.8vw, 24px); }
.scene-door { position: absolute; right: 2%; bottom: 0; width: 16%; height: 26%; background: var(--scene-door); border-radius: 8px 8px 0 0; display: grid; place-items: center; overflow: hidden; container-type: inline-size; }
/* Sized to the door itself, so the word fits on a small phone scene. */
.scene-door span { color: var(--scene-sign-ink); font-size: clamp(6.5px, 14cqw, 12px); font-weight: 800; letter-spacing: -.02em; text-transform: uppercase; text-align: center; }
.scene-people { position: absolute; inset: 0; pointer-events: none; }
.person { position: absolute; font-size: clamp(16px, 2.4vw, 30px); transform: translate(-50%, -50%); }
.person.sitting { animation: bob 3s ease-in-out infinite; }
.person.walking { transition: left 1.1s ease-in-out, top 1.1s ease-in-out, opacity .8s; }
.person.leaving { opacity: 0; }
.coin { position: absolute; font-size: clamp(14px, 1.8vw, 22px); transform: translate(-50%, -50%); animation: rise .9s ease-out forwards; }

/* ---------- plan steps */
.steps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.step-tab { border: 2px solid var(--c-border); background: var(--c-surface-2); border-radius: var(--radius-small); padding: 8px 4px; cursor: pointer; display: grid; justify-items: center; align-content: center; gap: 2px; min-height: 64px; min-width: 0; }
.step-tab.on { border-color: var(--c-primary); background: var(--c-surface); box-shadow: 0 0 0 2px var(--c-primary) inset; }
.step-tab.done .step-num { color: var(--c-good); }
.step-num { font-size: 1.3em; }
.step-name { font-size: .78em; font-weight: 700; text-align: center; line-height: 1.1; overflow-wrap: break-word; max-width: 100%; }
.step-title { display: none; font-size: 1.2em; margin: .2em 0 0; }
.hint { color: var(--c-muted); margin: .2em 0 .8em; }
.row { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 10px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--c-border); }
.row:last-child { border-bottom: 0; }
.row-icon { font-size: 30px; text-align: center; line-height: 1.3; }
.row-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.row-title { font-weight: 700; min-width: 0; }
.row-sub { font-size: .85em; color: var(--c-muted); }
.row-value { font-family: var(--font-display); font-size: 1.25em; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.row .btn-small { margin-top: 6px; }
.slider { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.nudge { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--c-border); background: var(--c-surface-2); font-size: 1.3em; font-weight: 800; cursor: pointer; line-height: 1; padding: 0; }
/* Range sliders with a large, finger-sized thumb. */
.slider input[type=range] { flex: 1; min-width: 0; height: 44px; margin: 0; background: transparent; -webkit-appearance: none; appearance: none; cursor: pointer; }
.slider input[type=range]::-webkit-slider-runnable-track { height: 8px; border-radius: 999px; background: var(--c-bg-2); }
.slider input[type=range]::-moz-range-track { height: 8px; border-radius: 999px; background: var(--c-bg-2); }
.slider input[type=range]::-moz-range-progress { height: 8px; border-radius: 999px; background: var(--c-primary); }
.slider input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; margin-top: -10px; border-radius: 50%; background: var(--c-primary); border: 3px solid var(--c-surface); box-shadow: var(--shadow-small); }
.slider input[type=range]::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: var(--c-primary); border: 3px solid var(--c-surface); box-shadow: var(--shadow-small); }
.tag { font-size: .7em; padding: 2px 8px; border-radius: 999px; font-weight: 700; vertical-align: middle; white-space: nowrap; }
.tag-warn { background: var(--c-warn-bg); color: var(--c-warn); }
.tag-ok { background: var(--c-good-bg); color: var(--c-good); }
.cap-box { background: var(--c-surface-2); border-radius: var(--radius-small); padding: 10px 12px; margin-top: 10px; }
.cap-legend { font-size: .85em; color: var(--c-muted); margin-bottom: 6px; }
.cap-row { display: grid; grid-template-columns: minmax(70px, 110px) minmax(0, 1fr) auto; gap: 10px; align-items: center; margin: 6px 0; }
.cap-name { font-weight: 700; font-size: .9em; overflow-wrap: anywhere; }
.cap-bar { position: relative; height: 16px; background: var(--c-bg-2); border-radius: 999px; }
.cap-fill { height: 100%; border-radius: 999px; transition: width .3s; }
.cap-fill.ok { background: var(--c-good); }
.cap-fill.short { background: var(--c-bad); }
.cap-mark { position: absolute; top: -4px; bottom: -4px; width: 3px; background: var(--c-ink); border-radius: 2px; }
.cap-num { text-align: right; min-width: 3ch; font-variant-numeric: tabular-nums; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr)); gap: 10px; }
.card-option { display: grid; gap: 4px; align-content: start; text-align: left; border: 2px solid var(--c-border); background: var(--c-surface-2); border-radius: var(--radius-small); padding: 12px; cursor: pointer; min-height: 56px; }
.card-option.on { border-color: var(--c-primary); background: var(--c-surface); box-shadow: 0 0 0 2px var(--c-primary) inset; }
.card-icon { font-size: 28px; }
.card-title { font-weight: 800; }
.card-cost { font-family: var(--font-display); color: var(--c-primary); }
.card-desc { font-size: .88em; color: var(--c-muted); }
.ai-card { background: var(--c-surface-2); border-radius: var(--radius); padding: 14px; }
.ai-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 6px; }
.ai-head p { margin: 0; }
.ai-icon { font-size: 40px; }
.ai-rec-hint { font-size: .9em; color: var(--c-muted); margin: 0 0 10px; }
.cards-ai { grid-template-columns: 1fr; }
.ai-option { background: var(--c-surface); position: relative; }
.ai-option.recommended { border-style: dashed; border-color: var(--c-secondary); }
.ai-option.recommended.on { border-style: solid; border-color: var(--c-primary); }
.rec-badge { justify-self: start; background: var(--c-secondary); color: var(--c-secondary-ink); font-size: .75em; font-weight: 800; border-radius: 999px; padding: 2px 10px; text-transform: uppercase; letter-spacing: .04em; }
.ai-line { font-size: .9em; }
.kind-ai .card-title::before { content: "🤖 "; }
.kind-hybrid .card-title::before { content: "🤝 "; }
.kind-human .card-title::before { content: "🙋 "; }
.flash { background: var(--c-bad-bg); color: var(--c-bad); border-radius: var(--radius-small); padding: 10px 14px; margin: 10px 0; font-weight: 700; }

/* ---------- forecast */
.forecast { background: var(--c-surface-2); border: 2px solid var(--c-border); border-radius: var(--radius); padding: 12px 14px; margin-top: 14px; }
.fc-title { font-weight: 800; margin-bottom: 6px; }
.fc-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.fc-label { font-size: .75em; text-transform: uppercase; letter-spacing: .04em; color: var(--c-muted); font-weight: 700; }
.fc-val { font-family: var(--font-display); font-size: 1.1em; font-variant-numeric: tabular-nums; }
.fc-small { font-size: .78em; color: var(--c-muted); }
.warnings { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 4px; }
.warnings li { font-size: .88em; padding: 6px 10px; border-radius: 8px; }
.warnings li.bad { background: var(--c-bad-bg); color: var(--c-bad); }
.warnings li.warn { background: var(--c-warn-bg); color: var(--c-warn); }
.nav-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- opening */
.opening, .block-wait { text-align: center; padding: 40px 10px; }
.opening-icon { font-size: 64px; animation: bob 1s ease-in-out infinite; }
.progress { height: 12px; background: var(--c-bg-2); border-radius: 999px; overflow: hidden; max-width: 320px; margin: 20px auto 0; }
.progress-bar { height: 100%; width: 100%; background: var(--c-primary); animation: fill 3.6s linear forwards; transform-origin: left; }
.progress-bar.pulse { animation: pulse 1.6s ease-in-out infinite; }

/* ---------- modal */
.modal-back { position: fixed; inset: 0; background: rgba(43, 33, 24, .55); display: grid; place-items: center; z-index: 20; animation: fade .25s ease;
  padding: calc(16px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px)); }
.modal { background: var(--c-surface); border-radius: 20px; box-shadow: var(--shadow); padding: clamp(18px, 5vw, 28px); max-width: 560px; width: 100%; max-height: 90vh; max-height: 100%; overflow: auto; overscroll-behavior: contain; text-align: center; animation: pop .3s ease; }
.modal p { font-size: 1.05em; }
.modal-kicker { font-size: .8em; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; color: var(--c-secondary); }
.modal-icon { font-size: 56px; }
.ev-options { text-align: left; margin-top: 12px; }
.ev-options .btn-big { width: 100%; margin-top: 8px; }
.chips-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0 18px; }
.chip-delta { padding: 4px 12px; border-radius: 999px; font-weight: 800; font-size: .9em; }
.chip-delta.good { background: var(--c-good-bg); color: var(--c-good); }
.chip-delta.bad { background: var(--c-bad-bg); color: var(--c-bad); }

/* ---------- summary */
.big-profit { text-align: center; padding: 10px; border-radius: var(--radius); margin-bottom: 12px; }
.big-profit.good { background: var(--c-good-bg); }
.big-profit.bad { background: var(--c-bad-bg); }
.big-profit .count { font-family: var(--font-display); font-size: clamp(2em, 9vw, 2.6em); font-variant-numeric: tabular-nums; }
.deltas { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; text-align: center; }
.delta { background: var(--c-surface-2); border-radius: var(--radius-small); padding: 8px 4px; min-width: 0; }
.delta b { font-family: var(--font-display); font-size: 1.3em; }
.sum-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 14px; }
.ledger { width: 100%; border-collapse: collapse; font-size: .95em; }
.ledger td { padding: 5px 4px; border-bottom: 1px solid var(--c-border); }
.ledger .total td { font-weight: 800; border-top: 2px solid var(--c-ink); border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.served { display: grid; gap: 8px; align-content: start; }
.served > div { background: var(--c-surface-2); border-radius: var(--radius-small); padding: 8px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.served b { font-family: var(--font-display); font-size: 1.2em; }
.drivers { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.drv { padding: 8px 12px 8px 36px; border-radius: 10px; position: relative; background: var(--c-surface-2); }
.drv::before { position: absolute; left: 10px; top: 8px; }
.drv-good::before { content: "✅"; } .drv-bad::before { content: "⚠️"; } .drv-neutral::before { content: "📊"; } .drv-event::before { content: "📰"; }
.drv-bad { background: var(--c-bad-bg); }
.drv-good { background: var(--c-good-bg); }

/* ---------- debrief */
.debrief h2 { font-size: 1.8em; }
.recap-mini { background: var(--c-surface-2); border-radius: var(--radius-small); padding: 10px 14px; font-size: .92em; }
.questions { font-size: 1.3em; line-height: 1.4; padding-left: 1.4em; display: grid; gap: .8em; margin: 1em 0; }
.questions li { padding-left: .3em; }

/* ---------- block summary */
.block-summary h2 { font-size: 1.7em; }
.block-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 12px 0; }
.tile { background: var(--c-surface-2); border-radius: var(--radius-small); padding: 12px; min-width: 0; }
.tile b { display: block; font-family: var(--font-display); font-size: 1.8em; font-variant-numeric: tabular-nums; }
.tile b small { font-size: .5em; }
.tile-ai { background: var(--c-surface); border: 2px dashed var(--c-secondary); }

/* ---------- end */
.end-screen { max-width: 1100px; margin: 0 auto; padding: calc(20px + env(safe-area-inset-top, 0px)) 16px 40px; display: grid; gap: 16px; }
.end-top { display: flex; justify-content: flex-end; }
.end-hero { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 20px; align-items: center; background: var(--c-surface); border-radius: 24px; box-shadow: var(--shadow); padding: 24px; }
.end-hero h1 { font-size: clamp(1.8em, 7vw, 2.4em); color: var(--c-primary); margin: .1em 0; }
.end-hero p { margin: 0; color: var(--c-muted); }
.end-icon { font-size: 72px; animation: pop .6s ease both; }
.score { text-align: center; }
.score-num { font-family: var(--font-display); font-size: 3em; color: var(--c-secondary); line-height: 1; }
.end-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 16px; }
.end-card { background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow-small); padding: 16px 18px; min-width: 0; }
.part { display: grid; grid-template-columns: minmax(80px, 110px) minmax(0, 1fr); gap: 10px; align-items: center; margin: 6px 0; }
.final-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 12px; text-align: center; }
.final-stats b { display: block; font-family: var(--font-display); font-size: 1.3em; }
.chart { width: 100%; height: auto; }
.chart .line { fill: none; stroke-width: 3; }
.chart .dot { stroke: var(--c-surface); stroke-width: 1.5; }
.chart .c-cash { stroke: var(--c-cash); } .chart .dot.c-cash { fill: var(--c-cash); }
.chart .c-rep { stroke: var(--c-rep); } .chart .dot.c-rep { fill: var(--c-rep); }
.chart .c-mor { stroke: var(--c-mor); } .chart .dot.c-mor { fill: var(--c-mor); }
.chart .zero { stroke: var(--c-bad); stroke-dasharray: 4 4; }
.chart .tick { font-size: 11px; fill: var(--c-muted); text-anchor: middle; }
.key.c-rep { color: var(--c-rep); } .key.c-mor { color: var(--c-mor); }
.ai-totals { margin: 0 0 8px; font-weight: 700; }
.ai-recap { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.ai-rec { border-left: 6px solid var(--c-border); background: var(--c-surface-2); border-radius: 8px; padding: 8px 12px; }
.ai-rec.ai-helped { border-left-color: var(--c-good); }
.ai-rec.ai-hurt { border-left-color: var(--c-bad); }
.ai-rec-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.ai-verdict { font-weight: 800; font-size: .85em; white-space: nowrap; }
.ai-rec-choice { font-size: .9em; color: var(--c-muted); }
.ai-rec-lesson { margin-top: 2px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.weeks { width: 100%; border-collapse: collapse; font-size: .9em; }
.weeks th, .weeks td { padding: 6px 8px; border-bottom: 1px solid var(--c-border); text-align: left; white-space: nowrap; }
.weeks th { font-size: .8em; text-transform: uppercase; color: var(--c-muted); }
.weeks .num { text-align: right; }

.fatal { max-width: 640px; margin: 60px auto; padding: 24px; background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ---------- tablet and phone */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; gap: 14px; }
  .scene-card { position: static; width: 100%; max-width: 520px; margin: 0 auto; }
  .hud { padding-left: 16px; padding-right: 16px; }
  .hud-stat, .meter { min-width: 96px; }
}
@media (max-width: 640px) {
  body { font-size: 16px; }
  .hud { gap: 6px 10px; padding-top: calc(6px + env(safe-area-inset-top, 0px)); padding-bottom: 6px; }
  .hud-brand { flex: 1 1 100%; }
  .hud-logo { font-size: 26px; }
  .hud-name { font-size: 1.05em; }
  .hud-actions .btn-text { display: none; }
  .hud-actions .btn-icon { padding: 0; width: 44px; }
  .hud-stats { flex: 1 1 100%; display: grid; grid-template-columns: auto auto minmax(0, 1fr) minmax(0, 1fr); gap: 4px 10px; }
  .hud-stat, .meter { min-width: 0; }
  .hud-big { font-size: 1.2em; }
  .hud-label { font-size: .68em; overflow: hidden; text-overflow: ellipsis; }
  .meter { height: 20px; }
  .scene-card { max-width: 420px; }
  .panel { padding: 14px 12px; border-radius: 14px; }
  .fc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sum-grid { grid-template-columns: minmax(0, 1fr); }
  .end-hero { grid-template-columns: minmax(0, 1fr); text-align: center; padding: 18px; }
  /* Narrow screens: tabs show icons only; the current step's name sits above its hint. */
  .step-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .step-tab { min-height: 52px; padding: 6px 2px; }
  .step-num { font-size: 1.5em; }
  .step-title { display: block; }
  .questions { font-size: 1.15em; }
}
@media (max-width: 400px) {
  .row { grid-template-columns: 32px minmax(0, 1fr); gap: 8px; }
  .row-icon { font-size: 24px; }
  .row-value { font-size: 1.1em; }
  .nudge { width: 44px; height: 44px; }
  .slider { gap: 4px; }
  .delta b { font-size: 1.1em; }
  .hud-stats { grid-template-columns: auto auto minmax(0, 1fr) minmax(0, 1fr); gap: 2px 8px; }
  .block-tiles { grid-template-columns: minmax(0, 1fr); }
}
/* Phones held sideways: little height, so keep the scene beside the
   decisions and let the top bar scroll away. */
@media (orientation: landscape) and (max-height: 520px) {
  .hud { position: static; }
  .layout { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); padding: 10px 16px; gap: 14px; }
  .scene-card { position: sticky; top: 10px; max-width: none; }
  .hud { flex-wrap: nowrap; }
  .hud-brand { flex: 1 1 auto; min-width: 150px; }
  .hud-actions .btn-text { display: none; }
  .hud-actions .btn-icon { padding: 0; width: 44px; }
  .hud-stats { flex: 0 1 auto; display: flex; gap: 10px; }
  .hud-stat, .meter { min-width: 80px; }
  .step-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .step-tab { min-height: 48px; }
  .step-title { display: block; }
  .title-screen { place-items: start center; }
  .modal-icon { font-size: 40px; }
}

/* ---------- motion */
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.person.sitting { animation-name: bobp; }
@keyframes bobp { 0%, 100% { transform: translate(-50%, -50%); } 50% { transform: translate(-50%, calc(-50% - 3px)); } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 1; transform: translate(-50%, -50%); } to { opacity: 0; transform: translate(-50%, -220%); } }
@keyframes twinkle { 50% { opacity: .55; } }
@keyframes fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- print (end-of-game results page) */
@media print {
  body { background: #fff; font-size: 12pt; padding: 0; }
  .no-print, .hud, .btn { display: none !important; }
  .print-only { display: block; }
  .print-head { font-weight: 700; border-bottom: 2px solid #000; padding-bottom: 6px; }
  .end-screen { padding: 0; gap: 10px; }
  .end-hero, .end-card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .ai-rec { break-inside: avoid; }
  .end-icon, .scene-lights { animation: none; }
}
