:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #17202e;
  --muted: #6a7486;
  --line: #dde2ea;
  --accent: #2563eb;
  --accent-soft: #dbe7ff;
  --start: #16a34a;
  --end: #dc2626;
  --path: #2563eb;
  --best: #f59e0b;
  --dot: #b8c1cf;
  --danger: #b91c1c;
  --radius: 12px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --card: #18202b;
    --text: #e6ebf2;
    --muted: #8b96a8;
    --line: #2a3442;
    --accent: #60a5fa;
    --accent-soft: #1e3352;
    --path: #60a5fa;
    --dot: #3a4656;
    --danger: #f87171;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.danger { color: var(--danger); }
button:disabled { opacity: .45; cursor: default; }
select, input {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; margin: 0; cursor: default; user-select: none; }
.tabs { display: flex; gap: 4px; }
.tabs button { background: transparent; color: var(--text); border-color: transparent; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }
.settings { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: var(--text); }
.seg button.active { background: var(--accent); color: #fff; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }

.admin { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; border-style: dashed; }
.admin input[type=number] { width: 60px; }
.admin input[type=text] { width: 140px; }

.title-right { display: inline-flex; align-items: center; gap: 10px; }
.small-btn { padding: 2px 8px; font-size: 13px; font-weight: 500; }
.puzzle-title { align-items: center;  display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-weight: 600; flex-wrap: wrap; }

.route { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; margin-bottom: 14px; text-align: center; }
.endpoint .tag { font-size: 11px; letter-spacing: .1em; color: var(--muted); }
.endpoint .code { font-size: 34px; font-weight: 800; letter-spacing: .08em; font-family: ui-monospace, Menlo, monospace; }
.endpoint:first-child .code { color: var(--start); }
.endpoint:last-child .code { color: var(--end); }
.endpoint .place { font-size: 13px; color: var(--muted); }
.route-mid { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.route-mid .arrow { font-size: 26px; color: var(--muted); line-height: 1; }
.target-badge {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: color-mix(in srgb, var(--best) 15%, transparent); border: 1px solid var(--best);
  border-radius: 10px; padding: 6px 14px;
}
.target-badge .tag { font-size: 10px; letter-spacing: .12em; color: var(--muted); }
.target-badge strong { font-size: 18px; }

.layout { display: grid; grid-template-columns: 1fr 280px; gap: 14px; }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } }
.col-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.map-card { padding: 6px; }
.map-svg { width: 100%; height: auto; display: block; }
.map-svg .bg { fill: var(--dot); }
.map-svg .cand { fill: var(--accent); }
.map-svg .leg { stroke: var(--path); stroke-width: 2.5; fill: none; stroke-linecap: round; }
.map-svg .best { stroke: var(--best); stroke-width: 2; stroke-dasharray: 6 5; fill: none; }
.map-svg .stop { fill: var(--path); }
.map-svg .start { fill: var(--start); }
.map-svg .end { fill: var(--end); }
.map-svg text { font: 600 13px ui-monospace, Menlo, monospace; fill: var(--text); paint-order: stroke; stroke: var(--card); stroke-width: 3px; }
.map-svg text.cand-label { font-size: 11px; fill: var(--accent); }

.play .current { font-size: 16px; margin-bottom: 10px; }
.code-inline { font-family: ui-monospace, Menlo, monospace; font-weight: 800; font-size: 20px; letter-spacing: .06em; }
#guessForm { display: flex; gap: 8px; }
#guessInput { width: 110px; text-transform: uppercase; font-family: ui-monospace, Menlo, monospace; font-size: 18px; letter-spacing: .1em; }
.message { min-height: 22px; margin: 8px 0; font-size: 14px; }
.message.error { color: var(--danger); }
.message.ok { color: var(--start); }
.options { display: flex; flex-wrap: wrap; gap: 6px; }
.options button {
  background: var(--accent-soft); color: var(--text); border-color: transparent;
  font-family: ui-monospace, Menlo, monospace; text-align: left;
}
.options button .opt-place { font-family: ui-sans-serif, system-ui, sans-serif; font-size: 12px; color: var(--muted); margin-left: 6px; }
.options button.visited { opacity: .4; }
.options button.target { outline: 2px solid var(--end); }
.options .none { color: var(--muted); font-size: 14px; }
.actions { display: flex; gap: 8px; margin-top: 12px; }

.col-side h3 { margin: 0 0 8px; font-size: 15px; }
.legs { margin: 0; padding-left: 20px; font-size: 14px; max-height: 360px; overflow: auto; }
.legs li { padding: 3px 0; }
.legs .leg-code { font-family: ui-monospace, Menlo, monospace; font-weight: 700; }
.legs .leg-d { float: right; color: var(--muted); }
.totals { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; display: grid; gap: 4px; font-size: 14px; }
.totals div { display: flex; justify-content: space-between; }

.archive-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.archive-list button { background: var(--bg); color: var(--text); border-color: var(--line); text-align: left; }
.archive-list button .a-num { font-weight: 700; }
.archive-list button .a-date { display: block; font-size: 12px; color: var(--muted); }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text);
  max-width: 460px; width: calc(100% - 32px);
}
#resultDialog { max-width: 760px; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
@media (max-width: 560px) { .result-grid { grid-template-columns: 1fr; } }
.result-map { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: 8px; }
.route-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
@media (max-width: 560px) { .route-compare { grid-template-columns: 1fr; } }
.route-col { border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-width: 0; }
.route-col-head { font-weight: 700; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.swatch { width: 22px; height: 0; border-top: 3px solid var(--path); display: inline-block; }
.route-col.optimal .swatch { border-top: 3px dashed var(--best); }
.route-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.route-table td { padding: 3px 4px; vertical-align: top; }
.route-table tr.shared td { background: var(--accent-soft); }
.r-code { font-family: ui-monospace, Menlo, monospace; font-weight: 700; }
.r-place { color: var(--muted); }
.r-leg { text-align: right; white-space: nowrap; color: var(--muted); }
.route-col-total { display: flex; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; font-size: 14px;
}
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h2 { margin-top: 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.result-grid div { background: var(--bg); border-radius: 8px; padding: 8px; }
.result-grid .big { font-size: 20px; font-weight: 700; display: block; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 14px;
}
