/* Plane Spotter — "Flight Strip" direction.
   The sky is read like a VFR chart and every aircraft gets a paper flight progress strip,
   the way a tower controller tracks it. Strip colour carries meaning:
   pale blue = climbing out, buff = descending, white = level, stone = on the ground. */

:root {
  color-scheme: light;
  --paper: #E6EAE0;      /* chart paper, grey-green lowland tint */
  --paper-2: #D8DFD0;
  --grid: #C9D0C1;
  --ink: #1D2733;        /* chart ink */
  --ink-soft: #56616B;
  --magenta: #A3247A;    /* aeronautical chart magenta */
  --strip: #F7F7F2;      /* level */
  --strip-climb: #D3E3EC;
  --strip-descend: #F1DFA4;
  --strip-ground: #DAD5C8;
  --rule: #1D2733;

  --font: "Archivo", "Helvetica Neue", Arial, system-ui, sans-serif;
  --narrow: 72;          /* font-stretch % for data */
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.5rem;
  --step-3: 2.25rem;
  --radius: 3px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--magenta); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--magenta); }
.fine { font-size: var(--step--1); color: var(--ink-soft); }

/* ---------- buttons ---------- */
.btn {
  display: block; width: 100%;
  min-height: 52px; padding: 0 20px;
  border: 2px solid var(--ink); border-radius: var(--radius);
  font-weight: 700; font-size: var(--step-1); letter-spacing: 0.01em;
  font-stretch: 85%;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:active { background: var(--magenta); border-color: var(--magenta); }
.btn-quiet { background: transparent; color: var(--ink); }
.btn-small { min-height: 44px; font-size: var(--step-0); width: auto; display: inline-block; }

.chip-btn {
  min-height: 36px; padding: 0 12px;
  border: 1.5px solid var(--ink); border-radius: 18px;
  background: var(--strip); font-weight: 600; font-size: var(--step--1); font-stretch: 85%;
}
.chip-btn[aria-pressed="true"] { background: var(--magenta); border-color: var(--magenta); color: #fff; }
.chip-btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: 20px;
  border: 1.5px solid var(--ink); background: var(--strip);
  display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge {
  position: absolute; top: -5px; right: -5px; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 10px; background: var(--magenta); color: #fff; font-size: 11px; font-weight: 700; line-height: 19px; text-align: center;
}

/* ---------- start ---------- */
.start {
  min-height: 100%;
  display: flex; align-items: flex-end;
  padding: calc(32px + var(--safe-t)) 20px calc(28px + var(--safe-b));
  /* chart graticule */
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 100% 64px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 64px 100%,
    var(--paper);
}
.start { position: relative; overflow: hidden; }
.start-inner { position: relative; width: 100%; max-width: 520px; margin: 0 auto; }
.start-demo { position: absolute; inset: 0; pointer-events: none; }
.start-demo .strip-tag { position: absolute; }
.start-demo .demo-a { left: 12%; top: calc(9% + var(--safe-t)); transform: rotate(-3deg); }
.start-demo .demo-b { left: auto; right: 7%; top: calc(22% + var(--safe-t)); transform: rotate(2deg); }
@media (max-height: 700px) { .start-demo { display: none; } }
.start-mark { width: 84px; height: 84px; margin-bottom: 28px; }
.start-mark .ring { fill: none; stroke: var(--magenta); stroke-width: 3; }
.start-mark .ring-in { stroke-width: 1.5; stroke-dasharray: 6 4; }
.start-mark .ticks line { stroke: var(--magenta); stroke-width: 3; }
.start-mark .plane { fill: var(--ink); }
.start h1 {
  margin: 0 0 16px;
  font-size: clamp(3.4rem, 17vw, 6.5rem);
  line-height: 0.88;
  font-weight: 800;
  font-stretch: 62%;
  letter-spacing: -0.01em;
}
.start-lede { font-size: var(--step-1); max-width: 30ch; margin: 0 0 28px; }
.start .btn + .btn { margin-top: 10px; }
.start-fine { font-size: var(--step--1); color: var(--ink-soft); margin: 18px 0 0; max-width: 46ch; }

/* ---------- app shell ---------- */
.app { position: fixed; inset: 0; overflow: hidden; }
.view { position: absolute; inset: 0; z-index: 0; }

.topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + var(--safe-t)) 12px 10px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.place {
  display: flex; flex-direction: column; align-items: flex-start;
  min-width: 0; max-width: 46vw; padding: 5px 12px 6px;
  border: 1.5px solid var(--ink); border-radius: var(--radius);
  background: var(--strip); text-align: left; line-height: 1.15;
}
#place-name { font-weight: 700; font-stretch: 80%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.feed-status { font-size: 12px; color: var(--ink-soft); font-stretch: 85%; }
.feed-status[data-state="bad"] { color: var(--magenta); font-weight: 600; }
.top-actions { display: flex; gap: 8px; align-items: center; }

.tabs {
  position: absolute; left: 12px; right: 12px; bottom: calc(12px + var(--safe-b)); z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  border: 2px solid var(--ink); border-radius: var(--radius);
  background: var(--ink); gap: 2px;
}
.tabs button {
  min-height: 50px; border: 0; background: var(--paper-2);
  font-weight: 700; font-stretch: 80%; font-size: var(--step-1);
}
.tabs button[aria-current="page"] { background: var(--strip); box-shadow: inset 0 -4px 0 var(--magenta); }
.tabs button:disabled { color: var(--ink-soft); background: var(--paper-2); text-decoration: line-through; text-decoration-thickness: 1px; }

/* ---------- banner ---------- */
.banner {
  position: absolute; z-index: 25; left: 12px; right: 12px;
  top: calc(64px + var(--safe-t));
  display: flex; align-items: stretch;
  background: var(--magenta); color: #fff; border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(29, 39, 51, .3);
}
.banner-open { flex: 1; text-align: left; border: 0; background: none; color: inherit; padding: 9px 12px; display: flex; flex-direction: column; line-height: 1.2; }
.banner-k { font-size: 12px; font-weight: 700; opacity: .85; }
.banner-t { font-weight: 700; font-stretch: 85%; font-size: var(--step-0); }
.banner-x { width: 44px; border: 0; border-left: 1px solid rgba(255,255,255,.35); background: none; color: #fff; font-size: 22px; }
.banner-note { margin: 0; padding: 10px 12px; font-weight: 600; font-size: var(--step--1); }
body[data-view="sky"] .banner,
body[data-view="list"] .banner { top: auto; bottom: calc(80px + var(--safe-b)); }

/* ---------- flight strips ---------- */
.strip {
  --strip-bg: var(--strip);
  background: var(--strip-bg);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-stretch: calc(var(--narrow) * 1%);
}
.strip[data-phase="climb"] { --strip-bg: var(--strip-climb); }
.strip[data-phase="descend"] { --strip-bg: var(--strip-descend); }
.strip[data-phase="ground"] { --strip-bg: var(--strip-ground); }

.chip {
  display: inline-grid; place-items: center;
  min-width: 30px; height: 30px; padding: 0 4px;
  background: var(--chip-bg); color: var(--chip-fg);
  border-radius: 2px;
  font-weight: 800; font-size: 13px; font-stretch: 75%; letter-spacing: .02em;
  box-shadow: inset 0 -5px 0 rgba(255,255,255,.18);
  flex: none;
}
.strip-flight { font-weight: 800; font-size: var(--step-1); line-height: 1; font-variant-numeric: tabular-nums; }

/* sky tags */
.view-sky { background: #2B3640; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
#sky-canvas { position: absolute; inset: 0; pointer-events: none; }
.sky-labels { position: absolute; inset: 0; overflow: hidden; }
.strip-tag {
  position: absolute; left: 0; top: 0;
  display: flex; align-items: center; gap: 7px;
  padding: 5px 9px 5px 5px; text-align: left;
  box-shadow: 0 1px 0 rgba(29,39,51,.4), 0 6px 18px rgba(0,0,0,.28);
  will-change: transform;
}
.strip-main { display: grid; grid-template-columns: auto auto; column-gap: 8px; row-gap: 2px; align-items: baseline; }
.strip-tag .strip-flight { grid-column: 1 / -1; }
.strip-route, .strip-alt { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.strip-alt { color: var(--ink-soft); }
.strip-tag.is-kid { padding: 8px 12px 8px 8px; }
.strip-tag.is-kid .chip { min-width: 40px; height: 40px; font-size: 16px; }
.strip-tag.is-kid .strip-flight { font-size: var(--step-2); }
.strip-tag.is-kid .strip-route, .strip-tag.is-kid .strip-alt { font-size: 16px; }
.sky-hint {
  position: absolute; left: 50%; bottom: calc(92px + var(--safe-b)); transform: translateX(-50%);
  margin: 0; padding: 8px 12px; max-width: calc(100% - 32px);
  background: rgba(29,39,51,.82); color: var(--strip); border-radius: var(--radius);
  font-size: var(--step--1); font-weight: 600; text-align: center;
}

/* radar */
#radar-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; }
.radar-controls {
  position: absolute; left: 12px; right: 12px; bottom: calc(80px + var(--safe-b));
  display: flex; gap: 8px; justify-content: space-between; align-items: center; flex-wrap: wrap;
}
.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 18px; overflow: hidden; background: var(--strip); }
.seg button { border: 0; background: none; min-height: 34px; padding: 0 12px; font-weight: 600; font-size: var(--step--1); font-stretch: 85%; }
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* list: a strip bay */
.view-list { overflow-y: auto; padding: calc(70px + var(--safe-t)) 12px calc(96px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.list-head { max-width: 760px; margin: 0 auto 10px; }
.list-head h2 { margin: 0; font-size: var(--step-3); font-stretch: 62%; font-weight: 800; line-height: 1; }
.list-sub { margin: 4px 0 0; color: var(--ink-soft); font-size: var(--step--1); }
.rack { list-style: none; margin: 0 auto; padding: 0; max-width: 760px; display: grid; gap: 4px; }
.strip-row {
  width: 100%; display: grid; align-items: stretch;
  grid-template-columns: 44px minmax(64px, .9fr) minmax(0, 1.4fr) minmax(0, 1.1fr) 68px;
  padding: 0; text-align: left; min-height: 58px;
}
.strip-row .chip { margin: auto; }
.strip-row .cell { display: flex; flex-direction: column; justify-content: center; padding: 6px 8px; border-left: 1px solid var(--rule); min-width: 0; line-height: 1.2; }
.strip-row .cell > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-sub { font-size: 12px; color: var(--ink-soft); }
.cell-route > span:first-child, .cell-num > span:first-child { font-weight: 700; font-variant-numeric: tabular-nums; }
.cell-dist { font-weight: 800; font-variant-numeric: tabular-nums; align-items: flex-end; white-space: nowrap; }
@media (max-width: 420px) {
  .strip-row { grid-template-columns: 40px minmax(64px, 1fr) minmax(0, 1.3fr) 64px; }
  .strip-row .cell-num { display: none; }
}
body.kid .strip-row { min-height: 72px; }
body.kid .strip-row .strip-flight { font-size: var(--step-2); }
body.kid .strip-row .cell-sub { font-size: 14px; color: var(--ink); }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; z-index: 40; background: rgba(29,39,51,.35); }
.sheet {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
  max-height: 88vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  margin: 0 auto; max-width: 640px;
  background: var(--paper); border-top: 2px solid var(--ink);
  border-radius: 10px 10px 0 0;
  padding: 10px 16px calc(24px + var(--safe-b));
  transform: translateY(24px); opacity: 0;
  transition: transform .22s cubic-bezier(.2,.8,.2,1), opacity .18s;
}
.sheet.is-open { transform: none; opacity: 1; }
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--ink-soft); opacity: .5; margin: 0 auto 8px; }
.sheet-close { position: absolute; top: 4px; right: 10px; width: 44px; height: 44px; border: 0; background: none; font-size: 28px; line-height: 1; }
.sheet h2 { font-size: var(--step-2); font-stretch: 70%; font-weight: 800; margin: 6px 48px 6px 0; line-height: 1.1; }
.sheet h3 { font-size: var(--step-1); font-stretch: 80%; font-weight: 700; margin: 22px 0 4px; }
.sheet-lede { margin: 0 0 12px; }

/* detail strip: boxes ruled like a printed strip */
.strip-detail { margin-top: 40px; padding: 0; }
.box { padding: 8px 10px; display: flex; flex-direction: column; min-width: 0; }
.box-k { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.box-v { font-weight: 800; font-size: var(--step-1); font-variant-numeric: tabular-nums; line-height: 1.15; }
.box-v-sm { font-size: var(--step-0); }
.box-s { font-size: 13px; color: var(--ink-soft); }
.box-id { flex-direction: row; gap: 10px; align-items: center; border-bottom: 1px solid var(--rule); }
.box-id .chip { min-width: 44px; height: 44px; font-size: 16px; }
.d-flight { margin: 0 !important; font-size: var(--step-3) !important; font-stretch: 62% !important; line-height: .95 !important; }
.d-op { margin: 2px 0 0; font-size: 14px; }
.d-route { display: grid; grid-template-columns: 1fr 36px 1fr; border-bottom: 1px solid var(--rule); }
.d-route .box-unknown { grid-column: 1 / -1; }
.end-code { font-weight: 800; font-size: 2.6rem; font-stretch: 62%; line-height: 1; }
.end-name { font-weight: 600; font-size: 14px; }
.end-time { font-size: 13px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.d-arrow { position: relative; }
.d-arrow::before { content: ""; position: absolute; left: 4px; right: 8px; top: 50%; border-top: 2px solid var(--ink); }
.d-arrow::after { content: ""; position: absolute; right: 6px; top: calc(50% - 6px); border: 6px solid transparent; border-left: 9px solid var(--ink); border-right: 0; }
.d-stops { margin: 0; padding: 6px 10px; font-size: 13px; border-bottom: 1px solid var(--rule); }
.d-grid { display: grid; grid-template-columns: repeat(2, 1fr); }
.d-grid .box { border-bottom: 1px solid var(--rule); }
.d-grid .box:nth-child(odd) { border-right: 1px solid var(--rule); }
@media (min-width: 560px) {
  .d-grid { grid-template-columns: repeat(3, 1fr); }
  .d-grid .box:nth-child(odd) { border-right: 0; }
  .d-grid .box:not(:nth-child(3n)) { border-right: 1px solid var(--rule); }
}
.d-pass { margin: 0; padding: 8px 10px; font-weight: 700; color: var(--magenta); border-bottom: 1px solid var(--rule); }
.track-map { display: block; width: 100%; height: 190px; border-bottom: 1px solid var(--rule); }
.strip-detail .fine { margin: 0; padding: 8px 10px; }
.kid-says { padding: 10px 12px; background: var(--strip); border-bottom: 1px solid var(--rule); }
.kid-says p { margin: 0 0 4px; font-size: var(--step-1); font-weight: 700; font-stretch: 85%; line-height: 1.25; }
.kid-says p:last-child { margin: 0; }

/* log */
.log-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.log-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 3px; background: var(--strip); border: 1px solid var(--rule); border-radius: 2px; font-size: 13px; font-weight: 600; font-stretch: 85%; }
.log-chip .chip { min-width: 26px; height: 24px; font-size: 11px; }
.log-list { list-style: none; padding: 0; margin: 0 0 16px; }
.log-list li { display: grid; grid-template-columns: auto 1fr auto; column-gap: 12px; padding: 8px 0; border-top: 1px solid var(--grid); font-stretch: 85%; }
.log-flight { font-weight: 800; }
.log-route { font-weight: 600; }
.log-type { grid-column: 1 / 3; font-size: 13px; color: var(--ink-soft); }
.log-list time { grid-row: 1; grid-column: 3; font-size: 12px; color: var(--ink-soft); text-align: right; }

/* place */
.place-form { display: flex; gap: 8px; margin-bottom: 8px; }
.place-form input { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border: 1.5px solid var(--ink); border-radius: var(--radius); background: var(--strip); font-size: 16px; }
.place-results { list-style: none; padding: 0; margin: 0 0 12px; }
.place-results button { width: 100%; text-align: left; padding: 10px 4px; border: 0; border-bottom: 1px solid var(--grid); background: none; font-size: 15px; }

/* about */
.slider { display: block; margin: 10px 0; font-weight: 600; font-size: 14px; }
.slider output { float: right; font-variant-numeric: tabular-nums; }
.slider input { width: 100%; accent-color: var(--magenta); height: 32px; }
.credits { padding-left: 18px; margin: 0; font-size: 14px; }
.credits li { margin-bottom: 6px; }

/* ---------- calibration ---------- */
.calib { position: fixed; inset: 0; z-index: 60; display: grid; place-items: end center; background: rgba(29,39,51,.55); padding: 16px 12px calc(16px + var(--safe-b)); }
.calib-card { width: 100%; max-width: 520px; background: var(--paper); border: 2px solid var(--ink); border-radius: 6px; padding: 18px 16px 16px; }
.calib-card h2 { margin: 0 0 8px; font-size: var(--step-2); font-stretch: 70%; font-weight: 800; }
.calib-steps { margin: 0 0 16px; padding-left: 22px; }
.calib-steps li { margin-bottom: 12px; }
.fig8 { display: block; width: 100%; max-width: 260px; height: auto; margin: 4px 0 6px; overflow: visible; }
.fig8 path { fill: none; stroke: var(--magenta); stroke-width: 2.5; stroke-dasharray: 6 5; }
.fig8-phone {
  fill: var(--ink);
  offset-path: path("M100 50 C 130 10, 190 10, 190 50 S 130 90, 100 50 S 10 10, 10 50 S 70 90, 100 50");
  offset-rotate: auto 90deg;
  animation: fig8 3.2s linear infinite;
}
@keyframes fig8 { to { offset-distance: 100%; } }

@media (prefers-reduced-motion: reduce) {
  .fig8-phone { animation: none; offset-distance: 12%; }
  .sheet { transition: none; }
}
