/* ------------------------------------------------------------------ *
 * Sundial — design system
 * Light-first, dawn-inspired. One coherent palette; semantic colors for
 * the timeline segments (amber = light, indigo = sleep, ...).
 * ------------------------------------------------------------------ */
:root {
  /* Surfaces & ink */
  --bg: #fbf7f0;
  --bg-grad-1: #fff4e6;
  --bg-grad-2: #f3f0ff;
  --surface: #ffffff;
  --surface-2: #f7f4fb;
  --ink: #1f2440;
  --ink-2: #4a5170;
  --muted: #8b90a8;
  --line: #e9e5f0;
  --line-strong: #d9d3e6;

  /* Brand — sunrise */
  --accent: #ff7a4d;
  --accent-2: #ffb547;
  --accent-ink: #b23c17;
  --accent-grad: linear-gradient(120deg, #ff8a5b 0%, #ffb547 100%);

  /* Segment (semantic) colors */
  --c-sleep: #4756b0;
  --c-sleep-soft: #e5e8f7;
  --c-nap: #8b93d6;
  --c-seek: #f4a413;
  --c-seek-soft: #fdeccb;
  --c-avoid: #5b6685;
  --c-meal: #10a06b;
  --c-caffeine: #a56a43;
  --c-melatonin: #8b5cf6;
  --c-flight: #98a2b6;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(31, 36, 64, .04), 0 12px 32px -12px rgba(31, 36, 64, .18);
  --shadow-sm: 0 1px 2px rgba(31, 36, 64, .05), 0 6px 16px -10px rgba(31, 36, 64, .16);
  --font-body: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14131c;
    --bg-grad-1: #1c1826;
    --bg-grad-2: #141726;
    --surface: #1e1c2a;
    --surface-2: #262433;
    --ink: #ecebf5;
    --ink-2: #b7b6cc;
    --muted: #86849c;
    --line: #302d3f;
    --line-strong: #3b3850;
    --c-sleep: #7684e0;
    --c-sleep-soft: #2a2e4d;
    --c-nap: #9aa2e6;
    --c-seek: #f7b43a;
    --c-seek-soft: #3a3115;
    --c-avoid: #8993b5;
    --c-meal: #2bc088;
    --c-caffeine: #c78a5f;
    --c-melatonin: #a888f7;
    --c-flight: #8b95ab;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 16px 40px -16px rgba(0,0,0,.6);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3), 0 8px 20px -12px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 15% -10%, var(--bg-grad-1), transparent 60%),
    radial-gradient(1000px 700px at 100% 0%, var(--bg-grad-2), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; line-height: 1.15; }
.muted { color: var(--muted); font-weight: 400; }
a { color: inherit; }

/* ---------------- Top bar ---------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px clamp(18px, 5vw, 56px);
  max-width: 1120px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; font-weight: 700; }
.brand-mark {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent-grad); color: #fff; font-size: 20px;
  box-shadow: 0 6px 16px -6px var(--accent);
}
.brand-name { font-family: var(--font-display); font-size: 20px; }
.topbar-link { text-decoration: none; color: var(--ink-2); font-weight: 500; font-size: 14px; }
.topbar-link:hover { color: var(--ink); }

/* ---------------- Layout ---------------- */
main { max-width: 1120px; margin: 0 auto; padding: 0 clamp(18px, 5vw, 56px) 80px; }

.hero { text-align: center; max-width: 720px; margin: clamp(24px, 6vw, 64px) auto clamp(28px, 5vw, 44px); }
.hero h1 { font-size: clamp(32px, 6vw, 54px); margin: 0 0 18px; }
.lede { font-size: clamp(16px, 2.2vw, 19px); color: var(--ink-2); margin: 0 auto; max-width: 620px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: clamp(20px, 3vw, 32px);
}

/* ---------------- Form ---------------- */
.planner { max-width: 760px; margin: 0 auto; }
.field-grid { display: grid; gap: 16px; margin-bottom: 16px; }
.field-grid.two { grid-template-columns: 1fr 1fr; }
.field-airport { position: relative; }
.field-grid:not(.two) { grid-template-columns: 1fr auto 1fr; align-items: end; }

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
input[type=text], input[type=datetime-local], input[type=time] {
  font-family: inherit; font-size: 15px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); padding: 12px 14px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 122, 77, .18); }
input::placeholder { color: var(--muted); }

.swap {
  align-self: end; margin-bottom: 4px; width: 40px; height: 40px; flex: none;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  border-radius: 50%; font-size: 17px; cursor: pointer; transition: transform .2s, color .15s;
}
.swap:hover { color: var(--accent); transform: rotate(180deg); }

/* Airport type-ahead */
.airport-menu {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); overflow: hidden; max-height: 320px; overflow-y: auto;
}
.airport-opt { display: flex; align-items: baseline; gap: 10px; padding: 10px 14px; cursor: pointer; }
.airport-opt:hover, .airport-opt.active { background: var(--surface-2); }
.airport-opt .code {
  font-weight: 700; font-size: 13px; color: var(--accent-ink);
  background: var(--c-seek-soft); border-radius: 6px; padding: 2px 7px; letter-spacing: .02em;
}
.airport-opt .city { font-weight: 600; }
.airport-opt .sub { color: var(--muted); font-size: 13px; margin-left: auto; text-align: right; }

.advanced { margin: 4px 0 20px; border-top: 1px solid var(--line); padding-top: 8px; }
.advanced summary { cursor: pointer; font-weight: 600; font-size: 14px; padding: 10px 0; color: var(--ink-2); list-style: none; }
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before { content: '＋'; color: var(--accent); margin-right: 8px; font-weight: 700; }
.advanced[open] summary::before { content: '－'; }
.advanced-body { display: flex; flex-direction: column; gap: 18px; padding: 6px 0 4px; }
.hint { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
input[type=range] { accent-color: var(--accent); }

.field-preadapt { margin-bottom: 16px; }
.field-preadapt #preadapt-val { color: var(--accent-ink); font-weight: 600; }
.range-scale {
  display: flex; justify-content: space-between; margin-top: 4px;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.range-scale span { flex: 1; text-align: center; line-height: 1.3; }
.range-scale span:first-child { text-align: left; }
.range-scale span:last-child { text-align: right; }
.range-scale small { font-weight: 500; color: var(--muted); font-size: 10.5px; }
.checkbox { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; cursor: pointer; }
.checkbox input { margin-top: 3px; accent-color: var(--accent); width: 16px; height: 16px; }

.submit {
  width: 100%; border: none; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--accent-grad); color: #fff; font-family: inherit; font-weight: 600;
  font-size: 16px; padding: 15px; box-shadow: 0 10px 24px -10px var(--accent);
  transition: transform .12s, box-shadow .2s;
}
.submit:hover { transform: translateY(-1px); box-shadow: 0 14px 30px -10px var(--accent); }
.submit:active { transform: translateY(0); }
.submit[disabled] { opacity: .65; cursor: wait; }
.form-error { color: #d64545; font-size: 14px; margin: 12px 0 0; text-align: center; }

.examples { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; margin-top: 20px; font-size: 13px; }
.example {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  border-radius: 999px; padding: 7px 14px; font-family: inherit; font-size: 13px; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.example:hover { border-color: var(--accent); color: var(--accent-ink); }

/* ---------------- Results ---------------- */
.results { margin-top: clamp(36px, 6vw, 60px); scroll-margin-top: 20px; }
.results[hidden] { display: none; }

.summary-card { margin-bottom: 28px; }
.route { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.route .ap { display: flex; flex-direction: column; }
.route .ap .code { font-family: var(--font-display); font-size: 26px; font-weight: 600; }
.route .ap .city { font-size: 13px; color: var(--muted); }
.route .arrow { color: var(--accent); font-size: 22px; }
.route .planes { flex: 1; height: 1px; background: repeating-linear-gradient(90deg, var(--line-strong) 0 6px, transparent 6px 12px); min-width: 30px; }

.headline { font-size: clamp(19px, 2.6vw, 24px); font-family: var(--font-display); margin: 16px 0 4px; }
.headline .twist { color: var(--accent-ink); }

.stat-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 20px 0 4px; }
.stat {
  flex: 1; min-width: 130px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 14px 16px;
}
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 700; font-family: var(--font-display); margin-top: 2px; }
.stat .v small { font-size: 14px; font-weight: 500; color: var(--ink-2); }

.tips { list-style: none; padding: 0; margin: 20px 0 0; display: flex; flex-direction: column; gap: 10px; }
.tips li { display: flex; gap: 10px; font-size: 14.5px; color: var(--ink-2); }
.tips li::before { content: '→'; color: var(--accent); font-weight: 700; }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 24px 0 8px; padding: 14px 16px; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--line); }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }

/* ---------------- Timeline ---------------- */
.timeline { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.tl-axis { display: grid; grid-template-columns: var(--label-w, 150px) 1fr; align-items: center; position: sticky; top: 0; z-index: 5; }
.tl-axis .ticks { position: relative; height: 20px; }
.tl-axis .tick { position: absolute; transform: translateX(-50%); font-size: 11px; color: var(--muted); top: 3px; }

.day {
  display: grid; grid-template-columns: var(--label-w, 150px) 1fr; gap: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.day.phase-flight { border-color: var(--c-flight); }
.day.phase-destination { border-left: 3px solid var(--c-seek); }

.day-label { padding: 12px 14px; border-right: 1px solid var(--line); background: var(--surface-2); display: flex; flex-direction: column; gap: 2px; justify-content: center; }
.day-label .date { font-weight: 700; font-size: 14px; }
.day-label .rel { font-size: 12px; color: var(--accent-ink); font-weight: 600; }
.day-label .tz { font-size: 11px; color: var(--muted); }
.day-label .dh { font-size: 11.5px; color: var(--ink-2); margin-top: 4px; line-height: 1.35; }

.track { position: relative; height: 78px; background:
  repeating-linear-gradient(90deg, transparent 0, transparent calc(100%/24 - 1px), var(--line) calc(100%/24 - 1px), var(--line) calc(100%/24));
}
.seg { position: absolute; border-radius: 5px; display: flex; align-items: center; overflow: hidden; cursor: default; box-shadow: 0 1px 2px rgba(31,36,64,.12); }
/* Height/vertical position comes from the lane (or seg-flight), declared after
   .seg so equal-specificity rules win in source order. */
.seg.lane-light { top: 6px; height: 20px; }
.seg.lane-sleep { top: 29px; height: 20px; }
.seg.lane-fuel  { top: 52px; height: 20px; }
.seg .ic { font-size: 11px; padding-left: 4px; line-height: 1; filter: saturate(1.1); }
.seg-sleep { background: var(--c-sleep); }
.seg-nap { background: var(--c-nap); border: 1px dashed rgba(255,255,255,.5); }
.seg-seek_light { background: var(--c-seek); }
.seg-avoid_light { background: var(--c-avoid); background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.16) 0 3px, transparent 3px 7px); }
.seg-meal { background: var(--c-meal); }
.seg-caffeine { background: var(--c-caffeine); opacity: .9; }
.seg-melatonin { background: var(--c-melatonin); }
.seg-flight { background: var(--c-flight); background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.22) 0 5px, transparent 5px 11px); top: 6px; height: 66px; border-radius: 6px; }
.seg:hover { z-index: 8; box-shadow: 0 3px 10px rgba(31,36,64,.28); outline: 2px solid var(--surface); }

/* Tooltip */
.tt {
  position: fixed; z-index: 100; pointer-events: none; max-width: 260px;
  background: var(--ink); color: #fff; border-radius: 10px; padding: 10px 12px;
  font-size: 12.5px; line-height: 1.4; box-shadow: 0 12px 30px -8px rgba(0,0,0,.5);
  opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s;
}
.tt.show { opacity: 1; transform: translateY(0); }
.tt .tt-t { font-weight: 700; margin-bottom: 2px; }
.tt .tt-time { color: #ffd9b0; font-weight: 600; font-size: 11.5px; }

/* Methodology */
#methodology { margin-top: 22px; }
.method-h { font-weight: 700; font-size: 14px; margin: 18px 0 8px; }
.cites { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.cite { font-size: 13px; color: var(--ink-2); }
.cite a { color: var(--accent-ink); text-decoration: none; font-weight: 600; }
.cite a:hover { text-decoration: underline; }
.cite .j { color: var(--muted); font-style: italic; }
.caveats { padding-left: 18px; margin: 6px 0 0; font-size: 13px; color: var(--ink-2); }
.caveats li { margin-bottom: 6px; }

/* ---------------- Footer ---------------- */
footer { max-width: 760px; margin: 0 auto; padding: 30px clamp(18px,5vw,56px) 60px; text-align: center; font-size: 13px; color: var(--ink-2); }
footer p { margin: 6px 0; }

.how { max-width: 820px; margin: clamp(40px,7vw,72px) auto 0; }
.how h2 { font-size: clamp(22px, 3vw, 30px); margin: 0 0 14px; }
.how p { color: var(--ink-2); }

/* Loading shimmer */
.loading { text-align: center; padding: 40px; color: var(--muted); }
.spinner { width: 30px; height: 30px; border: 3px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 14px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Saved trips (landing) ---------------- */
.saved-trips { margin-top: 22px; }
.saved-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.saved-head h2 { font-size: 18px; margin: 0; }
.saved-head .muted { font-size: 13px; }
.saved-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.saved-card {
  position: relative; display: flex;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-sm);
}
.saved-open {
  flex: 1; display: flex; flex-direction: column; gap: 3px; text-align: left;
  background: none; border: 0; cursor: pointer; font-family: inherit;
  padding: 13px 40px 13px 15px; color: var(--ink); border-radius: var(--radius-sm);
}
.saved-open:hover { background: var(--surface-2); }
.saved-route { font-weight: 700; font-size: 15px; letter-spacing: .01em; }
.saved-route .saved-arr { color: var(--accent); }
.saved-cities { font-size: 12.5px; }
.saved-date { font-size: 12px; color: var(--accent-ink); font-weight: 600; }
.saved-del {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px;
  border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1;
  border-radius: 7px; cursor: pointer;
}
.saved-del:hover { background: var(--surface-2); color: var(--accent-ink); }

/* ---------------- Save / share bar (results) ---------------- */
.actions-card { display: flex; flex-direction: column; gap: 14px; }
.actions-head { display: flex; flex-direction: column; gap: 3px; }
.actions-head strong { font-size: 16px; font-family: var(--font-display); font-weight: 600; }
.actions-head .muted { font-size: 13px; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: stretch; }
.link-field {
  flex: 1 1 220px; min-width: 0; font-family: inherit; font-size: 13px; color: var(--ink-2);
  padding: 11px 13px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.link-field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,122,77,.18); }
.act-btn {
  flex: 0 0 auto; cursor: pointer; font-family: inherit; font-weight: 600; font-size: 14px;
  padding: 11px 15px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); white-space: nowrap; transition: all .15s;
}
.act-btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.act-save.is-saved { background: var(--accent-grad); color: #fff; border-color: transparent; }
.act-save.is-saved:hover { color: #fff; filter: brightness(1.03); }

.offline-note {
  background: var(--c-seek-soft); color: var(--accent-ink);
  border: 1px solid var(--accent-2); border-radius: var(--radius-sm);
  padding: 11px 14px; font-size: 13px; font-weight: 500; margin-bottom: 4px;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; font-size: 13.5px; font-weight: 500;
  padding: 12px 18px; border-radius: 999px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- Responsive ---------------- */
@media (max-width: 640px) {
  .field-grid.two { grid-template-columns: 1fr; }
  .field-grid:not(.two) { grid-template-columns: 1fr; }
  .swap { justify-self: center; transform: rotate(90deg); margin: -6px 0; }
  .swap:hover { transform: rotate(270deg); }
  .day { grid-template-columns: 1fr; }
  .day-label { border-right: none; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; }
  .day-label .dh { flex-basis: 100%; }
  .tl-axis { grid-template-columns: 1fr; }
  .tl-axis .label-spacer { display: none; }
  :root { --label-w: 0px; }
  .actions-row .act-btn { flex: 1 1 auto; }
  .saved-list { grid-template-columns: 1fr; }
}
