/* Missoula housing analysis — walkthrough
   Same palette and restraint as the two slides, so the three read as one voice. */

:root {
  --ink:      #2B2B2B;
  --paper:    #FCFCFA;
  --quiet:    #6A6A6A;
  --rule:     #DCD9D2;
  --faint:    #F1EFEA;

  --grow:     #3F7D5A;
  --invest:   #3E7CA6;
  --protect:  #D9A441;
  --avoid:    #B05B57;
  --none:     #E4E2DD;
  --bus:      #C25A16;
  --freq:     #1C4257;

  --measure:  34rem;   /* comfortable reading width */
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 17px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 700; }
p  { margin: 0 0 1em; }
a  { color: var(--grow); }

/* ─────────────────────────────────────────────── masthead */

/* The landing fills the screen exactly, so nothing of the walkthrough shows
   until you ask for it. */
.masthead {
  min-height: 100vh;
  display: flex; align-items: center;
  padding: 3rem 1.5rem;
}
.masthead-inner { width: 100%; max-width: 62rem; margin: 0 auto; }

.narrative { max-width: 44rem; margin-top: 1.4rem; }
.narrative p { font-size: 1.02rem; color: var(--quiet); margin-bottom: .9rem; }
.narrative .stat { color: var(--ink); font-weight: 700; }
.kicker {
  font-size: .72rem; letter-spacing: .11em; text-transform: uppercase;
  color: var(--quiet); margin-bottom: 1.1rem;
}
.masthead h1 {
  font-size: clamp(2.1rem, 5.2vw, 3.5rem);
  letter-spacing: -0.02em;
  margin-bottom: .7rem;
}
.masthead .standfirst {
  font-size: clamp(1.05rem, 2.1vw, 1.3rem);
  color: var(--quiet); max-width: 40rem;
}

.figures {
  display: flex; flex-wrap: wrap; gap: 2.6rem;
  margin-top: 2.8rem; padding-top: 1.8rem;
  border-top: 1px solid var(--rule);
}
.figure b { display: block; font-size: 1.9rem; letter-spacing: -0.01em; }
.figure span { font-size: .85rem; color: var(--quiet); }

.start {
  margin-top: 3rem; font: inherit; font-size: .9rem;
  background: var(--ink); color: var(--paper);
  border: 0; border-radius: 4px; padding: .7rem 1.3rem; cursor: pointer;
}
.start:hover { background: #000; }

/* ─────────────────────────────────────────────── the stage
   One screen, nine chapters, driven by clicks rather than by scrolling. The
   reader sets the pace and can jump straight to the recommendation. */

.stage {
  height: 100vh; min-height: 620px;
  display: flex; flex-direction: column;
  border-top: 1px solid var(--rule);
  background: var(--paper);
}

.chapters {
  display: flex; gap: .2rem; align-items: stretch;
  padding: 0 1rem; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--rule); flex: none;
}
.chapters::-webkit-scrollbar { display: none; }
.chapters button {
  font: inherit; font-size: .74rem; white-space: nowrap;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--quiet); cursor: pointer; padding: .8rem .7rem;
  transition: color .15s ease, border-color .15s ease;
}
.chapters button:hover { color: var(--ink); }
.chapters button[aria-current="true"] {
  color: var(--ink); font-weight: 600; border-bottom-color: var(--ink);
}
.chapters b { font-weight: 600; margin-right: .4rem; }

.stage-body { position: relative; flex: 1 1 auto; min-height: 0; }
#map { position: absolute; inset: 0; }

/* The legend floats over the map and swaps content per step. It lives on the
   right because the reading card owns the left. */
.legend {
  position: absolute; right: 1.4rem; bottom: 2.9rem;
  background: rgba(252,252,250,.94);
  border: 1px solid var(--rule); border-radius: 5px;
  padding: .8rem .95rem; font-size: .78rem; line-height: 1.5;
  max-width: 15rem; pointer-events: none;
  transition: opacity .35s ease;
}
.legend h4 {
  font-size: .68rem; letter-spacing: .09em; text-transform: uppercase;
  color: var(--quiet); font-weight: 600; margin-bottom: .5rem;
}
.legend .row { display: flex; align-items: center; gap: .5rem; margin: .2rem 0; }
.legend .sw { width: 12px; height: 12px; border-radius: 2px; flex: none; }
.legend .ln { width: 16px; height: 3px; border-radius: 2px; flex: none; }
.legend.hidden { opacity: 0; }

/* the reading card floats over the map at a fixed size, so the map never
   reflows when a longer chapter comes up */
.card {
  position: absolute; z-index: 2;
  left: max(1.5rem, 3vw); top: 50%; transform: translateY(-50%);
  width: 27rem; max-width: calc(100% - 3rem);
  display: flex; flex-direction: column;
  background: rgba(252,252,250,.97);
  border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: 0 2px 22px rgba(0,0,0,.06);
}

.panels { position: relative; padding: 1.7rem 1.8rem 1.3rem; min-height: 19.5rem; }
.panel { display: none; }
.panel.active { display: block; animation: rise .28s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.panel .num {
  font-size: .72rem; letter-spacing: .11em; text-transform: uppercase;
  color: var(--quiet); margin-bottom: .55rem;
}
.panel h2 { font-size: 1.35rem; margin-bottom: .6rem; }
.panel p  { font-size: .96rem; }
.panel p:last-child { margin-bottom: 0; }
.panel .stat { color: var(--ink); font-weight: 700; }

.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .75rem 1.2rem;
  border-top: 1px solid var(--rule); flex: none;
}
.pager button {
  font: inherit; font-size: .82rem; color: var(--ink);
  background: none; border: 1px solid var(--rule); border-radius: 4px;
  padding: .35rem .8rem; cursor: pointer; transition: background .15s ease;
}
.pager button:hover:not(:disabled) { background: var(--faint); }
.pager button:disabled { color: var(--rule); border-color: var(--faint); cursor: default; }
.pager .count {
  font-size: .76rem; color: var(--quiet); font-variant-numeric: tabular-nums;
}

/* interactive controls inside a step */
.control { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.control label {
  display: block; font-size: .78rem; color: var(--quiet); margin-bottom: .5rem;
}
.control input[type=range] { width: 100%; accent-color: var(--grow); }
.control .readout { font-size: 1.45rem; font-weight: 700; margin-top: .3rem; line-height: 1.25; }
.control .readout small {
  display: block; font-size: .78rem; font-weight: 400;
  color: var(--quiet); line-height: 1.45; margin-top: .15rem;
}

.toggles { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .9rem; }
.toggles button {
  font: inherit; font-size: .78rem;
  border: 1px solid var(--rule); background: var(--paper); color: var(--quiet);
  border-radius: 999px; padding: .28rem .7rem; cursor: pointer;
  transition: all .15s ease;
}
.toggles button[aria-pressed="true"] {
  color: var(--paper); border-color: transparent; background: var(--ink);
}
.toggles button[data-action="Grow now"][aria-pressed="true"]                   { background: var(--grow); }
.toggles button[data-action="Invest first, then grow"][aria-pressed="true"]    { background: var(--invest); }
.toggles button[data-action="Protect and grow carefully"][aria-pressed="true"] { background: var(--protect); }
.toggles button[data-action="Avoid additional growth"][aria-pressed="true"]    { background: var(--avoid); }

/* hover readout for hexes */
.probe {
  position: absolute; top: 1.4rem; right: 1.4rem;
  background: rgba(252,252,250,.96);
  border: 1px solid var(--rule); border-radius: 5px;
  padding: .75rem .9rem; font-size: .8rem; line-height: 1.5;
  min-width: 12rem; pointer-events: none; opacity: 0;
  transition: opacity .2s ease;
}
.probe.on { opacity: 1; }
.probe b { display: block; font-size: .68rem; letter-spacing: .09em;
           text-transform: uppercase; color: var(--quiet); margin-bottom: .35rem; }
.probe dl { display: grid; grid-template-columns: auto auto; gap: .12rem .9rem; margin: 0; }
.probe dt { color: var(--quiet); }
.probe dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ─────────────────────────────────────────────── closing */

.outro {
  max-width: 62rem;
  margin: 0 auto; padding: 5rem 1.5rem 4rem;
  border-top: 1px solid var(--rule);
}
.end-head { max-width: 44rem; margin-bottom: 3rem; }
.outro h2 { font-size: 1.9rem; margin: .4rem 0 1.1rem; }
.outro .lede { font-size: 1.05rem; color: var(--quiet); margin: 0; }

.outro h3 {
  font-size: .7rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--quiet); margin: 2.8rem 0 .9rem;
}

.table-wrap { overflow-x: auto; }

.outro table {
  width: 100%; border-collapse: collapse;
  font-size: .82rem; line-height: 1.55; color: var(--quiet);
}
.outro th {
  text-align: left; font-weight: 600; color: var(--ink);
  border-bottom: 1px solid var(--rule); padding: .4rem .8rem .4rem 0;
  vertical-align: bottom;
}
.outro td {
  padding: .55rem .8rem .55rem 0; vertical-align: top;
  border-bottom: 1px solid var(--faint);
}
.assump td:first-child, .sources .ds { color: var(--ink); font-weight: 600; }
.assump td:nth-child(2) { color: var(--ink); }
.assump td { width: 33%; }
.sources td:first-child { min-width: 13rem; }
.sources .lim { min-width: 18rem; }
.sources tr.grp th {
  font-size: .66rem; letter-spacing: .1em; text-transform: uppercase;
  color: var(--quiet); border-bottom: 0; padding-top: 1.5rem;
}
.outro a { color: var(--grow); text-decoration: none; }
.outro a:hover { text-decoration: underline; }

.caveats { padding-left: 1.1rem; font-size: .86rem; color: var(--quiet); line-height: 1.6; }
.caveats li { margin-bottom: .55rem; }
.caveats b { color: var(--ink); }

.end-nav { margin-top: 3rem; padding-top: 1.4rem; border-top: 1px solid var(--rule); }

footer {
  max-width: var(--measure); margin: 0 auto;
  padding: 2rem 1.5rem 5rem; font-size: .8rem; color: var(--quiet);
  border-top: 1px solid var(--rule);
}

/* ─────────────────────────────────────────────── small screens */

/* On a phone there is no room to float the card over the map, so they stack:
   map on top, card below it, chapters still along the top. */
@media (max-width: 720px) {
  .stage { height: auto; min-height: 0; }
  .stage-body { display: flex; flex-direction: column; }
  #map { position: relative; inset: auto; height: 58vh; flex: none; }
  .card {
    position: relative; left: auto; top: auto; transform: none;
    width: auto; max-width: none; border-radius: 0;
    border-left: 0; border-right: 0; box-shadow: none;
  }
  .panels { padding: 1.3rem 1.1rem 1rem; min-height: 0; }
  .legend { font-size: .72rem; max-width: 11rem; right: .8rem; bottom: 2.4rem; }
  .probe { display: none; }
  .figures { gap: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .panel.active { animation: none; }
}

/* the last chapter's Next hands off to the end page */
.pager button.to-end {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
}
.pager button.to-end:hover { background: #000; }
