/* Rucksack Roamer — the whole design system.
 *
 * Read design-brief.md before changing anything here. The five decisions are
 * pinned: condensed display + typewriter mono, kraft-and-ink palette, ZERO
 * radius, editorial density with deliberate rhythm variation, and passport
 * stamps as the recurring motif.
 *
 * tests/design.test.js enforces the mechanical subset (banned palette, banned
 * fonts, radius, stamp count, dark-mode counterparts). It cannot enforce taste.
 */

/* ---- tokens -------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  --kraft: #c9b28c;
  --kraft-light: #e0d0b4;
  --paper: #f2e9d8;
  --ink: #241f1a;
  --ink-soft: #5c5045;
  --rule: #8a7a63;
  --stamp-red: #a33b2c;
  --stamp-blue: #2f4b6e;
  --stamp-green: #4a6146;

  --display: Haettenschweiler, "Arial Narrow", "Franklin Gothic Bold", Impact, sans-serif;
  --mono: "Courier New", Courier, "Nimbus Mono PS", monospace;

  /* Deliberately not a uniform scale — the brief bans metronomic spacing. */
  --gap-hair: 2px;
  --gap-tight: 6px;
  --gap: 14px;
  --gap-wide: 34px;
  --gap-section: 56px;
}

/* Dark scheme. Every text/surface token above has a counterpart here — that is
 * the guard: on the previous project a more-specific selector defeated one
 * dark-mode override and made text invisible ONLY in dark mode, while every
 * light render and every string assertion passed. */
@media (prefers-color-scheme: dark) {
  :root {
    --kraft: #241f1a;
    --kraft-light: #322b24;
    --paper: #2b251f;
    --ink: #ede0c8;
    --ink-soft: #b3a48c;
    --rule: #6b5d4a;
    --stamp-red: #d4705f;
    --stamp-blue: #7d9dc4;
    --stamp-green: #8aa583;
  }
}

:root[data-theme="dark"] {
  --kraft: #241f1a;
  --kraft-light: #322b24;
  --paper: #2b251f;
  --ink: #ede0c8;
  --ink-soft: #b3a48c;
  --rule: #6b5d4a;
  --stamp-red: #d4705f;
  --stamp-blue: #7d9dc4;
  --stamp-green: #8aa583;
}

:root[data-theme="light"] {
  --kraft: #c9b28c;
  --kraft-light: #e0d0b4;
  --paper: #f2e9d8;
  --ink: #241f1a;
  --ink-soft: #5c5045;
  --rule: #8a7a63;
  --stamp-red: #a33b2c;
  --stamp-blue: #2f4b6e;
  --stamp-green: #4a6146;
}

/* ---- ground -------------------------------------------------------------- */

* { box-sizing: border-box; border-radius: 0; }

body {
  margin: 0;
  background-color: var(--kraft);
  /* paper grain, drawn not downloaded */
  background-image:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.022) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.016) 0 1px, transparent 1px 4px);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, .display {
  font-family: var(--display);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  line-height: 0.92;
  margin: 0;
}

h1 { font-size: clamp(2.6rem, 9vw, 4.4rem); }
h2 { font-size: clamp(1.7rem, 5vw, 2.5rem); }
h3 { font-size: 1.25rem; letter-spacing: 0.04em; }

a { color: var(--stamp-blue); text-underline-offset: 3px; }
a:hover { color: var(--stamp-red); }

.meta {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: var(--gap-hair) 0 0;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px 90px; }

/* ---- masthead: a ticket, torn along the bottom --------------------------- */

.masthead {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-bottom: none;
  margin-top: 26px;
  padding: 22px 24px 20px;
  position: relative;
  /* asymmetric on purpose — the brief bans all-centred symmetric layout */
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: var(--gap);
}

.masthead__perf {
  height: 14px;
  background: var(--paper);
  border-left: 3px solid var(--ink);
  border-right: 3px solid var(--ink);
  -webkit-mask-image: radial-gradient(circle at 7px 14px, transparent 7px, #000 7.5px);
  mask-image: radial-gradient(circle at 7px 14px, transparent 7px, #000 7.5px);
  -webkit-mask-size: 14px 14px;
  mask-size: 14px 14px;
  -webkit-mask-repeat: repeat-x;
  mask-repeat: repeat-x;
}

.masthead h1 { letter-spacing: -0.01em; }
.masthead__tag {
  font-size: 0.8rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--stamp-red);
  border-top: 1px solid var(--rule);
  padding-top: 6px;
  margin-top: 8px;
}
.masthead__ref { text-align: right; }

/* ---- navigation: luggage tags -------------------------------------------- */

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 20px 0 var(--gap-wide);
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--rule);
}

.nav button {
  appearance: none;
  background: transparent;
  border: none;
  border-right: 1px solid var(--rule);
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--display);
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  padding: 11px 18px 9px;
  text-transform: uppercase;
}
.nav button:hover { color: var(--ink); background: var(--kraft-light); }
.nav button[aria-current="page"] {
  background: var(--ink);
  color: var(--paper);
}

/* ---- passport stamp: the signature element (use 1 of 4) ------------------ */

.stamp {
  display: inline-grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border: 3px double var(--stamp-red);
  border-radius: 50%; /* the only curve in the product, and it is deliberate */
  color: var(--stamp-red);
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  transform: rotate(-8deg);
  opacity: 0.9;
  padding: 6px;
  line-height: 1.15;
}
.stamp--blue { border-color: var(--stamp-blue); color: var(--stamp-blue); transform: rotate(6deg); }
.stamp--green { border-color: var(--stamp-green); color: var(--stamp-green); transform: rotate(-4deg); }
.stamp--pending { border-style: dashed; border-width: 2px; color: var(--ink-soft); border-color: var(--rule); opacity: 0.55; }
.stamp--sm { width: 54px; height: 54px; font-size: 0.5rem; border-width: 2px; }

/* progress markers (use 2 of 4) */
.progress {
  display: flex;
  align-items: center;
  gap: var(--gap-tight);
  margin: 0 0 var(--gap-wide);
  flex-wrap: wrap;
}
.progress__link { flex: 1 0 12px; height: 1px; background: var(--rule); min-width: 12px; }

/* section dividers (use 3 of 4) */
.divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--gap);
  margin: var(--gap-section) 0 var(--gap-wide);
}
.divider::before, .divider::after { content: ""; height: 3px; background: var(--ink); }
.divider .stamp { transform: rotate(-11deg); }

/* completion states, slapped on at an angle (use 4 of 4) */
.stamp--slap {
  position: absolute;
  top: -14px;
  right: 12px;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  transform: rotate(-14deg);
  z-index: 2;
}

/* ---- ticket stub cards --------------------------------------------------- */

.stub {
  background: var(--paper);
  border: 2px solid var(--ink);
  display: grid;
  grid-template-columns: 118px 1fr;
  margin-bottom: var(--gap);
  position: relative;
}
.stub__side {
  border-right: 2px dashed var(--rule);
  padding: 14px 12px;
  background: var(--kraft-light);
}
.stub__body { padding: 16px 18px 18px; min-width: 0; }
.stub--plain { grid-template-columns: 1fr; }

.stub__num {
  font-family: var(--display);
  font-size: 2.1rem;
  line-height: 0.85;
  color: var(--stamp-red);
}

/* ---- editorial layout: content column plus a margin rail ----------------- */

.editorial {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: var(--gap-wide);
  align-items: start;
}
.rail > * + * { margin-top: var(--gap-wide); }

/* In the margin rail a stub is too narrow for a side column — the stub tears
 * along the top instead, so the perforation survives and the text doesn't end
 * up one word per line. */
.rail .stub { grid-template-columns: minmax(0, 1fr); }
.rail .stub__side {
  border-right: none;
  border-bottom: 2px dashed var(--rule);
  padding: 8px 12px 6px;
}

@media (max-width: 820px) {
  .editorial { grid-template-columns: minmax(0, 1fr); }
  .stub { grid-template-columns: 84px 1fr; }
}

/* ---- forms --------------------------------------------------------------- */

.field { margin-bottom: var(--gap-wide); }
.field > label,
.field > .label {
  display: block;
  font-family: var(--display);
  font-size: 1.2rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: var(--gap-hair);
}
.field .hint { font-size: 0.78rem; color: var(--ink-soft); margin: 0 0 var(--gap-tight); }

input[type="text"], input[type="number"], input[type="date"], select {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  padding: 9px 11px;
  width: 100%;
  max-width: 420px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--stamp-blue);
  outline-offset: 2px;
}

.row { display: flex; flex-wrap: wrap; gap: var(--gap); }
.row > * { flex: 1 1 190px; }

/* interest chips — flat, sharp, ink-stamped when on */
.chips { display: flex; flex-wrap: wrap; gap: var(--gap-tight); }
.chip {
  appearance: none;
  background: var(--paper);
  border: 2px solid var(--ink);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.09em;
  padding: 7px 13px;
  text-transform: uppercase;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

input[type="range"] { width: 100%; max-width: 420px; accent-color: var(--stamp-red); }
.dial-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-soft);
  max-width: 420px;
}

/* one primary action, never a two-button hero cluster */
.go {
  appearance: none;
  background: var(--stamp-red);
  border: 3px solid var(--ink);
  color: var(--paper);
  cursor: pointer;
  font-family: var(--display);
  font-size: 1.7rem;
  letter-spacing: 0.05em;
  padding: 13px 34px 11px;
  text-transform: uppercase;
}
.go:hover { background: var(--ink); }
.go[disabled] { background: var(--rule); cursor: not-allowed; }

.btn {
  appearance: none;
  background: transparent;
  border: 2px solid var(--ink);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  padding: 7px 13px;
  text-transform: uppercase;
}
.btn:hover { background: var(--ink); color: var(--paper); }

/* ---- notices ------------------------------------------------------------- */

.notice {
  border-left: 6px solid var(--stamp-blue);
  background: var(--kraft-light);
  padding: 11px 14px;
  margin: var(--gap) 0;
  font-size: 0.87rem;
}
.notice--warn { border-left-color: var(--stamp-red); }
.notice--good { border-left-color: var(--stamp-green); }
.notice strong { letter-spacing: 0.04em; }

/* confidence is never decoration — it is the honesty rule made visible */
.confidence {
  display: inline-block;
  font-size: 0.66rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: 2px;
}
.confidence--low { color: var(--stamp-red); }
.confidence--medium { color: var(--stamp-blue); }
.confidence--none { color: var(--ink-soft); }

.empty {
  border: 2px dashed var(--rule);
  color: var(--ink-soft);
  padding: 18px;
  font-size: 0.88rem;
}

/* ---- data displays ------------------------------------------------------- */

.figure {
  font-family: var(--display);
  font-size: 2.8rem;
  line-height: 0.9;
  letter-spacing: -0.005em;
}
.figure--sm { font-size: 1.8rem; }
.figure--red { color: var(--stamp-red); }
.figure--green { color: var(--stamp-green); }

table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { text-align: left; padding: 7px 10px 6px; border-bottom: 1px solid var(--rule); }
th {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  border-bottom: 2px solid var(--ink);
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.legs { list-style: none; margin: 0; padding: 0; }
.leg {
  border-bottom: 1px solid var(--rule);
  padding: 12px 0 11px;
  display: grid;
  grid-template-columns: 74px 1fr auto;
  gap: var(--gap);
  align-items: baseline;
}
.leg__mode {
  font-family: var(--display);
  font-size: 1.1rem;
  letter-spacing: 0.07em;
  color: var(--stamp-blue);
}

.day { border-top: 1px solid var(--rule); padding: var(--gap) 0; }
.day__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--gap);
}
.day ol { margin: var(--gap-tight) 0 0; padding-left: 20px; }
.day li { margin-bottom: var(--gap-tight); }
.day li .note { color: var(--ink-soft); font-size: 0.83rem; display: block; }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { border-bottom: 1px dotted var(--rule); padding: 6px 0; display: flex; gap: 10px; align-items: baseline; }
.checklist input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--stamp-green); flex: none; }
.checklist .why { display: block; color: var(--ink-soft); font-size: 0.79rem; }
.checklist li.is-done label { text-decoration: line-through; color: var(--ink-soft); }

.bar { height: 16px; border: 2px solid var(--ink); background: var(--kraft-light); position: relative; }
.bar__fill { position: absolute; inset: 0 auto 0 0; background: var(--stamp-green); }
.bar__fill--over { background: var(--stamp-red); }

/* ---- footer -------------------------------------------------------------- */

.foot {
  border-top: 3px solid var(--ink);
  margin-top: var(--gap-section);
  padding-top: var(--gap);
  font-size: 0.76rem;
  color: var(--ink-soft);
  letter-spacing: 0.05em;
}

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

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