:root {
  --bg: #f6f4ee;
  --panel: #fffdf8;
  --ink: #22201b;
  --muted: #555047;
  --post: #5a3e25;
  --post-ink: #fffaf0;
  --trail: #2d6a3e;
  --line: #d6cfbf;
  --alt: #eee9dd;
  --hl: #f5d77e;
  --hl-ink: #22201b;
  --err: #a12a1c;
  --focus: #1f5fbf;
  --r: 6px;
  --ui: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --num: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a17;
    --panel: #23221e;
    --ink: #ece8df;
    --muted: #c2bbad;
    --post: #e0b88d;
    --post-ink: #1b1a17;
    --trail: #86c99a;
    --line: #45413a;
    --alt: #2a2824;
    --hl: #6e5718;
    --hl-ink: #fff6dc;
    --err: #ff9c8c;
    --focus: #8ab4ff;
  }
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.5 var(--ui); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
a { color: var(--trail); text-underline-offset: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.vh, .vh-s { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--panel); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
[hidden] { display: none !important; }

/* header: a trail sign */
.top { padding: 22px 0 6px; }
h1 { margin: 0; font-size: clamp(1.7rem, 4.5vw, 2.4rem); line-height: 1.15; letter-spacing: -0.01em; display: flex; align-items: center; gap: 12px; }
h1::before {
  content: ""; flex: none; width: 18px; height: 1.05em; border-radius: 3px 3px 0 0; background: var(--post);
  box-shadow: inset 0 6px 0 var(--post), inset 0 8px 0 var(--post-ink), inset 0 11px 0 var(--post);
}
.lede { margin: 8px 0 0; max-width: 62ch; color: var(--muted); font-size: 1.05rem; }
h2 { font-size: 1.25rem; margin: 26px 0 10px; line-height: 1.25; }
h3 { font-size: 1.05rem; margin: 20px 0 4px; }

/* layout */
.tool { display: grid; gap: 8px 40px; align-items: start; }
@media (min-width: 940px) { .tool { grid-template-columns: minmax(380px, 430px) minmax(0, 1fr); } }
.editor, .result { min-width: 0; }
.editor.viewing { opacity: .72; }
@media (min-width: 940px) { .btn.jump { display: none; } }

/* buttons and fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 16px;
  font: inherit; font-size: 1rem; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--post); color: var(--post-ink); border-color: var(--post); font-weight: 600; }
.btn.quiet { border-color: transparent; background: transparent; text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: default; }
.link { font: inherit; color: var(--trail); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; min-height: 0; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.file-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 4px; }
.vh-file { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.vh-file:focus-visible + .btn, .file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
input[type="text"], textarea, select {
  font: inherit; font-size: 1rem; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 9px 10px; min-height: 44px; width: 100%;
}
input::placeholder, textarea::placeholder { color: #7a7468; }
@media (prefers-color-scheme: dark) { input::placeholder, textarea::placeholder { color: #958e80; } }
.field { margin: 16px 0 8px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.units { margin-top: 14px; }
.unit-note { margin: 8px 0 4px; }
.unit-note p { margin: 0 0 6px; }
.show-unit { margin: 0 0 10px; }
.paste-pick { margin: 6px 0; }
.paste-pick label { display: inline; font-weight: 600; margin: 0 6px 0 0; }
.paste-pick select { width: auto; max-width: 100%; }
.seg { border: 0; padding: 0; margin: 8px 0 0; }
.seg legend { font-weight: 600; padding: 0; margin-bottom: 4px; }
.seg label { display: inline-block; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.seg span { display: inline-flex; align-items: center; min-height: 44px; padding: 6px 14px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.seg label:first-of-type span { border-radius: var(--r) 0 0 var(--r); }
.seg label:last-of-type span { border-radius: 0 var(--r) var(--r) 0; margin-left: -1px; }
.seg input:checked + span { background: var(--trail); border-color: var(--trail); color: var(--panel); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* stops */
.stop-head, .stop { display: grid; grid-template-columns: 1.7rem minmax(0, 1fr) 5.6rem 2.9rem 2.75rem; gap: 6px; align-items: center; }
.stop-head { font-size: .95rem; font-weight: 600; color: var(--muted); padding-bottom: 2px; }
.stop-head span:nth-child(3) { padding-left: 2px; }
.stops { list-style: none; margin: 0; padding: 0; }
.stop { padding: 3px 0; border-bottom: 1px solid var(--line); }
.stop .num { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; font-size: .95rem; }
.stop .s-mm { text-align: right; font-variant-numeric: tabular-nums; }
.s-night { display: flex; align-items: center; justify-content: center; min-height: 44px; cursor: pointer; }
.s-night input { width: 22px; height: 22px; accent-color: var(--post); margin: 0; }
.s-x { width: 44px; height: 44px; font-size: 1.4rem; line-height: 1; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: var(--r); }
.s-x:hover { color: var(--err); }
.s-hint { grid-column: 2 / -1; margin: 0 0 4px; font-size: 1rem; color: var(--muted); }
.s-hint.err { color: var(--err); }
.s-mm[aria-invalid="true"] { border-color: var(--err); }
.msgs p, .ask p { margin: 8px 0; }
.msgs p { color: var(--ink); }
.ask { padding: 4px 0; }
.store-note, .view-bar { background: var(--alt); border-radius: var(--r); padding: 10px 14px; margin: 12px 0; }
.view-bar p { margin: 0; }
.view-bar .row-btns { margin-bottom: 0; }

/* GPX import and paste */
.imp, .paste { margin: 12px 0; padding: 4px 0 2px; border-top: 2px solid var(--post); border-bottom: 1px solid var(--line); }
.imp h2 { margin-top: 10px; font-size: 1.1rem; overflow-wrap: anywhere; }
.imp-list { list-style: none; padding: 0; margin: 8px 0; max-height: none; }
.imp-list li { border-bottom: 1px solid var(--line); }
.imp-list label { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 2px 8px; align-items: center; min-height: 44px; padding: 4px 0; cursor: pointer; }
.imp-list input { width: 20px; height: 20px; accent-color: var(--post); }
.imp-name { overflow-wrap: anywhere; }
.imp-at { font-variant-numeric: tabular-nums; white-space: nowrap; }
.imp-note { grid-column: 2 / -1; color: var(--muted); font-size: 1rem; }
.imp-track label { font-weight: 600; margin-right: 6px; }
.imp-track select { width: auto; max-width: 100%; }
.paste label { display: block; font-weight: 600; margin: 8px 0 4px; }
.paste textarea { resize: vertical; min-height: 9em; }
.paste-sum { margin: 6px 0; color: var(--muted); overflow-wrap: anywhere; }
.err { color: var(--err); }

/* result */
.sum { margin: 0 0 10px; font-size: 1.1rem; font-weight: 600; }
.pick { margin: 0 0 8px; padding: 6px 10px; background: var(--hl); color: var(--hl-ink); border-radius: var(--r); display: inline-block; }
.chart-box { position: relative; overflow-x: auto; max-width: 100%; padding: 2px 2px 10px; font: 16px var(--num); }
.stair { border-collapse: collapse; table-layout: fixed; font-variant-numeric: tabular-nums; }
.stair td.d { text-align: right; padding: 4px 8px; border: 1px solid var(--line); background: var(--panel); white-space: nowrap; cursor: pointer; }
.stair tr:nth-child(even) td.d { background: var(--alt); }
.stair th.nm { text-align: left; font-weight: 600; padding: 4px 8px; white-space: nowrap; border-bottom: 2px solid var(--post); }
.stair th.nm.night::after { content: " · night"; color: var(--muted); font-weight: 400; font-size: .9em; }
.stair .hl, .stair tr:nth-child(even) td.d.hl { background: var(--hl); color: var(--hl-ink); }
.stair th.cn { font-weight: 400; color: var(--muted); }
.tip { color: var(--muted); margin: 0 0 8px; }
.legs table { border-collapse: collapse; width: 100%; max-width: 560px; font-variant-numeric: tabular-nums; margin-bottom: 16px; }
.legs th, .legs td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); }
.legs thead th { font-size: .95rem; color: var(--muted); border-bottom: 2px solid var(--line); }
.legs tbody th { font-weight: 600; overflow-wrap: anywhere; }
.legs .n { text-align: right; white-space: nowrap; }
.legs .dayrow th { background: var(--alt); color: var(--ink); font-weight: 600; }
.legs tr.night th::after { content: " · night"; color: var(--muted); font-weight: 400; font-size: .9em; }
.out { margin-top: 18px; padding-top: 6px; border-top: 1px solid var(--line); }
.share-box label { display: block; margin: 4px 0; }
.share-row { display: flex; gap: 8px; }
.share-row input { flex: 1; min-width: 0; }
.kept { margin: 18px 0; }
.kept summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.kept ul { list-style: none; padding: 0; margin: 0; }
.kept li { border-bottom: 1px solid var(--line); padding: 6px 0; }
.kept li p { margin: 4px 0; overflow-wrap: anywhere; }
.kept .row-btns { margin: 4px 0; }

/* text below the tool */
.explain { max-width: 70ch; margin-top: 36px; border-top: 1px solid var(--line); }
.explain p { margin: 0 0 12px; }

/* footer */
.site-footer { margin-top: 48px; padding: 20px 16px 28px; border-top: 1px solid var(--line); color: var(--muted); }
.sb-footer { max-width: 1180px; margin: 0 auto; font-size: 1rem; }
.sb-footer p { margin: 0 0 10px; }
.sb-more { line-height: 1.8; }
.sb-footer a { color: var(--ink); }
.sb-credit a { color: var(--trail); }

.toast {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(560px, calc(100% - 32px));
  background: var(--ink); color: var(--bg); padding: 10px 12px 10px 16px; border-radius: var(--r); display: flex; align-items: center; gap: 8px; z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
.toast-text { flex: 1; }
.toast button { font: inherit; min-height: 44px; min-width: 44px; background: none; color: inherit; border: 1px solid currentColor; border-radius: var(--r); cursor: pointer; }
.toast .toast-x { border: 0; font-size: 1.3rem; }

@media (max-width: 420px) {
  .stop-head, .stop { grid-template-columns: 1.3rem minmax(0, 1fr) 4.9rem 2.75rem 2.6rem; gap: 4px; }
  .s-x { width: 40px; }
}
@media (max-width: 350px) {
  .stop-head, .stop { grid-template-columns: 1.1rem minmax(0, 1fr) 4.2rem 2.6rem 2.4rem; gap: 3px; }
  .stop input[type="text"] { padding: 9px 7px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }

/* ---------------------------------------------------------------- print */
.print-root { display: none; }
@page { margin: 0.5in; }
@media print {
  body { background: #fff; color: #000; font: 10pt/1.3 Arial, Helvetica, sans-serif; }
  body > *:not(.print-root) { display: none !important; }
  .print-root { display: block; color: #000; }
  .print-root .vh { display: none; }
  .p-head h2 { font-size: 15pt; margin: 0 0 2pt; }
  .p-head p { margin: 0 0 10pt; font-size: 10pt; }
  .piece { break-inside: avoid; margin: 0 0 14pt; }
  .p-cap { margin: 0 0 3pt; font-size: 9pt; break-after: avoid; }
  .stair { border-collapse: collapse; table-layout: fixed; font-variant-numeric: tabular-nums; }
  .stair td.d { border: 0.5pt solid #888; padding: 0 3pt; text-align: right; white-space: nowrap; height: 14.5pt; font-size: 10pt; }
  .stair tr:nth-child(even) td.d { background: #ececec; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .stair th.nm { text-align: left; font-weight: 700; white-space: nowrap; padding: 0 3pt; border-bottom: 1pt solid #000; font-size: 10pt; }
  .stair th.nm.night::after { content: " (night)"; font-weight: 400; }
  .stair .no { font-weight: 400; }
  .stair th.cn { font-weight: 400; font-size: 8pt; text-align: right; padding: 0 3pt; }
  .stair.blank th.nm { height: 39pt; padding: 0; border-bottom: 0.75pt solid #000; vertical-align: bottom; }
  .stair.blank .line { display: none; }
  .stair.blank td.d { height: 39pt; background: none !important; }
  .p-legs h3 { font-size: 12pt; margin: 6pt 0 4pt; break-after: avoid; }
  .p-legs table, .card table.days, .card table.legtab { border-collapse: collapse; width: 100%; max-width: 6in; font-variant-numeric: tabular-nums; margin-bottom: 10pt; }
  .p-legs th, .p-legs td { text-align: left; padding: 2pt 4pt; border-bottom: 0.5pt solid #999; font-size: 10pt; }
  .p-legs .n { text-align: right; }
  .p-legs tr { break-inside: avoid; }
  .p-legs .dayrow, .p-legs h3 { break-after: avoid; }
  .p-legs thead { display: table-header-group; }
  .p-legs .dayrow th, .card .dayrow th { font-weight: 700; border-bottom: 1pt solid #000; padding-top: 6pt; }
  .p-legs tr.night th::after { content: " (night)"; font-weight: 400; }
  .card .stair th.nm.night::after, .card tr.night th::after { content: " *"; font-weight: 700; color: #000; font-size: 1em; }
  .c-key { margin: 3pt 0 0; font-size: 7pt; }

  /* pocket cards: four to a page, 3.55 by 4.9 in, with a cut line */
  .cards { display: grid; grid-template-columns: repeat(2, 3.55in); grid-auto-rows: 4.9in; gap: 0.12in; justify-content: center; }
  .card { border: 0.75pt dashed #777; padding: 6pt 8pt; overflow: hidden; break-inside: avoid; font-size: 7.5pt; }
  .cards + .cards { break-before: page; }
  .c-head { display: flex; justify-content: space-between; gap: 6pt; font-size: 8pt; border-bottom: 0.75pt solid #000; margin-bottom: 3pt; padding-bottom: 1pt; }
  .c-head b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .c-head span { white-space: nowrap; }
  .c-sub { margin: 0 0 4pt; font-size: 7pt; }
  .card .p-cap { font-size: 7pt; margin-bottom: 2pt; }
  .card .stair td.d { font-size: 7.5pt; height: 10.5pt; padding: 0 2pt; }
  .card .stair th.nm { font-size: 7.5pt; padding: 0 2pt; }
  .card .stair th.cn { font-size: 6.5pt; }
  .card .stair.blank td.d, .card .stair.blank th.nm { height: 33pt; }
  .card th, .card td { text-align: left; padding: 1pt 2pt; border-bottom: 0.5pt solid #999; font-size: 7.5pt; }
  .card .n { text-align: right; }
  .card .p-head h2 { font-size: 10pt; }
  .card .p-head p { font-size: 7.5pt; margin-bottom: 6pt; }
}
