:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e6ec;
  --text: #1c2430;
  --muted: #67717f;
  --primary: #1f5fbf;
  --primary-dark: #164a97;
  --primary-soft: #e8f0fd;
  --ok: #1f9254;
  --ok-soft: #e6f4ec;
  --warn: #b7791f;
  --warn-soft: #fbf3e2;
  --danger: #c0392b;
  --danger-soft: #fbebe8;
  --cmp-b: #7a4dd6;
  --cmp-b-soft: #efe8fb;
  --surface-2: #fbfcfe;
  --border-strong: #c3ccd8;
  --primary-line: #cfe0fb;
  --primary-rgb: 31, 95, 191;
  --btn-primary: #1f5fbf;
  --btn-primary-hover: #164a97;
  --warn-line: #f0dcb4;
  --danger-line: #f1c9c3;
  --cmp-b-rgb: 122, 77, 214;
  --chip-bg: #eef1f5;
  --disabled: #a9b6c7;
  --hover-overlay: rgba(20, 30, 45, 0.04);
  --tip-bg: #1c2430;
  --tip-border: transparent;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 45, 0.08), 0 6px 20px rgba(20, 30, 45, 0.05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f141b;
    --surface: #171e27;
    --surface-2: #1c242f;
    --border: #2a3441;
    --border-strong: #3d4958;
    --text: #e4e9f0;
    --muted: #95a1b1;
    --primary: #6ea2ff;
    --primary-dark: #a9c6ff;
    --primary-soft: #1b2b45;
    --primary-line: #2d4b7b;
    --primary-rgb: 110, 162, 255;
    --btn-primary: #2f6fd6;
    --btn-primary-hover: #3f7fe6;
    --ok: #4cc286;
    --ok-soft: #13301f;
    --warn: #e3ab4f;
    --warn-soft: #33270f;
    --warn-line: #5c4518;
    --danger: #f27d6f;
    --danger-soft: #3a1b18;
    --danger-line: #5d2b26;
    --cmp-b: #ab8df2;
    --cmp-b-soft: #2a2144;
    --cmp-b-rgb: 171, 141, 242;
    --chip-bg: #232c38;
    --disabled: #4b5667;
    --hover-overlay: rgba(255, 255, 255, 0.04);
    --tip-bg: #26303d;
    --tip-border: #3d4958;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.25);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141b;
  --surface: #171e27;
  --surface-2: #1c242f;
  --border: #2a3441;
  --border-strong: #3d4958;
  --text: #e4e9f0;
  --muted: #95a1b1;
  --primary: #6ea2ff;
  --primary-dark: #a9c6ff;
  --primary-soft: #1b2b45;
  --primary-line: #2d4b7b;
  --primary-rgb: 110, 162, 255;
  --btn-primary: #2f6fd6;
  --btn-primary-hover: #3f7fe6;
  --ok: #4cc286;
  --ok-soft: #13301f;
  --warn: #e3ab4f;
  --warn-soft: #33270f;
  --warn-line: #5c4518;
  --danger: #f27d6f;
  --danger-soft: #3a1b18;
  --danger-line: #5d2b26;
  --cmp-b: #ab8df2;
  --cmp-b-soft: #2a2144;
  --cmp-b-rgb: 171, 141, 242;
  --chip-bg: #232c38;
  --disabled: #4b5667;
  --hover-overlay: rgba(255, 255, 255, 0.04);
  --tip-bg: #26303d;
  --tip-border: #3d4958;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 20px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 20px 80px; }

header { background: var(--surface); border-bottom: 1px solid var(--border); }
header .wrap { padding-bottom: 0; }
.head-bar { display: flex; align-items: center; gap: 12px; min-height: 56px; }
.brand {
  display: flex; align-items: center; gap: 10px; margin: 0;
  font-size: 1rem; line-height: 1.3; font-weight: 650; color: var(--text);
}
.brand-mark {
  display: grid; place-items: center; flex: none; width: 30px; height: 30px; border-radius: 8px;
  background: var(--btn-primary); color: #fff;
}
.brand-mark svg { width: 18px; height: 18px; }
.theme-toggle {
  margin-left: auto; flex: none; appearance: none; cursor: pointer; font: inherit; font-size: 0.95rem; line-height: 1;
  width: 34px; height: 34px; border-radius: 50%;
  color: var(--muted); background: none; border: 1px solid var(--border);
}
.theme-toggle:hover { color: var(--text); background: var(--hover-overlay); }
.theme-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.notice {
  display: flex; align-items: flex-start; gap: 8px;
  padding-top: 8px; padding-bottom: 9px; border-top: 1px solid var(--border);
  font-size: 0.8rem; line-height: 1.45; color: var(--muted);
}
header .notice { padding-bottom: 10px; }
.notice p { margin: 0; }
.notice strong { color: var(--text); font-weight: 600; }
.notice-icon { flex: none; width: 15px; height: 15px; margin-top: 2px; color: var(--warn); }

footer { border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--muted); }
footer .wrap { padding-top: 16px; padding-bottom: 24px; }
footer p { margin: 0; }
footer p + p { margin-top: 8px; }
footer strong { color: var(--text); font-weight: 600; }

.tabs { display: flex; gap: 6px; margin: 12px 0 20px; border-bottom: 2px solid var(--border); }
.tab {
  appearance: none; border: none; background: none; cursor: pointer;
  font: inherit; font-weight: 600; color: var(--muted);
  padding: 12px 18px; border-radius: 10px 10px 0 0; position: relative; top: 2px;
  border-bottom: 3px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

@media (min-width: 641px) and (max-width: 900px) {
  .tab { padding: 12px 10px; white-space: nowrap; }
}
@media (max-width: 640px) {
  .tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 0 4px; }
  .tab { padding: 9px 6px; font-size: 0.82rem; }
}

.panel { display: none; }
.panel.active { display: block; animation: fade 0.18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 16px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.badge {
  flex: none; width: 44px; height: 44px; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary-dark);
  display: grid; place-items: center; font-weight: 700; font-size: 0.95rem;
}
.card-title { flex: 1; min-width: 0; }
.card-title .name { font-weight: 650; }
.card-title .sub { font-size: 0.78rem; color: var(--muted); }
.dir {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 999px; text-transform: uppercase;
}
.dir.min { background: var(--warn-soft); color: var(--warn); }
.dir.max { background: var(--ok-soft); color: var(--ok); }

.pts {
  flex: none; font-variant-numeric: tabular-nums; font-weight: 700;
  font-size: 1.05rem; min-width: 62px; text-align: right;
}
.pts .of { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.pts.done { color: var(--ok); }
.pts.partial { color: var(--muted); }

.card-body { padding: 6px 18px 16px; }

.sub { padding: 12px 0; border-bottom: 1px dashed var(--border); }
.sub:last-child { border-bottom: none; }
.sub-label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.sub-label .t { font-size: 0.9rem; }
.sub-label .t b { color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.sub-label .unit { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.sub-desc { font-size: 0.76rem; color: var(--muted); margin: 0 0 8px; }

select {
  width: 100%; font: inherit; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
select.chosen { border-color: var(--primary); background: var(--primary-soft); }

.summary {
  position: sticky; bottom: 16px; margin-top: 22px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 20px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.summary .total { font-size: 1.6rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.summary .total .of { color: var(--muted); font-size: 1rem; font-weight: 500; }
.summary .label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.meter { flex: 1; min-width: 160px; height: 10px; background: var(--border); border-radius: 999px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--ok)); transition: width 0.25s ease; }
.status-pill { font-size: 0.78rem; font-weight: 600; padding: 5px 12px; border-radius: 999px; }
.status-pill.done { background: var(--ok-soft); color: var(--ok); }
.status-pill.partial { background: var(--warn-soft); color: var(--warn); }

.rev-picker { margin-bottom: 10px; }
.rev-picker label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.rev-picker select.chosen { border-color: var(--primary); background: var(--primary-soft); }
.rev-or { font-size: 0.8rem; color: var(--muted); margin: 0 0 8px; }

.rev-input { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; margin-bottom: 6px; }
.rev-input input[type=text] {
  flex: 1; min-width: 240px; font: inherit; font-family: var(--mono); font-size: 1rem;
  padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.rev-input input[type=text]:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.hint { font-size: 0.8rem; color: var(--muted); margin: 4px 0 18px; }
.hint code { font-family: var(--mono); background: var(--chip-bg); padding: 1px 6px; border-radius: 5px; }

.cmp-bar { position: relative; background: var(--bg); border-radius: 6px; height: 22px; display: flex; align-items: center; overflow: hidden; }
.cmp-bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; }
.cmp-bar.a > i { background: rgba(var(--primary-rgb), 0.22); }
.cmp-bar.b > i { background: rgba(var(--cmp-b-rgb), 0.22); }
.cmp-val { position: relative; padding-left: 9px; font-variant-numeric: tabular-nums; font-weight: 650; }
.cmp-delta { white-space: nowrap; font-weight: 650; font-variant-numeric: tabular-nums; }
.cmp-delta.eq { color: var(--muted); font-weight: 500; }
.cmp-delta.a { color: var(--primary); }
.cmp-delta.b { color: var(--cmp-b); }

button.primary {
  appearance: none; border: none; cursor: pointer; font: inherit; font-weight: 650;
  background: var(--btn-primary); color: #fff; padding: 12px 20px; border-radius: 10px;
}
button.primary:hover { background: var(--btn-primary-hover); }
button.primary:disabled { background: var(--disabled); cursor: not-allowed; }
button.ghost {
  appearance: none; cursor: pointer; font: inherit; font-weight: 600;
  background: var(--surface); color: var(--primary); border: 1px solid var(--primary); padding: 11px 18px; border-radius: 10px;
}
button.ghost:hover { background: var(--primary-soft); }
button.ghost:disabled { color: var(--disabled); border-color: var(--border); cursor: not-allowed; }

.rev-summary {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 14px 18px; border-radius: var(--radius); margin-bottom: 18px;
  background: var(--primary-soft); border: 1px solid var(--primary-line);
}
.rev-summary .big { font-size: 1.35rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.chip { font-size: 0.78rem; font-weight: 600; padding: 4px 11px; border-radius: 999px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--danger-soft); color: var(--danger); }

.errors { background: var(--danger-soft); border: 1px solid var(--danger-line); color: var(--danger);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; font-size: 0.88rem; }
.errors ul { margin: 6px 0 0; padding-left: 20px; }

.variant-count { font-size: 0.78rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--chip-bg); color: var(--muted); }
.variant-count.multi { background: var(--primary-soft); color: var(--primary-dark); }
.variant-count.none { background: var(--danger-soft); color: var(--danger); }

.variants { display: flex; flex-direction: column; gap: 8px; }
.variant {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; cursor: pointer;
  display: flex; gap: 10px; align-items: flex-start; background: var(--surface); transition: border-color .12s, background .12s;
}
.variant:hover { border-color: var(--primary); }
.variant.selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.variant .radio {
  flex: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); margin-top: 2px;
  display: grid; place-items: center;
}
.variant.selected .radio { border-color: var(--primary); }
.variant.selected .radio::after { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--primary); }
.variant .choices { flex: 1; display: flex; flex-direction: column; gap: 3px; font-size: 0.83rem; }
.variant .choice { display: flex; gap: 8px; }
.variant .choice .cp { font-family: var(--mono); font-weight: 700; color: var(--primary-dark); flex: none; min-width: 42px; }
.variant .choice .cw { color: var(--text); }
.variant .choice .cs { color: var(--muted); }
.no-variant { color: var(--danger); font-size: 0.85rem; padding: 8px 0; }

.rev-actions { position: sticky; bottom: 16px; margin-top: 22px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; }
.rev-actions .note { font-size: 0.82rem; color: var(--muted); flex: 1; min-width: 180px; }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty svg { opacity: 0.4; }

.road-search { display: flex; gap: 10px; flex-wrap: wrap; }
.road-search input[type=search] {
  flex: 1 1 260px; font: inherit; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.road-search input[type=search]:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.road-search select { flex: 2 1 340px; width: auto; min-width: 0; }

.road-head {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin: 14px 0 18px;
}
.road-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.road-title h2 { margin: 0; font-size: 1.35rem; line-height: 1.25; }
.road-title .meta { font-size: 0.82rem; color: var(--muted); margin-top: 2px; }
.chip.out { background: var(--warn-soft); color: var(--warn); white-space: nowrap; }
.road-title .chip { white-space: nowrap; }

.road-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 16px; }
.road-stat { background: var(--bg); border-radius: 10px; padding: 12px 14px; }
.road-stat .label { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.road-stat .value { font-size: 1.6rem; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.3; }
.road-stat .value .of { color: var(--muted); font-size: 0.95rem; font-weight: 500; }
.road-stat .note { font-size: 0.78rem; color: var(--muted); }
.road-stat .meter { margin-top: 8px; min-width: 0; height: 8px; }

.road-near { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.road-near .lbl { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.near-chip {
  appearance: none; cursor: pointer; font: inherit; font-size: 0.8rem; font-weight: 600;
  background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-line);
  padding: 4px 11px; border-radius: 999px;
}
.near-chip:hover { border-color: var(--warn); }
.road-actions { margin-top: 14px; display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.crit-bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 6px; max-width: 320px; }
.crit-bar > i { display: block; height: 100%; background: var(--primary); }
.crit-bar.full > i { background: var(--ok); }

.rs { padding: 12px 0; border-bottom: 1px dashed var(--border); border-radius: 6px; }
.rs:last-child { border-bottom: none; }
.rs.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: var(--warn-soft); } 100% { background: transparent; } }
.rs-top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr) auto; gap: 14px; align-items: baseline; }
.rs-name { font-size: 0.9rem; }
.rs-name b { color: var(--primary-dark); font-variant-numeric: tabular-nums; margin-right: 2px; }
.rs-val { font-size: 0.9rem; font-weight: 600; }
.rs-sub { display: block; font-size: 0.78rem; font-weight: 400; color: var(--muted); }
.rs-pts { font-size: 0.85rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; min-width: 72px; }
.rs-pts b { font-size: 1.05rem; color: var(--text); }

.scale { display: flex; gap: 3px; margin: 8px 0 6px; }
.seg {
  appearance: none; font: inherit; cursor: pointer;
  flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center;
  padding: 4px 4px; border-radius: 6px; background: var(--bg); border: 1px solid transparent;
  color: var(--muted); font-size: 0.72rem; line-height: 1.3; text-align: center;
}
.seg-l { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg-p { font-size: 0.68rem; opacity: 0.85; }
.seg.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); font-weight: 700; }
.seg.next { border: 1px dashed var(--warn); color: var(--warn); }
.seg:hover { border-color: var(--cmp-b); }
.seg:focus-visible { outline: 2px solid var(--cmp-b); outline-offset: 1px; }
.seg.sim { background: var(--cmp-b-soft); border: 1px solid var(--cmp-b); color: var(--cmp-b); font-weight: 700; }
.rs.simulated .seg.on { background: var(--bg); border-style: dashed; }

.rs-gap { font-size: 0.83rem; }
.rs-gap.gap { color: var(--warn); font-weight: 600; }
.rs-gap.max { color: var(--ok); font-weight: 600; }
.rs-gap.na { color: var(--muted); }
.rs-note { font-size: 0.76rem; color: var(--muted); margin-top: 4px; padding-left: 10px; border-left: 3px solid var(--border); }

@media (max-width: 640px) {
  .rs-top { grid-template-columns: minmax(0, 1fr) auto; }
  .rs-val { grid-column: 1 / -1; grid-row: 2; }
  .road-title { flex-direction: column; }
  .seg { font-size: 0.66rem; padding: 4px 2px; }
  .seg-l { white-space: normal; overflow-wrap: anywhere; }
}

.sim-hint { font-size: 0.8rem; color: var(--muted); margin: -6px 0 14px; }
.rs-sim { font-size: 0.83rem; font-weight: 600; color: var(--cmp-b); }
.rs-sim:empty { display: none; }
.rs-pts s, .pts s { color: var(--muted); font-weight: 500; }
.rs-pts b.sim-val, .pts.sim { color: var(--cmp-b); }
.sim-bar {
  position: sticky; bottom: 16px; margin-top: 22px; z-index: 2;
  background: var(--surface); border: 1px solid var(--cmp-b); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 18px; display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
}
.sim-bar[hidden] { display: none; }
.sim-cell .label { font-size: 0.74rem; color: var(--cmp-b); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.sim-cell .big { font-size: 1.35rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.sim-cell .big .of { color: var(--muted); font-size: 0.9rem; font-weight: 500; }
.sim-cell .note { font-size: 0.78rem; color: var(--muted); }
.sim-cell .note.up { color: var(--ok); font-weight: 600; }
.sim-cell .note.down { color: var(--danger); font-weight: 600; }
.sim-bar button { margin-left: auto; }
@media (max-width: 640px) {
  .sim-bar { gap: 6px 18px; padding: 10px 12px; bottom: 8px; }
  .sim-cell .big { font-size: 1.1rem; }
  .sim-cell { flex: 1 1 130px; min-width: 0; }
  .sim-cell .note { display: none; }
  .sim-bar button { margin-left: 0; width: 100%; padding: 7px 12px; }
}
.place-delta { font-size: 0.85rem; font-weight: 700; margin-left: 6px; color: var(--muted); white-space: nowrap; }
.place-delta.up { color: var(--ok); }
.place-delta.down { color: var(--danger); }

.part { margin-top: 10px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.part-head { display: flex; flex-direction: column; gap: 2px; font-size: 0.85rem; margin-bottom: 6px; }
.part-head span { color: var(--muted); font-size: 0.8rem; }
.part-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; font-variant-numeric: tabular-nums; }
.part-table th, .part-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.part-table th { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
.part-table .num { text-align: right; white-space: nowrap; }
.part-table .strong { font-weight: 700; }
.part-table tr:last-child td { border-bottom: none; }
.part-table tr.on td { background: var(--primary-soft); }
.part-table tr.sim td { background: var(--cmp-b-soft); color: var(--cmp-b); }
.part-note { font-size: 0.74rem; color: var(--muted); margin: 6px 0 0; }
@media (max-width: 640px) {
  .part-table th:nth-child(2), .part-table td:nth-child(2) { display: none; }
  .part { padding: 8px; }
  .part-table { table-layout: fixed; font-size: 0.76rem; }
  .part-table th { white-space: normal; font-size: 0.64rem; }
  .part-table th, .part-table td { padding: 5px 3px; }
  .part-table .num { white-space: normal; }
}

.rank-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.rank-bar input[type=search] {
  flex: 1 1 260px; font: inherit; padding: 9px 12px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.rank-bar input[type=search]:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.rank-count { font-size: 0.82rem; color: var(--muted); font-weight: 600; white-space: nowrap; }

.rank-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: auto; max-height: calc(100vh - 140px);
}
.rank-wrap:has(.rank-table.w1) { margin-inline: min(0px, calc(50% - min(800px, 50vw - 28px))); }
.rank-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; font-variant-numeric: tabular-nums; }
.rank-table th, .rank-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.rank-table th.num, .rank-table td.num { text-align: right; }
.rank-table thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); padding: 0; border-bottom: 2px solid var(--border); }
.rank-table th button {
  appearance: none; border: none; background: none; cursor: pointer; width: 100%;
  font: inherit; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); padding: 10px 8px; text-align: inherit; white-space: nowrap;
}
.rank-table th button:hover { color: var(--text); }
.rank-table th button:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.rank-table th.sorted button { color: var(--primary); }
.rank-table th .arrow { margin-left: 4px; font-size: 0.7rem; opacity: 0.45; }
.rank-table th.sorted .arrow { opacity: 1; }
.rank-table tbody tr:hover td { box-shadow: inset 0 0 0 999px var(--hover-overlay); }
.rank-table td.place { color: var(--muted); font-weight: 600; }
.rank-table td.street a { color: var(--text); font-weight: 600; text-decoration: none; }
.rank-table td.street a:hover { color: var(--primary); text-decoration: underline; }
.rank-table td.score { font-weight: 600; min-width: 42px; }
.rank-table td.total { font-weight: 750; font-size: 0.95rem; }
.rank-view { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.rank-view > span { margin-right: 4px; }
.rank-view label { position: relative; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap; }
.rank-view label:hover { color: var(--text); }
.rank-view label:has(input:checked) { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.rank-view label:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }
.rank-view input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.rank-table .group { border-left: 2px solid var(--border); }
.rank-table th.sub button { text-transform: none; letter-spacing: 0; font-weight: 500; }
.rank-table th button small { display: block; text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 0.66rem; }
.rank-table.w1 thead tr.g1 th { height: 34px; }
.rank-table.w1 thead tr.g2 th { top: 34px; }
.rank-table th.gk { padding: 6px 8px; font-size: 0.74rem; font-weight: 700; color: var(--text); text-align: center; border-left: 2px solid var(--border-strong); }
.rank-table thead th.alt { background: color-mix(in srgb, var(--surface-2), var(--primary) 6%); }
.rank-table.w1 thead tr.g2 th button { text-transform: none; letter-spacing: 0; font-size: 0.7rem; white-space: normal; line-height: 1.2; max-width: 84px; padding: 6px; }
.rank-table.w1 thead tr.g2 th.group button { font-weight: 700; color: var(--text); }
.rank-table.w1 thead tr.g2 th.sorted button { color: var(--primary); }
.rank-table.w1 .group { border-left-color: var(--border-strong); }
.rank-table td.has-tip { cursor: help; }
.rank-table td.has-tip:hover, .rank-table td.has-tip:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.rank-table .exp { width: 30px; padding: 0 0 0 6px; }
.exp-btn { appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--muted); width: 24px; height: 24px; border-radius: 6px; cursor: pointer; font-size: 0.7rem; line-height: 1; transition: transform 0.15s; }
.exp-btn:hover { color: var(--primary); border-color: var(--primary); }
.exp-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
tr.open .exp-btn { transform: rotate(90deg); color: var(--primary); border-color: var(--primary); }
.rank-table tbody tr.main { cursor: pointer; }
.rank-table tbody tr.open td { background-color: var(--primary-soft); }
.rank-table tr.detail > td { padding: 12px; background: var(--surface-2); white-space: normal; }
.rank-table tbody tr.detail:hover td { box-shadow: none; }
.det { position: sticky; left: 12px; max-width: calc(100vw - 60px); }
.det-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.det-card { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); padding: 9px 11px; }
.det-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; font-weight: 700; font-size: 0.82rem; }
.det-head small { color: var(--muted); font-weight: 500; }
.det-head span small { font-weight: 600; margin-right: 4px; }
.det-head b { white-space: nowrap; }
.det-bar { height: 4px; border-radius: 3px; background: var(--chip-bg); margin: 6px 0 4px; overflow: hidden; }
.det-bar i { display: block; height: 100%; background: var(--primary); }
.det-sub { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; padding: 4px 0; border-top: 1px solid var(--border); font-size: 0.78rem; }
.det-bar + .det-sub { border-top: none; }
.det-sub .n small { color: var(--muted); margin-right: 4px; }
.det-sub .v { grid-column: 1; color: var(--muted); font-size: 0.72rem; }
.det-sub .p { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-weight: 700; white-space: nowrap; }
.det-sub .p small { color: var(--muted); font-weight: 500; }
.det-sub.full .p { color: var(--ok); }
.det-sub.zero .p { color: var(--muted); }
.det-foot { margin-top: 10px; font-size: 0.8rem; }
.det-foot a { color: var(--primary); font-weight: 600; }
.rank-table td.sub { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
.rank-table .street { position: sticky; left: 0; background: var(--surface); box-shadow: 1px 0 0 var(--border); }
.rank-table td.street { white-space: normal; overflow-wrap: anywhere; min-width: 140px; max-width: 220px; }
.rank-table thead th.street { z-index: 2; background: var(--surface-2); }
@media (max-width: 640px) {
  .rank-table { font-size: 0.8rem; }
  .rank-table th, .rank-table td { padding: 5px 6px; }
  .rank-table th button { padding: 8px 6px; }
  .rank-table td.street { min-width: 100px; max-width: 130px; line-height: 1.3; }
  .det-grid { grid-template-columns: 1fr; }
}

.rank-tip {
  position: fixed; z-index: 20; width: max-content; max-width: min(380px, calc(100vw - 16px));
  background: var(--tip-bg); color: #fff; border: 1px solid var(--tip-border); border-radius: 10px; box-shadow: 0 8px 28px rgba(20, 30, 45, 0.28);
  padding: 11px 13px; font-size: 0.78rem; line-height: 1.45; overflow-y: auto; overscroll-behavior: contain;
}
.rank-tip[hidden] { display: none; }
.rank-tip .tip-title { font-weight: 700; font-size: 0.86rem; }
.rank-tip .tip-scale { color: #b9c4d3; font-size: 0.74rem; margin-top: 1px; }
.rank-tip p { margin: 7px 0 0; color: #e3e8ef; }
.rank-tip .tip-list-head { margin-top: 8px; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em; color: #b9c4d3; font-weight: 600; }
.rank-tip ul { list-style: none; margin: 3px 0 0; padding: 0; }
.rank-tip li { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; border-top: 1px solid rgba(255, 255, 255, 0.1); }
.rank-tip li:first-child { border-top: none; }
.rank-tip li b { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank-tip .tip-scale b { color: #fff; }
.rank-tip .tip-value { margin-top: 7px; color: #e3e8ef; }
.rank-tip .tip-value small { display: block; color: #b9c4d3; }
.rank-tip .tip-steps li:not(.on) { color: #b9c4d3; }
.rank-tip .tip-steps li.on { color: #fff; font-weight: 700; }
.rank-tip .tip-steps li.on span::before { content: "● "; color: #7fb0ff; }
.rank-tip .tip-steps li.on b { color: #7fb0ff; }
.rank-tip .tip-gap { margin-top: 8px; padding: 6px 8px; border-radius: 7px; background: rgba(255, 255, 255, 0.07); color: #e3e8ef; }
.rank-tip .tip-gap.max { color: #7ee0a5; }
.rank-tip .tip-sum { display: flex; justify-content: space-between; margin-top: 4px; padding-top: 4px; border-top: 1px solid rgba(255, 255, 255, 0.35); font-weight: 700; }

.cmp-pickers { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px; align-items: end; margin-bottom: 16px; }
.cmp-picker { margin-bottom: 0; }
.cmp-picker label .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.cmp-picker.a label .dot { background: var(--primary); }
.cmp-picker.b label .dot { background: var(--cmp-b); }
.cmp-picker .road-search { flex-direction: column; gap: 6px; }
.cmp-picker .road-search input[type=search], .cmp-picker .road-search select { flex: none; width: 100%; }
.cmp-picker.a select.chosen { border-color: var(--primary); background: var(--primary-soft); }
.cmp-picker.b select.chosen { border-color: var(--cmp-b); background: var(--cmp-b-soft); }
.cmp-swap { padding: 9px 12px; font-size: 1.1rem; line-height: 1; margin-bottom: 1px; }

.cmp-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cmp-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; border-top: 4px solid var(--primary); min-width: 0;
}
.cmp-card.b { border-top-color: var(--cmp-b); }
.cmp-card-side { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--primary); }
.cmp-card.b .cmp-card-side { color: var(--cmp-b); }
.cmp-card h3 { margin: 2px 0 0; font-size: 1.15rem; line-height: 1.25; overflow-wrap: anywhere; }
.cmp-card .meta { font-size: 0.8rem; color: var(--muted); }
.cmp-card .value { font-size: 1.6rem; font-weight: 750; font-variant-numeric: tabular-nums; margin-top: 6px; line-height: 1.2; }
.cmp-card .value .of { color: var(--muted); font-size: 0.95rem; font-weight: 500; }
.cmp-card .note { font-size: 0.8rem; color: var(--muted); }
.cmp-card-link { display: inline-block; margin-top: 6px; font-size: 0.82rem; font-weight: 600; color: var(--primary); text-decoration: none; }
.cmp-card.b .cmp-card-link { color: var(--cmp-b); }
.cmp-card-link:hover { text-decoration: underline; }
.cmp-balance { font-size: 0.86rem; color: var(--muted); margin: 12px 2px; }

.cmpd {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.cmpd-row {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) 76px;
  gap: 4px 12px; align-items: center; padding: 8px 14px; border-bottom: 1px solid var(--border);
}
.cmpd-row:last-child { border-bottom: none; }
.cmpd-head { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.cmpd-head .cmpd-cell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmpd-head .cmpd-cell.a { color: var(--primary); }
.cmpd-head .cmpd-cell.b { color: var(--cmp-b); }
.cmpd-crit { background: var(--surface-2); border-top: 2px solid var(--border); font-weight: 650; font-size: 0.9rem; }
.cmpd-total { font-size: 1rem; font-weight: 750; }
.cmpd-name { font-size: 0.86rem; min-width: 0; }
.cmpd-name b { color: var(--primary-dark); font-variant-numeric: tabular-nums; margin-right: 2px; }
.cmpd-cell { display: flex; flex-direction: column; min-width: 0; font-size: 0.86rem; padding: 3px 8px; border-radius: 7px; }
.cmpd-crit .cmpd-cell { padding: 0; }
.cmpd-val { font-weight: 600; overflow-wrap: anywhere; }
.cmpd-sub { font-size: 0.74rem; color: var(--muted); }
.cmpd-pts { font-size: 0.76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.cmpd-cell.win.a { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.cmpd-cell.win.b { background: var(--cmp-b-soft); box-shadow: inset 3px 0 0 var(--cmp-b); }
.cmpd-cell.win .cmpd-pts { color: var(--text); font-weight: 650; }
.cmpd-delta { text-align: right; font-size: 0.84rem; }
@media (max-width: 640px) {
  .cmp-pickers { grid-template-columns: 1fr; }
  .cmp-swap { justify-self: center; transform: rotate(90deg); }
  .cmp-cards { gap: 8px; }
  .cmp-card { padding: 10px 12px; }
  .cmp-card h3 { font-size: 1rem; }
  .cmp-card .value { font-size: 1.3rem; }
  .cmpd-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; padding: 8px 10px; gap: 4px 8px; }
  .cmpd-name { grid-column: 1 / -1; }
  .cmpd-head .cmpd-name { display: none; }
  .cmpd-cell { font-size: 0.8rem; padding: 3px 6px; }
}
