/* Rural Route — shared styles.
   Field-manual layout: one sturdy column on a paper ground, badge-cornered cards,
   slab headings, typewriter data. Map screens run edge to edge. */

:root {
  /* Palette (CR-001 §4.1) */
  --paper: #FBF7EC;
  --paper-shade: #F3ECD9;
  --khaki: #E9DFC4;
  --khaki-deep: #D6C8A1;
  --olive: #5B6236;
  --olive-deep: #434826;
  --red: #9E2B25;
  --red-deep: #7E1F1A;
  --gold: #D9A441;
  --gold-deep: #B9842A;
  --ink: #1F2A44;
  --ink-soft: #46506A;
  --sepia: #8A6A45;
  --rule: #CDBF99;

  /* Type */
  --font-head: "Arvo", "Rockwell", "Roboto Slab", Georgia, serif;
  --font-body: "Bitter", "Rockwell", Georgia, serif;
  --font-type: "Courier Prime", "Courier New", Courier, monospace;
  --font-hand: "Yellowtail", "Brush Script MT", cursive;

  --step--1: 0.875rem;
  --step-0: 1.0625rem;
  --step-1: 1.25rem;
  --step-2: 1.5625rem;
  --step-3: 2rem;
  --step-4: 2.75rem;

  /* Shape */
  --notch: 12px;
  --tap: 56px;          /* minimum tap height on driving screens */
  --gutter-l: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));

  /* Faint paper grain, drawn with SVG noise */
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .35  0 0 0 0 .27  0 0 0 0 .15  0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  --halftone: radial-gradient(circle at center, rgba(31,42,68,.16) 1.1px, transparent 1.4px) 0 0 / 6px 6px;

  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper) var(--grain);
  color: var(--ink);
  font: 400 var(--step-0)/1.55 var(--font-body);
}
img, svg { max-width: 100%; }
a { color: var(--red); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: 700;
  line-height: 1.15;
  margin: 0;
  text-wrap: balance;
}
h1 { font-size: var(--step-3); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
p { margin: 0; }

.hand { font-family: var(--font-hand); font-weight: 400; color: var(--red); }
.type { font-family: var(--font-type); }
.label {
  font-family: var(--font-head);
  font-size: var(--step--1);
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--olive);
}
.muted { color: var(--ink-soft); }
.num { font-family: var(--font-type); font-variant-numeric: tabular-nums; }

/* ---------- Page frame ---------- */
.page {
  max-width: 600px;
  margin: 0 auto;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  padding-block: 0 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.page.wide { max-width: 980px; }

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: var(--olive) var(--grain);
  color: var(--paper);
  border-bottom: 3px double var(--khaki-deep);
}
body.has-topbar::before {
  content: ""; position: fixed; inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px); z-index: 21;
  background: var(--olive);
}
.topbar-inner {
  max-width: 980px;
  margin: 0 auto;
  padding-left: var(--gutter-l);
  padding-right: var(--gutter-r);
  padding-block: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}
.wordmark {
  font-family: var(--font-hand);
  font-size: 1.75rem;
  line-height: 1;
  color: var(--paper);
  text-decoration: none;
  text-shadow: 1px 1px 0 var(--olive-deep);
}
.wordmark small {
  display: block;
  font-family: var(--font-head);
  font-size: .625rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--khaki);
  margin-top: 2px;
}
.topbar a.menu-link {
  color: var(--paper);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: var(--step--1);
  letter-spacing: .1em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding-inline: 12px;
  border: 2px solid var(--khaki);
  border-radius: 4px;
}

.screen-head { display: flex; flex-direction: column; gap: 6px; padding-top: 20px; }
.screen-head .hand { font-size: var(--step-3); line-height: 1; }

/* ---------- Badge cards ---------- */
.card {
  position: relative;
  background: var(--paper-shade) var(--grain);
  padding: 18px;
  clip-path: polygon(var(--notch) 0, calc(100% - var(--notch)) 0, 100% var(--notch),
                     100% calc(100% - var(--notch)), calc(100% - var(--notch)) 100%,
                     var(--notch) 100%, 0 calc(100% - var(--notch)), 0 var(--notch));
  box-shadow: inset 0 0 0 2px var(--ink);
}
.card::after {               /* inner dashed rule, like a stitched field-guide box */
  content: "";
  position: absolute;
  inset: 6px;
  border: 1.5px dashed var(--rule);
  pointer-events: none;
  clip-path: inherit;
}
.card > * { position: relative; z-index: 1; }
.card.khaki { background: var(--khaki) var(--grain); }
.card.plain { box-shadow: inset 0 0 0 1.5px var(--rule); }
.card.plain::after { display: none; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 20px;
  font: 700 var(--step-0)/1.1 var(--font-head);
  letter-spacing: .04em;
  text-decoration: none;
  color: var(--paper);
  background: var(--ink);
  border: 0;
  border-radius: 6px;
  box-shadow: 0 3px 0 rgba(31,42,68,.45), inset 0 0 0 2px rgba(251,247,236,.18);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(31,42,68,.45); }
.btn svg { width: 26px; height: 26px; flex: none; }
.btn.red { background: var(--red); box-shadow: 0 3px 0 var(--red-deep); }
.btn.olive { background: var(--olive); box-shadow: 0 3px 0 var(--olive-deep); }
.btn.gold { background: var(--gold); color: var(--ink); box-shadow: 0 3px 0 var(--gold-deep); }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink);
}
.btn.big { min-height: var(--tap); font-size: var(--step-1); padding-inline: 24px; }
.btn.huge {
  min-height: 112px;
  width: 100%;
  font-size: var(--step-3);
  border-radius: 10px;
  flex-direction: column;
  gap: 4px;
}
.btn.huge small { font: 400 var(--step--1)/1.2 var(--font-type); letter-spacing: 0; opacity: .9; }
.btn.block { width: 100%; }

/* Next / back footer that ties the screens together */
.flow {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 2px solid var(--ink);
  padding-top: 16px;
}
.flow a { flex: 1 1 140px; }

/* ---------- Tags, chips ---------- */
.tags { display: flex; flex-wrap: wrap; gap: 8px; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font: 700 var(--step--1)/1.3 var(--font-type);
  background: var(--khaki);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 3px;
}
.tag.season { background: var(--gold); }
.tag.gravel { background: var(--paper); border-style: dashed; }
.tag svg { width: 16px; height: 16px; }

/* ---------- Icons ---------- */
.ico { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; border: 2px solid var(--ink); }
.stat { padding: 10px 12px; border-right: 1.5px solid var(--rule); min-width: 0; }
.stat:last-child { border-right: 0; }
.stat .v { font: 700 var(--step-2)/1.1 var(--font-type); font-variant-numeric: tabular-nums; }
.stat .k { font: 700 .75rem/1.2 var(--font-head); letter-spacing: .1em; text-transform: uppercase; color: var(--olive); }

/* ---------- Map frames ---------- */
.mapbox {
  position: relative;
  height: 280px;
  border: 2px solid var(--ink);
  outline: 1.5px solid var(--ink);
  outline-offset: 3px;
  margin: 4px;
  background: var(--paper);
}
.mapbox .map { position: absolute; inset: 0; }
.map-credit {
  font: 400 .6875rem/1.3 var(--font-type);
  color: var(--ink-soft);
}
.maplibregl-ctrl-attrib { font-family: var(--font-type); font-size: 10px; background: rgba(251,247,236,.85) !important; }
.maplibregl-ctrl-attrib a { color: var(--ink); }

/* Ink pins drawn as HTML markers */
.pin-marker {
  width: 34px; height: 40px;
  display: grid; place-items: start center;
  pointer-events: none;
}
.pin-marker svg { width: 34px; height: 40px; }

/* Lock / privacy */
.privacy {
  display: inline-flex; align-items: center; gap: 6px;
  font: 700 var(--step--1)/1 var(--font-type);
  color: var(--olive-deep);
}

/* Toggle (Private / Share) */
.seg {
  display: grid; grid-template-columns: 1fr 1fr;
  border: 2px solid var(--ink); border-radius: 6px; overflow: hidden;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; cursor: pointer;
  font: 700 var(--step-0)/1 var(--font-head);
  background: var(--paper);
  color: var(--ink);
}
.seg label + input + label, .seg input + label + input + label { border-left: 2px solid var(--ink); }
.seg input:checked + label { background: var(--olive); color: var(--paper); }
.seg input:focus-visible + label { outline: 3px solid var(--gold); outline-offset: -5px; }

/* Ink illustration frames */
.ink-art { display: block; width: 100%; height: auto; }

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

/* ---------- Toast ---------- */
#rr-toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 140%);
  z-index: 50;
  max-width: calc(100% - 32px);
  padding: 14px 20px;
  background: var(--ink);
  color: var(--paper);
  font: 700 var(--step-0)/1.3 var(--font-type);
  border-radius: 6px;
  box-shadow: 0 4px 0 rgba(0,0,0,.25);
  transition: transform .25s ease;
  pointer-events: none;
}
#rr-toast.show { transform: translate(-50%, 0); }
body.driving #rr-toast { bottom: calc(260px + env(safe-area-inset-bottom, 0px)); }

/* Mockup ribbon */
.mock-note {
  font: 400 var(--step--1)/1.45 var(--font-type);
  color: var(--ink-soft);
  border-left: 3px solid var(--gold);
  padding: 4px 0 4px 12px;
}
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
