:root {
  color-scheme: light;
  --paper: #f3f0e8;
  --paper-deep: #e8e3d7;
  --ink: #14221b;
  --ink-soft: #566159;
  --line: rgba(20, 34, 27, 0.15);
  --accent: #2f6d56;
  --accent-deep: #173e2f;
  --accent-pale: #d9e6de;
  --warning: #9a5b2c;
  --warning-pale: #eee0cf;
  --white: #fcfbf7;
  --rail-width: 274px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { color: inherit; }

button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid rgba(47, 109, 86, 0.28);
  outline-offset: 3px;
}

.app-shell { min-height: 100svh; display: grid; grid-template-columns: var(--rail-width) 1fr; }

.rail {
  position: sticky;
  top: 0;
  height: 100svh;
  display: flex;
  flex-direction: column;
  padding: 34px 27px 26px;
  background: var(--ink);
  color: var(--white);
}

.brand {
  color: inherit;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px;
  line-height: 1;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.brand-block p {
  margin: 9px 0 0;
  color: rgba(252, 251, 247, 0.55);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.step-nav { margin-top: 74px; display: grid; }

.step-link {
  position: relative;
  display: grid;
  grid-template-columns: 35px 1fr;
  gap: 1px 8px;
  width: 100%;
  padding: 17px 0;
  border: 0;
  border-top: 1px solid rgba(252, 251, 247, 0.13);
  background: transparent;
  color: rgba(252, 251, 247, 0.42);
  text-align: left;
  cursor: pointer;
  transition: color 180ms ease, transform 180ms ease;
}

.step-link:last-child { border-bottom: 1px solid rgba(252, 251, 247, 0.13); }
.step-link:not(:disabled):hover { color: var(--white); transform: translateX(3px); }
.step-link:disabled { cursor: default; }
.step-link.is-active, .step-link.is-complete { color: var(--white); }
.step-link.is-active::before {
  content: "";
  position: absolute;
  left: -27px;
  top: 14px;
  bottom: 14px;
  width: 3px;
  background: #78aa8d;
}

.step-link > span { grid-row: 1 / span 2; font-size: 11px; padding-top: 3px; }
.step-link strong { font-weight: 590; font-size: 14px; }
.step-link small { font-size: 11px; color: inherit; opacity: 0.7; margin-top: 2px; }

.rail-note {
  margin-top: auto;
  display: grid;
  grid-template-columns: 9px 1fr;
  gap: 11px;
  color: rgba(252, 251, 247, 0.64);
  font-size: 11px;
  line-height: 1.5;
}

.rail-note p { margin: 0; }
.rail-note strong { display: block; color: var(--white); font-size: 12px; font-weight: 570; }
.status-dot { width: 7px; height: 7px; margin-top: 5px; border-radius: 50%; background: #78aa8d; box-shadow: 0 0 0 4px rgba(120, 170, 141, 0.12); }

.workspace {
  min-width: 0;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding: 0 52px;
}

.workspace-header {
  min-height: 113px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  border-bottom: 1px solid var(--line);
}

.eyebrow { display: block; margin-bottom: 8px; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: 0.15em; text-transform: uppercase; }
.workspace-header h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(25px, 2.5vw, 39px); font-weight: 400; letter-spacing: -0.035em; }

.dataset-control { display: flex; align-items: center; gap: 18px; text-align: right; }
.dataset-control span { display: block; font-size: 12px; font-weight: 650; }
.dataset-control small { display: block; margin-top: 3px; color: var(--ink-soft); font-size: 11px; }
.text-button { padding: 6px 0; border: 0; border-bottom: 1px solid currentColor; background: transparent; color: var(--accent); font-size: 12px; font-weight: 650; cursor: pointer; }

.notice { display: flex; align-items: center; gap: 18px; padding: 12px 0; border-bottom: 1px solid var(--line); color: var(--ink-soft); }
.notice span { flex: 0 0 auto; padding: 4px 8px; background: var(--warning-pale); color: var(--warning); font-size: 9px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.notice p { margin: 0; font-size: 12px; }
.notice.is-real span { background: var(--accent-pale); color: var(--accent-deep); }

.stage { display: none; min-height: 0; padding: 42px 0 36px; }
.stage.is-active { display: block; animation: stage-in 380ms cubic-bezier(.2,.75,.2,1) both; }
@keyframes stage-in { from { opacity: 0; transform: translateY(13px); } to { opacity: 1; transform: none; } }

.stage-intro { max-width: 700px; margin-bottom: 44px; }
.stage-intro-row { max-width: none; display: flex; justify-content: space-between; align-items: flex-end; gap: 32px; }
.stage-intro h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(31px, 4vw, 57px); font-weight: 400; line-height: 1.02; letter-spacing: -0.045em; }
.stage-intro p { max-width: 590px; margin: 15px 0 0; color: var(--ink-soft); line-height: 1.6; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 48px; max-width: 950px; }
.field { min-width: 0; margin: 0; padding: 26px 0 30px; border: 0; border-top: 1px solid var(--line); }
.field-wide { grid-column: 1 / -1; }
.field legend, .field-heading label { font-size: 13px; font-weight: 700; }
.field-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; }
.field-heading output { font-family: Georgia, "Times New Roman", serif; font-size: 33px; color: var(--accent-deep); }
.field-help { margin: 13px 0 0; color: var(--ink-soft); font-size: 11px; line-height: 1.5; }

input[type="range"] { width: 100%; height: 3px; margin: 30px 0 0; appearance: none; border-radius: 3px; background: linear-gradient(to right, var(--accent) var(--range-progress, 41%), var(--paper-deep) var(--range-progress, 41%)); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 19px; height: 19px; border: 4px solid var(--white); border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 1px rgba(20, 34, 27, 0.2); cursor: grab; }
.range-labels { display: flex; justify-content: space-between; margin-top: 10px; color: var(--ink-soft); font-size: 10px; }

.choice-row { display: flex; gap: 8px; margin-top: 18px; }
.choice-row label { cursor: pointer; }
.choice-row input { position: absolute; opacity: 0; pointer-events: none; }
.choice-row span { display: grid; place-items: center; min-width: 48px; height: 42px; padding: 0 14px; border: 1px solid var(--line); color: var(--ink-soft); font-size: 12px; transition: background 160ms ease, border-color 160ms ease, color 160ms ease; }
.choice-row input:checked + span { border-color: var(--accent); background: var(--accent); color: var(--white); }
.choice-row-text span { min-width: 70px; }

.selection-count { flex: 0 0 auto; text-align: right; }
.selection-count strong { display: block; font-family: Georgia, "Times New Roman", serif; font-size: 49px; font-weight: 400; line-height: 0.9; }
.selection-count span { color: var(--ink-soft); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; }

.list-tools { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; padding-bottom: 15px; border-bottom: 1px solid var(--ink); }
.search-field span { display: block; margin-bottom: 5px; color: var(--ink-soft); font-size: 9px; font-weight: 750; letter-spacing: 0.12em; text-transform: uppercase; }
.search-field input { width: min(360px, 55vw); padding: 8px 0; border: 0; background: transparent; color: var(--ink); font-size: 15px; }
.search-field input::placeholder { color: #8b928c; }

.town-list { max-height: calc(100svh - 400px); min-height: 280px; overflow: auto; }
.town-row { display: grid; grid-template-columns: 34px minmax(170px, 1fr) 130px 95px; align-items: center; min-height: 58px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background 150ms ease, padding 150ms ease; }
.town-row:hover { padding-left: 7px; background: rgba(255,255,255,0.26); }
.town-row input { position: absolute; opacity: 0; }
.checkmark { width: 17px; height: 17px; border: 1px solid rgba(20,34,27,.35); display: grid; place-items: center; }
.town-row input:checked + .checkmark { border-color: var(--accent); background: var(--accent); }
.town-row input:checked + .checkmark::after { content: "✓"; color: white; font-size: 11px; }
.town-name strong { display: block; font-size: 13px; }
.town-name span, .town-source { color: var(--ink-soft); font-size: 11px; }
.town-readiness { text-align: right; font-size: 11px; font-variant-numeric: tabular-nums; }

.readiness-mark { position: relative; width: 78px; height: 78px; flex: 0 0 auto; }
.readiness-mark svg { width: 100%; transform: rotate(-90deg); }
.readiness-mark circle { fill: none; stroke: var(--paper-deep); stroke-width: 3; }
.readiness-mark .readiness-progress { stroke: var(--accent); stroke-dasharray: 125.66; stroke-dashoffset: 125.66; stroke-linecap: round; transition: stroke-dashoffset 750ms cubic-bezier(.2,.75,.2,1); }
.readiness-mark strong { position: absolute; inset: 0; display: grid; place-items: center; font-family: Georgia, "Times New Roman", serif; font-size: 18px; font-weight: 400; }

.evidence-summary { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); }
.evidence-summary div { padding: 18px 20px 18px 0; }
.evidence-summary div + div { padding-left: 20px; border-left: 1px solid var(--line); }
.evidence-summary span { display: block; color: var(--ink-soft); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
.evidence-summary strong { display: block; margin-top: 5px; font-size: 12px; font-weight: 650; }
.evidence-list { margin-top: 24px; }
.evidence-row { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr 75px; gap: 18px; align-items: center; min-height: 48px; border-bottom: 1px solid var(--line); font-size: 12px; }
.evidence-bar { height: 3px; background: var(--paper-deep); }
.evidence-bar i { display: block; height: 100%; background: var(--accent); transform-origin: left; animation: bar-in 650ms ease both; }
@keyframes bar-in { from { transform: scaleX(0); } }
.evidence-row span:last-child { color: var(--ink-soft); text-align: right; }

.results-empty { min-height: 58vh; display: grid; place-items: center; align-content: center; text-align: center; }
.results-empty h2 { margin: 24px 0 8px; font-family: Georgia, "Times New Roman", serif; font-size: 38px; font-weight: 400; }
.results-empty p { max-width: 520px; margin: 0; color: var(--ink-soft); line-height: 1.6; }
.loading-line { position: relative; width: 160px; height: 2px; overflow: hidden; background: var(--paper-deep); }
.loading-line::after { content: ""; position: absolute; inset: 0; background: var(--accent); animation: load 1.2s ease-in-out infinite; }
@keyframes load { 0% { transform: translateX(-100%); } 60%,100% { transform: translateX(100%); } }

.result-lead { display: flex; justify-content: space-between; align-items: flex-end; gap: 30px; margin-bottom: 42px; }
.result-lead h2 { margin: 0; max-width: 780px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(36px, 5vw, 68px); font-weight: 400; line-height: .98; letter-spacing: -.05em; }
.result-lead p { max-width: 340px; margin: 0; color: var(--ink-soft); line-height: 1.5; }
.result-layout { display: grid; grid-template-columns: minmax(380px, 1.2fr) minmax(300px, .8fr); gap: 56px; align-items: start; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; padding-bottom: 10px; border-bottom: 1px solid var(--ink); }
.section-heading h3 { margin: 0; font-size: 11px; letter-spacing: .13em; text-transform: uppercase; }
.section-heading span { color: var(--ink-soft); font-size: 10px; }
.ranking-row { display: grid; grid-template-columns: 35px minmax(130px, 1fr) 70px 70px; align-items: center; width: 100%; min-height: 66px; padding: 0; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; transition: padding 160ms ease, color 160ms ease; animation: rank-in 420ms ease both; }
.ranking-row:hover, .ranking-row.is-selected { padding-left: 8px; color: var(--accent-deep); }
.ranking-row .rank { color: var(--ink-soft); font-size: 11px; }
.ranking-row strong { display: block; font-size: 13px; }
.ranking-row small { color: var(--ink-soft); font-size: 10px; }
.ranking-row .score { font-family: Georgia, "Times New Roman", serif; font-size: 24px; text-align: right; }
.ranking-row .stability { color: var(--ink-soft); font-size: 10px; text-align: right; }
@keyframes rank-in { from { opacity: 0; transform: translateY(8px); } }

.result-inspector { position: sticky; top: 20px; padding: 24px 0 0; border-top: 1px solid var(--ink); }
.inspector-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.inspector-heading h3 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 29px; font-weight: 400; }
.inspector-heading span { color: var(--ink-soft); font-size: 10px; }
.criterion-list { margin-top: 26px; }
.criterion-row { display: grid; grid-template-columns: 1fr 48px; gap: 7px 15px; margin-bottom: 14px; font-size: 10px; }
.criterion-row strong { text-align: right; font-weight: 650; }
.criterion-track { grid-column: 1 / -1; height: 2px; background: var(--paper-deep); }
.criterion-track i { display: block; height: 100%; background: var(--accent); }
.gate-summary { margin-top: 28px; padding-top: 17px; border-top: 1px solid var(--line); }
.gate-summary h4 { margin: 0 0 10px; font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.gate-chip { display: flex; justify-content: space-between; gap: 14px; padding: 7px 0; border-bottom: 1px dotted var(--line); font-size: 10px; }
.gate-chip b { color: var(--accent); }

.blocked-section { margin-top: 56px; }
.blocked-section h3 { margin: 0; padding-bottom: 10px; border-bottom: 1px solid var(--ink); font-size: 11px; letter-spacing: .13em; text-transform: uppercase; }
.blocked-row { display: grid; grid-template-columns: minmax(150px, .8fr) 2fr; gap: 30px; padding: 15px 0; border-bottom: 1px solid var(--line); font-size: 11px; }
.blocked-row p { margin: 0; color: var(--warning); }
.download-strip { display: flex; align-items: center; gap: 26px; margin-top: 48px; padding: 24px 0; border-top: 1px solid var(--ink); }
.download-strip strong { margin-right: auto; font-size: 12px; }
.download-strip a { color: var(--accent); font-size: 11px; font-weight: 650; text-decoration-thickness: 1px; text-underline-offset: 5px; }

.action-bar { position: sticky; bottom: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 24px; min-height: 80px; border-top: 1px solid var(--line); background: rgba(243, 240, 232, .94); backdrop-filter: blur(12px); }
.action-bar p { margin: 0; color: var(--ink-soft); font-size: 11px; text-align: right; }
.primary-button, .secondary-button { min-height: 43px; padding: 0 18px; border: 1px solid var(--ink); cursor: pointer; font-size: 12px; font-weight: 650; transition: transform 150ms ease, background 150ms ease; }
.primary-button { min-width: 150px; border-color: var(--accent-deep); background: var(--accent-deep); color: white; }
.primary-button:hover { transform: translateY(-2px); background: var(--accent); }
.primary-button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.primary-button span { margin-left: 10px; }
.secondary-button { background: transparent; }
.secondary-button:hover { background: var(--paper-deep); }

.toast { position: fixed; right: 28px; bottom: 96px; z-index: 20; max-width: 380px; padding: 13px 16px; background: var(--ink); color: white; font-size: 12px; opacity: 0; transform: translateY(10px); pointer-events: none; transition: 180ms ease; }
.toast.is-visible { opacity: 1; transform: none; }
.loading-screen { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: var(--ink); color: white; transition: opacity 420ms ease, visibility 420ms; }
.loading-screen.is-hidden { opacity: 0; visibility: hidden; }
.loading-screen span { font-family: Georgia, "Times New Roman", serif; font-size: 42px; letter-spacing: -.04em; }
.loading-screen p { color: rgba(255,255,255,.55); font-size: 11px; }

@media (max-width: 920px) {
  :root { --rail-width: 100%; }
  .app-shell { display: block; }
  .rail { position: sticky; z-index: 10; width: 100%; height: auto; padding: 17px 22px 0; }
  .brand-block { display: flex; align-items: baseline; gap: 13px; }
  .brand { font-size: 24px; }
  .brand-block p { margin: 0; }
  .step-nav { grid-template-columns: repeat(4, 1fr); margin-top: 17px; }
  .step-link { display: block; padding: 11px 4px 12px; border-bottom: 0; text-align: center; }
  .step-link:last-child { border-bottom: 0; }
  .step-link::before, .step-link small { display: none; }
  .step-link > span { display: block; margin-bottom: 3px; }
  .rail-note { display: none; }
  .workspace { min-height: calc(100svh - 113px); padding: 0 25px; }
  .workspace-header { min-height: 92px; }
  .dataset-control > div { display: none; }
  .stage { padding-top: 32px; }
  .stage-intro { margin-bottom: 32px; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .result-layout { grid-template-columns: 1fr; }
  .result-inspector { position: static; }
}

@media (max-width: 620px) {
  .workspace { padding: 0 18px; }
  .workspace-header h1 { font-size: 25px; }
  .notice { align-items: flex-start; }
  .stage-intro-row, .result-lead { align-items: flex-start; }
  .stage-intro h2 { font-size: 36px; }
  .selection-count { display: none; }
  .town-row { grid-template-columns: 30px 1fr 70px; }
  .town-source { display: none; }
  .evidence-summary { grid-template-columns: 1fr; }
  .evidence-summary div + div { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
  .result-lead { display: block; }
  .result-lead p { margin-top: 14px; }
  .ranking-row { grid-template-columns: 30px 1fr 55px; }
  .ranking-row .stability { display: none; }
  .blocked-row { grid-template-columns: 1fr; gap: 7px; }
  .download-strip { flex-wrap: wrap; gap: 18px; }
  .download-strip strong { width: 100%; }
  .action-bar { grid-template-columns: auto 1fr; }
  .action-bar p { display: none; }
  .primary-button { justify-self: end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
