:root {
  --bg: #eef5fd;
  --surface: #ffffff;
  --surface-alt: #e4f0fc;
  --primary: #2f7de1;
  --primary-dark: #1d5fc0;
  --primary-contrast: #ffffff;
  --text: #14243a;
  --text-muted: #5b7290;
  --border: #d7e6f7;
  --danger: #d93a2f;
  --danger-bg: #fdeceb;
  --success: #1f9d5c;
  --shadow: 0 2px 10px rgba(31, 74, 128, 0.08);
}

:root[data-theme="dark"] {
  --bg: #0e1620;
  --surface: #16212f;
  --surface-alt: #1c2a3b;
  --primary: #5b9dff;
  --primary-dark: #7fb4ff;
  --primary-contrast: #06111f;
  --text: #eaf1fb;
  --text-muted: #93a7c2;
  --border: #263449;
  --danger: #ff7a70;
  --danger-bg: #3a1d1c;
  --success: #4fce93;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input {
  font-family: inherit;
}

.theme-toggle {
  position: fixed;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 12px;
  z-index: 50;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* ---------- Landing / setup screens ---------- */

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  color: var(--primary-dark);
}

.card .subtitle {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 16px;
}

.field input:focus, .field textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: var(--primary-contrast);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn:active {
  background: var(--primary-dark);
}

.btn.secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn.small {
  width: auto;
  padding: 8px 12px;
  font-size: 14px;
}

.error-text {
  color: var(--danger);
  font-size: 14px;
  margin-top: 10px;
}

.hint {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 14px;
  line-height: 1.4;
}

/* ---------- Route results (landing) ---------- */

.route-results {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.route-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.route-card-name {
  font-weight: 700;
  color: var(--text);
  font-size: 15px;
}

.route-card-meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

.route-card .btn.small {
  flex: 0 0 auto;
}

.orientation-banner {
  display: none;
  background: var(--surface-alt);
  color: var(--text-muted);
  text-align: center;
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

@media (orientation: portrait) {
  .orientation-banner.show-in-portrait {
    display: block;
  }
}

/* ---------- Playback screen ---------- */

.playback {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.playback-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.playback-header .bus-tag {
  font-weight: 700;
  color: var(--primary-dark);
}

.playback-header .progress-tag {
  color: var(--text-muted);
  font-size: 13px;
}

.playback-header .icon-btn {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 14px;
  cursor: pointer;
}

.progress-track {
  height: 4px;
  background: var(--surface-alt);
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.2s ease;
}

.playback-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.stop-tap-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  padding-bottom: 76px;
  cursor: pointer;
  user-select: none;
  overflow-y: auto;
}

.stop-tap-area .next-label {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.stop-tap-area .stop-name {
  font-size: clamp(28px, 8vw, 56px);
  font-weight: 800;
  color: var(--text);
  line-height: 1.15;
}

.stop-tap-area .stop-note {
  margin-top: 14px;
  font-size: clamp(16px, 3.5vw, 22px);
  color: var(--primary-dark);
}

.stop-tap-area .upcoming {
  margin-top: 10px;
  font-size: 14px;
  color: var(--text-muted);
}

.tap-hint {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  font-size: 15px;
  font-weight: 700;
  color: var(--primary-contrast);
  background: var(--primary);
  border: none;
  border-radius: 999px;
  padding: 10px 22px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.stop-tap-area {
  position: relative;
}

.pb-minimap {
  max-width: min(90%, 420px);
  max-height: 26vh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-top: 14px;
}

.pb-step {
  margin-top: 18px;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: min(92%, 480px);
}

.pb-step-counter {
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.pb-step-text {
  font-size: clamp(16px, 3.2vw, 20px);
  font-weight: 700;
  color: var(--primary-dark);
}

.pb-step-image {
  display: block;
  max-width: 100%;
  max-height: 22vh;
  object-fit: contain;
  border-radius: 10px;
  margin-top: 10px;
}

.steps-panel {
  flex: 0 0 280px;
  max-width: 40vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px 14px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.steps-panel-title {
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.steps-panel-list {
  display: flex;
  flex-direction: column;
}

.steps-panel-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 0;
  border-radius: 8px;
}

.steps-panel-item.active {
  background: var(--surface-alt);
  padding: 12px 8px;
  margin: 0 -8px;
}

.steps-panel-item-main {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}

.steps-panel-item-num {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.steps-panel-item.active .steps-panel-item-num {
  background: var(--primary);
  color: var(--primary-contrast);
}

.steps-panel-item-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
}

.steps-panel-item-img {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.steps-panel-divider {
  height: 1px;
  background: var(--border);
}

@media (orientation: portrait) {
  .playback-body {
    flex-direction: column;
  }

  .steps-panel {
    flex: 0 0 auto;
    max-width: none;
    max-height: 34vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

.complete-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.complete-panel .checkmark {
  font-size: 48px;
  color: var(--success);
}

/* ---------- Editor screen ---------- */

.editor-wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

.editor-wrap h1 {
  color: var(--primary-dark);
  font-size: 22px;
  margin-bottom: 4px;
}

.stop-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}

.stop-row .stop-num {
  flex: 0 0 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
}

.stop-row .stop-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stop-row input {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 15px;
}

.stop-row .stop-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stop-row .stop-actions button {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 6px;
  width: 30px;
  height: 26px;
  font-size: 13px;
  cursor: pointer;
}

.stop-row .stop-actions button.remove {
  color: var(--danger);
}

.toolbar {
  display: flex;
  gap: 10px;
  margin: 16px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

.toast.show {
  opacity: 1;
}

.route-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 4px;
}

.route-list button {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}

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

.img-field input {
  flex: 1;
  min-width: 160px;
}

.img-preview {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.img-unavailable {
  font-size: 12px;
  color: var(--text-muted);
}

.stop-steps {
  margin-top: 8px;
  padding: 10px;
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stop-steps-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.step-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.step-row .step-num {
  flex: 0 0 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
}

.step-row .step-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.step-row input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 14px;
}

.step-row .step-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.step-row .step-actions button {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 6px;
  width: 28px;
  height: 24px;
  font-size: 12px;
  cursor: pointer;
}

.step-row .step-actions button.remove {
  color: var(--danger);
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 22px 0 8px;
}
