:root {
  --bg: #f4f4f2;
  --bg-2: #ffffff;
  --bg-3: #ececec;
  --ink: #1c1c1c;
  --muted: #5c5c5c;
  --faint: #6f6f6f;
  --line: rgba(0, 0, 0, 0.08);
  --kmb: #e10613;
  --ctb: #f0c14a;
  --mtr: #c8102e;
  --lwb: #6fbf73;
  --gmb: #148a46;
  --warn: #9f2d2d;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.06);
  --sans: Inter, "Segoe UI", "Helvetica Neue", "PingFang HK", "Noto Sans TC", "WenQuanYi Micro Hei", "Droid Sans Fallback", sans-serif;
  --footer-space: 9rem;
  --header-pad: env(safe-area-inset-top);
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

html { background: #dededc; }

body {
  min-height: 100dvh;
  max-width: 480px;
  margin-inline: auto;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.4;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04);
}

.wrap {
  width: min(40rem, calc(100% - 1.5rem));
  margin-inline: auto;
}

.skip {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  background: #161616;
  color: #fff;
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  z-index: 10;
}

.skip:focus { top: 0.75rem; }

.chrome {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fff;
  padding-top: var(--header-pad);
}

.chrome-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 3.25rem;
  padding: 0.2rem 0.85rem 0;
}

.chrome-bar h1 {
  grid-column: 2;
  margin: 0;
  text-align: center;
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.back {
  grid-column: 1;
  justify-self: start;
  appearance: none;
  border: 0;
  background: transparent;
  color: #1c1c1c;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.35rem 0.15rem;
  min-height: 2.75rem;
  cursor: pointer;
}

.back-arrow {
  font-size: 1.25rem;
  line-height: 1;
  transform: translateY(-1px);
}

nav {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.15rem 0.75rem 0.7rem;
}

nav button,
.primary,
.save,
.text-btn,
.route-row,
.track-open,
.back {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

nav button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  min-height: 2.5rem;
  font-weight: 600;
}

nav button[aria-selected="true"] {
  color: #fff;
  background: #161616;
  border-color: #161616;
}

main { padding: 0.85rem 0 var(--footer-space); }

.segment {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.segment button {
  font: inherit;
  font-size: 0.92rem;
  min-height: 2.75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--ink);
  cursor: pointer;
  padding: 0.35rem 0.25rem;
}

.segment button[aria-selected="true"] {
  background: #161616;
  color: #fff;
  border-color: #161616;
}

label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.8rem;
}

input, select {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid rgba(0, 0, 0, 0.14);
  border-radius: 12px;
  padding: 0.7rem 0.75rem;
  min-height: 2.75rem;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
.route-row:focus-visible {
  outline: 2px solid #161616;
  outline-offset: 2px;
}

.hint, .checked, .meta, .rmk, .en { color: var(--muted); }

.warn { color: var(--warn); }

.route-row {
  width: 100%;
  display: flex;
  gap: 0.8rem;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
  margin: 0 0 0.5rem;
}

.route-no {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 2.6rem;
}

.route-copy, .stop-name, .place, .dir { display: flex; flex-direction: column; }

.card h2, .stop-head h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.7rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.tc { color: var(--ink); }

.en { font-size: 0.86rem; }

.stop-row.station { grid-template-columns: 1fr auto; }

.stop-head h2 {
  font-size: 1.15rem;
  margin: 0.4rem 0;
}

.stop-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.stop-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.7rem;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}

.seq {
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  min-width: 1.4rem;
}

.save, .primary, .text-btn {
  border-radius: 999px;
  min-height: 2.5rem;
}

.save, .primary {
  border: 0;
  background: #161616;
  color: #fff;
  font-weight: 700;
  padding: 0.4rem 0.9rem;
}

.save.saved, .primary:disabled {
  background: var(--bg-3);
  color: var(--muted);
  cursor: default;
}

.text-btn {
  background: transparent;
  border: 0;
  color: #1c1c1c;
  padding: 0.2rem 0;
  font-weight: 600;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

.toolbar p { margin: 0; color: var(--muted); font-size: 0.88rem; }

.cards { display: flex; flex-direction: column; gap: 0.8rem; }

.card {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid #161616;
  border-radius: 18px;
  padding: 0.95rem 1rem 0.75rem;
  box-shadow: var(--shadow);
}

.card[data-operator="kmb"] { border-left-color: var(--kmb); }
.card[data-operator="lwb"] { border-left-color: var(--lwb); }
.card[data-operator="ctb"] { border-left-color: var(--ctb); }
.card[data-operator="mtr"] { border-left-color: var(--mtr); }
.card[data-operator="gmb"] { border-left-color: var(--gmb); }

.track-body {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.track-copy { min-width: 0; flex: 1; }

.track-open {
  position: absolute;
  inset: 0;
  z-index: 1;
  border: 0;
  padding: 0;
  min-height: 0;
  background: transparent;
  border-radius: inherit;
}

.card-foot {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  pointer-events: none;
}

.card-foot .remove { pointer-events: auto; }

.mini-mins {
  width: 3.5rem;
  height: 3.5rem;
  flex: none;
  background: #111;
  color: #fff;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.mini-num {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.mini-unit { font-size: 0.68rem; font-weight: 600; margin-top: 0.12rem; }

.badge {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--faint);
}

.card h2, .empty h2, .mtr-dirs h3 {
  margin: 0;
  letter-spacing: -0.02em;
}

.card h2 { font-size: 1.15rem; }

.place { margin: 0.25rem 0 0; }

.remove { position: static; }

.etas {
  list-style: none;
  margin: 0;
  padding: 0;
}

.etas li {
  display: grid;
  grid-template-columns: 6.2rem 4.5rem 1fr;
  gap: 0.4rem;
  align-items: baseline;
  padding: 0.38rem 0;
  border-top: 1px solid var(--line);
}

.mins {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.clock { font-variant-numeric: tabular-nums; color: var(--muted); }

.mtr-dirs { display: grid; gap: 0.8rem; }

.mtr-dirs h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.checked {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.7rem 0 0;
  font-size: 0.78rem;
}

.dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--gmb);
  display: inline-block;
}

.empty {
  padding: 2.5rem 0 1rem;
  max-width: 26rem;
}

.empty h2 { font-size: 1.7rem; margin-bottom: 0.4rem; }

.empty p { color: var(--muted); margin-top: 0; }

.empty-mark {
  width: 4.8rem;
  height: 3.35rem;
  border-radius: 0.7rem 1rem 0.45rem 0.45rem;
  margin-bottom: 1rem;
  background:
    linear-gradient(#1b2430, #1b2430) 0.45rem 0.38rem / 3.5rem 0.72rem no-repeat,
    linear-gradient(#1b2430, #1b2430) 0.45rem 1.35rem / 2.3rem 0.52rem no-repeat,
    #e10613;
  box-shadow: 0 8px 18px rgba(225, 6, 19, 0.22);
}

.attrib {
  position: fixed;
  left: 50%;
  right: auto;
  width: min(480px, 100%);
  transform: translateX(-50%);
  bottom: 0;
  z-index: 4;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  padding: 0.65rem 0 calc(0.7rem + env(safe-area-inset-bottom));
}

.attrib .wrap { width: min(40rem, calc(100% - 1.5rem)); }

.attrib p { margin: 0; }

.attrib-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.45rem;
  font-weight: 700;
}

.attrib a { color: var(--ink); }

.attrib-note {
  color: var(--faint);
  font-size: 0.78rem;
  margin-top: 0.15rem;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--footer-space) - 0.4rem);
  transform: translateX(-50%);
  background: #161616;
  color: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  z-index: 6;
  margin: 0;
}

body.is-live {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #e8e8e8;
  box-shadow: none;
}

body.is-live .chrome {
  flex: none;
  border-radius: 0 0 16px 16px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

body.is-live main {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0;
  position: relative;
  overflow: hidden;
}

body.is-live .wrap { display: none; }

body.is-live .live {
  display: block;
  position: absolute;
  inset: 0;
}

.live-stage {
  height: 100%;
  position: relative;
  background: #e8e8e8;
}

.live-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
}

.live-stage .maplibregl-ctrl-top-left,
.live-stage .maplibregl-ctrl-top-right {
  z-index: 2;
}

.live-stage .maplibregl-ctrl-top-right {
  top: 0.35rem;
  right: 0.35rem;
  max-width: calc(100% - 4.5rem);
}

.live-stage .maplibregl-ctrl-attrib {
  font-size: 10px;
  line-height: 1.3;
  background: rgba(255, 255, 255, 0.9);
  max-width: 12.5rem;
}

.live-stage .maplibregl-ctrl-attrib a { color: #1c1c1c; }

.live-stage .maplibregl-marker { pointer-events: none; }

.map-note {
  position: absolute;
  z-index: 3;
  top: 0.55rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 6.5rem);
  margin: 0;
  background: rgba(255, 255, 255, 0.94);
  color: #5c5c5c;
  font-size: 0.75rem;
  font-weight: 650;
  line-height: 1.3;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  pointer-events: none;
  text-align: center;
}

.bus-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.bus-bubble {
  background: #fff;
  color: #1c1c1c;
  font-family: Inter, "WenQuanYi Micro Hei", sans-serif;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 8px 4px;
  border-radius: 8px;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.18);
  margin-bottom: 2px;
  white-space: nowrap;
}

.vehicle-svg {
  display: block;
  overflow: visible;
}

.stop-pin-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #161616;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.terminus-mark { position: relative; }

.terminus-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #2c2c2c;
  border: 2px solid #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.terminus-label {
  position: absolute;
  left: 14px;
  top: -6px;
  display: flex;
  flex-direction: column;
  color: #3a3a3a;
  font-family: Inter, "WenQuanYi Micro Hei", sans-serif;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.15;
  white-space: nowrap;
  text-shadow: 0 0 4px #fff, 0 0 4px #fff, 0 1px 0 #fff;
}

.sheet {
  position: absolute;
  z-index: 4;
  left: 0.7rem;
  right: 0.7rem;
  bottom: calc(0.7rem + env(safe-area-inset-bottom));
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.14);
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1.05rem 0.9rem 1.05rem 1.15rem;
}

.sheet-copy { min-width: 0; flex: 1; }

.sheet-route {
  margin: 0 0 0.15rem;
  color: #6d6d6d;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.sheet-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sheet-meta {
  margin: 0.28rem 0 0;
  color: #666;
  font-size: 0.82rem;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sheet-meta:empty { display: none; }

.sheet-mins {
  width: 5.35rem;
  height: 5.35rem;
  flex: none;
  background: #111;
  color: #fff;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.sheet-num {
  font-size: 2.85rem;
  font-weight: 700;
  line-height: 0.85;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
}

.sheet-unit {
  margin-top: 0.18rem;
  font-size: 0.95rem;
  font-weight: 600;
}

@media (max-width: 420px) {
  .segment { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .etas li { grid-template-columns: 5.4rem 3.6rem 1fr; }
  .mins { font-size: 1.1rem; }
  .sheet-title { font-size: 1.12rem; }
  .sheet-num { font-size: 2.65rem; }
  .sheet-mins { width: 5rem; height: 5rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
