:root {
  color-scheme: light;
  --canvas: #f2f4f3;
  --surface: #ffffff;
  --surface-muted: #f6f7f6;
  --line: #d9ddda;
  --line-strong: #b8c0bb;
  --ink: #202521;
  --muted: #687078;
  --accent: #d53f3a;
  --accent-soft: #f8e9e7;
  --teal: #18786f;
  --amber: #e09a24;
  --shadow: 0 12px 28px rgba(32, 37, 33, 0.12);
  --radius: 6px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
  color: var(--ink);
}

body,
button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button,
a {
  color: inherit;
}

button {
  cursor: pointer;
}

.app-frame {
  height: 100dvh;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
}

.app-header {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.97);
}

.brand-block,
.header-actions,
.detail-heading,
.detail-meta,
.route-main,
.route-meta,
.city-label {
  display: flex;
  align-items: center;
}

.brand-block {
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
}

.brand-block > div {
  display: grid;
  min-width: 0;
}

.brand-block strong {
  overflow: hidden;
  font-size: 15px;
  line-height: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-block small,
.brand-block span,
.route-group-header span,
.detail-heading span,
.route-meta,
.list-summary {
  color: var(--muted);
  font-size: 12px;
}

.header-actions {
  gap: 8px;
}

.city-label {
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.city-label svg,
.detail-meta svg {
  width: 15px;
  height: 15px;
}

.offline-download-button,
.offline-badge {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.offline-download-button:hover,
.offline-download-button:focus-visible {
  border-color: var(--line-strong);
  background: var(--surface-muted);
  outline: none;
}

.offline-download-button svg,
.offline-badge svg {
  width: 16px;
  height: 16px;
}

.offline-badge {
  color: var(--muted);
  cursor: default;
}

.icon-button,
.bare-icon {
  display: inline-grid;
  place-items: center;
  border: 0;
  background: transparent;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 5px;
  text-decoration: none;
}

.icon-button:hover,
.icon-button:focus-visible,
.bare-icon:hover,
.bare-icon:focus-visible {
  border-color: var(--line-strong);
  background: var(--surface-muted);
  outline: none;
}

.icon-button svg,
.bare-icon svg {
  width: 18px;
  height: 18px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 310px) minmax(0, 1fr);
}

.workspace.is-route-panel-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.workspace.is-route-panel-collapsed .route-panel {
  display: none;
}

.route-panel {
  position: relative;
  z-index: 10;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.panel-tools {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.place-selector {
  display: grid;
  gap: 7px;
  padding-bottom: 2px;
}

.place-selector-heading {
  min-height: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.place-selector-heading > span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.place-selector-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.place-selector-actions .bare-icon {
  width: 26px;
  height: 26px;
}

.place-selector-actions .bare-icon svg {
  width: 14px;
  height: 14px;
}

.place-selector-heading small {
  color: #8a918d;
  font-size: 11px;
  font-weight: 500;
}

.place-selector-heading svg {
  width: 14px;
  height: 14px;
}

.place-search-box {
  min-height: 34px;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 26px;
  align-items: center;
  gap: 5px;
  padding: 0 6px 0 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
}

.place-search-box:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(32, 37, 33, 0.08);
}

.place-search-box > svg {
  width: 15px;
  height: 15px;
  color: var(--muted);
}

.place-search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
}

.place-search-box input::placeholder {
  color: #8a918d;
}

.place-search-box .bare-icon {
  width: 26px;
  height: 26px;
}

.place-search-box .bare-icon svg {
  width: 14px;
  height: 14px;
}

.place-list {
  max-height: min(240px, 32vh);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: 5px;
  overflow-y: auto;
  padding-right: 2px;
  scrollbar-gutter: stable;
}

.place-selector.is-expanded .place-list {
  max-height: min(560px, 64vh);
}

.place-item {
  min-width: 0;
  min-height: 38px;
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-muted);
  text-align: left;
}

.place-item:hover,
.place-item:focus-visible {
  border-color: var(--line-strong);
  outline: none;
}

.place-item.is-selected {
  border-color: var(--place-color);
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--place-color);
}

.place-swatch {
  width: 4px;
  height: 18px;
  border-radius: 2px;
  background: var(--place-color);
}

.place-item strong {
  min-width: 0;
  overflow: visible;
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  white-space: normal;
}

.place-empty {
  grid-column: 1 / -1;
  padding: 6px 8px;
  border: 1px dashed var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.search-box {
  height: 38px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) 42px 28px;
  align-items: center;
  gap: 6px;
  padding: 0 8px 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

.search-box:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px rgba(32, 37, 33, 0.08);
}

.search-box svg {
  width: 17px;
  height: 17px;
  color: var(--muted);
}

.search-box input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
}

.search-box input::placeholder {
  color: #8a918d;
}

.search-mode-button {
  width: 42px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.search-mode-button:hover,
.search-mode-button:focus-visible {
  border-color: var(--line-strong);
  color: var(--ink);
  outline: none;
}

.search-mode-button[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.bare-icon {
  width: 28px;
  height: 28px;
  border-radius: 4px;
}

.segmented-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.segmented-tabs::-webkit-scrollbar {
  display: none;
}

.segmented-tabs button {
  min-height: 29px;
  flex: 0 0 auto;
  padding: 0 9px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
}

.segmented-tabs button[aria-selected="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.list-summary {
  min-height: 31px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
}

.text-button {
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--teal);
  font-size: 12px;
}

.route-list {
  min-height: 0;
  overflow: auto;
  padding-bottom: 12px;
}

.route-group {
  border-bottom: 1px solid var(--line);
}

.route-group-header {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: rgba(246, 247, 246, 0.97);
}

.route-group-header strong {
  font-size: 12px;
}

.route-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid #e5e9e6;
  background: var(--surface);
}

.route-item {
  width: 100%;
  height: 36px;
  display: grid;
  grid-template-columns: 3px minmax(0, 1fr);
  gap: 7px;
  align-items: center;
  padding: 0 7px;
  border: 0;
  border-right: 1px solid #e5e9e6;
  border-bottom: 1px solid #e5e9e6;
  background: var(--surface);
  text-align: left;
}

.route-item:hover,
.route-item:focus-visible {
  background: #f8f9f8;
  outline: none;
}

.route-item.is-selected {
  background: #edf1ee;
  box-shadow: inset 0 0 0 1px var(--route-color);
}

.route-item .route-swatch {
  width: 3px;
  height: 21px;
  border-radius: 2px;
  background: var(--route-color);
}

.route-item strong {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  line-height: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty-list {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 30px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.map-stage,
.map-surface {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.map-stage {
  overflow: hidden;
  background: #e9eeeb;
}

.map-surface {
  width: 100%;
  height: 100%;
}

.route-panel-toggle {
  position: absolute;
  z-index: 9;
  top: 50%;
  left: 8px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  transform: translateY(-50%);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
}

.route-panel-toggle:hover,
.route-panel-toggle:focus-visible {
  border-color: var(--line-strong);
  background: #fff;
  color: var(--ink);
  outline: none;
}

.route-panel-toggle svg {
  width: 18px;
  height: 18px;
}

.fallback-map {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.fallback-map.is-dragging {
  cursor: grabbing;
}

.map-toolbar {
  position: absolute;
  z-index: 8;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.direction-mode-tabs {
  position: absolute;
  z-index: 8;
  top: 58px;
  right: 14px;
  display: grid;
  grid-template-columns: repeat(3, max-content);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
}

.direction-mode-tabs button {
  height: 29px;
  min-width: 52px;
  padding: 0 10px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.direction-mode-tabs button[aria-selected="true"] {
  background: var(--ink);
  color: #fff;
}

.surface-button {
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 5px 16px rgba(32, 37, 33, 0.1);
}

.line-width-control {
  display: grid;
  grid-template-columns: 17px 96px 30px;
  align-items: center;
  height: 36px;
  padding: 0 8px;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
}

.line-width-control svg {
  width: 17px;
  height: 17px;
}

.line-width-control input {
  width: 96px;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

.line-width-control output {
  color: var(--ink);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.route-stops-toggle,
.route-labels-toggle {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font-size: 12px;
}

.route-stops-toggle svg,
.route-labels-toggle svg {
  width: 16px;
  height: 16px;
}

.map-button-group {
  display: flex;
}

.map-button-group .icon-button {
  border-radius: 0;
}

.map-button-group .icon-button:first-child {
  border-radius: 5px 0 0 5px;
}

.map-button-group .icon-button:last-child {
  margin-left: -1px;
  border-radius: 0 5px 5px 0;
}

.surface-button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.map-mode {
  position: absolute;
  z-index: 7;
  top: 14px;
  left: 14px;
  padding: 7px 9px;
  border: 1px solid rgba(184, 192, 187, 0.8);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 11px;
  box-shadow: 0 5px 16px rgba(32, 37, 33, 0.08);
}

.map-attribution {
  position: absolute;
  z-index: 7;
  right: 7px;
  bottom: 5px;
  padding: 2px 4px;
  background: rgba(255, 255, 255, 0.78);
  color: #59615d;
  font-size: 10px;
  line-height: 14px;
  pointer-events: none;
}

.route-detail-toggle {
  position: absolute;
  z-index: 9;
  left: 16px;
  bottom: 16px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--route-color, var(--ink));
  border-radius: 5px;
  color: var(--route-color, var(--ink));
}

.route-detail-toggle svg {
  width: 18px;
  height: 18px;
}

.route-detail {
  position: absolute;
  z-index: 9;
  left: 16px;
  bottom: 16px;
  width: min(460px, calc(100% - 32px));
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: var(--shadow);
}

.detail-heading {
  gap: 10px;
}

.detail-heading > div {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.detail-heading strong {
  font-size: 18px;
}

.route-color {
  width: 8px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 3px;
  background: var(--route-color, var(--accent));
}

.detail-meta {
  min-width: 0;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.detail-meta > span {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.detail-meta b {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-stops {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.detail-stops-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 12px;
}

.detail-stops-heading span {
  color: var(--muted);
}

.detail-stop-list {
  max-height: 96px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 3px 12px;
  overflow: auto;
  color: #4f5752;
  font-size: 11px;
  line-height: 21px;
}

.detail-stop-list > span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-stop-list b {
  display: inline-block;
  min-width: 20px;
  margin-right: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 24px;
  max-width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  box-shadow: var(--shadow);
}

@media (max-width: 760px) {
  .app-frame {
    grid-template-rows: 54px minmax(0, 1fr);
  }

  .app-header {
    padding: 0 10px;
  }

  .brand-block strong {
    font-size: 14px;
  }

  .brand-block span,
  .city-label {
    display: none;
  }

  .offline-download-button {
    width: 36px;
    min-height: 36px;
    padding: 0;
  }

  .offline-download-button span {
    display: none;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 50vh) minmax(0, 1fr);
  }

  .workspace.is-route-panel-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
  }

  .route-panel {
    grid-row: 2;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .map-stage {
    grid-row: 1;
  }

  .route-panel-toggle {
    top: 98px;
    left: 10px;
    transform: none;
  }

  .panel-tools {
    padding: 8px;
  }

  .place-list {
    max-height: min(180px, 24vh);
  }

  .place-selector.is-expanded .place-list {
    max-height: min(320px, 40vh);
  }

  .search-box {
    height: 38px;
  }

  .list-summary {
    min-height: 29px;
    padding: 0 8px;
  }

  .route-group-header {
    min-height: 30px;
    padding: 0 8px;
  }

  .route-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .route-item {
    height: 34px;
    padding: 0 5px;
  }

  .route-item strong {
    font-size: 11px;
  }

  .route-detail {
    left: 10px;
    bottom: 10px;
    width: calc(100% - 20px);
    padding: 10px;
  }

  .route-detail-toggle {
    left: 10px;
    bottom: 10px;
  }

  .detail-heading strong {
    font-size: 16px;
  }

  .map-toolbar {
    top: 10px;
    right: 6px;
    gap: 4px;
  }

  .direction-mode-tabs {
    top: 56px;
    right: 10px;
  }

  .map-mode {
    top: 56px;
    left: 10px;
  }

  .line-width-control {
    grid-template-columns: 15px 44px;
    height: 34px;
    padding: 0 5px;
    gap: 4px;
  }

  .line-width-control svg {
    width: 15px;
    height: 15px;
  }

  .line-width-control output {
    display: none;
  }

  .route-stops-toggle,
  .route-labels-toggle {
    width: 34px;
    height: 34px;
    justify-content: center;
    padding: 0;
  }

  .map-toolbar .icon-button {
    width: 34px;
    height: 34px;
  }

  .route-stops-toggle span,
  .route-labels-toggle span {
    display: none;
  }

  .line-width-control input {
    width: 44px;
  }

  .detail-stop-list {
    max-height: 76px;
  }
}

@media (max-width: 360px) {
  .map-mode {
    display: none;
  }
}
