:root {
  --bg: #0b0e14;
  --panel: #121722;
  --panel-2: #171f2e;
  --border: #232c3d;
  --text: #eef2f8;
  --text-dim: #8b96ab;
  --accent: #f2a900;
  --led: #ffb703;
  --danger: #ff5d5d;
  --success: #35d07f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "PingFang HK", "Noto Sans", system-ui, sans-serif;
}

.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.line-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.3px;
}

.line-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ctrl-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, transform 0.1s;
}
.ctrl-btn:hover { background: #1e2739; }
.ctrl-btn:active { transform: scale(0.96); }
.ctrl-btn.primary {
  background: var(--accent);
  color: #1a1300;
  border-color: var(--accent);
  font-weight: 600;
}
.ctrl-btn.primary:hover { filter: brightness(1.08); }
.ctrl-btn.active {
  background: var(--success);
  border-color: var(--success);
  color: #062915;
  font-weight: 600;
}

.mute-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}

/* ---------- language select ---------- */
.lang-select {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.lang-select .lang-select-title {
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.5px;
}

.lang-checkbox {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  user-select: none;
}
.lang-checkbox input { accent-color: var(--accent); cursor: pointer; }
.lang-checkbox.disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- data panel ---------- */
.data-panel {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.data-panel[hidden] { display: none; }

.data-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.data-textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  background: #05070c;
  color: #c9f7d8;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 12.5px;
  line-height: 1.5;
}

.data-panel-status {
  font-size: 12px;
  color: var(--text-dim);
  min-height: 16px;
}
.data-panel-status.error { color: var(--danger); }
.data-panel-status.ok { color: var(--success); }

/* ---------- data panel: server files / audio generation ---------- */
.data-panel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.server-files,
.audio-gen {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.field-label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}

.server-files select,
.filename-input {
  background: #05070c;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: "SF Mono", "Courier New", monospace;
}

.filename-input {
  width: 160px;
}

.ctrl-btn.accent {
  background: var(--led);
  color: #1a1300;
  border-color: var(--led);
  font-weight: 600;
}
.ctrl-btn.accent:hover { filter: brightness(1.08); }
.ctrl-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.audio-gen-progress {
  font-size: 12.5px;
  color: var(--text-dim);
  font-family: "SF Mono", "Courier New", monospace;
}

.audio-gen-log {
  max-height: 140px;
  overflow-y: auto;
  background: #05070c;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-dim);
}
.audio-gen-log[hidden] { display: none; }
.audio-gen-log .log-fail { color: var(--danger); }
.audio-gen-log .log-ok { color: var(--success); }

/* ---------- station editor ---------- */
.station-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.station-editor-header h3 {
  margin: 0;
  font-size: 14px;
  color: var(--text-dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.station-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 480px;
  overflow-y: auto;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--panel);
}
.station-cards::-webkit-scrollbar {
  width: 8px;
}
.station-cards::-webkit-scrollbar-track {
  background: var(--panel);
  border-radius: 999px;
}
.station-cards::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
.station-cards::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.station-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.station-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.station-card-order {
  display: flex;
  gap: 2px;
}

.station-card-order button,
.station-card-delete {
  background: #1a2233;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}
.station-card-order button:hover { background: #232f47; color: var(--text); }
.station-card-delete:hover { background: var(--danger); color: #2a0000; border-color: var(--danger); }

.station-id-input {
  background: #05070c;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 12.5px;
  width: 170px;
}

.station-card-delete { margin-left: auto; }

.station-names-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
}

.station-name-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.station-name-field label {
  font-size: 11px;
  color: var(--text-dim);
}
.station-name-field input {
  background: #05070c;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 13px;
}

.station-interchange-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12.5px;
}
.station-interchange-row .ic-label {
  color: var(--text-dim);
}
.station-interchange-row label {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.station-interchange-row .ic-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.advanced-json {
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.advanced-json summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 12.5px;
  margin-bottom: 8px;
}
.advanced-json .data-panel-actions { margin-top: 10px; }

/* ---------- board ---------- */
.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 8px;
  gap: 22px;
}

.destination-strip {
  background: #000;
  color: var(--led);
  font-family: "Courier New", monospace;
  font-weight: 700;
  letter-spacing: 3px;
  padding: 6px 20px;
  border-radius: 6px;
  font-size: 14px;
  border: 1px solid #2a2200;
  text-transform: uppercase;
  box-shadow: inset 0 0 12px rgba(255, 183, 3, 0.15);
}

.station-display {
  width: 100%;
  max-width: 720px;
  background: radial-gradient(ellipse at center, #04121a 0%, #01080c 100%);
  border: 2px solid #0e2a33;
  border-radius: 16px;
  padding: 34px 20px 22px;
  text-align: center;
  box-shadow: 0 0 30px rgba(0, 255, 200, 0.05), inset 0 0 40px rgba(0,0,0,0.6);
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.station-name-fade {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  animation: fadeSwap 0.45s ease;
}

@keyframes fadeSwap {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.station-name {
  font-size: clamp(28px, 6vw, 52px);
  font-weight: 800;
  color: #baf6ff;
  text-shadow: 0 0 18px rgba(120, 235, 255, 0.55);
  line-height: 1.2;
}

.lang-tag {
  font-size: 13px;
  color: #4fb9c9;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.interchange-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 24px;
}

.interchange-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-weight: 600;
}

/* ---------- line diagram ---------- */
.diagram-label {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--text-dim);
  margin-top: -6px;
}

.line-diagram-wrap {
  position: relative;
  width: 100%;
  max-width: 960px;
}

.line-diagram-wrap::before,
.line-diagram-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 30px;
  width: 36px;
  z-index: 3;
  pointer-events: none;
  transition: opacity 0.2s;
  opacity: 0;
}
.line-diagram-wrap::before {
  left: 0;
  background: linear-gradient(to right, var(--bg), transparent);
}
.line-diagram-wrap::after {
  right: 0;
  background: linear-gradient(to left, var(--bg), transparent);
}
.line-diagram-wrap.scroll-left::before,
.line-diagram-wrap.scroll-right::after {
  opacity: 1;
}

.line-diagram {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 10px 6px 22px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scroll-padding: 0 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--panel-2);
}
.line-diagram::-webkit-scrollbar {
  height: 8px;
}
.line-diagram::-webkit-scrollbar-track {
  background: var(--panel-2);
  border-radius: 999px;
}
.line-diagram::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
.line-diagram::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.diag-station {
  flex: 0 0 auto;
  width: 104px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  cursor: pointer;
  padding: 10px 4px 4px;
  border-radius: 10px;
  scroll-snap-align: center;
  transition: background 0.15s;
}
.diag-station:hover {
  background: rgba(242, 169, 0, 0.08);
}
.diag-station:hover .diag-node {
  transform: scale(1.2);
}
.diag-station:active {
  background: rgba(242, 169, 0, 0.16);
}

.diag-track {
  position: relative;
  width: 100%;
  height: 6px;
  background: var(--border);
}

.diag-track::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
}

.diag-station:first-child .diag-track { border-radius: 6px 0 0 6px; }
.diag-station:last-child .diag-track { border-radius: 0 6px 6px 0; }

.diag-node {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--panel-2);
  border: 3px solid var(--text-dim);
  margin-top: -6px;
  z-index: 2;
  transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
}

.diag-station.passed .diag-node {
  border-color: var(--accent);
  background: var(--accent);
}
.diag-station.current .diag-node {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 6px rgba(242, 169, 0, 0.25);
  animation: pulse 1.2s infinite;
}
.diag-station.passed .diag-track::before,
.diag-station.current .diag-track::before {
  transform: scaleX(1);
  transition: transform 0.6s ease;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px rgba(242, 169, 0, 0.25); }
  50% { box-shadow: 0 0 0 9px rgba(242, 169, 0, 0.12); }
}

.diag-label {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  white-space: nowrap;
}
.diag-station.current .diag-label {
  color: var(--text);
  font-weight: 700;
}
.diag-station.interchange .diag-node {
  border-style: double;
  width: 22px;
  height: 22px;
  margin-top: -8px;
}

.diag-here {
  position: absolute;
  top: -18px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}
.diag-station.current .diag-here { opacity: 1; }

.diag-ic-dots {
  display: flex;
  gap: 4px;
  margin-top: 5px;
  min-height: 8px;
}
.diag-ic-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

/* ---------- doors scene ---------- */
.doors-scene {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.platform-label {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--text-dim);
}

.train-car {
  position: relative;
  width: 100%;
  height: 130px;
  background: linear-gradient(180deg, #2b3547, #1a212e);
  border: 2px solid #333f55;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
}

.door {
  flex: 1;
  background: linear-gradient(180deg, #4a5a78, #2f3b52);
  position: relative;
  transition: transform 0.9s cubic-bezier(0.65, 0, 0.35, 1);
  border-right: 1px solid #1a212e;
}
.door::after {
  content: "";
  position: absolute;
  top: 10%;
  bottom: 10%;
  left: 8%;
  right: 8%;
  background: rgba(150, 210, 255, 0.12);
  border-radius: 4px;
  border: 1px solid rgba(150, 210, 255, 0.2);
}
.door-left { transform: translateX(0); border-radius: 0 0 0 8px; }
.door-right { transform: translateX(0); border-radius: 0 0 8px 0; }

.train-car.open .door-left { transform: translateX(-100%); }
.train-car.open .door-right { transform: translateX(100%); }

.door-gap-warning {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #1a1300;
  background: repeating-linear-gradient(45deg, #ffce33, #ffce33 8px, #1a1300 8px, #1a1300 16px);
  padding: 2px 10px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.3s;
}
.train-car.open .door-gap-warning { opacity: 1; }

/* ---------- statusbar ---------- */
.statusbar {
  padding: 8px 20px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
}

@media (max-width: 560px) {
  .controls { width: 100%; justify-content: flex-start; }
}
