:root {
  --navy: #0b2340; --navy2: #12335a; --ink: #f2f7fb; --muted: #a9bfd3; --teal: #36c9a4; --teal2: #1ea184;
  --gold: #ffd45a; --red: #ff6b5e; --card: #ffffff; --cardInk: #14243a; --line: rgba(255,255,255,.14);
  --fs: 16px; --safeB: env(safe-area-inset-bottom, 0px);
}
:root[data-large="1"] { --fs: 20px; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0f3b63; color: var(--ink); font: var(--fs)/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; }
body { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto; height: 100dvh; }
[hidden] { display: none !important; }
#hud, #stage, #toolbar, .tools, .ctrl { min-width: 0; }
button { font: inherit; color: inherit; cursor: pointer; }
.sr, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 99; background: var(--gold); color: #000; padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

#hud { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 8px 12px; background: linear-gradient(var(--navy2), var(--navy)); border-bottom: 1px solid var(--line); z-index: 5; }
.hud-name { background: none; border: 0; font-weight: 800; font-size: 1.1rem; padding: 6px 8px; border-radius: 8px; min-height: 48px; }
.hud-name:hover { background: rgba(255,255,255,.08); }
.hud-date { min-width: 108px; font-weight: 700; }
.mbar { height: 4px; background: rgba(255,255,255,.18); border-radius: 3px; margin-top: 3px; overflow: hidden; }
.mbar i { display: block; height: 100%; width: 0; background: var(--teal); }
.hud-stat { display: flex; flex-direction: column; line-height: 1.1; min-width: 70px; }
.hud-stat .k { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hud-stat b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.hud-stat.bad b { color: var(--red); }
.hud-demand { margin-left: auto; display: flex; gap: 4px; background: rgba(255,255,255,.06); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; min-height: 44px; align-items: flex-end; }
.dm { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 46px; height: 46px; justify-content: flex-end; position: relative; }
.dm u { text-decoration: none; font-size: .62rem; color: var(--muted); font-weight: 700; order: 2; white-space: nowrap; line-height: 1; }
.dm u em { font-style: normal; color: var(--teal); }
.dm i { width: 14px; border-radius: 2px; background: var(--teal); min-height: 2px; max-height: 26px; }
.dm i.neg { background: var(--red); }
.dm i.neg + u em { color: var(--red); }
.dm i.flat { background: #8a9bb0; }
.dm i.flat + u em { color: #8a9bb0; }

#stage { position: relative; min-height: 0; overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: grab; }
#zoomctl { position: absolute; right: 10px; top: 44px; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
#zoomctl button { width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: rgba(10,30,56,.82); font-size: 1.3rem; font-weight: 700; }

/* One flex column holds the tutorial (top) and the dock (bottom), so the cards can never overlap each other. */
#overlays { position: absolute; left: 10px; right: 10px; top: 10px; bottom: calc(10px + var(--sheetH, 0px)); z-index: 6; display: flex; flex-direction: column; justify-content: space-between; gap: 8px; pointer-events: none; }
#overlays > * { pointer-events: auto; }
#coach { flex: 0 1 auto; min-height: 0; overflow: auto; align-self: flex-start; max-width: min(360px, calc(100% - 70px)); background: rgba(255,255,255,.97); color: var(--cardInk); border-radius: 14px; padding: 12px 14px; box-shadow: 0 6px 22px rgba(0,0,0,.35); border-left: 6px solid var(--teal); }
#coach .skip-tut { color: #8a3a2f; }
#coach b { display: block; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: #0f7a63; margin-bottom: 2px; }
#coach p { margin: 0 0 6px; font-size: .98rem; }
#coach .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: .8rem; color: #50657d; }
#coach button { border: 0; background: none; color: #1f6fb2; text-decoration: underline; padding: 6px 8px; min-height: 48px; min-width: 48px; }
/* One bottom dock stacks report, toasts, the action bar and the save pill so they can never overlap. */
#dock { flex: 0 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; pointer-events: none; }
#dock > * { pointer-events: auto; flex: 0 0 auto; }
#dock > #saveState, #dock > #toasts { pointer-events: none; }
#report { width: min(380px, 100%); background: rgba(255,255,255,.97); color: var(--cardInk); border-radius: 14px; padding: 10px 12px; box-shadow: 0 6px 22px rgba(0,0,0,.35); font-size: .88rem; border-left: 6px solid var(--gold); animation: rise .25s ease-out; }
#report .adv { margin: 6px 0 0; padding: 6px 8px; background: #eaf7f2; border-radius: 8px; color: #0b4f40; font-weight: 600; }
#report .adv b { color: #0b6b55; }
@keyframes rise { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
#toasts { display: flex; flex-direction: column; gap: 6px; align-self: center; align-items: center; max-width: min(560px, 100%); }
.toast { animation-duration: .12s; background: var(--card); color: var(--cardInk); padding: 9px 14px; border-radius: 12px; box-shadow: 0 6px 22px rgba(0,0,0,.4); font-weight: 600; font-size: .92rem; animation: rise .2s ease-out; }
.toast.err { background: #fff0ee; border: 2px solid var(--red); }
#report ul { margin: 4px 0 0; padding-left: 18px; }
#report li { margin: 1px 0; }
#report h3 { margin: 0; font-size: .9rem; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
#report h3 button { border: 0; background: none; font-size: 1.3rem; min-width: 48px; min-height: 48px; margin: -8px -8px -8px 0; color: inherit; }

#legend { background: rgba(8,24,44,.88); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: .85rem; max-width: 280px; }
#inspector { position: absolute; right: 72px; top: 44px; width: 320px; max-width: calc(100% - 20px); max-height: calc(100% - 60px); overflow: auto; background: var(--card); color: var(--cardInk); border-radius: 14px; padding: 14px; box-shadow: 0 8px 28px rgba(0,0,0,.4); z-index: 4; }
#inspector h2 { margin: 0 0 4px; font-size: 1.1rem; padding-right: 40px; }
#inspector .x { position: absolute; top: 6px; right: 6px; width: 48px; height: 48px; border: 0; border-radius: 10px; background: #e8eef5; font-size: 1.2rem; color: #14243a; }
#inspector dl { margin: 8px 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: .92rem; }
#inspector dt { color: #5a6f86; } #inspector dd { margin: 0; font-weight: 600; }
#inspector .why { background: #eef6ff; border-radius: 10px; padding: 8px 10px; font-size: .9rem; margin: 8px 0; }
#inspector .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

#action { align-self: center; max-width: min(560px, 100%); background: var(--card); color: var(--cardInk); padding: 10px 12px; border-radius: 14px; box-shadow: 0 8px 28px rgba(0,0,0,.45); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#action span { flex: 1 1 200px; font-weight: 600; font-size: .92rem; }
#action.err { background: #fff0ee; border: 2px solid var(--red); }

.btn { min-height: 48px; min-width: 48px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.08); padding: 4px 10px; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 0; font-weight: 600; line-height: 1.1; }
.btn span { font-size: .68rem; font-weight: 600; color: var(--muted); }
.btn:active:not(:disabled) { background: rgba(255,255,255,.26); }
@media (hover: hover) { .btn:hover:not(:disabled) { background: rgba(255,255,255,.18); } }
.btn.on, .btn.lit, .btn[aria-pressed="true"], .btn.on:hover, .btn.on:active, .btn.on:focus { background: var(--teal); color: #052; border-color: var(--teal); }
.btn.primary, .btn.primary:hover:not(:disabled), .btn.primary:focus, .btn.primary:focus-visible, .btn.primary:active:not(:disabled) { background: var(--gold); color: #3a2a00; border-color: var(--gold); }
.btn.primary:active:not(:disabled) { background: #ffc21f; transform: translateY(1px); }
.btn.primary { flex-direction: row; gap: 6px; padding: 4px 18px; font-weight: 800; font-size: 1.05rem; box-shadow: 0 2px 10px rgba(255,212,90,.35); }
.btn.dot { position: relative; }
.btn.dot::after { content: ""; position: absolute; top: 5px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 2px rgba(11,35,64,.9); }
.btn.primary span { color: inherit; font-size: 1rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.pulse { animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,212,90,.7); } 50% { box-shadow: 0 0 0 7px rgba(255,212,90,0); } }
@media (prefers-reduced-motion: reduce) { .btn.pulse { animation: none; outline: 3px solid var(--gold); } }
:root[data-motion="0"] .btn.pulse { animation: none; outline: 3px solid var(--gold); }

#toolbar { background: linear-gradient(var(--navy), #081a30); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safeB)); display: flex; flex-direction: column; gap: 6px; z-index: 5; }
.tools { display: flex; gap: 6px; overflow-x: auto; -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 22px), transparent); padding-bottom: 2px; scrollbar-width: thin; }
.tool { flex: 0 0 auto; min-width: 62px; min-height: 60px; border: 2px solid transparent; border-radius: 12px; background: rgba(255,255,255,.07); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 6px; line-height: 1.1; }
.tool .ic { font-size: 1.35rem; }
.tool .lb { font-size: .72rem; font-weight: 700; white-space: nowrap; }
.tool .cs { font-size: .72rem; color: var(--muted); }
.tool[aria-pressed="true"] { border-color: var(--gold); background: rgba(255,212,90,.18); }
.tool:disabled { opacity: .4; }
.tool.sep { margin-left: 8px; }
.ctrl { display: flex; gap: 6px; align-items: center; overflow-x: auto; }
.speed { display: flex; gap: 4px; }
.speed .btn { font-size: .85rem; padding: 4px 8px; }
.ctrl .btn { flex: 0 0 auto; }

dialog { border: 0; border-radius: 18px; padding: 0; width: min(680px, calc(100vw - 20px)); max-height: calc(100dvh - 24px); background: var(--card); color: var(--cardInk); box-shadow: 0 20px 60px rgba(0,0,0,.55); }
dialog { overflow: visible; }
dialog::backdrop { background: rgba(4,14,28,.66); }
.dlg { padding: 18px 18px 16px; max-height: calc(100dvh - 24px); overflow: auto; position: relative; }
.dlg h2 { margin: 0 8px 8px 0; font-size: 1.3rem; outline: none; }
.dlg h2:focus { outline: none; }
.dlg h3 { margin: 16px 0 6px; font-size: 1rem; }
.dlg p { margin: 6px 0; }
/* The title row is a solid sticky header of its own, so table rows never show through or run under the close button. */
.dlg-head { position: sticky; top: -18px; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: -18px -18px 8px; padding: 12px 12px 8px 18px; background: var(--card); border-bottom: 1px solid #e3eaf2; border-radius: 18px 18px 0 0; }
.dlg-head h2 { margin: 0; }
.dlg .x { flex: 0 0 auto; width: 48px; height: 48px; border: 0; border-radius: 12px; background: #e8eef5; font-size: 1.3rem; color: #14243a; }
.hero { position: relative; }
.hero .x { position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,.2); color: #fff; }
.dlg table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.dlg th, .dlg td { text-align: right; padding: 4px 6px; border-bottom: 1px solid #e3eaf2; }
.dlg th:first-child, .dlg td:first-child { text-align: left; }
.dlg .pos { color: #0b7a4d; } .dlg .neg { color: #b3261e; }
.dlg .row.tax { flex-wrap: nowrap; }
.dlg .row.tax label { min-width: 6.5em; }
.dlg .row.tax output { min-width: 3em; text-align: right; }
.bt.close { width: 100%; margin-top: 12px; }
.dlg .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.dlg label { font-weight: 600; }
.dlg input[type=range] { flex: 1 1 160px; min-height: 44px; }
.bt { min-height: 48px; padding: 8px 16px; border-radius: 12px; border: 2px solid #c5d3e2; background: #f3f7fb; color: #14243a; font-weight: 700; }
.bt.pri { background: #1f8f74; border-color: #1f8f74; color: #fff; }
.bt.warn { background: #b3261e; border-color: #b3261e; color: #fff; }
.bt:disabled { opacity: .5; cursor: not-allowed; }
.note { background: #fff7df; border: 1px solid #f0d78a; border-radius: 10px; padding: 8px 10px; font-size: .9rem; }
.pbar { height: 10px; background: #dde6ef; border-radius: 6px; overflow: hidden; }
.pbar i { display: block; height: 100%; background: #1f8f74; }
.ms { border: 1px solid #d7e1ec; border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.ms.done { background: #eafaf3; border-color: #8fd3b5; }
.hero { margin-top: -18px; background: linear-gradient(135deg, #12335a, #1d6fa5); color: #fff; margin: -18px -18px 12px; padding: 22px 18px; border-radius: 18px 18px 0 0; }
.hero h2 { font-size: 1.7rem; margin: 0 0 4px; }
.hero p { margin: 0; color: #d6e7f5; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.list button { display: block; width: 100%; text-align: left; min-height: 48px; margin: 3px 0; border: 1px solid #d3deea; background: #f7fafd; border-radius: 10px; padding: 6px 10px; color: #14243a; }

@media (max-width: 760px) {
  .ctrl { flex-wrap: wrap; overflow: visible; justify-content: space-between; }
  .ctrl .btn { flex: 1 1 0; min-width: 48px; }
  #undo { order: 0; flex: 0 0 auto; } .speed { order: 1; flex: 1 1 auto; } .speed .btn { flex: 1 1 0; }
  #next { order: 2; flex: 1 1 100%; }
  #overlayBtn, #budgetBtn, #goalsBtn, #menuBtn { order: 3; flex: 1 1 20%; }
  #overlays { left: 8px; right: 8px; top: 8px; bottom: calc(8px + var(--sheetH, 0px)); }
  #report { width: 100%; padding: 8px 10px; font-size: .84rem; }
  #action { max-width: 100%; }
  #inspector { top: auto; right: 0; left: 0; bottom: 0; width: auto; max-width: none; max-height: 52%; border-radius: 16px 16px 0 0; }
  #zoomctl { top: 8px; }
  /* the inspector is a bottom sheet: --sheetH (set from JS) lifts the overlay column above it */
}
@media (max-height: 520px) and (orientation: landscape) { #hud { padding: 4px 10px; } .tool { min-height: 48px; } .tool .cs { display: none; } }

:root[data-large="1"] #coach { max-height: 34%; overflow: auto; }
:root[data-large="1"] .btn span { font-size: .6rem; }
:root[data-large="1"] .tool .lb, :root[data-large="1"] .tool .cs { font-size: .6rem; }

.goal-note { color: #0b7a4d; }

/* ---- round 4 UI ---- */
/* The tutorial lives bottom-right on wide screens so the starter town in the middle stays clear. */
#coach .tipsbtn { font-weight: 700; }
#report.ticker { padding: 0; width: min(560px, 100%); }
#report .tk { display: block; width: 100%; min-height: 48px; padding: 6px 12px; border: 0; background: none; color: inherit; text-align: left; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#report .tk b { color: #0b6b55; }
.menu-sep { border: 0; border-top: 1px solid #d3deea; margin: 22px 0 14px; }
.bt.wide { width: 100%; }
.event-opts { display: grid; gap: 14px; margin: 12px 0 4px; }
.event-opts small { display: block; margin-top: 4px; color: #50657d; }
.event-opts small.neg { color: #b3261e; font-weight: 700; }
.ms.focus { border: 2px solid #1f8f74; background: #f0fbf7; box-shadow: 0 0 0 3px rgba(31,143,116,.15); }
.why-happy ul { margin: 4px 0; padding-left: 20px; }
#moreBtn { display: none; }

@media (max-width: 600px) {
  .ctrl { flex-wrap: nowrap; gap: 3px; justify-content: stretch; }
  #overlayBtn, #budgetBtn, #goalsBtn, #menuBtn { display: none; }
  #moreBtn { display: inline-flex; order: 3; flex: 0 0 48px; }
  #undo { order: 0; flex: 0 0 48px; }
  #undo span { display: none; }
  .speed { order: 1; flex: 0 0 auto; gap: 3px; }
  .speed .btn { flex: 0 0 40px; min-width: 40px; width: 40px; padding: 4px 0; font-size: .7rem; }
  #next { order: 2; flex: 1 1 auto; min-width: 64px; padding: 4px 8px; font-size: .95rem; }
  #next .mo { display: none; }
  #toolbar { gap: 3px; padding: 3px 6px calc(3px + var(--safeB)); }
}
#dock { margin-top: auto; }

/* ---- round 5 UI ---- */
/* Tutorial: a tappable pill (Step n of N + two lines) that expands to the full card and back. */
#coach.pill { padding: 0; border-left-width: 4px; }
#coach .pillbtn, #coach .chead { display: block; width: 100%; text-align: left; border: 0; background: none; text-decoration: none; color: inherit; padding: 8px 12px; min-height: 44px; }
#coach .pillbtn b, #coach .chead b { display: block; margin: 0 0 1px; }
#coach .pt { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; font-size: .88rem; line-height: 1.25; color: var(--cardInk); }
#coach .chead { display: flex; align-items: center; justify-content: space-between; padding: 0; min-height: 28px; }
#coach .chead b { margin: 0; }
#coach .cx { color: #50657d; padding-left: 10px; }
#coach .tutnote { font-size: .8rem; color: #8a5a00; }
#coach .row .tipsbtn { min-height: 44px; }
@media (min-width: 761px) {
  #coach { position: absolute; right: 0; bottom: 0; width: 300px; max-width: 300px; align-self: auto; }
  #coach.pill { width: 280px; }
  /* The monthly card docks in the top-right (left of the zoom buttons) so the lower-left build area stays clear. */
  #report { position: absolute; top: 0; right: 60px; left: auto; width: min(360px, calc(100% - 140px)); }
  #report.ticker { width: min(460px, calc(100% - 140px)); }
}
@media (min-width: 1000px) {
  #report { right: auto; left: 0; }
}
#report .advbtn { display: inline-block; margin: 6px 0 0 8px; min-height: 40px; padding: 4px 12px; }
.dm-why { position: absolute; top: calc(100% + 4px); right: 0; z-index: 7; max-width: 380px; width: max-content; padding: 4px 10px; border-radius: 8px; background: rgba(8,24,44,.94); border: 1px solid var(--red); color: #ffd9d4; font-size: .76rem; line-height: 1.25; pointer-events: none; }
.hud-demandwrap { margin-left: auto; position: relative; display: flex; }
.hud-demandwrap .hud-demand { margin-left: 0; }
.mi { color: #0b6b55 !important; font-weight: 700; }
.unlocks { margin-top: 4px; font-size: .85rem; color: #0b6b55; font-weight: 600; }
.why-red { margin-top: 4px; font-size: .88rem; color: #b3261e; font-weight: 600; }
.chip-k { display: none; }

/* ---- Phones: HUD folds into two compact rows (about 64px), toolbar into two (about 100px). ---- */
@media (max-width: 600px) {
  #hud { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-template-rows: auto auto; gap: 2px 6px; align-items: center; padding: 2px 8px; }
  .hud-name { grid-column: 1 / 5; grid-row: 1; min-height: 26px; height: 26px; padding: 0 4px; font-size: .95rem; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .hud-date { grid-column: 5 / 8; grid-row: 1; min-width: 0; font-size: .78rem; white-space: nowrap; text-align: right; }
  .mbar { margin-top: 1px; height: 3px; }
  .hud-demandwrap { grid-column: 8 / 13; grid-row: 1; margin-left: 0; justify-self: end; }
  .hud-stat { grid-column: span 3; }
  .hud-demand { padding: 1px 4px; min-height: 26px; gap: 2px; }
  .dm { min-width: 28px; height: 26px; gap: 1px; }
  .dm i { width: 12px; max-height: 14px; }
  .dm u { font-size: .5rem; }
  .dm-why { display: none; }
  /* chips: label over value, equal share of the row, numbers never wrap or overprint */
  .hud-stat { grid-row: 2; min-width: 0; padding: 1px 6px; border-radius: 8px; background: rgba(255,255,255,.07); height: 27px; justify-content: center; overflow: hidden; }
  .hud-stat .k { font-size: .5rem; letter-spacing: 0; white-space: nowrap; line-height: 1; overflow: hidden; text-overflow: ellipsis; }
  .hud-stat b { font-size: .88rem; line-height: 1.35; padding-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  #toolbar .tools { scrollbar-width: none; padding-bottom: 0; }
  #toolbar .tools::-webkit-scrollbar { display: none; }
  .tool { min-height: 46px; min-width: 56px; padding: 1px 4px; }
  .tool .ic { font-size: 1.15rem; line-height: 1.15; }
  .tool .lb, .tool .cs { font-size: .62rem; }
  .ctrl .btn, .speed .btn { min-height: 40px; }
  #next { font-size: .95rem; }

  /* the report is a one-line bar; the full card only appears when asked for */
  #report.ticker { width: 100%; }
  #report .tk { min-height: 38px; padding: 4px 10px; font-size: .84rem; }
  #report .tk .ex { color: #50657d; }
  #report ul li:nth-child(n+4) { display: none; }
  #action { gap: 6px 8px; padding: 6px 10px; }
  #action span { flex: 1 1 100%; font-size: .84rem; line-height: 1.25; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
  #action .bt { min-height: 44px; padding: 4px 14px; flex: 1 1 0; max-width: 50%; }
  /* the tutorial is a one-line chip until tapped */
  #coach { max-width: calc(100% - 62px); }
  #coach.pill .pillbtn { display: flex; align-items: center; gap: 8px; padding: 4px 10px; min-height: 40px; }
  #coach.pill .pillbtn b { display: inline; margin: 0; white-space: nowrap; font-size: .7rem; flex: 0 0 auto; }
  #coach.pill .pt { -webkit-line-clamp: 1; flex: 1 1 auto; min-width: 0; font-size: .8rem; display: block; white-space: nowrap; text-overflow: ellipsis; }
  #coach:not(.pill) { padding: 8px 10px; max-height: 38%; overflow: auto; } #coach p { font-size: .88rem; }
}
:root[data-large="1"] #coach:not(.pill) { max-height: 34%; }

/* ---- round 6 UI ---- */
/* The report never intercepts a map drag: only its buttons take pointer input. */
#dock > #report, #report { pointer-events: none; }
#report button { pointer-events: auto; }
#report .tk { display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 40px; padding: 2px 4px 2px 12px; font-size: .86rem; white-space: nowrap; overflow: hidden; background: none; border: 0; }
#report .tk .tkt { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#report .tk .net.pos { color: #0b7a4d; font-weight: 700; } #report .tk .net.neg { color: #b3261e; font-weight: 700; }
#report .tk button { flex: 0 0 auto; min-height: 44px; min-width: 56px; border: 0; background: none; color: #1f6fb2; text-decoration: underline; font-size: .82rem; padding: 0 10px; }
/* Toasts ride at the top of the dock stack, above the confirm bar and its preview label. */
#toasts { align-self: center; }

/* Tutorial: the help offer, and a two-line chip on phones. */
#coach .showbtn { text-decoration: none; background: #1f8f74; color: #fff; border-radius: 10px; padding: 6px 12px; min-height: 44px; font-weight: 700; }
#coach .needhand { font-size: .85rem; color: #8a5a00; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#coach.pill.stuck { display: flex; align-items: stretch; }
#coach.pill.stuck .pillbtn { flex: 1 1 auto; min-width: 0; }
#coach.pill.stuck .showbtn { flex: 0 0 auto; margin: 4px 6px 4px 0; align-self: center; }
.showme { outline: 4px solid var(--gold); outline-offset: 2px; animation: pulse 1s infinite; position: relative; z-index: 2; }

/* Toolbar scroll cue: edge fades on whichever side has more tools, a chevron, and a NEW badge for freshly unlocked builds. */
.toolswrap { position: relative; min-width: 0; }
.toolswrap .tools { -webkit-mask-image: none; mask-image: none; }
.toolswrap.fade-r .tools { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 44px), transparent); }
.toolswrap.fade-l .tools { -webkit-mask-image: linear-gradient(270deg, #000 calc(100% - 44px), transparent); mask-image: linear-gradient(270deg, #000 calc(100% - 44px), transparent); }
.toolswrap.fade-l.fade-r .tools { -webkit-mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 44px), transparent); mask-image: linear-gradient(90deg, transparent, #000 36px, #000 calc(100% - 44px), transparent); }
.tcue { position: absolute; top: 50%; transform: translateY(-50%); width: 30px; height: 44px; border: 0; border-radius: 10px; background: rgba(255,212,90,.92); color: #3a2a00; font-size: 1.5rem; font-weight: 800; line-height: 1; padding: 0; z-index: 2; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.tcue-r { right: 0; } .tcue-l { left: 0; }
.tcue.pulse { animation: pulse 1.2s infinite; }
.tool { position: relative; }
.tool.fresh { border-color: var(--teal); animation: pulse 1.6s infinite; }
.newbadge { position: absolute; top: -5px; right: -3px; background: var(--teal); color: #052; font-size: .55rem; font-weight: 800; padding: 1px 5px; border-radius: 99px; letter-spacing: .03em; }
@media (prefers-reduced-motion: reduce) { .tool.fresh, .tcue.pulse, .showme { animation: none; } }
:root[data-motion="0"] .tool.fresh, :root[data-motion="0"] .tcue.pulse, :root[data-motion="0"] .showme { animation: none; }

details.upk { margin: 8px 0; } details.upk summary { cursor: pointer; font-weight: 600; min-height: 32px; }

@media (max-width: 600px) {
  /* Two-line, at least 44px tall chip; the step text is already a short imperative. */
  #coach.pill .pillbtn { align-items: center; min-height: 44px; padding: 4px 10px; }
  #coach.pill .pt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; overflow: hidden; font-size: .84rem; line-height: 1.2; font-weight: 600; }
  #coach { max-width: calc(100% - 62px); }
  /* The Saved pill would sit under the chip: show it only when the chip is gone, and show a failure just below the chip. */
  #action span { -webkit-line-clamp: 3; }
  #report.ticker .tk { min-height: 40px; }
  .tcue { height: 46px; }
}

/* ---- round 7 UI ---- */
/* Save status lives in the HUD beside the date: a dot, plus a short word where there is room. */
.dateRow { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.savestate { display: inline-flex; align-items: center; gap: 4px; font-size: .68rem; font-weight: 600; color: var(--muted); }
.savestate .sdot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); flex: 0 0 auto; }
.savestate[data-state="saving"] .sdot { background: var(--gold); }
.savestate[data-state="fail"] { color: #ffd9d4; font-weight: 800; }
.savestate[data-state="fail"] .sdot { background: var(--red); box-shadow: 0 0 0 3px rgba(255,107,94,.35); }
.hud-stat.warn b { color: var(--gold); }
.toast.warn { background: #fff6dc; border: 2px solid #e0a800; }

/* Tutorial: the help button sits UNDER the text so the text keeps the full width. */
#coach.pill.stuck { display: flex; flex-direction: column; align-items: stretch; }
#coach.pill.stuck .pillbtn { flex: 0 0 auto; width: 100%; }
#coach.pill.stuck .showbtn { align-self: flex-start; margin: 0 10px 8px; flex: 0 0 auto; }
@media (min-width: 601px) {
  #coach .pt { display: block; -webkit-line-clamp: unset; overflow: visible; }
  #coach.pill { width: 300px; max-width: 300px; }
}
@media (max-width: 600px) {
  #coach.pill.stuck .pillbtn { display: flex; }
  #coach.pill.stuck .showbtn { margin: 0 8px 6px; min-height: 44px; }
  .hud-name { grid-column: 1 / 4; }
  .hud-date { grid-column: 4 / 8; }
  .hud-date .stxt { display: none; }
  .savestate[data-state="fail"] .stxt { display: inline; font-size: .55rem; }
  .dm-why { display: none; }
}
:root[data-large="1"] #coach.pill .pt { -webkit-line-clamp: 3; line-clamp: 3; }
:root[data-large="1"] #coach.pill .pillbtn { min-height: 48px; }
@media (max-width: 600px) {
  :root[data-large="1"] #coach { max-width: calc(100% - 58px); }
  :root[data-large="1"] .hud-date .stxt { display: none; }
}

/* Phone: the full report card is capped to about a fifth of the map, and the ticker is one line. */
@media (max-width: 760px) {
  #report:not(.ticker) { max-height: calc((100dvh - 170px) * .2); overflow: auto; pointer-events: auto; }
  #report:not(.ticker) ul { margin: 2px 0 0; }
  #report:not(.ticker) .adv { display: none; }
  #toasts .toast { padding: 6px 10px; font-size: .84rem; line-height: 1.25; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
  #toasts { max-height: 3.4em; }
  /* Inspector sheet: hint first, two columns of facts, at most 30% of the map. */
  #inspector { max-height: 30%; padding: 8px 10px; }
  #inspector h2 { font-size: .98rem; margin: 0; padding-right: 52px; }
  #inspector .x { width: 44px; height: 44px; top: 2px; right: 2px; }
  #inspector dl { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 1px 10px; font-size: .8rem; margin: 4px 0; }
  #inspector .why { padding: 4px 8px; font-size: .8rem; margin: 4px 0; }
  #inspector .acts { margin-top: 4px; }
  #inspector .acts .bt { min-height: 44px; padding: 4px 12px; }
}
@media (max-width: 760px) { :root[data-large="1"] #inspector { max-height: 30%; } :root[data-large="1"] #inspector dl { font-size: .72rem; } }

/* NEW badge sits inside its tile (the scroller clips anything outside), and the chevron carries a count. */
.newbadge { top: 2px; right: 2px; z-index: 1; }
.tcue[data-new]:not([data-new=""])::after { content: attr(data-new) " new"; position: absolute; top: -9px; left: 50%; transform: translateX(-50%); background: var(--teal); color: #052; font-size: .55rem; font-weight: 800; padding: 1px 5px; border-radius: 99px; white-space: nowrap; pointer-events: none; }

/* ---- round 8 UI ---- */
/* Touch and pen never show keyboard focus rings (a Tab press brings them back). */
:root[data-input="touch"] :focus-visible { outline: none; }
/* Large-text phone: the "Show me" button sits inline to the right of the step text, not in a tall stacked card. */
@media (max-width: 600px) {
  #coach.pill.stuck { flex-direction: row; align-items: center; }
  #coach.pill.stuck .pillbtn { flex: 1 1 auto; width: auto; min-width: 0; }
  #coach.pill.stuck .showbtn { flex: 0 0 auto; align-self: center; margin: 0 8px 0 0; padding: 6px 10px; min-height: 44px; }
  /* "Saved" is hidden on phones except for ~1.5 s after a save completes, then it fades. */
  .hud-date .stxt, :root[data-large="1"] .hud-date .stxt { display: inline-block; max-width: 0; opacity: 0; overflow: hidden; transition: opacity .4s ease, max-width .4s ease; }
  .savestate.flash .stxt, :root[data-large="1"] .savestate.flash .stxt { max-width: 3.4em; opacity: 1; }
  .savestate[data-state="fail"] .stxt, :root[data-large="1"] .savestate[data-state="fail"] .stxt { max-width: none; opacity: 1; display: inline; font-size: .55rem; }
}
.ms .blocked { margin-top: 6px; padding: 6px 8px; border-radius: 8px; background: #fff6dc; border: 1px solid #e0a800; color: #5a3d00; font-size: .9rem; }

/* ---- round 9 ---- */
/* The demand reason is never a standing tag: it lives in the demand chip's tooltip and the demand dialog. */
.dm-why { display: none !important; }
/* Desktop single message slot: an advisor/confirm bar or a toast owns the screen; the report ticker and tutorial chip stand down. */
@media (min-width: 761px) {
  #stage[data-slot] #report { display: none; }
  #stage[data-slot] #coach { visibility: hidden; }
}
/* Power chip pulses red when spare power is 0. */
#powerStat.zero { animation: pwrzero 1.2s ease-in-out infinite; border-radius: 8px; }
@keyframes pwrzero { 0%,100% { box-shadow: 0 0 0 0 rgba(255,107,94,.75); } 50% { box-shadow: 0 0 0 6px rgba(255,107,94,0); } }
:root[data-motion="0"] #powerStat.zero { animation: none; outline: 2px solid var(--red); }
/* Tutorial step 1: the real Next-month button glows (the base pulse is gold on a gold button). */
#next.pulse { animation: pulseNext 1.2s ease-in-out infinite; }
@keyframes pulseNext { 0%,100% { box-shadow: 0 0 0 0 rgba(255,255,255,.9), 0 0 0 0 rgba(255,212,90,.8); transform: scale(1); } 50% { box-shadow: 0 0 0 3px rgba(255,255,255,.9), 0 0 0 11px rgba(255,212,90,0); transform: scale(1.05); } }
:root[data-motion="0"] #next.pulse { animation: none; transform: none; outline: 3px solid #fff; }
/* "Saved" flashes for ~1.5 s on every screen size after a save, then fades to the dot. */
.hud-date .stxt, :root[data-large="1"] .hud-date .stxt { display: inline-block; max-width: 0; opacity: 0; overflow: hidden; transition: opacity .4s ease, max-width .4s ease; }
.savestate.flash .stxt, :root[data-large="1"] .savestate.flash .stxt { max-width: 3.4em; opacity: 1; }
.savestate[data-state="fail"] .stxt, :root[data-large="1"] .savestate[data-state="fail"] .stxt { max-width: none; opacity: 1; display: inline; }

/* A modal dialog is the only thing to read: the report card and tutorial chip wait behind it. */
body.dlg-open #report, body.dlg-open #coach { visibility: hidden; }

/* Large text: the date row keeps only the save dot, so the word never collides with the demand pill (a failure still spells itself out). */
:root[data-large="1"] .hud-date .stxt { display: none; }
:root[data-large="1"] .savestate[data-state="fail"] .stxt { display: inline; max-width: none; opacity: 1; }

/* keep the thousands comma visible (it was clipped to look like a decimal point) */
.hud-stat b { padding-bottom: 3px; line-height: 1.3; }

/* Large text on narrow phones: keep tax readouts and HUD labels inside their boxes */
.dlg .row output { min-width: 3em; text-align: right; }
.dlg input[type=range] { min-width: 0; }
:root[data-large="1"] .dlg .row label { flex: 1 1 100%; }
:root[data-large="1"] .hud-stat .k { line-height: 1.35; overflow: visible; }

/* Phone HUD: let each stat grow to fit its label and value (Large text was cutting values in half). */
@media (max-width: 760px) {
  .hud-stat { height: auto; min-height: 27px; overflow: visible; }
}
:root[data-large="1"] .hud-stat .k { line-height: 1.15; }

/* ---- Top menu buttons (Maps, Budget, Goals, Menu) and the map move pad ---- */
.hud-menu { display: flex; gap: 6px; margin-left: auto; }
.hud-menu .btn { min-height: 44px; min-width: 52px; padding: 2px 8px; }
@media (max-width: 600px) { .hud-menu { display: none; } }
.padgrp { position: relative; display: flex; flex-direction: column; align-items: center; }
.padtoggle { width: 100%; }
.pad { position: absolute; right: calc(100% + 6px); bottom: 0; display: grid; grid-template-columns: repeat(3, 44px); grid-template-rows: repeat(3, 44px); gap: 4px; }
.pad[hidden] { display: none; }
#zoomctl .pad button { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: rgba(14,42,71,.92); color: var(--ink, #fff); font-size: 1rem; }
.pad [data-pan=up] { grid-column: 2; grid-row: 1; } .pad [data-pan=left] { grid-column: 1; grid-row: 2; }
.pad [data-pan=right] { grid-column: 3; grid-row: 2; } .pad [data-pan=down] { grid-column: 2; grid-row: 3; }

/* ---- Desktop: docked bars, nothing floating. Status bar on top; one bottom line with the time controls left and the tools right. ---- */
@media (min-width: 761px) {
  #hud { padding: 6px 14px; gap: 6px 18px; }
  .hud-name { min-height: 44px; }
  .hud-stat { display: grid; grid-template-columns: auto auto; column-gap: 8px; align-items: center; min-width: 0; padding: 4px 10px; border-radius: 10px; background: rgba(255,255,255,.06); }
  .hud-stat::before { content: attr(data-ic); grid-row: 1 / 3; font-size: 1.35rem; }
  .hud-stat b { grid-column: 2; grid-row: 1; font-size: 1.1rem; }
  .hud-stat .k { grid-column: 2; grid-row: 2; font-size: .62rem; }
  .hud-menu .btn { min-height: 44px; border-radius: 10px; }
  #toolbar { flex-direction: row; align-items: center; gap: 12px; padding: 6px 12px calc(6px + var(--safeB)); }
  .ctrl { order: 0; flex: 0 0 auto; overflow: visible; padding-right: 12px; border-right: 1px solid var(--line); }
  .toolswrap { order: 1; flex: 1 1 0; min-width: 0; }
  .tool { min-height: 58px; }
}
/* Desktop: Build/Cancel, toasts and the month report appear under the top bar, out of the way of the play area. */
@media (min-width: 761px) {
  #overlays { justify-content: flex-start; }
  #dock { order: -1; margin-top: 0; align-self: center; width: 100%; align-items: center; }
  #action, #report { align-self: center; }
}

/* Story scenes: full-screen still, caption over the calm navy lower third, typewriter text. */
.story{position:fixed;inset:0;z-index:300;background:#0b1530;opacity:0;transition:opacity .6s ease;display:flex;flex-direction:column;justify-content:flex-end;overflow:hidden}
.story.on{opacity:1}
.story-img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;object-position:28% top;animation:storydrift 22s ease-out forwards}
@keyframes storydrift{from{transform:scale(1)}to{transform:scale(1.06)}}
.story-cap{position:relative;max-width:880px;width:100%;margin:0 auto;padding:0 20px max(22px,env(safe-area-inset-bottom));color:#f4efe2;text-shadow:0 2px 10px rgba(0,0,0,.6)}
.story-cap h2{margin:0 0 8px;font-size:clamp(1.1rem,2.6vw,1.5rem);color:#ffd45a;letter-spacing:.02em}
.story-text{margin:0 0 14px;font-size:clamp(1rem,2.2vw,1.3rem);line-height:1.5;min-height:4.5em}
.story-row{display:flex;gap:10px;flex-wrap:wrap}
@media (prefers-reduced-motion:reduce){.story,.story-img{transition:none;animation:none}}

/* Contact and bug report dialogs (src/support.js) */
.sup-back{position:fixed;inset:0;z-index:400;background:rgba(4,14,28,.7);display:flex;align-items:center;justify-content:center;padding:16px}
.sup{background:var(--card);color:var(--cardInk);border-radius:14px;max-width:560px;width:100%;max-height:92vh;overflow:auto;padding:18px;box-shadow:0 12px 40px rgba(0,0,0,.5)}
.sup .dlg-head{display:flex;justify-content:space-between;align-items:center;gap:10px;margin-bottom:8px}
.sup .fld{display:block;margin:10px 0;font-weight:600}
.sup textarea,.sup input{display:block;width:100%;margin-top:4px;padding:8px;border-radius:8px;border:1px solid #b8c6d6;background:#fff;color:var(--cardInk);font:inherit}
.sup .row{display:flex;gap:10px;flex-wrap:wrap;margin-top:10px}
.sup a.bt{text-decoration:none;display:inline-flex;align-items:center}
.sup .note:empty{display:none}
