/* Tokens from DESIGN.md. Every contrast ratio here is measured in tests/test_design.py. */
:root {
  --ink: #1A1C1E;
  --paper: #FAF8F5;
  --rule: #D8D2C9;
  --deep: #6C2A1F;
  --signal: #1F5E6B;
  --muted: #58554E;

  --ramp-1: #F6E3D0;
  --ramp-2: #D4B5A4;
  --ramp-3: #B18678;
  --ramp-4: #8E584B;
  --ramp-5: #6C2A1F;

  --gutter: 16px;
  --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.55 var(--font);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

/* One column, left-aligned to a single edge. The map is the only full-bleed element. */
.wrap { max-width: 44rem; margin: 0 auto; padding: 0 var(--gutter); }

a { color: var(--signal); }
a:focus-visible, button:focus-visible, summary:focus-visible, select:focus-visible {
  outline: 3px solid var(--deep);
  outline-offset: 2px;
}

header.site { border-bottom: 1px solid var(--rule); }
header.site h1 { font-size: 1.35rem; font-weight: 600; margin: 0; padding: 10px 0 4px; }
@media (max-width: 480px) {
  header.site h1 { font-size: 1.1rem; padding: 8px 0 2px; }
  /* Tighter horizontal padding keeps six links to two rows without shrinking the
     44px tap height, which is the part that matters standing up in the sun. */
  header.site nav a { padding: 0 8px; font-size: 0.9rem; }
  header.site nav { margin-left: -8px; }
}
header.site nav { display: flex; flex-wrap: wrap; gap: 2px; margin-left: -12px; }
header.site nav a {
  display: inline-flex; align-items: center;
  min-height: var(--tap); padding: 0 12px;
  text-decoration: none; color: var(--signal); font-size: 0.95rem;
}
header.site nav a[aria-current="page"] {
  color: var(--ink); font-weight: 600; box-shadow: inset 0 -3px 0 var(--deep);
}

main { padding-bottom: 3rem; }
main > .wrap:first-child h2 { margin-top: 1rem; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 2rem 0 0.5rem; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 1.4rem 0 0.4rem; }
p, li { max-width: 38rem; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

.notice {
  border-left: 3px solid var(--deep);
  padding: 0.5rem 0 0.5rem 12px;
  margin: 0.75rem 0;
  background: none;
}

table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 6px 10px 6px 0; border-bottom: 1px solid var(--rule); }
th { font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

footer.site {
  border-top: 1px solid var(--rule);
  margin-top: 2.5rem; padding: 1rem 0 2rem;
  color: var(--muted); font-size: 0.875rem;
}
footer.site p { max-width: 38rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.skip {
  position: absolute; left: -9999px;
  background: var(--paper); color: var(--ink);
  padding: 10px 14px; border: 2px solid var(--deep); z-index: 100;
}
.skip:focus { left: var(--gutter); top: 8px; }

/* --- map ------------------------------------------------------------------ */
.map-frame { position: relative; margin: 0.75rem 0 0; }
#map {
  width: 100%;
  height: clamp(320px, 62vh, 640px);
  background: var(--rule);
}
.leaflet-container { font: 0.8rem var(--font); background: var(--rule); }
.leaflet-container a { color: var(--signal); }

.legend {
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px var(--gutter) 0;
  max-width: 44rem; margin: 0 auto;
}
.legend-swatches { display: flex; height: 14px; border: 1px solid var(--rule); }
.legend-swatch { flex: 1 1 0; }
.legend-ends {
  display: flex; justify-content: space-between;
  font-size: 0.8rem; color: var(--muted);
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Keyboard focus must be visible on the map too. */
.leaflet-interactive:focus { outline: 3px solid var(--deep); outline-offset: 1px; }


/* --- layer picker --------------------------------------------------------- */
.layer-picker { display: flex; align-items: center; gap: 8px; padding-top: 4px; }
.layer-picker label { font-size: 0.875rem; color: var(--muted); font-weight: 600; }
.layer-picker select {
  min-height: var(--tap); padding: 0 8px;
  font: 1rem var(--font); color: var(--ink);
  background: var(--paper); border: 1px solid var(--rule);
}

/* --- uncertainty hatching (DESIGN.md principle 1) ------------------------- */
/* A cell the model is unsure about must LOOK unsure. Hatch, not a lighter tint:
   a tint would read as "lower priority", which is a different claim. */
.cell-uncertain {
  stroke: #FFFFFF;
  stroke-dasharray: 3 2;
  stroke-width: 1.4;
}

/* --- cell panel ----------------------------------------------------------- */
.panel-wrap { border-top: 1px solid var(--rule); }
.panel-inner { max-width: 44rem; margin: 0 auto; padding: 0 var(--gutter) 1rem; position: relative; }
.panel-close {
  position: absolute; top: 8px; right: var(--gutter);
  min-height: var(--tap); min-width: var(--tap);
  background: none; border: 1px solid var(--rule); color: var(--signal);
  font: 0.875rem var(--font); cursor: pointer;
}
.panel-wrap:not(.is-open) .panel-close { display: none; }
.panel-rank { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums;
              margin: 0.75rem 0 0; }
.panel-band { margin: 0 0 0.5rem; font-weight: 600; }
#panel h4 { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.01em;
            margin: 1.1rem 0 0.3rem; color: var(--muted); }
.reasons { margin: 0; padding-left: 1.1rem; }
.chip {
  display: inline-block; padding: 2px 8px; border: 1px solid var(--rule);
  font-size: 0.8rem; font-weight: 600;
}
.chip-uncertain { border-color: var(--deep); }
.cannot { margin-top: 1.2rem; border-top: 1px solid var(--rule); padding-top: 0.6rem; }
.cannot summary { cursor: pointer; font-weight: 600; min-height: var(--tap);
                  display: flex; align-items: center; }
.cannot ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }


.formula {
  font-size: 1.05rem; font-variant-numeric: tabular-nums;
  border-left: 3px solid var(--rule); padding-left: 12px; margin: 0.8rem 0;
}

/* --- planner (P4-03) ------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 4px; margin: 0.6rem 0; max-width: 24rem; }
.field label { font-size: 0.875rem; font-weight: 600; color: var(--muted); }
.field select, .point input {
  min-height: var(--tap); padding: 0 8px; font: 1rem var(--font); color: var(--ink);
  background: var(--paper); border: 1px solid var(--rule);
}
.points { padding-left: 0; list-style: none; margin: 0.5rem 0; }
.point { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
         border-bottom: 1px solid var(--rule); padding: 4px 0; }
.point-name { font-weight: 600; min-width: 7rem; }
.point input { width: 7.5rem; }
.point-stock { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0.6rem 0 0.2rem; }
.button, .linkish {
  min-height: var(--tap); padding: 0 14px; font: 0.95rem var(--font); cursor: pointer;
  border: 1px solid var(--signal); background: var(--paper); color: var(--signal);
}
.button.primary { background: var(--signal); color: #FFFFFF; }
.button:disabled { border-color: var(--rule); color: var(--muted); background: var(--paper);
                   cursor: not-allowed; }
.linkish { border-color: transparent; padding: 0 6px; text-decoration: underline; }
.tag { font-size: 0.75rem; font-weight: 600; border: 1px solid var(--deep);
       padding: 1px 6px; margin-left: 6px; vertical-align: middle; }
.table-scroll { overflow-x: auto; }
caption { text-align: left; padding: 4px 0; }
.point-label { font: 600 0.8rem var(--font); }

/* --- field briefs list (P5-01) -------------------------------------------- */
table.briefs .links { display: flex; flex-wrap: wrap; gap: 0 14px; }
table.briefs .links a { display: inline-flex; align-items: center; min-height: var(--tap); }

/* --- brand ------------------------------------------------------------------ */
.brand { display: inline-flex; align-items: center; gap: 10px; min-height: var(--tap);
         color: var(--ink); text-decoration: none; }
.brand:hover span { text-decoration: underline; text-underline-offset: 3px; }
.mark { width: 28px; height: 24px; flex: 0 0 auto; }

/* --- the map page: the map IS the page (DESIGN.md, revised 2026-09-30) ----------------
   Everything below is scoped to body.app, so the content pages and the planner keep their
   one-column document layout. */
body.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column;
           overflow: hidden; }
body.app header.site { flex: 0 0 auto; background: var(--paper); position: relative; z-index: 1100; }
body.app header.site .bar { display: flex; align-items: center; gap: 0 24px; padding: 0 16px; }
body.app header.site h1 { font-size: 1.05rem; padding: 0; white-space: nowrap; }
body.app header.site nav { margin: 0 0 0 auto; flex-wrap: nowrap; }
body.app .app-main { flex: 1 1 auto; min-height: 0; padding: 0; display: grid;
                     grid-template-columns: minmax(0, 1fr) 400px; }
body.app .map-frame { position: relative; margin: 0; min-height: 0; }
body.app #map { position: absolute; inset: 0; height: auto; }

/* overlays on the map: paper surfaces with a hairline, so they read over any tile */
.map-top { position: absolute; z-index: 800; top: 12px; left: 12px; width: 380px;
           background: rgba(250, 248, 245, 0.97); border: 1px solid var(--rule);
           padding: 12px 14px 12px; box-shadow: 0 2px 10px rgba(26, 28, 30, 0.08); }
body.app .map-top h2 { font-size: 1.2rem; margin: 0 0 2px; letter-spacing: -0.01em; }
.map-sub { margin: 0 0 6px; font-size: 0.875rem; color: var(--muted); }
.map-top .layer-picker { padding-top: 2px; }
.map-top .layer-note { margin: 6px 0 0; color: var(--muted); }
.flag { font-size: 0.8rem; margin: 8px 0 0; padding-left: 10px;
        border-left: 3px solid var(--deep); line-height: 1.45; }
.map-bottom { position: absolute; z-index: 800; left: 12px; right: 12px; bottom: 22px;
              display: flex; align-items: flex-end; gap: 8px; pointer-events: none; }
.map-bottom > * { pointer-events: auto; }
body.app .legend { width: 300px; margin: 0; padding: 8px 10px;
                   background: rgba(250, 248, 245, 0.97); border: 1px solid var(--rule); }
body.app .legend-ends { gap: 12px; }
.legend-unsure { display: flex; align-items: center; gap: 8px; font-size: 0.8rem;
                 color: var(--muted); margin-top: 4px; }
.legend-dash { width: 22px; height: 14px; background: var(--ramp-2);
               outline: 2px dashed var(--ink); outline-offset: -2px; }
.list-toggle { display: none; margin-left: auto; min-height: var(--tap); padding: 0 16px;
               background: var(--signal); color: #FFFFFF; border: 0;
               font: 600 0.95rem var(--font); cursor: pointer; }
.map-error { position: absolute; z-index: 900; left: 12px; right: 12px; top: 45%;
             background: var(--paper); padding: 12px; }
body.app .leaflet-top.leaflet-right { top: 4px; }

/* the one-line first-visit hint: never modal, never blocks the map */
.coach { position: absolute; z-index: 900; left: 324px; bottom: 22px;
         width: max-content; max-width: calc(100% - 336px); display: flex; align-items: center;
         gap: 14px; background: var(--ink); color: #FFFFFF; padding: 8px 8px 8px 16px;
         box-shadow: 0 6px 24px rgba(26, 28, 30, 0.25); }
.coach[hidden] { display: none; }
.coach p { margin: 0; font-size: 0.95rem; max-width: 30rem; }
.coach button { min-height: var(--tap); padding: 0 16px; background: #FFFFFF; color: var(--ink);
                border: 0; font: 600 0.95rem var(--font); cursor: pointer; flex: 0 0 auto; }
.coach button:focus-visible { outline: 3px solid #F6E3D0; }

/* place names from OpenStreetMap: text on a paper label, never on a ramp colour */
.place-label { background: none; border: 0; }
.place-label span { position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
                    font: 600 12px/1 var(--font); color: var(--ink);
                    background: rgba(250, 248, 245, 0.94); border: 1px solid var(--rule);
                    padding: 3px 6px; }

/* the selected area: a heavy ink outline, over any hatching */
.leaflet-interactive.cell-selected { stroke: #1A1C1E; stroke-width: 3.5; stroke-dasharray: none; }

/* the sidebar (laptop) / bottom sheet (phone) */
body.app .panel-wrap { border-left: 1px solid var(--rule); border-top: 0; overflow-y: auto;
                       background: var(--paper); min-height: 0; }
body.app .panel-inner { max-width: none; margin: 0; padding: 12px 20px 24px; position: relative; }
.sheet-handle { display: none; }
body.app .panel-wrap.mode-list .panel-close { display: none; }
body.app .panel-wrap.mode-detail .panel-close { display: block; }
body.app .panel-close { top: 12px; right: 16px; padding: 0 12px; background: var(--paper); }
.list-view h3 { font-size: 1.15rem; margin: 6px 0 2px; }
.top-list { list-style: none; padding: 0; margin: 10px 0 16px; border-top: 1px solid var(--rule); }
.top-item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 56px;
            padding: 8px 6px; background: none; border: 0; border-bottom: 1px solid var(--rule);
            text-align: left; font: inherit; color: var(--ink); cursor: pointer; }
.top-item:hover { background: #F1EDE6; }
.top-rank { width: 1.6rem; flex: 0 0 auto; text-align: right; font-weight: 600;
            font-variant-numeric: tabular-nums; color: var(--muted); }
.top-swatch { width: 18px; height: 18px; flex: 0 0 auto; }
.top-swatch.is-unsure { outline: 2px dashed var(--ink); outline-offset: -2px; }
.top-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.top-place { font-weight: 600; }
.top-why { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden;
           text-overflow: ellipsis; }
.top-sure { flex: 0 0 auto; font-size: 0.75rem; font-weight: 600; color: var(--muted);
            border: 1px solid var(--rule); padding: 2px 6px; }
.about-map { border-top: 1px solid var(--rule); padding-top: 4px; }
.about-map summary { cursor: pointer; font-weight: 600; min-height: var(--tap);
                     display: flex; align-items: center; }
.about-map ul { padding-left: 1.1rem; margin: 0.2rem 0 0.4rem; }
.about-map li { margin-bottom: 0.4rem; }
body.app footer.app-foot { margin-top: 1rem; padding: 0.8rem 0 0; border-top: 1px solid var(--rule);
                           font-size: 0.8rem; }
body.app footer.app-foot p { margin: 0 0 0.5rem; }
.panel-near { margin: 6px 5rem 0 0; font-size: 0.875rem; color: var(--muted); }
body.app .panel-rank { margin-top: 2px; }
table.values th { font-weight: 500; color: var(--muted); }
table.values td, table.values th { padding: 5px 10px 5px 0; font-size: 0.875rem; }

@media (max-width: 899px) {
  body.app header.site .bar { flex-direction: column; align-items: stretch; padding: 0; }
  body.app header.site h1 { padding: 0 16px; font-size: 1rem; }
  body.app header.site nav { margin: 0; padding: 0 8px; overflow-x: auto; scrollbar-width: none; }
  body.app header.site nav::-webkit-scrollbar { display: none; }
  body.app header.site nav a { flex: 0 0 auto; }
  body.app .app-main { grid-template-columns: minmax(0, 1fr); }
  .map-top { left: 8px; right: 8px; top: 8px; width: auto; padding: 10px 12px; }
  body.app .map-top h2 { font-size: 1.02rem; }
  .map-sub, .flag-more { display: none; }
  .map-top .layer-picker select { min-height: 40px; }
  .map-bottom { left: 8px; right: 8px; bottom: 34px; }
  body.app .leaflet-control-attribution { font-size: 10px; }
  body.app .legend-ends { font-size: 0.72rem; }
  /* with the sheet up, the strip of map above it belongs to the selected area */
  body.app.sheet-open .map-top, body.app.sheet-open .map-bottom,
  body.app.sheet-open .leaflet-top.leaflet-right, body.app.sheet-open .coach { display: none; }
  body.app .legend { width: auto; flex: 1 1 auto; max-width: 250px; padding: 6px 8px; }
  .legend-unsure { display: none; }
  .list-toggle { display: inline-flex; align-items: center; }
  .coach { left: 8px; bottom: 96px; max-width: calc(100% - 16px); }
  body.app .leaflet-top.leaflet-right { top: 120px; }
  /* bottom sheet: same DOM as the sidebar, so one reading order at both widths */
  body.app .panel-wrap { position: fixed; z-index: 1000; left: 0; right: 0; bottom: 0;
                         height: 62vh; height: 62dvh; border-left: 0; border-top: 1px solid var(--rule);
                         transform: translateY(105%); transition: transform 0.22s ease;
                         box-shadow: 0 -12px 32px rgba(26, 28, 30, 0.18); visibility: hidden; }
  body.app .panel-wrap.is-open { transform: none; visibility: visible; }
  body.app .panel-wrap.mode-list .panel-close { display: block; }
  .sheet-handle { display: block; width: 44px; height: 5px; border-radius: 3px;
                  background: var(--rule); margin: 0 auto 6px; }
  body.app .panel-inner { padding: 8px 16px 32px; }
}
