:root {
  --sign: #000;
  --ink: #1d1d1d;
  --ink-soft: #5c5c5c;
  --line: #d9d9d6;
  --tile: #f2f2f0;
  --paper: #fff;
  --start: #fff;
  --end: #000;
  --error: #b3261e;
  --focus: #0062cf;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --panel-w: 420px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  font-size: 16px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- station sign header ---------- */
.sign {
  background: var(--sign);
  color: #fff;
  position: relative;
  flex: none;
}
.sign::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 7px;
  height: 2px;
  background: #fff;
}
.sign-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 14px;
}
.sign h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
}
.sign-goal {
  margin: 0 0 0 16px; flex: 1; min-width: 0;
  font-size: 16px; line-height: 1.3; color: #fff;
}
.sign-goal .pin-chip { font-size: 13px; line-height: 20px; border-color: #fff; }
.sign-goal .pin-end { background: #000; }
.sign-meta { flex: none; display: flex; align-items: center; gap: 12px; font-size: 15px; }
.sign-meta #puzzle-label { color: #fff; opacity: 0.85; }

/* ---------- route bullets ---------- */
.bullet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  flex: none;
}
.bullet-sm { width: 18px; height: 18px; font-size: 11px; }
.bullet-diamond { border-radius: 4px; transform: rotate(45deg) scale(0.78); }
.bullet-diamond > span { transform: rotate(-45deg); }
.bullet-sign { background: #fff; color: #000; width: 32px; height: 32px; font-size: 17px; }
.bullet-sign.bullet-pill { width: auto; padding: 0 12px; border-radius: 16px; font-size: 15px; white-space: nowrap; }

/* ---------- layout ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.panel {
  width: var(--panel-w);
  flex: none;
  overflow-y: auto;
  padding: 20px 24px 24px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.map-wrap { flex: 1; position: relative; background: var(--tile); }
#map { position: absolute; inset: 0; }
.map-fallback { position: absolute; inset: auto 16px 16px 16px; margin: 0; padding: 12px 14px; background: var(--paper); border: 1px solid var(--line); font-size: 14px; }

.brief { margin: 0 0 12px; max-width: 60ch; color: var(--ink); }

/* ---------- how to play ---------- */
.how { margin: 0 0 18px; }
.how summary {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer; font-weight: 700; font-size: 15px;
  list-style: none; padding: 2px 0;
  text-decoration: underline; text-underline-offset: 3px;
}
.how summary::-webkit-details-marker { display: none; }
.how summary::before {
  content: ""; width: 0; height: 0;
  border-left: 6px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent;
  transition: transform 120ms ease;
}
.how[open] summary::before { transform: rotate(90deg); }
.how-body { max-width: 60ch; font-size: 15px; }
.how-body p { margin: 10px 0 0; }
.how-fine { color: var(--ink-soft); font-size: 14px; }
.pin-chip {
  display: inline-block;
  padding: 0 8px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 14px;
  line-height: 22px;
  border: 2px solid #000;
}
.pin-start { background: var(--start); color: #000; }
.pin-end { background: var(--end); color: #fff; }

/* ---------- legs ---------- */
.legs { list-style: none; margin: 0; padding: 0; }
.leg {
  padding: 16px 0 18px;
  border-top: 1px solid var(--line);
}
.leg-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.leg-title { font-weight: 700; font-size: 17px; }
.leg-remove {
  background: none; border: 0; padding: 2px 0;
  color: var(--ink-soft); font: inherit; font-size: 14px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}
.leg-walk { margin: -4px 0 10px; font-size: 14px; color: var(--ink-soft); }
.leg-walk::before { content: ""; display: inline-block; width: 18px; border-top: 2px dashed var(--ink-soft); vertical-align: middle; margin-right: 8px; }

.field { display: block; margin-top: 12px; }
.field:first-of-type { margin-top: 0; }
.field-label { display: block; font-size: 14px; color: var(--ink-soft); margin-bottom: 6px; }

.combo { position: relative; }
.combo-input, .exit-select {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1.5px solid #9a9a9a;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
}
.combo-input:focus, .exit-select:focus { border-color: #000; outline: none; box-shadow: 0 0 0 3px rgba(0, 98, 207, 0.35); }
.combo-list {
  position: absolute; z-index: 1000; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px 0; list-style: none;
  background: var(--paper);
  border: 1.5px solid #000;
  border-radius: 6px;
  max-height: 320px; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.combo-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; cursor: pointer;
}
.combo-list li[aria-selected="true"], .combo-list li:hover { background: var(--tile); }
.combo-list .combo-head { cursor: default; justify-content: flex-start; gap: 6px; font-size: 13px; color: var(--ink-soft); background: var(--paper); position: sticky; top: -4px; }
.combo-list .combo-empty { color: var(--ink-soft); cursor: default; }
.mini-bullets { display: inline-flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; }

.lines { display: flex; flex-wrap: wrap; gap: 8px; }
.line-btn {
  border: 0; padding: 0; background: none; cursor: pointer; border-radius: 50%;
  outline-offset: 3px;
}
.line-btn .bullet { width: 36px; height: 36px; font-size: 19px; transition: transform 120ms ease; }
.line-btn[aria-checked="true"] .bullet { box-shadow: 0 0 0 3px var(--paper), 0 0 0 5px #000; }
.lines:has([aria-checked="true"]) .line-btn[aria-checked="false"] .bullet { opacity: 0.35; }
.line-btn:hover .bullet { transform: scale(1.06); }

/* ---------- actions ---------- */
.actions { display: flex; gap: 12px; flex-wrap: wrap; padding-top: 16px; border-top: 1px solid var(--line); }
.btn {
  font: inherit; font-weight: 700; font-size: 15px;
  padding: 11px 18px; border-radius: 24px; cursor: pointer;
  border: 2px solid #000;
}
.btn-primary { background: #000; color: #fff; }
.btn-primary:disabled { background: #bdbdbd; border-color: #bdbdbd; cursor: not-allowed; }
.btn-quiet { background: var(--paper); color: #000; }
.next-label { flex-basis: 100%; margin: 0; font-weight: 700; font-size: 17px; }
.board-help { display: block; margin-top: 6px; font-size: 13px; color: var(--ink-soft); }
.errors { margin: 14px 0 0; padding: 0; list-style: none; color: var(--error); font-size: 14px; }
.errors li + li { margin-top: 6px; }

/* ---------- result ---------- */
.result-score { margin: 4px 0 6px; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.05; }
.nowrap { white-space: nowrap; }
.result-par { margin: 0 0 18px; font-size: 17px; }
.result-par strong { font-weight: 700; }
.route-toggle { display: flex; gap: 0; margin-bottom: 14px; border: 2px solid #000; border-radius: 22px; overflow: hidden; width: fit-content; }
.route-toggle button { font: inherit; font-size: 14px; font-weight: 700; border: 0; padding: 7px 16px; background: var(--paper); cursor: pointer; }
.route-toggle button[aria-pressed="true"] { background: #000; color: #fff; }
.steps-title { font-size: 15px; font-weight: 700; margin: 18px 0 6px; }
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 15px; border-bottom: 1px solid var(--tile); }
.steps .step-walk { color: var(--ink-soft); }
.steps .walk-icon { width: 28px; text-align: center; flex: none; }
.steps .meters { margin-left: auto; font-variant-numeric: tabular-nums; white-space: nowrap; }
.result-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.copied { font-size: 14px; color: var(--ink-soft); align-self: center; }

.panel-foot { margin-top: auto; padding-top: 28px; font-size: 14px; display: flex; gap: 16px; }
.panel-foot a { color: var(--ink); }

/* ---------- map bits ---------- */
.pin {
  display: inline-block; white-space: nowrap;
  padding: 2px 9px; border-radius: 12px; border: 2px solid #000;
  font: 700 13px/18px var(--font);
  transform: translate(-50%, -130%);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.pin::after {
  content: ""; position: absolute; left: 50%; bottom: -8px; width: 2px; height: 7px; background: #000; transform: translateX(-50%);
}
.pin-start-m { background: #fff; color: #000; }
.pin-end-m { background: #000; color: #fff; }
.pin-dot { width: 10px; height: 10px; border-radius: 50%; background: #000; border: 2px solid #fff; box-shadow: 0 0 0 1px #000; }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  body { height: auto; min-height: 100%; }
  .layout { flex-direction: column; }
  .map-wrap { order: -1; height: 46vh; flex: none; }
  .panel { width: 100%; border-right: 0; padding: 18px 16px 24px; overflow: visible; }
  .sign-inner { padding: 20px 16px 12px; }
  .sign h1 { font-size: 24px; }
  .sign-inner { flex-wrap: wrap; row-gap: 10px; }
  .sign-goal { order: 3; flex-basis: 100%; margin-left: 0; font-size: 15px; }
}

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