:root {
  --bg: #edf5f6;
  --surface: #ffffff;
  --surface-2: #dfecee;
  --text: #10292e;
  --muted: #587075;
  --faint: #8ba1a5;
  --accent: #0b8f84;
  --accent-soft: #d3eeea;
  --accent-ink: #076b63;
  --on-accent: #ffffff;
  --border: #d1e2e5;
  --danger: #c8442f;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d181b;
    --surface: #142327;
    --surface-2: #1b2e33;
    --text: #e3f0f1;
    --muted: #94acb1;
    --faint: #5f777c;
    --accent: #3fcfbd;
    --accent-soft: #163a38;
    --accent-ink: #7fe3d6;
    --on-accent: #032421;
    --border: #23383d;
    --danger: #ff7a63;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }

.wrap {
  max-width: 520px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(env(safe-area-inset-top) + 12px) 0 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.app-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 2px 10px;
}

.tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
}

.tab {
  border: 0;
  border-radius: 10px;
  padding: 10px 4px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / .08);
}

.view { padding-top: 8px; padding-bottom: calc(env(safe-area-inset-bottom) + 28px); }

.tool { display: flex; flex-direction: column; gap: 18px; }

.field-label {
  margin: 0 2px 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.time-row { display: flex; gap: 10px; }

.time-input {
  flex: 1;
  min-width: 0;
  height: 76px;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 44px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  text-align: center;
  outline: none;
  transition: border-color .15s;
}

.time-input::placeholder { color: var(--faint); }
.time-input:focus { border-color: var(--accent); }
.time-input.is-invalid { border-color: var(--danger); color: var(--danger); }

.now-btn {
  flex: 0 0 auto;
  padding: 0 20px;
  border: 0;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 800;
}

.now-btn:active, .choice:active, .tab:active { transform: scale(.97); }

.results {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 10px;
}

.result {
  padding: 14px 16px 12px;
  border-radius: 20px;
  border: 1.5px solid transparent;
  transition: background .2s, color .2s;
}

.result--soft { background: var(--accent-soft); color: var(--accent-ink); }
.result--strong { background: var(--accent); color: var(--on-accent); }

.result.is-empty {
  background: var(--surface);
  color: var(--faint);
  border-color: var(--border);
  border-style: dashed;
}

.result-label { font-size: 13px; font-weight: 700; opacity: .9; }

.result-value {
  margin-top: 2px;
  font-size: 40px;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.result-note { min-height: 16px; font-size: 12px; font-weight: 600; opacity: .85; }

.choices {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 8px;
}

.choice {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 2px;
  min-height: 58px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  transition: border-color .15s, background .15s;
}

.choice-title { font-size: 15px; font-weight: 700; }
.choice-hint { font-size: 12px; color: var(--muted); }

.choice.is-active { border-color: var(--accent); background: var(--accent-soft); }
.choice.is-active .choice-title { color: var(--accent-ink); }

.toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 58px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s;
}

.toggle:has(.toggle-input:checked) { border-color: var(--accent); }

.toggle-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.toggle-title { font-size: 15px; font-weight: 700; }
.toggle-hint { font-size: 12px; color: var(--muted); }

.toggle-input { position: absolute; opacity: 0; pointer-events: none; }

.toggle-switch {
  position: relative;
  flex: 0 0 auto;
  width: 50px;
  height: 30px;
  border-radius: 999px;
  background: var(--surface-2);
  transition: background .2s;
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--faint);
  transition: transform .2s, background .2s;
}

.toggle-input:checked + .toggle-switch { background: var(--accent); }
.toggle-input:checked + .toggle-switch::after { transform: translateX(20px); background: var(--on-accent); }
.toggle-input:focus-visible + .toggle-switch { outline: 2px solid var(--accent); outline-offset: 2px; }

.section-caption {
  margin: 0 2px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--faint);
}

.breakdown {
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
}

.breakdown-list { margin: 0; padding-left: 20px; }
.breakdown-list li { margin-bottom: 4px; }
.breakdown-list li::marker { color: var(--faint); }
.breakdown-empty { list-style: none; margin-left: -20px; color: var(--faint); }

.bd-time { font-variant-numeric: tabular-nums; }
.bd-result, .bd-amount { font-weight: 700; }
.bd-op { color: var(--faint); }
.bd-reason { color: var(--faint); }

.norms {
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

.norms summary { cursor: pointer; list-style: none; }
.norms summary::-webkit-details-marker { display: none; }
.norms summary::after { content: ' ▾'; }
.norms[open] summary::after { content: ' ▴'; }

.norms table { width: 100%; margin-top: 6px; border-collapse: collapse; }
.norms td { padding: 6px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.norms td:last-child { padding-left: 12px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.norms p { margin: 10px 0 0; }

.meters {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) minmax(0, 1fr) minmax(58px, max-content);
  gap: 8px 8px;
  align-items: center;
}

.meters-head {
  display: flex;
  flex-direction: column;
  align-self: end;
  min-height: 34px;
  padding: 0 4px 2px;
}

.meters-head--diff { text-align: right; justify-content: flex-end; }

.meters-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  transition: color .2s;
}

.meters-hint { font-size: 11px; line-height: 1.25; color: var(--faint); }

.meters-head--car { align-items: center; padding: 0 0 2px; }

.car-input {
  width: 100%;
  height: 52px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
  text-decoration: underline dotted var(--faint);
  text-underline-offset: 4px;
}

.car-input:focus { background: var(--surface); color: var(--text); text-decoration: none; box-shadow: inset 0 0 0 1.5px var(--accent); }

.meter-input {
  width: 100%;
  height: 52px;
  padding: 0 6px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
  transition: border-color .15s;
}

.meter-input::placeholder { color: var(--faint); font-weight: 500; }
.meter-input:focus { border-color: var(--accent); }

.meters-diff {
  height: 52px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  padding: 0 6px;
  border: 1.5px dashed transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--accent-ink);
  white-space: nowrap;
  transition: border-color .15s, background .15s;
}

.meters-diff-value { font-size: 18px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.meters-diff-extra { font-size: 11px; font-weight: 800; line-height: 1.2; color: var(--muted); }
.meters-diff-extra:empty { display: none; }
.meters-diff.has-extra .meters-diff-extra { color: var(--accent-ink); }
.meters-diff.is-empty .meters-diff-value { color: var(--faint); font-weight: 500; }
.meters-diff.is-odd .meters-diff-value { color: var(--danger); }
.meters-diff.is-target { border-color: var(--accent); background: var(--accent-soft); }
.car-input.is-target { background: var(--accent-soft); color: var(--accent-ink); text-decoration: none; }

.extra-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
}

.extra-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.extra-card-title { font-size: 16px; font-weight: 800; }
.extra-note { font-size: 12px; font-weight: 700; color: var(--accent-ink); text-align: right; }
.extra-label { margin-top: 4px; font-size: 12px; font-weight: 700; color: var(--muted); }

.extra-targets { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 6px; }

.extra-target {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 48px;
  min-width: 0;
  padding: 0 2px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  transition: border-color .15s, background .15s;
}

.extra-target-title { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.extra-target-sub { font-size: 11px; font-weight: 800; line-height: 1.1; color: var(--accent-ink); }
.extra-target-sub:empty { display: none; }
.extra-target.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }

.extra-chips { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }

.extra-chip, .extra-custom {
  height: 44px;
  min-width: 0;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 15px;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.extra-custom { padding: 0 4px; outline: none; }
.extra-custom::placeholder { color: var(--faint); font-weight: 600; font-size: 13px; }
.extra-chip.is-active, .extra-custom.is-active, .extra-custom:focus { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }

.meters-tip { margin: 10px 2px 0; font-size: 12px; color: var(--faint); }

.meters-total .result-value { font-size: 40px; }

.tool-actions { display: flex; justify-content: center; }
.tool-actions .ghost-btn { padding: 10px 18px; }

.ghost-btn {
  padding: 10px 18px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  transition: color .15s, border-color .15s;
}

.ghost-btn--danger { color: var(--danger); border-color: var(--danger); }
.ghost-btn--accent { color: var(--accent-ink); border-color: var(--accent); }

.clear-control { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; }
.clear-control.is-armed, .clear-control.is-done {
  padding: 14px;
  border-radius: 16px;
  border: 1.5px solid var(--border);
}
.clear-control.is-armed { border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.clear-text { font-size: 14px; font-weight: 700; color: var(--muted); text-align: center; }
.clear-buttons { display: flex; gap: 10px; }

.handover-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.handover-card[hidden] { display: none; }
.handover-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.handover-title { font-size: 16px; font-weight: 800; }
.handover-sub { font-size: 12px; font-weight: 600; opacity: .8; }

.handover-grid {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-top: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  font-variant-numeric: tabular-nums;
}

.handover-grid--head { border-top: 0; padding: 0; font-size: 11px; font-weight: 700; opacity: .75; }
.handover-grid > :last-child { text-align: right; }
.handover-car { font-weight: 800; }
.handover-value { display: flex; flex-direction: column; }
.handover-final { font-size: 22px; font-weight: 800; color: var(--text); line-height: 1.15; }
.handover-was { font-size: 12px; font-weight: 600; opacity: .75; }
.handover-diff { font-size: 16px; white-space: nowrap; }
.handover-diff b { font-weight: 800; color: var(--text); }
.handover-arrow { opacity: .6; }
.handover-grid.has-extra .handover-final { color: var(--accent-ink); }

@media (min-width: 400px) {
  .result-value { font-size: 44px; }
}

[hidden] { display: none !important; }

.tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 1 0 auto; padding: 10px 12px; scroll-snap-align: center; }

.step {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
}

.step-head { display: flex; align-items: center; gap: 10px; }

.step-num {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 800;
}

.step-title { font-size: 16px; font-weight: 800; }

.step .field-label { margin-bottom: 6px; }
.step .choice, .step .text-input { background: var(--bg); }
.step .choice.is-active { background: var(--accent-soft); }

.text-row { display: flex; gap: 8px; }

.text-input {
  flex: 1;
  min-width: 0;
  height: 50px;
  padding: 0 14px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-size: 17px;
  font-weight: 700;
  outline: none;
  transition: border-color .15s;
}

.text-input::placeholder { color: var(--faint); font-weight: 500; }
.text-input:focus { border-color: var(--accent); }

.search-status { margin-top: -4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.search-status.is-loading { color: var(--accent-ink); }
.search-status.is-error { color: var(--danger); }

.train-list { display: flex; flex-direction: column; gap: 6px; }

.train-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  text-align: left;
}

.train-option.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.train-number { font-weight: 800; font-variant-numeric: tabular-nums; }
.train-route { font-size: 14px; font-weight: 600; }

.time-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.time-pair .field { min-width: 0; }
.time-pair .time-row { gap: 6px; }
.time-input--compact { height: 56px; font-size: 26px; border-radius: 14px; background: var(--bg); }
.time-pair .now-btn { padding: 0 10px; border-radius: 14px; font-size: 13px; }

.delay-info {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.delay-main { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.delay-human { font-size: 15px; font-weight: 700; }
.delay-calc { flex-basis: 100%; font-size: 12px; font-weight: 600; opacity: .8; }
.delay-muted { font-size: 13px; font-weight: 600; opacity: .8; }

.recent-stations { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }

.recent-chip {
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  font-size: 13px;
  font-weight: 700;
}

.recent-chip.is-active { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }

.reason-list { display: flex; flex-direction: column; gap: 6px; }

.reason {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  text-align: left;
}

.reason-title { font-size: 15px; font-weight: 700; }
.reason-hint { font-size: 12px; color: var(--muted); }
.reason.is-active { border-color: var(--accent); background: var(--accent-soft); }
.reason.is-active .reason-title { color: var(--accent-ink); }

.report-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.report-title { font-size: 16px; font-weight: 800; }

.report-text {
  margin: 0;
  padding: 14px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.report-line { display: block; }
.report-line.is-missing { color: var(--faint); }
.report-line.is-missing::after { content: ' …'; }

.report-missing { font-size: 12px; font-weight: 700; color: var(--danger); }

.copy-btn {
  height: 54px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 17px;
  font-weight: 800;
  transition: background .15s;
}

.copy-btn:active { transform: scale(.98); }
.copy-btn.is-done { background: var(--accent-ink); }

.copy-btn:disabled {
  background: var(--surface-2);
  color: var(--faint);
  cursor: not-allowed;
  transform: none;
}

.train-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: -4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.train-notice.is-loading, .train-notice.is-ok { color: var(--accent-ink); }
.train-notice.is-error { color: var(--danger); }
.train-notice.is-error .link-btn { color: var(--danger); }

.stops-caption { margin: 2px 2px -4px; }

.stop-list {
  display: flex;
  flex-direction: column;
  max-height: 300px;
  overflow-y: auto;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  overscroll-behavior: contain;
}

.stop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  text-align: left;
}

.stop:last-child { border-bottom: 0; }
.stop-name { font-size: 15px; font-weight: 500; }
.stop.is-major .stop-name { font-weight: 800; }
.stop-time { flex: 0 0 auto; font-size: 14px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.stop.is-active { background: var(--accent-soft); }
.stop.is-active .stop-name, .stop.is-active .stop-time { color: var(--accent-ink); }

.moved-block { display: flex; flex-direction: column; gap: 8px; }

.scheduled-source {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.time-pair .time-input--compact { font-size: 22px; padding: 0 4px; letter-spacing: 0; }
.time-pair .now-btn { padding: 0 8px; font-size: 12px; }
