:root {
  color-scheme: light dark;
  --bg: #f4f1ea;
  --card: #fffdf8;
  --ink: #1d1b18;
  --dim: #6a655c;
  --line: #e3ded3;
  --track: #e3ded3;
  --accent: #4b4fd6;
  --on-accent: #ffffff;
  --bad: #b3311f;
  --now: #d93a2b;
  /* what each kind of advice is drawn in */
  --c-light: #f6b93b;
  --c-shade: #2c3140;
  --on-shade: #ffffff;
  --c-sleep: #4b4fd6;
  --c-caffeine: #8a5a2b;
  --c-melatonin: #0d8577;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f14;
    --card: #171b23;
    --ink: #eceef2;
    --dim: #9aa2af;
    --line: #272d39;
    --track: #232935;
    --accent: #9296ff;
    --on-accent: #0d0f14;
    --bad: #ff8a7a;
    --now: #ff6b5c;
    --c-light: #ffc24a;
    --c-shade: #7c869e;
    --on-shade: #0d0f14;
    --c-sleep: #6f73f2;
    --c-caffeine: #a9743f;
    --c-melatonin: #17a392;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  background: var(--bg); color: var(--ink);
  font: 16px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
.pane { position: relative; flex: 1; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior: none; touch-action: pan-y; outline: none; }
.view { max-width: 560px; margin: 0 auto; padding: 0 16px 32px; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon { flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 12px; background: none; }
.icon:active { background: var(--line); }

/* ---- trip form ---- */
.bar { display: flex; justify-content: space-between; min-height: 16px; padding-top: 6px; margin: 0 -8px; }
.bar .sure { width: auto; padding: 0 16px; margin-left: auto; background: var(--bad); color: var(--bg); font-weight: 600; }
#remove { margin-left: auto; }
.card { margin-top: 12px; padding: 0 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--card); }
.bar + .card { margin-top: 0; }
.line { display: flex; align-items: center; gap: 10px; min-height: 58px; border-top: 1px solid var(--line); }
.line:first-child { border-top: 0; }
.name { flex: none; width: 88px; color: var(--dim); font-size: 15px; }
.line input:not(.switch):not([type='radio']) {
  flex: 1; min-width: 0; height: 44px; margin: 0; padding: 0 8px; border: 0; border-radius: 10px;
  background: transparent; color: var(--ink); font: inherit; font-variant-numeric: tabular-nums;
  -webkit-appearance: none; appearance: none; text-align: left;
}
.line input::-webkit-date-and-time-value { text-align: left; }
.line input::placeholder { color: var(--dim); opacity: .75; }
/* An empty date field is blank on iPhone and "mm/dd/yyyy" elsewhere: show a calendar instead until it has a value. */
.line input[data-empty]:not(.switch):not([type='radio']) { color: transparent; background: var(--cal) 8px center / 20px 20px no-repeat; }
.line input[data-empty]:not(.switch):not([type='radio']):focus { color: var(--ink); background-image: none; }
.line input[data-empty]::-webkit-calendar-picker-indicator { opacity: 0; }
[aria-invalid='true'] { box-shadow: inset 0 0 0 2px var(--bad); }
.code { flex: 1; min-width: 0; display: flex; align-items: center; }
.code input { text-transform: uppercase; }
.code input::placeholder { text-transform: none; }
.code i { flex: none; width: 20px; height: 20px; margin-left: 6px; }
.code i.busy { border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: turn .8s linear infinite; }
.code i.ok { background: var(--c-melatonin); -webkit-mask: var(--tick) center / contain no-repeat; mask: var(--tick) center / contain no-repeat; }
:root { --cal: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238d8a84' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3.5' y='5' width='17' height='15.5' rx='3'/%3E%3Cpath d='M3.5 10h17M8 3v4M16 3v4'/%3E%3C/svg%3E"); --tick: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E"); --lens: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5L21 21'/%3E%3C/svg%3E"); }
@keyframes turn { to { transform: rotate(360deg); } }
.place { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 8px; border: 0; border-radius: 10px; background: none; text-align: left; }
.place b { flex: none; font-weight: 700; letter-spacing: .02em; }
.place span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--dim); }
.place:empty::before { content: ''; width: 20px; height: 20px; background: var(--dim); -webkit-mask: var(--lens) center / contain no-repeat; mask: var(--lens) center / contain no-repeat; }
.length { margin: -3px 0 0; padding: 0 0 12px 106px; color: var(--dim); font-size: 14px; font-variant-numeric: tabular-nums; }
.length.bad { color: var(--bad); }
.pair { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; color: var(--dim); }
.pair input { flex: 0 1 7.4em !important; width: 0; padding: 0 6px !important; }
.pair input::-webkit-calendar-picker-indicator { display: none; }

.seg { display: flex; gap: 2px; padding: 3px; border-radius: 13px; background: var(--bg); margin-left: auto; }
.seg.wide { flex: 1; margin: 7px 0; }
.seg label { position: relative; flex: 1; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span { display: grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0 10px; border-radius: 10px; color: var(--dim); font-size: 15px; white-space: nowrap; }
.seg input:checked + span { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .16); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.switch { -webkit-appearance: none; appearance: none; flex: none; position: relative; width: 52px; height: 32px; margin: 0 0 0 auto; border-radius: 16px; background: var(--track); cursor: pointer; transition: background .15s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

.go { display: block; width: 100%; min-height: 54px; margin-top: 16px; border: 0; border-radius: 16px; background: var(--ink); color: var(--bg); font-size: 17px; font-weight: 650; }
.go:active { opacity: .85; }

/* ---- plan ---- */
.head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 2px; margin: 0 -8px 0 0; padding: 10px 0 8px; background: var(--bg); }
.title { flex: 1; min-width: 0; display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 12px; }
h1 { margin: 0; font-size: 27px; font-weight: 750; letter-spacing: -.01em; white-space: nowrap; }
#meta { margin: 0; color: var(--dim); font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.trips { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0 6px; }
.trips button { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; min-height: 46px; padding: 4px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); line-height: 1.2; font-weight: 600; }
.trips small { color: var(--dim); font-size: 12px; font-weight: 400; }
.trips [aria-current] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

.days { list-style: none; margin: 0; padding: 0; }
.day { margin-top: 20px; }
.days > :first-child { margin-top: 6px; }
.day-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 2px; }
.day-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.day-head span { color: var(--dim); font-size: 13px; font-weight: 650; letter-spacing: .05em; }
.strip { position: relative; height: 10px; margin: 8px 0; }
.bars { position: absolute; inset: 0; overflow: hidden; border-radius: 5px; background: var(--track); }
.bars i { position: absolute; top: 0; bottom: 0; }
.bars .sleep, .bars .nap { background: var(--c-sleep); }
.bars .light { background: var(--c-light); }
.bars .dark { background: var(--c-shade); }
.bars .air { top: auto; height: 3px; background: var(--ink); }
.bars .off { background: var(--bg); }
.needle { position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1.5px; border-radius: 2px; background: var(--now); box-shadow: 0 0 0 2px var(--bg); }

.rows { list-style: none; margin: 0; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.row { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 8px 14px 8px 10px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.ico { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px; color: #fff; }
.row.light .ico { background: var(--c-light); color: #1d1b18; }
.row.dark .ico { background: var(--c-shade); color: var(--on-shade); }
.row.sleep .ico { background: var(--c-sleep); }
.row.nap .ico { background: color-mix(in srgb, var(--c-sleep) 20%, var(--card)); color: var(--accent); }
.row.caffeine .ico { background: var(--c-caffeine); }
.row.melatonin .ico { background: var(--c-melatonin); }
.what { flex: 1; min-width: 0; font-weight: 600; }
.what small { margin-left: 8px; color: var(--dim); font-size: 14px; font-weight: 400; white-space: nowrap; }
.when { flex: none; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row.past { color: var(--dim); }
.row.past .ico { filter: grayscale(1); opacity: .45; }
.row.past .what { font-weight: 400; }
.row.now { background: color-mix(in srgb, var(--now) 9%, var(--card)); box-shadow: inset 3px 0 0 var(--now); }

.leg { display: flex; align-items: center; gap: 12px; margin-top: 20px; padding: 12px 18px; border-radius: 16px; background: var(--ink); color: var(--bg); }
.leg .end { flex: none; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.leg .end:last-child { align-items: flex-end; }
.leg .end b { font-size: 20px; font-weight: 750; letter-spacing: .03em; }
.leg .end span { font-size: 14px; }
.leg .path { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; }
.leg .path .ico { width: 100%; height: 24px; border-radius: 0; color: inherit; background: linear-gradient(currentColor, currentColor) left center / calc(50% - 20px) 1.5px no-repeat, linear-gradient(currentColor, currentColor) right center / calc(50% - 20px) 1.5px no-repeat; }
.leg .path svg { transform: rotate(45deg); }
.leg .path small { font-size: 13px; font-weight: 600; letter-spacing: .04em; }
.leg.past { background: var(--track); color: var(--ink); }
.leg.now { box-shadow: 0 0 0 3px var(--now); }

/* ---- airport search ---- */
#finder { width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; padding: 0; border: 0; background: var(--bg); color: var(--ink); overflow: hidden; overscroll-behavior: none; }
#finder::backdrop { background: rgba(0, 0, 0, .5); }
.finder { display: flex; flex-direction: column; height: 100%; max-width: 560px; margin: 0 auto; }
.finder-bar { flex: none; display: flex; align-items: center; gap: 4px; padding: 10px 8px 10px 16px; }
#q { flex: 1; min-width: 0; height: 48px; padding: 0 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); font: inherit; -webkit-appearance: none; appearance: none; }
#q::placeholder { color: var(--dim); opacity: .8; }
#q::-webkit-search-cancel-button { display: none; }
.results { flex: 1; min-height: 0; margin: 0; padding: 0 16px 28px; list-style: none; overflow-x: hidden; overflow-y: auto; overscroll-behavior: none; touch-action: pan-y; outline: none; }
.results li + li { border-top: 1px solid var(--line); }
.results button { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 60px; padding: 8px 4px; border: 0; background: none; text-align: left; }
.results b { flex: none; width: 46px; font-size: 17px; font-weight: 700; letter-spacing: .02em; }
.results span { min-width: 0; display: flex; flex-direction: column; }
.results small { color: var(--dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .none { padding: 28px 4px; color: var(--dim); text-align: center; }
.results .none button { display: inline-flex; width: auto; min-height: 46px; padding: 0 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); font-weight: 600; }
.results .spin { display: grid; place-items: center; padding: 32px; }
.results .spin i { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: turn .8s linear infinite; }
@media (min-width: 700px) {
  #finder { width: 520px; height: min(640px, 82dvh); margin: auto; border: 1px solid var(--line); border-radius: 22px; }
  .view { padding-top: 16px; }
}

/* ---- the shared install prompt, in this app's colours ---- */
install-prompt {
  --ip-bg: var(--card); --ip-fg: var(--ink); --ip-muted: var(--dim); --ip-line: var(--line); --ip-chip: var(--bg);
  --ip-accent: var(--accent); --ip-on-accent: var(--on-accent); --ip-arrow: var(--accent); --ip-arrow-outline: var(--card);
  --ip-radius: 22px; --ip-radius-inner: 12px; --ip-card-border: 1px solid var(--line);
}
