:root {
  --bg: #080b10;
  --panel: #0f141c;
  --panel-2: #141b25;
  --line: #1e2834;
  --text: #e9eef4;
  --dim: #8796a8;
  --faint: #56637a;
  --amber: #ffb340;
  --amber-soft: rgba(255, 179, 64, 0.14);
  --cyan: #5cc8f0;
  --cyan-soft: rgba(92, 200, 240, 0.12);
  --green: #5bd17a;
  --red: #ff5f56;
  --violet: #a78bfa;
  --radius: 0.9rem;
  /* One unit that scales with the screen: everything is sized in rem. */
  font-size: min(1.02vw, 1.85vh);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body {
  font-family: "Inter", "SF Pro Display", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-feature-settings: "tnum" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
}
body.idle, body.idle * { cursor: none !important; }
body.setting-up #shift { visibility: hidden; }
button { font: inherit; color: inherit; }
body.night #shift { filter: brightness(0.62) saturate(0.85); }
#shift { height: 100%; display: flex; flex-direction: column; padding: 1rem 1.2rem 1.2rem; gap: 1rem; transition: transform 2s ease, filter 4s ease; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 2rem; min-height: 3rem; }
.brand { display: flex; align-items: baseline; gap: 0.8rem; min-width: 0; flex-shrink: 1; }
.brand-name { font-weight: 700; font-size: 1.6rem; letter-spacing: 0.02em; }
.brand-place { color: var(--dim); font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.live { width: 0.8rem; height: 0.8rem; border-radius: 50%; background: var(--faint); align-self: center; }
.live.ok { background: var(--green); box-shadow: 0 0 0.6rem var(--green); animation: breathe 3s ease-in-out infinite; }
.live.bad { background: var(--red); }
@keyframes breathe { 50% { opacity: 0.45; } }
.wx { flex: 1; display: flex; justify-content: center; gap: 0.3rem 1.6rem; color: var(--dim); font-size: 1.15rem; flex-wrap: wrap; white-space: nowrap; }
.wx b { color: var(--text); font-weight: 600; }
.wx .cat { padding: 0.1rem 0.55rem; border-radius: 0.4rem; font-weight: 700; color: #0b0f14; font-size: 0.95rem; }
.cat.VFR { background: var(--green); } .cat.MVFR { background: var(--cyan); } .cat.IFR { background: var(--red); } .cat.LIFR { background: #e061e0; }
.clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
#time { font-size: 2rem; font-weight: 600; }
#date { color: var(--dim); font-size: 1rem; }
.gear { background: none; border: 0; padding: 0.3rem; color: var(--faint); cursor: pointer; width: 2.6rem; height: 2.6rem; flex: none; border-radius: 50%; transition: color 0.3s, opacity 0.6s; }
.gear svg { width: 100%; height: 100%; }
.gear:hover, .gear:focus-visible { color: var(--text); }
body.idle .gear { opacity: 0.25; }

/* ---------- layout ---------- */
.grid {
  flex: 1; min-height: 0;
  display: grid; gap: 1rem;
  grid-template-columns: repeat(12, 1fr);
  grid-template-rows: 1.65fr 1fr;
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; min-width: 0; min-height: 0; overflow: hidden; }
.hero { grid-column: 1 / 8; grid-row: 1; display: flex; flex-direction: column; gap: 0.9rem; position: relative; }
.radar { grid-column: 8 / 13; grid-row: 1; padding: 0; position: relative; }
.recent { grid-column: 1 / 6; grid-row: 2; }
.upcoming { grid-column: 6 / 9; grid-row: 2; }
.stats { grid-column: 9 / 13; grid-row: 2; }
h2 { margin: 0 0 0.7rem; font-size: 0.95rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.h-sub { letter-spacing: 0; text-transform: none; color: var(--faint); font-weight: 500; margin-left: 0.4rem; }

/* ---------- hero ---------- */
.hero-banner { display: flex; align-items: center; gap: 0.8rem; font-size: 1.05rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--dim); }
.hero-banner .pill { padding: 0.35rem 0.8rem; border-radius: 99rem; background: var(--panel-2); border: 1px solid var(--line); }
.hero.overhead { border-color: rgba(255, 179, 64, 0.55); box-shadow: 0 0 0 1px rgba(255, 179, 64, 0.25), 0 0 3rem rgba(255, 179, 64, 0.08) inset; }
.hero.overhead .hero-banner .pill { background: var(--amber); color: #1a1205; border-color: var(--amber); animation: glow 1.6s ease-in-out infinite; }
.hero.incoming .hero-banner .pill { background: var(--cyan-soft); color: var(--cyan); border-color: rgba(92, 200, 240, 0.4); }
.hero.emergency { border-color: var(--red); }
.hero.emergency .hero-banner .pill { background: var(--red); color: #fff; }
@keyframes glow { 50% { box-shadow: 0 0 1.2rem rgba(255, 179, 64, 0.65); } }
.countdown { font-size: 1.05rem; color: var(--text); letter-spacing: 0.04em; }

.hero-body { display: grid; grid-template-columns: 42% 1fr; gap: 1.4rem; flex: 1; min-height: 0; overflow: hidden; }
.photo { margin: 0; position: relative; border-radius: 0.7rem; overflow: hidden; background: var(--panel-2); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; min-height: 0; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity 0.8s ease; }
.photo img.loaded { opacity: 1; }
.photo figcaption { position: absolute; left: 0; right: 0; bottom: 0; padding: 1.4rem 0.7rem 0.45rem; font-size: 0.8rem; color: #c9d3de; background: linear-gradient(transparent, rgba(0,0,0,0.75)); }
.photo .silhouette { width: 62%; opacity: 0.22; color: var(--dim); }

.ident { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; min-height: 0; overflow: hidden; }
.callsign { font-size: 3.9rem; font-weight: 800; letter-spacing: -0.01em; line-height: 0.95; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.operator { font-size: 1.45rem; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actype { font-size: 1.25rem; color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.chip { font-size: 0.85rem; padding: 0.2rem 0.6rem; border-radius: 0.4rem; background: var(--panel-2); border: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
.chip.amber { color: var(--amber); border-color: rgba(255,179,64,0.4); background: var(--amber-soft); }
.chip.cyan { color: var(--cyan); border-color: rgba(92,200,240,0.4); background: var(--cyan-soft); }
.chip.red { color: #fff; background: var(--red); border-color: var(--red); }
.chip.violet { color: var(--violet); border-color: rgba(167,139,250,0.4); }

.route { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 0.8rem; margin-top: 0.3rem; padding: 0.7rem 0.9rem; background: var(--panel-2); border: 1px solid var(--line); border-radius: 0.7rem; }
.route .end { min-width: 0; }
.route .end.right { text-align: right; }
.route .code { font-size: 2.1rem; font-weight: 700; line-height: 1; }
.route .city { font-size: 0.95rem; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route .arrow { color: var(--faint); font-size: 1.6rem; }

.phase { display: flex; align-items: center; gap: 1rem; padding: 0.7rem 0.9rem; border-radius: 0.7rem; background: var(--panel-2); border: 1px solid var(--line); }
.phase-label { font-size: 1.3rem; font-weight: 600; }
.phase-detail { color: var(--dim); font-size: 1rem; }
.phase.final { border-color: rgba(91, 209, 122, 0.4); }
.phase.departure { border-color: rgba(92, 200, 240, 0.4); }
.glide { width: 1.4rem; height: 4.2rem; position: relative; flex: none; }
.glide::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: var(--line); transform: translateX(-50%); }
.glide i { position: absolute; left: 50%; width: 0.7rem; height: 2px; background: var(--faint); transform: translateX(-50%); }
.glide b { position: absolute; left: 50%; width: 0.9rem; height: 0.9rem; background: var(--green); transform: translate(-50%, -50%) rotate(45deg); border-radius: 2px; transition: top 1s ease; }

.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 0.6rem; }
.tile { background: var(--panel-2); border: 1px solid var(--line); border-radius: 0.7rem; padding: 0.5rem 0.9rem; min-width: 0; }
.tile .k { font-size: 0.78rem; color: var(--dim); letter-spacing: 0.1em; text-transform: uppercase; }
.tile .v { font-size: 1.75rem; font-weight: 700; line-height: 1.15; white-space: nowrap; display: flex; align-items: center; gap: 0.35rem; }
.tile .v small { font-size: 1rem; font-weight: 500; color: var(--dim); }
.tile .s { font-size: 0.9rem; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdg-arrow { width: 1.5rem; height: 1.5rem; transition: transform 1s ease; color: var(--cyan); flex: none; }

.quiet { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--dim); gap: 0.6rem; text-align: center; }
.quiet .big { font-size: 2.6rem; color: var(--text); font-weight: 700; }

/* ---------- radar ---------- */
#radar { width: 100%; height: 100%; display: block; }
.radar-legend { position: absolute; left: 0.9rem; bottom: 0.7rem; display: flex; gap: 0.25rem; align-items: center; font-size: 0.75rem; color: var(--dim); }
.radar-legend .bar { width: 7rem; height: 0.4rem; border-radius: 1rem; }

/* ---------- lists ---------- */
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.row { display: grid; align-items: center; gap: 0.8rem; padding: 0.45rem 0.7rem; border-radius: 0.55rem; background: var(--panel-2); border: 1px solid transparent; }
.row .main { min-width: 0; }
.row .name { font-weight: 700; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { color: var(--dim); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .num { font-size: 1.15rem; font-weight: 600; text-align: right; white-space: nowrap; }
.row .num small { display: block; font-size: 0.8rem; color: var(--dim); font-weight: 500; }
#upcoming .row { grid-template-columns: 4.2rem 1fr auto; }
#upcoming .eta { font-size: 1.35rem; font-weight: 700; color: var(--cyan); }
.recent .rows { gap: 0.4rem; }
#recent .row { grid-template-columns: 4.6rem 1fr auto auto; }
#recent .when { color: var(--dim); font-size: 1rem; }
#recent .row.fresh { border-color: rgba(255, 179, 64, 0.45); animation: fresh 2.5s ease-out; }
@keyframes fresh { from { background: var(--amber-soft); } }
.empty { color: var(--faint); font-size: 1rem; padding: 0.4rem 0.2rem; }
.tag { font-size: 0.75rem; padding: 0.1rem 0.4rem; border-radius: 0.3rem; border: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
.tag.land { color: var(--green); border-color: rgba(91, 209, 122, 0.35); }
.tag.dep { color: var(--cyan); border-color: rgba(92, 200, 240, 0.35); }

/* ---------- stats ---------- */
.stats { display: flex; flex-direction: column; gap: 0.65rem; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; }
.kpi .n { font-size: 2rem; font-weight: 800; line-height: 1; }
.kpi .l { font-size: 0.8rem; color: var(--dim); margin-top: 0.25rem; }
.hours { display: grid; grid-template-columns: repeat(24, 1fr); gap: 2px; align-items: end; height: 3.4rem; position: relative; }
.hours .b { background: var(--cyan); opacity: 0.55; border-radius: 2px 2px 0 0; min-height: 2px; position: relative; }
.hours .b.now { background: var(--amber); opacity: 1; }
.hours .b.future { background: var(--line); opacity: 1; }
.hours .avg { position: absolute; height: 2px; background: var(--text); opacity: 0.4; }
.hours-axis { display: flex; justify-content: space-between; font-size: 0.72rem; color: var(--faint); margin-top: 0.2rem; }
.facts { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 0.3rem 0.8rem; font-size: 0.92rem; }
.facts .k { color: var(--dim); }
.facts .v { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stale { position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%); background: var(--red); color: #fff; padding: 0.6rem 1.2rem; border-radius: 99rem; font-weight: 600; font-size: 1.1rem; }

/* Portrait screens (phones, a tablet on its side): one scrolling column. */
@media (max-aspect-ratio: 1/1) {
  :root { font-size: clamp(11px, 3.4vw, 18px); }
  html, body { overflow: auto; height: auto; }
  #shift { height: auto; min-height: 100%; padding: max(0.8rem, env(safe-area-inset-top)) 0.9rem 1.2rem; }
  .top { flex-wrap: wrap; gap: 0.4rem 1rem; }
  .brand { flex: 1; min-width: 0; }
  .brand-place { display: none; }
  #time { font-size: 1.7rem; }
  .clock { order: 2; }
  .gear { order: 3; }
  .wx { order: 4; flex-basis: 100%; justify-content: flex-start; gap: 0.4rem 1rem; font-size: 1rem; }
  .wx-sky { display: none; }
  .grid { display: flex; flex-direction: column; }
  .hero-body { grid-template-columns: 1fr; }
  .photo { aspect-ratio: 16 / 9; }
  .photo:has(.silhouette) { display: none; }
  .callsign { font-size: 3.4rem; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .tile { padding: 0.5rem 0.7rem; }
  .tile .s { white-space: normal; font-size: 0.82rem; line-height: 1.25; }
  .radar { aspect-ratio: 1; }
  .recent .rows { display: flex; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- setup ---------- */
.setup { position: fixed; inset: 0; background: var(--bg); overflow-y: auto; z-index: 10; display: flex; justify-content: center; padding: max(1rem, env(safe-area-inset-top)) 1rem 2rem; font-size: 16px; }
.setup[hidden] { display: none; }
.setup-card { width: 100%; max-width: 40rem; display: flex; flex-direction: column; gap: 0.9rem; }
.setup-head h1 { margin: 0.4rem 0 0.3rem; font-size: 1.8rem; }
.setup-head p { margin: 0; color: var(--dim); line-height: 1.45; }
.setup input[type=search], .setup input:not([type]) { width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 0.7rem; padding: 0.75rem 0.9rem; min-width: 0; }
.setup input:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }
.search { display: flex; gap: 0.5rem; }
.setup button { cursor: pointer; border-radius: 0.7rem; padding: 0.75rem 1.1rem; font-weight: 600; font-size: 16px; border: 1px solid var(--line); background: var(--panel-2); }
.setup button.primary { background: var(--amber); color: #1a1205; border-color: var(--amber); }
.setup button.primary:disabled { opacity: 0.4; cursor: default; }
.setup button.ghost { background: transparent; }
.setup button.danger { color: var(--red); border-color: rgba(255, 95, 86, 0.4); }
.locate { display: flex; align-items: center; justify-content: center; gap: 0.5rem; color: var(--cyan) !important; border-color: rgba(92, 200, 240, 0.4) !important; }
.locate svg { width: 1.2rem; height: 1.2rem; }
.setup-msg { color: var(--dim); min-height: 1.2em; font-size: 0.95rem; }
.setup-msg:empty { display: none; }
.setup-msg.warn { color: var(--amber); }
.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.results:empty { display: none; }
.results button { width: 100%; text-align: left; font-weight: 500 !important; font-size: 0.95rem !important; line-height: 1.35; }
.map { height: min(52vh, 26rem); border-radius: 0.8rem; overflow: hidden; border: 1px solid var(--line); background: var(--panel); }
.map-fail { padding: 2rem 1rem; color: var(--dim); text-align: center; }
.hint { margin: -0.4rem 0 0; color: var(--faint); font-size: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field label { color: var(--dim); }
.field output { color: var(--text); font-weight: 600; }
.field input[type=range] { width: 100%; accent-color: var(--amber); height: 1.6rem; }
.check { display: flex; align-items: center; gap: 0.6rem; color: var(--dim); }
.check input { width: 1.2rem; height: 1.2rem; accent-color: var(--amber); }
.actions { display: flex; gap: 0.6rem; justify-content: flex-end; position: sticky; bottom: 0; padding: 0.8rem 0; background: linear-gradient(transparent, var(--bg) 30%); }
.actions .primary { flex: 1; max-width: 16rem; }
.privacy { color: var(--dim); font-size: 0.9rem; line-height: 1.5; }
.privacy summary { cursor: pointer; color: var(--faint); }
.leaflet-container { background: #1a2230; font: inherit; }
