:root {
  /* Almanac palette: aged cream, sepia ink, forest + brass accents. */
  --bg: #efe5d0;
  --bg-2: #e8dcc3;
  --panel: #f6efdf;
  --panel-2: #efe6d0;
  --line: #cdbb98;
  --line-2: #b39f78;
  --ink: #2e2519;
  --ink-dim: #5b4f3c;
  --ink-faint: #8a7b62;
  --accent: #5d7a4f;        /* forest (primary) */
  --accent-2: #4e6a3f;      /* deep forest (emphasis text) */
  --brass: #9a6b3a;         /* brass (secondary) */
  --enjoyable: #5d7a4f;
  --rain: #5a7a8c;
  --gust: #9a6b3a;
  --cold: #ddd0b3;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(74,56,28,.08), 0 6px 22px rgba(74,56,28,.10);
  --font-serif: 'Spectral', Georgia, 'Times New Roman', serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background:
    radial-gradient(1100px 700px at 50% -8%, #f7f1e3, transparent 62%),
    radial-gradient(1400px 900px at 50% 120%, #e3d6ba, transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(154,107,58,.22); }

h1, h2, h3 { margin: 0; font-family: var(--font-serif); font-weight: 600; letter-spacing: 0; }

/* small letterspaced mono caps, the almanac label voice */
.eyebrow {
  font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .14em;
  font-size: 10.5px; font-weight: 600;
}

/* ---------- top bar ---------- */
.topbar {
  border-bottom: 3px double var(--line-2);
  background: linear-gradient(180deg, rgba(246,239,223,.92), rgba(239,229,208,.78));
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 20;
}
.topbar-inner {
  max-width: 1560px; margin: 0 auto; padding: 18px 26px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; flex-wrap: wrap;
}
.brand-row { display: flex; align-items: center; gap: 14px; }
.logo { display: inline-flex; flex: none; filter: drop-shadow(0 2px 4px rgba(74,56,28,.18)); }
.logo svg { width: 46px; height: 46px; display: block; }
.brand h1 {
  font-size: 33px; font-weight: 600; color: var(--ink); letter-spacing: .005em;
}
.tagline {
  margin: 7px 0 0; max-width: 560px; color: var(--ink-dim);
  font-size: 15px; line-height: 1.5; font-style: italic;
}
.tagline em { font-style: normal; font-weight: 600; color: var(--ink); }

.topbar-right { display: flex; flex-direction: column; align-items: flex-end; gap: 11px; }

.feedback-btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  font-family: var(--font-serif); font-size: 14px; font-weight: 600; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 4px;
  padding: 7px 14px; transition: .15s; white-space: nowrap;
}
.feedback-btn:hover { border-color: var(--accent); color: var(--accent-2); background: #fbf6ea; }
.feedback-btn svg { color: var(--brass); }

.readout { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.readout .chip {
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-dim);
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 4px; white-space: nowrap;
}
.readout .chip b { color: var(--brass); font-weight: 600; }

/* ---------- layout ---------- */
.layout {
  max-width: 1560px; margin: 0 auto; padding: 24px 26px 64px;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  grid-template-areas: "controls map" "controls board";
  gap: 22px;
  align-items: start;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; grid-template-areas: "controls" "map" "board"; }
}

/* Framed parchment panel with an inner hairline (a double-rule border). */
.panel {
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  box-shadow: inset 0 0 0 3px var(--panel), inset 0 0 0 4px rgba(179,159,120,.55), var(--shadow);
}
.controls { grid-area: controls; padding: 22px; }
.map-panel { grid-area: map; padding: 20px 20px 12px; }
.board-panel { grid-area: board; padding: 20px; }

.panel h2 { font-size: 18px; color: var(--ink); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding-bottom: 11px; margin-bottom: 16px; border-bottom: 1px solid var(--line);
}

/* ---------- controls ---------- */
.controls > h2 {
  font-size: 18px; padding-bottom: 11px; margin-bottom: 16px; border-bottom: 1px solid var(--line);
}

.explainer {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brass);
  border-radius: 4px;
  padding: 13px 15px;
  margin-bottom: 20px;
}
.explainer-title {
  margin: 0 0 7px; font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--brass);
}
.explainer p:not(.explainer-title) {
  margin: 0; font-size: 13.5px; line-height: 1.6; color: var(--ink-dim);
}
.explainer strong { color: var(--ink); font-weight: 600; }

.control { padding: 16px 0; border-top: 1px solid var(--line); }
.control:first-of-type { border-top: none; padding-top: 0; }
.control-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.control-head label { font-size: 14.5px; font-weight: 600; color: var(--ink); }
.control-head output {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 500;
  color: var(--accent-2); background: var(--panel-2); border: 1px solid var(--line);
  padding: 3px 8px; border-radius: 4px; white-space: nowrap;
}
.hint { margin: 13px 0 0; font-size: 12.5px; line-height: 1.55; color: var(--ink-faint); font-style: italic; }
.hint strong { color: var(--ink-dim); font-weight: 600; font-style: normal; }

.control-actions { margin: 20px 0 6px; }
#reset {
  width: 100%; padding: 10px; border-radius: 4px; cursor: pointer;
  background: var(--panel-2); color: var(--ink-dim); border: 1px solid var(--line-2);
  font-family: var(--font-serif); font-size: 14px; transition: .15s;
}
#reset:hover { color: var(--accent-2); border-color: var(--accent); background: #fbf6ea; }
.provenance {
  margin-top: 16px; font-family: var(--font-mono); font-size: 10.5px; line-height: 1.6;
  color: var(--ink-faint); letter-spacing: .02em;
}

/* ---------- slider tracks ---------- */
.dual, .single { position: relative; height: 30px; }
.track { position: absolute; top: 14px; left: 0; right: 0; height: 3px; background: var(--line-2); border-radius: 2px; }
.fill { position: absolute; top: 14px; height: 3px; border-radius: 2px; background: var(--accent); }
.dual input[type=range], .single input[type=range] {
  position: absolute; top: 0; left: 0; width: 100%; margin: 0;
  -webkit-appearance: none; appearance: none; background: none; pointer-events: none; height: 30px;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; pointer-events: auto;
  width: 17px; height: 17px; border-radius: 50%;
  background: #fbf6ea; border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(74,56,28,.35); cursor: pointer; margin-top: -1px;
}
input[type=range]::-moz-range-thumb {
  pointer-events: auto; width: 15px; height: 15px; border-radius: 50%;
  background: #fbf6ea; border: 2px solid var(--accent); cursor: pointer;
}
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px rgba(93,122,79,.28); }

/* ---------- map ---------- */
.map-wrap { width: 100%; }
#map { width: 100%; max-width: 820px; height: auto; display: block; margin: 0 auto; }
.sea { fill: #e6ddc4; stroke: var(--line-2); stroke-width: 1; }
.grat { stroke: #c6b693; stroke-width: 0.5; opacity: 0.55; }
.state { fill: #f1e8d3; stroke: #8a7456; stroke-width: 0.8; }
.inset-frame { fill: rgba(140,116,86,.05); stroke: var(--line-2); stroke-width: 1; stroke-dasharray: 3 3; }
.inset-label {
  font-family: var(--font-mono); font-size: 9.5px; fill: var(--ink-faint);
  letter-spacing: .16em; font-weight: 600;
}
.city-dot { stroke: #2e2519; stroke-width: 1.1; cursor: pointer; transition: r .12s; }
.city-dot:hover { stroke: #2e2519; stroke-width: 2; }
.city-label {
  font-family: var(--font-serif); font-size: 12px; font-weight: 600; fill: var(--ink); pointer-events: none;
  paint-order: stroke; stroke: rgba(241,232,211,.92); stroke-width: 3.5px;
}
.city-score {
  font-family: var(--font-mono); font-size: 10px; fill: var(--ink-dim); font-weight: 600; pointer-events: none;
  paint-order: stroke; stroke: rgba(241,232,211,.92); stroke-width: 3.5px;
}

.legend { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-dim); }
.legend .bar {
  width: 130px; height: 9px; border-radius: 2px; border: 1px solid var(--line);
  background: linear-gradient(90deg, #b0492f, #d6b15c, #5d7a4f);
}

.offmap { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 4px 4px; }
.offmap .pill {
  display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 11px;
  color: var(--ink-dim);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 4px 10px;
  cursor: pointer; transition: border-color .12s, background .12s;
}
.offmap .pill:hover { border-color: var(--accent); background: #fbf6ea; }
.offmap .pill i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; opacity: 0; transform: translateY(4px);
  transition: opacity .12s; background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 5px; padding: 11px 13px; box-shadow: var(--shadow); max-width: 240px; color: var(--ink);
}
.tooltip.show { opacity: 1; transform: none; }
.tooltip h4 { margin: 0 0 4px; font-size: 14px; font-weight: 600; }
.tooltip .big { font-family: var(--font-mono); font-size: 22px; font-weight: 600; color: var(--accent-2); }
.tooltip .rows { margin-top: 7px; font-size: 12.5px; color: var(--ink-dim); line-height: 1.65; }
.tooltip .rows b { color: var(--ink); font-weight: 600; }

/* ---------- leaderboard ---------- */
.board-key { display: flex; gap: 12px; flex-wrap: wrap; font-family: var(--font-mono); font-size: 10px; color: var(--ink-dim); }
.board-key span { display: inline-flex; align-items: center; gap: 5px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.sw.enjoyable { background: var(--enjoyable); }
.sw.rain { background: var(--rain); }
.sw.gust { background: var(--gust); }
.sw.cold { background: var(--cold); border: 1px solid var(--line-2); }

.board { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 14px;
  padding: 11px 6px; cursor: default; border-bottom: 1px solid var(--line);
  transition: background .12s, transform .35s cubic-bezier(.2,.8,.2,1);
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--panel-2); }
.row.flash { background: rgba(154,107,58,.10); }
.rank { font-family: var(--font-mono); font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; text-align: right; }
.row .meta { min-width: 0; }
.row .name { font-size: 15px; font-weight: 600; color: var(--ink); }
.row .barwrap {
  margin-top: 7px; height: 8px; border-radius: 2px; overflow: hidden; display: flex;
  background: var(--cold); border: 1px solid var(--line);
}
.row .seg { height: 100%; }
.row .seg.enjoyable { background: var(--enjoyable); }
.row .seg.rain { background: var(--rain); }
.row .seg.gust { background: var(--gust); }
.row .score { font-family: var(--font-mono); font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }

.loading {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); color: var(--ink-dim); font-style: italic; font-size: 15px; z-index: 100;
  transition: opacity .3s;
}
.loading.hide { opacity: 0; pointer-events: none; }

/* ---------- feedback modal ---------- */
.modal {
  border: 1px solid var(--line-2); border-radius: 8px; padding: 0;
  background: var(--panel); color: var(--ink); width: min(440px, calc(100vw - 32px));
  box-shadow: inset 0 0 0 3px var(--panel), inset 0 0 0 4px rgba(179,159,120,.5), 0 24px 64px rgba(46,37,25,.35);
}
.modal::backdrop { background: rgba(46,37,25,.5); backdrop-filter: blur(3px); }
.modal[open] { animation: modal-in .18s cubic-bezier(.2,.8,.2,1); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }

.feedback-form { padding: 24px; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: 20px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--ink-faint); font-size: 26px; line-height: 1;
  cursor: pointer; padding: 0 4px; border-radius: 4px; transition: color .12s;
}
.modal-close:hover { color: var(--ink); }
.modal-sub { margin: 7px 0 20px; font-size: 14px; color: var(--ink-dim); line-height: 1.5; font-style: italic; }

.feedback-form label { font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.feedback-form label .opt { font-weight: 400; color: var(--ink-faint); font-style: italic; }
.feedback-form input[type=email], .feedback-form textarea {
  font-family: var(--font-serif); font-size: 15px; color: var(--ink);
  background: #fbf7ec; border: 1px solid var(--line-2); border-radius: 4px;
  padding: 10px 12px; margin-bottom: 18px; width: 100%; resize: vertical;
  transition: border-color .12s, box-shadow .12s;
}
.feedback-form input::placeholder, .feedback-form textarea::placeholder { color: var(--ink-faint); }
.feedback-form input:focus, .feedback-form textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(93,122,79,.20);
}
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

.modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.form-status { margin: 0; font-size: 13px; line-height: 1.4; flex: 1; font-style: italic; }
.form-status.ok { color: var(--accent-2); }
.form-status.err { color: #b0492f; }
.btn-primary {
  font-family: var(--font-serif); font-size: 14.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
  color: #f6efdf; background: var(--accent); border: 1px solid #46603a;
  border-radius: 4px; padding: 10px 20px; transition: filter .12s, opacity .12s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .55; cursor: default; }

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translate(-50%, 16px);
  z-index: 120; pointer-events: none; opacity: 0;
  background: var(--panel); border: 1px solid var(--accent); color: var(--ink);
  font-size: 14px; font-weight: 600; padding: 11px 18px; border-radius: 5px;
  box-shadow: var(--shadow); transition: opacity .2s, transform .2s;
}
.toast::before { content: "\2713  "; color: var(--accent-2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
