:root {
  --ink: #173b36;
  --ink-2: #234c46;
  --cream: #f6f4ec;
  --paper: #f8f8f4;
  --line: #cfd3ce;
  --muted: #737b76;
  --accent: #cf4c3b;
  --shadow: 0 8px 24px rgba(28, 42, 38, 0.1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: #203b37;
  background: #dfe2de;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  overflow: hidden;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

.app-shell { display: grid; grid-template-columns: 372px minmax(0, 1fr); height: 100%; }

.sidebar {
  position: relative;
  z-index: 3;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 22px 22px 18px;
  background: #f8f8f5;
  border-right: 1px solid #cfd3ce;
  overflow: auto;
  scrollbar-gutter: stable;
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand, .intro, .editor-card { flex-shrink: 0; }
.brand-home { display: flex; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.brand-home:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 4px; background: var(--ink); }
.brand-mark svg { width: 24px; fill: #f5f3eb; }
.brand h1 { margin: 2px 0 0; font-family: "Noto Serif SC", "Songti SC", SimSun, serif; font-size: 24px; letter-spacing: 1.5px; font-weight: 700; }
.eyebrow { margin: 0; color: #76807b; font: 600 9px/1.2 Arial, sans-serif; letter-spacing: 1.7px; }

.intro { margin: 20px 0 17px; }
.intro p { margin: 0 0 6px; font: 600 15px/1.5 "Microsoft YaHei", sans-serif; }
.intro span { color: #89908b; font-size: 12px; }

.editor-card { padding: 15px; border: 1px solid #cfd3ce; border-radius: 4px; background: #fff; box-shadow: none; }
.mode-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin-bottom: 16px; padding: 0; border-bottom: 1px solid #d8dbd7; background: transparent; }
.mode-tab { border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px; color: #777d78; background: transparent; cursor: pointer; font-size: 13px; }
.mode-tab.active { color: var(--ink); border-bottom-color: var(--ink); background: transparent; box-shadow: none; font-weight: 700; }
.mode-panel.hidden { display: none; }
label { display: block; margin-bottom: 7px; color: #59635f; font-size: 12px; font-weight: 700; }
input, textarea { width: 100%; border: 1px solid #cfd3ce; outline: none; border-radius: 3px; background: #fff; transition: border .2s, box-shadow .2s; }
input { height: 40px; padding: 0 12px; }
textarea { padding: 10px 12px; resize: vertical; line-height: 1.6; }
input:focus, textarea:focus { border-color: #79968f; box-shadow: 0 0 0 3px rgba(52, 104, 94, .09); }
.combo-wrap { position: relative; }
.combo-wrap input { padding-right: 35px; text-transform: uppercase; }
.input-icon { position: absolute; top: 8px; right: 12px; color: #929a95; font-size: 20px; pointer-events: none; }
.train-keypad { position: absolute; top: 47px; left: 0; z-index: 30; width: 302px; padding: 9px; border: 1px solid #c8cdc8; border-radius: 4px; background: #fff; box-shadow: 0 12px 28px rgba(31,48,44,.16); }
.train-keypad.hidden { display: none; }
.keypad-heading { display: flex; align-items: center; justify-content: space-between; height: 28px; padding: 0 4px 7px; color: #7e8580; font-size: 10px; }
.keypad-heading button { border: 0; color: #2982cc; background: transparent; cursor: pointer; font-size: 11px; font-weight: 700; }
.keypad-grid { display: grid; grid-template-columns: repeat(5, 1fr); border-top: 1px solid #e6e6e2; border-left: 1px solid #e6e6e2; }
.keypad-grid button { height: 39px; padding: 0; border: 0; border-right: 1px solid #e6e6e2; border-bottom: 1px solid #e6e6e2; color: #263d38; background: #fff; cursor: pointer; font-size: 15px; }
.keypad-grid button[data-key="G"], .keypad-grid button[data-key="D"], .keypad-grid button[data-key="C"], .keypad-grid button[data-key="K"], .keypad-grid button[data-key="L"], .keypad-grid button[data-key="T"], .keypad-grid button[data-key="Z"], .keypad-grid button[data-key="Y"], .keypad-grid button[data-key="S"] { color: #dc741e; font-weight: 700; }
.keypad-grid button:hover { background: #edf5fb; }
.keypad-grid button:active { background: #dcecf8; }
.keypad-clear { width: 100%; height: 29px; margin-top: 7px; border: 0; border-radius: 2px; color: #69736e; background: #eef0ed; cursor: pointer; font-size: 10px; }
.field-hint { margin: 7px 2px 0; color: #a09f99; font-size: 10px; line-height: 1.45; }
.train-query-grid { display: block; }
.query-button { width: 100%; height: 34px; margin-top: 9px; border: 1px solid #91a69f; border-radius: 3px; color: var(--ink); background: #edf3f0; cursor: pointer; font-size: 11px; font-weight: 700; }
.query-button:hover { background: #e2ece8; }
.query-button:disabled { color: #8d9692; cursor: wait; }
.segment-picker { margin-top: 11px; padding: 10px; border: 1px solid #dde0dc; border-radius: 3px; background: #f6f7f4; }
.segment-picker.hidden { display: none; }
.segment-selects { display: grid; grid-template-columns: minmax(0, 1fr) 16px minmax(0, 1fr); align-items: center; gap: 4px; }
.segment-selects span { color: #a29d94; text-align: center; font-size: 11px; }
.segment-selects select { min-width: 0; height: 34px; padding: 0 7px; border: 1px solid #cfd3ce; border-radius: 3px; color: #334640; background: white; outline: none; font-size: 11px; }
.segment-selects select:focus { border-color: #79968f; box-shadow: 0 0 0 3px rgba(52,104,94,.08); }

.route-preview { margin-top: 14px; max-height: 125px; overflow: auto; border: 1px solid #d8dbd7; border-radius: 3px; background: #f8f8f5; }
.preview-empty { display: flex; align-items: center; justify-content: center; gap: 7px; height: 56px; color: #a8aaa4; font-size: 11px; }
.preview-empty span { font-size: 18px; }
.preview-empty p { margin: 0; }
.station-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px; }
.station-chip { padding: 5px 8px; border-radius: 2px; background: white; border: 1px solid #d9ddd8; color: #44514e; font-size: 11px; }
.station-chip small { display: block; margin-top: 2px; color: #9b8478; font: 8px Georgia, serif; text-align: center; }
.chain-arrow { color: #b1aaa0; font-size: 11px; }

.form-row { display: grid; grid-template-columns: 1fr 112px; gap: 12px; margin-top: 14px; }
.color-picker { display: flex; flex-wrap: wrap; gap: 7px; padding-top: 3px; }
.color-swatch { width: 19px; height: 19px; border: 0; padding: 0; border-radius: 2px; background: var(--swatch); cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }
.color-swatch.active { outline: 2px solid var(--ink); outline-offset: 2px; }

.primary-button { width: 100%; margin-top: 15px; height: 42px; border: 0; border-radius: 3px; color: white; background: var(--ink); cursor: pointer; font-weight: 700; font-size: 13px; box-shadow: none; }
.primary-button:hover { background: #214c45; }

.journey-section { min-height: 0; margin-top: 22px; flex-shrink: 0; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading h2 { margin: 0; font-size: 13px; letter-spacing: .5px; }
.section-heading span { color: #9a9f9b; font-size: 11px; }
.journey-list { display: grid; gap: 9px; margin-top: 11px; }
.journey-empty { padding: 18px 0; text-align: center; color: #a0a49f; border-bottom: 1px solid #d9ddd8; border-radius: 0; font-size: 11px; }
.journey-item { display: grid; grid-template-columns: 4px 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border: 0; border-bottom: 1px solid #d9ddd8; border-radius: 0; background: transparent; }
.journey-stripe { width: 3px; height: 34px; border-radius: 0; background: var(--route-color); }
.journey-copy { min-width: 0; }
.journey-copy strong { display: block; margin-bottom: 4px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.journey-copy span { display: block; color: #939892; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.journey-delete { display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: 50%; color: #a2a5a0; background: transparent; cursor: pointer; }
.journey-delete:hover { color: #b74e3e; background: #faece9; }

.sidebar-footer { position: static; display: flex; flex-shrink: 0; justify-content: space-between; align-items: center; margin-top: 20px; padding-top: 14px; border-top: 1px solid #d9ddd8; color: #8b928e; font-size: 9px; }
.text-button { border: 0; padding: 0; color: #98786a; background: transparent; cursor: pointer; font-size: 10px; }

.canvas-area { display: flex; flex-direction: column; min-width: 0; background: #dfe2de; }
.topbar { display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 0 24px; border-bottom: 1px solid #cbd0cb; background: #f5f6f3; }
.poster-title-edit span { display: block; color: #8b918c; font-size: 10px; }
.poster-title-edit input { width: 220px; height: 28px; padding: 0; border: 0; border-radius: 0; color: var(--ink); background: transparent; font-weight: 700; font-size: 14px; }
.poster-title-edit input:focus { box-shadow: none; border-bottom: 1px solid #809790; }
.topbar-actions { display: flex; gap: 8px; }
.icon-button, .secondary-button, .export-button { height: 36px; border-radius: 3px; cursor: pointer; }
.icon-button { display: grid; place-items: center; width: 38px; border: 1px solid #d6d4ce; background: #f9f8f4; }
.icon-button svg { width: 17px; fill: #61716c; }
.icon-button[aria-pressed="false"] { opacity: .52; }
.secondary-button { padding: 0 15px; border: 1px solid #d6d4ce; background: #f9f8f4; font-size: 12px; }
.option-button[aria-pressed="true"] { color: white; border-color: var(--ink); background: var(--ink); }
.export-button { display: flex; align-items: center; gap: 6px; padding: 0 17px; border: 0; color: white; background: var(--ink); font-weight: 700; font-size: 12px; }
.export-button svg { width: 17px; fill: currentColor; }

.poster-wrap { flex: 1; min-height: 0; display: grid; place-items: center; padding: 12px 16px 8px; overflow: auto; }
.poster { position: relative; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; width: min(100%, calc((100vh - 102px) * 1.5)); aspect-ratio: 1.5; min-height: 520px; overflow: hidden; border: 1px solid #bfc5bf; border-radius: 0; background: var(--cream); box-shadow: var(--shadow); }
.poster::before { display: none; }
.poster-heading { position: relative; z-index: 6; display: flex; align-items: flex-start; padding: 28px 42px 4px; pointer-events: none; }
.poster-kicker { margin: 0 0 6px; color: #68736e; font: 600 9px Arial, sans-serif; letter-spacing: 2.2px; }
.poster-heading h2 { margin: 0; color: var(--ink); font: 700 clamp(24px, 2.7vw, 38px)/1.15 "Noto Serif SC", "Songti SC", SimSun, serif; letter-spacing: 4px; }

.map-stage { position: relative; min-height: 0; margin: -4px 20px -4px; overflow: hidden; cursor: grab; touch-action: none; }
.map-stage.dragging { cursor: grabbing; }
#rail-map { width: 100%; height: 100%; min-height: 350px; overflow: hidden; user-select: none; }
.china-land { fill: #e6e5df; stroke: #a7aea8; stroke-width: .9; vector-effect: non-scaling-stroke; }
.china-land:nth-child(2n) { fill: #ebeae4; }
.china-land:hover { fill: #dddeda; }
.route-halo { fill: none; stroke: #f9f7f0; stroke-width: 10; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; opacity: .95; }
.route-line { fill: none; stroke: var(--route-color); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.route-dash { fill: none; stroke: rgba(255,255,255,.74); stroke-width: 1.6; stroke-dasharray: 1 8; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.route-line.animate { stroke-dasharray: 10 7; animation: railMove 2.4s linear infinite; }
@keyframes railMove { to { stroke-dashoffset: -34; } }
.station-dot { fill: #fffdf7; stroke: var(--route-color); stroke-width: 3; vector-effect: non-scaling-stroke; }
.station-label { fill: #263e3a; paint-order: stroke; stroke: #f6f4ec; stroke-width: 5; stroke-linejoin: round; font-size: 16px; font-weight: 700; }
.station-label.intermediate { fill: #6d7571; stroke-width: 4; font-size: 13px; font-weight: 500; }
.route-badge rect { fill: var(--route-color); rx: 10; }
.route-badge text { fill: white; font-size: 11px; font-weight: 700; letter-spacing: .3px; }
.north-mark text { fill: #173b36; font: 700 14px Georgia, serif; }

.empty-map { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; color: #76807b; pointer-events: none; }
.empty-map[hidden] { display: none; }
.empty-train { display: grid; place-items: center; width: 70px; height: 70px; margin-bottom: 12px; border-radius: 4px; background: rgba(255,255,255,.65); border: 1px solid #d5d1c6; }
.empty-train svg { width: 42px; fill: #8b9690; }
.empty-map strong { font: 700 17px "Noto Serif SC", "Songti SC", SimSun, serif; letter-spacing: 1px; }
.empty-map span { margin-top: 6px; color: #a0a39d; font-size: 10px; }
.map-controls { position: absolute; right: 18px; bottom: 19px; z-index: 8; display: grid; overflow: hidden; border: 1px solid rgba(23,59,54,.24); border-radius: 3px; background: rgba(250,248,242,.94); box-shadow: none; cursor: default; }
.map-controls button { display: grid; place-items: center; width: 34px; height: 31px; padding: 0; border: 0; border-bottom: 1px solid rgba(23,59,54,.12); color: var(--ink); background: transparent; cursor: pointer; font: 700 18px/1 Georgia, serif; }
.map-controls button:last-child { border-bottom: 0; font-size: 16px; }
.map-controls button:hover { background: #e5ece8; }

.poster-footer { position: relative; z-index: 6; display: grid; grid-template-columns: auto 1fr auto; align-items: end; gap: 30px; min-height: 74px; margin: 0 42px 22px; padding-top: 12px; border-top: 1px solid rgba(23, 59, 54, .22); }
.stats { display: flex; align-items: center; gap: 15px; }
.stats div { display: flex; align-items: baseline; gap: 4px; white-space: nowrap; }
.stats strong { color: var(--ink); font: 700 22px Georgia, serif; }
.stats span { color: #858b86; font-size: 8px; }
.stats i { display: block; width: 1px; height: 23px; background: #cfcbc1; }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 13px; align-self: center; }
.legend-item { display: flex; align-items: center; gap: 6px; color: #505d58; font-size: 11px; font-weight: 600; }
.legend-line { width: 18px; height: 3px; border-radius: 2px; background: var(--legend-color); }
.signature { text-align: right; color: #8d928d; }
.signature b { color: #65726d; font: 600 11px "Microsoft YaHei", sans-serif; letter-spacing: 1px; }
.canvas-tip { margin: 0 30px 9px; color: #747c77; text-align: center; font-size: 10px; }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 20; padding: 11px 17px; border-radius: 9px; color: white; background: #233e39; box-shadow: 0 10px 30px rgba(0,0,0,.16); opacity: 0; transform: translate(-50%, 15px); pointer-events: none; transition: .25s; font-size: 12px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-shell { display: block; height: auto; }
  .sidebar { min-height: auto; max-height: none; border-right: 0; border-bottom: 1px solid #ddd; }
  .canvas-area { min-height: 740px; }
  .poster-wrap { display: block; }
  .poster { width: 100%; min-width: 760px; }
  .poster-wrap { overflow-x: auto; }
  .sidebar-footer { margin-top: 20px; }
}

@media (max-height: 760px) and (min-width: 981px) {
  .sidebar { padding-block: 16px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand-mark svg { width: 22px; }
  .brand h1 { font-size: 21px; }
  .intro { margin: 13px 0 11px; }
  .editor-card { padding: 12px; }
  .mode-tabs { margin-bottom: 11px; }
  .route-preview { max-height: 92px; }
  .form-row { margin-top: 11px; }
  .primary-button { margin-top: 11px; }
  .journey-section { margin-top: 16px; }
  .sidebar-footer { margin-top: 16px; }
}

@media (max-width: 600px) {
  .sidebar { padding: 22px 18px; }
  .topbar { height: auto; gap: 15px; padding: 14px 18px; align-items: flex-end; }
  .poster-title-edit input { width: 150px; }
  .secondary-button { display: none; }
  .poster-wrap { padding: 16px 12px; }
  .canvas-tip { margin-inline: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
