/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ──────────────────────────────────────────────── */
:root {
  --bg:        #080f1b;
  --surface:   #0c1624;
  --border:    #162744;
  --text:      #dce6f2;
  --muted:     #3f607a;
  --dim:       #1e3654;
  --accent:    #e07a40;
  --sidebar-w: 268px;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg:      #f0f3f8;
  --surface: #ffffff;
  --border:  #d6dde8;
  --text:    #0e1b2e;
  --muted:   #7a8fa6;
  --dim:     #c5d0de;
  --accent:  #d96c2e;
  color-scheme: light;
}

/* ── Base ────────────────────────────────────────────────── */
html, body {
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── Layout ──────────────────────────────────────────────── */
.layout {
  display: flex;
  width: 100vw;
  height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 30px 24px 24px;
  gap: 28px;
  overflow: hidden;
}

/* Fields section scrolls when flight-selector grows */
.fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.fields::-webkit-scrollbar { width: 4px; }
.fields::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.brand {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  flex-shrink: 0;
}
.brand-mark {
  font-size: 18px;
  color: var(--accent);
  margin-top: 2px;
  flex-shrink: 0;
  line-height: 1;
}
.brand h1 {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: 0.01em;
  flex: 1;
}
.btn-mode-toggle {
  margin-left: auto;
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
}
.btn-mode-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* ── Form fields ─────────────────────────────────────────── */
.fields {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13.5px;
  padding: 10px 12px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%233f607a' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}
select:focus { border-color: var(--accent); }

/* ── Buttons ─────────────────────────────────────────────── */
.actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.btn {
  padding: 11px 16px;
  border: none;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.30; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:not(:disabled):hover { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:not(:disabled):hover {
  border-color: var(--muted);
  color: var(--text);
}

/* ── Theme picker ─────────────────────────────────────────── */
#theme-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.theme-swatch {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  padding: 0;
  position: relative;
  outline: none;
}
.theme-swatch:hover {
  transform: scale(1.10);
}
.theme-swatch.active {
  border-color: var(--text);
  transform: scale(1.10);
}
.theme-swatch.active::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 9px;
  border: 1px solid rgba(255,255,255,0.15);
  pointer-events: none;
}

/* ── Sidebar footer ──────────────────────────────────────── */
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 11px;
  line-height: 1.65;
  color: var(--muted);
}
.hint { color: var(--dim); }
.hint code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 10.5px;
  color: var(--dim);
  background: var(--border);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ── Canvas area ─────────────────────────────────────────── */
.canvas {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  padding: 20px;
}

/* ── Empty state ─────────────────────────────────────────── */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--dim);
  text-align: center;
  border: 1px dashed #162338;
  border-radius: 4px;
  /* Matches 1:√2 aspect, scaled for display */
  width: min(480px, 60vw);
  aspect-ratio: 1 / 1.414;
  max-height: calc(100vh - 40px);
}
.empty-icon {
  font-size: 32px;
  opacity: 0.35;
}
#empty-state p {
  font-size: 13px;
  line-height: 1.7;
  letter-spacing: 0.03em;
  color: var(--muted);
  opacity: 0.6;
}

/* ── SVG map ─────────────────────────────────────────────── */
#route-map {
  display: none;
  max-width: 100%;
  max-height: calc(100vh - 40px);
  width: auto;
  height: auto;
  /* drop-shadow for depth */
  filter: drop-shadow(0 8px 40px rgba(0,0,0,0.6));
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 640px) {
  html, body {
    overflow: auto;
    height: auto;
  }

  .layout {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 20px 16px 16px;
    gap: 20px;
    overflow: visible;
  }

  /* Let fields grow naturally — no scroll needed when stacked */
  .fields {
    overflow-y: visible;
  }

  .canvas {
    flex: none;
    padding: 16px;
    justify-content: flex-start;
    min-height: 50vh;
  }

  #empty-state {
    width: min(360px, 88vw);
  }

  #route-map {
    max-height: none;
    width: 100%;
    height: auto;
  }

  /* Video player full-width on mobile */
  #video-player-wrap {
    position: static;
    padding: 16px;
  }

  .export-row {
    flex-direction: column;
  }

  .export-size-select {
    width: 100%;
  }
}
