:root {
  --primary: #d97706;
  --primary-hover: #b45309;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 12px;

  /* Per-mode colors: the primary visual distinction mechanism for transit legs. */
  --mode-walk: #64748b;
  --mode-bus: #16a34a;
  --mode-mrt: #dc2626;
  --mode-lrt: #748477;

  /* Official Singapore MRT line colours, applied on top of --mode-mrt for a specific line. */
  --line-ns: #d42e12;
  --line-ew: #009645;
  --line-ne: #9900aa;
  --line-cc: #fa9e0d;
  --line-dt: #005ec4;
  --line-te: #9d5b25;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}

.app-container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.top-bar {
  display: flex;
  justify-content: flex-end;
}

.lang-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  background: var(--card-bg);
  color: var(--text);
}

main {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Header */
header {
  text-align: center;
  padding: 12px 0 4px;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
}

header h1 span {
  color: var(--primary);
}

header p {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Search Card */
.search-card {
  background: var(--card-bg);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.input-group {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-group label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.input-group input[type="text"] {
  width: 100%;
  padding: 10px 36px 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.input-wrapper {
  position: relative;
}
.btn-field-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.15rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
}
.btn-field-clear:hover {
  color: var(--text);
  background: var(--border);
}

.input-group input[type="text"]:focus {
  border-color: var(--primary);
}

.swap-row {
  display: flex;
  justify-content: flex-end;
  margin: -8px 0;
}

.btn-swap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--card-bg);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
}

.btn-swap svg {
  width: 16px;
  height: 16px;
}

.btn-swap:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-swap:active {
  transform: rotate(180deg);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.btn-submit {
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-submit:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-submit:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.dropdown {
  list-style: none;
  position: absolute;
  z-index: 10;
  top: 100%;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-height: 240px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.dropdown li {
  padding: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.dropdown li:hover {
  background: var(--bg);
}

.dropdown li.highlighted {
  background: var(--bg);
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.error {
  color: #b00020;
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

/* Route Card */
.route-card {
  background: var(--card-bg);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.route-header {
  margin-bottom: 12px;
}

.route-header h2 {
  font-size: 1.1rem;
}

.route-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 2px;
}

.route-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.btn-secondary {
  background: var(--card-bg);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.btn-secondary:hover {
  background: var(--primary);
  color: white;
}

.status-message {
  font-size: 0.8rem;
  color: var(--muted);
}

.map-preview {
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.map-preview img {
  width: 100%;
  height: auto;
  display: block;
}

/* Timeline Legs */
.timeline {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.timeline-step {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-left: 12px;
  border-left: 3px solid var(--primary);
}

.timeline-step .map-preview {
  margin-bottom: 0;
}

.step-desc {
  font-size: 0.88rem;
  line-height: 1.4;
}

/* Per-mode timeline left border: primary visual cue distinguishing walk/bus/mrt/lrt legs */
.step-mode-walk {
  border-left-color: var(--mode-walk);
  border-left-style: dashed;
}
.step-mode-bus {
  border-left-color: var(--mode-bus);
}
.step-mode-mrt {
  border-left-color: var(--mode-mrt);
}
.step-mode-lrt {
  border-left-color: var(--mode-lrt);
}

.step-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.step-header-main {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.step-duration {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

/* Mode badge: icon (aria-hidden) + real text label, never color alone */
.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 6px;
  white-space: nowrap;
}

.mode-badge svg {
  width: 12px;
  height: 12px;
  flex: none;
}

.mode-badge--walk {
  background-color: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}
.mode-badge--bus {
  background-color: #dcfce7;
  color: #15803d;
  border: 1px solid #bbf7d0;
}
.mode-badge--mrt {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}
.mode-badge--lrt {
  background-color: #eef1e4;
  color: #4d5a1f;
  border: 1px solid #d7ddc0;
}

/* Route/line code pill for transit legs, e.g. bus number */
.route-pill {
  color: white;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.route-pill--bus {
  background-color: var(--mode-bus);
}
.route-pill--mrt {
  background-color: var(--mode-mrt);
}
.route-pill--lrt {
  background-color: var(--mode-lrt);
}

/* Alternative bus services chip, shown when multiple buses ply the same corridor */
.route-alt-chip {
  font-size: 0.72rem;
  font-weight: 600;
  color: #166534;
  background-color: #f0fdf4;
  border: 1px dashed #86efac;
  padding: 1px 7px;
  border-radius: 4px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}

/* Localized helper hint below bus step with alternative options */
.route-alt-hint {
  font-size: 0.76rem;
  color: #15803d;
  background-color: #f0fdf4;
  border-left: 2px solid var(--mode-bus);
  padding: 3px 8px;
  border-radius: 0 4px 4px 0;
  margin-top: 2px;
}

/* Stop count / distance detail chip for transit legs */
.transit-detail {
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.transit-detail--bus {
  background-color: #f0fdf4;
  border: 1px solid #dcfce7;
  color: #166534;
}
.transit-detail--mrt {
  background-color: #fef2f2;
  border: 1px solid #fee2e2;
  color: #991b1b;
}
.transit-detail--lrt {
  background-color: #f4f6ef;
  border: 1px solid #e4e8d8;
  color: #4d5a1f;
}

/* Shown only when printing (Download PDF button triggers window.print()) - see @media print below. */
.print-only {
  display: none;
}

@media print {
  .top-bar,
  header,
  .search-card,
  footer,
  .route-actions {
    display: none !important;
  }

  .print-only {
    display: block;
    margin-top: 4px;
    font-size: 0.9rem;
    color: var(--muted);
  }

  .route-card {
    border: none;
    box-shadow: none;
    padding: 0;
  }

  .timeline-step,
  .map-preview {
    break-inside: avoid;
  }

  .route-alt-chip {
    border: 1px solid #166534;
    color: #166534;
    background: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .route-alt-hint {
    background: none;
    border-left: 2px solid #166534;
    color: #166534;
  }
}


/* Mode sequence summary bar, above the overview map */
.route-summary-flow {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.summary-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.summary-chip svg {
  width: 10px;
  height: 10px;
  flex: none;
}

.transition-arrow,
.summary-chip-sep {
  width: 14px;
  height: 14px;
  color: #64748b;        /* Crisp slate gray with high readability */
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
}

/* Optional hover or accent emphasis */
.transition-arrow:hover,
.summary-chip-sep:hover {
  color: #334155;
}

/* Footer */
footer {
  margin-top: 8px;
  padding: 4px 0 12px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.5;
}

.footer-brand {
  margin-bottom: 8px;
}