:root {
  color-scheme: light;
  --background: #fafafa;
  --surface: #ffffff;
  --surface-subtle: #f4f4f5;
  --surface-selected: #f4f4f5;
  --text: #27272a;
  --text-strong: #09090b;
  --muted: #71717a;
  --muted-soft: #a1a1aa;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --primary: #18181b;
  --primary-hover: #27272a;
  --danger: #b42318;
  --ring: #18181b;
  --radius: 0.5rem;
  --shadow-control: 0 1px 2px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html,
body { min-height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  background: var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
select,
input { font: inherit; }

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.brand-lockup {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  position: relative;
  display: block;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 8px;
  background: var(--text-strong);
}

.brand-mark span {
  position: absolute;
  display: block;
  width: 25px;
  height: 3px;
  border-radius: 2px;
  background: #ffffff;
  transform: rotate(-38deg);
}

.brand-mark span:nth-child(1) { top: 9px; left: -2px; opacity: 0.55; }
.brand-mark span:nth-child(2) { top: 17px; left: 5px; opacity: 0.78; }
.brand-mark span:nth-child(3) { top: 25px; left: 12px; }

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.69rem;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.2;
  text-transform: none;
}

.brand-lockup .eyebrow {
  font-size: 0.61rem;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--text-strong);
  letter-spacing: -0.025em;
}

h1 { font-size: clamp(1.2rem, 1.8vw, 1.55rem); line-height: 1.1; }
h2 { font-size: 1.06rem; line-height: 1.25; }

.product-subtitle,
.preview-description {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.topbar-meta {
  display: flex;
  align-items: center;
  gap: 18px;
}

.language-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.language-icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.35;
}

.language-control select {
  width: auto;
  min-width: 116px;
  height: 34px;
  margin: 0;
  padding: 0 30px 0 10px;
  font-size: 0.75rem;
}

.workspace {
  display: grid;
  height: calc(100vh - 72px);
  grid-template-columns: minmax(340px, 380px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.mobile-view-tabs { display: none; }

.controls-panel,
.preview-panel {
  min-height: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.controls-panel {
  display: flex;
  align-self: stretch;
  overflow: hidden;
  flex-direction: column;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  padding: 19px 18px 15px;
}

#generatorForm {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1 1 auto;
  padding: 0 17px;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-width: thin;
}

.controls-footer {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  padding: 13px 17px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.format-badge {
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-subtle);
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.form-section {
  margin: 0;
  padding: 18px 0;
  border: 0;
}

.form-section + .form-section { border-top: 1px solid #f0f0f1; }
.source-section { padding-top: 13px; }

legend,
.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 0.81rem;
  font-weight: 650;
}

.field-description,
.form-section-heading p {
  margin: -3px 0 10px;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.4;
}

.form-section-heading { margin-bottom: 12px; }
.form-section-heading h3 {
  margin: 0 0 5px;
  color: var(--text-strong);
  font-size: 0.85rem;
  line-height: 1.3;
}
.form-section-heading p { margin: 0; }

select {
  width: 100%;
  height: 40px;
  margin: 0;
  padding: 0 35px 0 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-strong);
  font-size: 0.82rem;
  box-shadow: var(--shadow-control);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

select:hover:not(:disabled) { border-color: #969f9b; }
select:focus-visible { border-color: var(--primary); }
select:disabled { cursor: not-allowed; background: var(--surface-subtle); color: var(--muted-soft); }

.source-attribution {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.source-attribution a {
  color: var(--text-strong);
  text-decoration-color: var(--border-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.source-freshness {
  margin: 3px 0 0;
  color: var(--muted-soft);
  font-size: 0.7rem;
  line-height: 1.35;
}

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

.mode-option {
  position: relative;
  display: flex;
  min-width: 0;
  min-height: 82px;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 8px 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.mode-option:hover:not(:has(input:disabled)) { border-color: #aab2ae; }

.mode-option:has(input:checked) {
  border-color: #a1a1aa;
  background: var(--surface-selected);
  box-shadow: var(--shadow-control);
}

.mode-option:has(input:checked)::after {
  position: absolute;
  top: 7px;
  right: 7px;
  display: grid;
  width: 16px;
  height: 16px;
  place-items: center;
  border-radius: 50%;
  background: var(--text-strong);
  color: #fff;
  content: "✓";
  font-size: 0.62rem;
  font-weight: 800;
}

.mode-option:has(input:focus-visible) { outline: 2px solid var(--ring); outline-offset: 2px; }
.mode-option:has(input:disabled) { cursor: not-allowed; opacity: 0.58; }
.mode-option input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.mode-option strong,
.mode-option small { display: block; overflow: hidden; text-overflow: ellipsis; }
.mode-option strong { color: var(--text-strong); font-size: 0.82rem; line-height: 1.15; }
.mode-option small { margin-top: 3px; color: var(--muted); font-size: 0.72rem; line-height: 1.2; }

.mode-icon {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.68rem;
  font-weight: 750;
}

.mode-option:has(input:checked) .mode-icon {
  background: var(--surface);
  color: var(--text-strong);
  box-shadow: 0 0 0 1px var(--border);
}

.route-fieldset { padding-bottom: 13px; }

.route-search {
  position: relative;
  display: block;
  margin: 1px 0 11px;
}

.route-search svg {
  position: absolute;
  top: 50%;
  left: 11px;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-width: 1.5;
  transform: translateY(-50%);
  pointer-events: none;
}

.route-search input {
  width: 100%;
  height: 40px;
  padding: 0 34px 0 34px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-strong);
  font-size: 0.8rem;
  box-shadow: var(--shadow-control);
  appearance: none;
}

.route-search input::placeholder { color: var(--muted-soft); }
.route-search input::-webkit-search-cancel-button { opacity: 0.55; }

.route-selection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -1px 0 8px;
}

.route-selection-header output,
.route-empty { color: var(--muted); font-size: 0.75rem; }

.route-actions { display: flex; gap: 10px; }

.route-actions button {
  padding: 2px 0;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
  cursor: pointer;
}

.route-actions button:hover:not(:disabled) { border-bottom-color: var(--text); color: var(--text-strong); }
.route-actions button:disabled { color: var(--muted-soft); cursor: default; opacity: 0.58; }

.route-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 5px;
  padding: 1px;
}

.route-option {
  display: grid;
  min-width: 0;
  min-height: 36px;
  grid-template-columns: auto 3px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 100ms ease, background 100ms ease;
}

.route-option:hover { border-color: #aab2ae; }
.route-option:has(input:checked) { border-color: #a1a1aa; background: var(--surface-selected); }
.route-option:has(input:focus-visible) { outline: 2px solid var(--ring); outline-offset: 1px; }
.route-option input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
.route-swatch { width: 3px; height: 16px; border-radius: 1px; background: var(--route-color); }
.route-name { overflow: hidden; color: var(--text-strong); font-size: 0.79rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.route-empty { margin: 4px 0 0; }

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

.settings-grid select { font-size: 0.74rem; }

.output-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.output-actions .primary-button { grid-column: 1 / -1; }

.primary-button,
.export-button {
  display: inline-flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.primary-button svg,
.export-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.primary-button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fafafa;
  box-shadow: var(--shadow-control);
}
.primary-button:hover:not(:disabled) { border-color: var(--primary-hover); background: var(--primary-hover); }
.export-button {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-strong);
  box-shadow: var(--shadow-control);
}
.export-button:hover:not(:disabled) { border-color: #858f8a; background: var(--surface-subtle); }
.primary-button:disabled,
.export-button:disabled { cursor: not-allowed; opacity: 0.45; }
.primary-button[data-loading="true"]:disabled,
.export-button[data-loading="true"]:disabled { cursor: wait; opacity: 0.72; }

.button-loader {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

.primary-button[data-loading="true"] svg,
.export-button[data-loading="true"] svg { display: none; }
.primary-button[data-loading="true"] .button-loader,
.export-button[data-loading="true"] .button-loader { display: inline-block; }
.export-button .button-loader { border-color: var(--border); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

.form-message {
  min-height: 17px;
  margin: 8px 1px 0;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.35;
}

.form-message.error { color: var(--danger); }

.stats {
  display: flex;
  align-items: baseline;
  gap: 24px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e9ecea;
}

.stats div {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 5px;
  padding: 0;
  background: transparent;
  text-align: left;
}

.stats strong { color: var(--text-strong); font-size: 0.95rem; line-height: 1; }
.stats span { color: var(--muted); font-size: 0.67rem; }
.preview-panel {
  display: flex;
  min-width: 0;
  overflow: hidden;
  flex-direction: column;
}

.preview-toolbar {
  display: flex;
  min-height: 72px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px 12px 17px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-control);
}

.zoom-controls button {
  min-width: 36px;
  height: 36px;
  padding: 0 9px;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  color: var(--text);
  font-size: 0.75rem;
  cursor: pointer;
}

.zoom-controls button:first-child { border-left: 0; }
.zoom-controls button:hover:not(:disabled) { background: var(--surface-subtle); }
.zoom-controls button:disabled { color: var(--muted-soft); cursor: default; }
.zoom-controls button:last-child { min-width: 44px; }
.zoom-controls output { min-width: 50px; color: var(--muted); font-size: 0.7rem; text-align: center; }

.map-viewport {
  position: relative;
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  background: #ffffff;
  scrollbar-color: var(--border-strong) transparent;
  scrollbar-width: thin;
}

.map-viewport[aria-busy="true"]::after {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.88);
  content: attr(data-loading-label);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 650;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  margin-top: 17px;
  color: var(--text-strong);
  font-size: 0.88rem;
  font-weight: 650;
}

.empty-state p { max-width: 300px; margin: 6px 0 0; font-size: 0.78rem; line-height: 1.5; }

.empty-illustration {
  display: block;
  width: 96px;
  height: 64px;
}

.empty-illustration svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.empty-illustration .empty-route {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.empty-illustration .empty-route-primary { stroke: var(--text-strong); }
.empty-illustration .empty-route-secondary { stroke: var(--border-strong); }

.empty-illustration circle {
  fill: var(--surface);
  stroke: var(--text-strong);
  stroke-width: 2;
}

#diagramPreview {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  background: var(--surface);
  transition: width 140ms ease;
}

@media (max-width: 1080px) {
  .workspace { grid-template-columns: minmax(305px, 335px) minmax(0, 1fr); }
  .topbar { padding-inline: 18px; }
  .product-subtitle { display: none; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .topbar { height: auto; min-height: 68px; padding: 12px 14px; }
  .workspace { height: auto; grid-template-columns: 1fr; gap: 10px; padding: 10px; }
  .mobile-view-tabs {
    position: sticky;
    z-index: 20;
    top: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-subtle);
    box-shadow: var(--shadow-control);
  }
  .mobile-view-tabs button {
    min-height: 40px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 650;
  }
  .mobile-view-tabs button[aria-selected="true"] {
    background: var(--surface);
    color: var(--text-strong);
    box-shadow: var(--shadow-control);
  }
  .workspace[data-mobile-view="controls"] .preview-panel { display: none; }
  .workspace[data-mobile-view="preview"] .controls-panel { display: none; }
  .controls-panel { max-height: none; overflow: visible; padding: 16px; }
  .panel-heading { padding: 0 0 13px; }
  #generatorForm { overflow: visible; padding: 0; }
  .controls-footer {
    margin: 0 -16px -16px;
    padding: 13px 16px 12px;
    border-radius: 0 0 8px 8px;
  }
  .preview-panel { min-height: calc(100vh - 88px); }
}

@media (max-width: 560px) {
  .topbar-meta { align-self: flex-start; }
  .language-control > span { display: none; }
  .language-control { gap: 6px; }
  .language-control select { min-width: 102px; }
  h1 { font-size: 1.12rem; }
  .brand-mark { display: none; }
  .panel-heading { padding-bottom: 11px; }
  .mode-grid { grid-template-columns: repeat(3, minmax(82px, 1fr)); overflow-x: auto; }
  .route-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .route-option { min-height: 42px; padding-inline: 7px; }
  .settings-grid { grid-template-columns: 1fr; }
  .output-actions { grid-template-columns: 1fr; }
  .preview-toolbar { align-items: flex-start; flex-direction: column; }
  .zoom-controls { width: 100%; }
  .zoom-controls button:last-child { margin-left: auto; border-left: 1px solid var(--border); }
  .preview-panel { min-height: 540px; }
}

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