:root, [data-theme="dark"] {
  --bg: #0b1f33;
  --bg-elev: #122c46;
  --fg: #eaf2fb;
  --muted: #7e96b0;
  --accent: #4cc2ff;
  --on-accent: #002033;
  --climb: #38d66b;
  --sink: #ff5c5c;
  --warn: #ffb020;
  --danger: #ff5c5c;
  --overlay: rgba(4, 14, 24, 0.94);
  --stale-bg: #3a1414;
  --radius: 14px;
}

[data-theme="light"] {
  --bg: #eef3f9;
  --bg-elev: #ffffff;
  --fg: #0b1f33;
  --muted: #5a6b7e;
  --accent: #0a6fb0;
  --on-accent: #ffffff;
  --climb: #1f9d4d;
  --sink: #d92626;
  --warn: #b8730a;
  --danger: #d92626;
  --overlay: rgba(238, 243, 249, 0.95);
  --stale-bg: #f7d4d4;
}

/* Lift tiles off the page when background and elevation are both light. */
[data-theme="light"] .tile,
[data-theme="light"] .ro { box-shadow: 0 1px 3px rgba(11, 31, 51, 0.12); }

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
}

/* Status bar */
.statusbar { display: flex; justify-content: space-between; align-items: center; }
.status-right { display: flex; align-items: center; gap: 8px; }
.iconbtn {
  width: 38px; height: 38px; border-radius: 50%; border: none; line-height: 1;
  background: var(--bg-elev); color: var(--fg); font-size: 1.15rem;
  -webkit-tap-highlight-color: transparent; cursor: pointer;
}
.iconbtn:active { background: var(--accent); color: var(--on-accent); }
.lang-btn { font-size: 0.85rem; font-weight: 700; letter-spacing: 0.5px; }
.badge {
  font-size: 0.95rem; font-weight: 700; letter-spacing: 0.5px;
  padding: 6px 12px; border-radius: 999px; background: var(--bg-elev);
  text-transform: uppercase;
}
.mode-circling { background: var(--accent); color: var(--on-accent); }
.mode-gliding  { background: var(--bg-elev); color: var(--fg); }
.mode-unknown  { background: var(--bg-elev); color: var(--muted); }
.gps-ok    { color: var(--climb); }
.gps-stale { color: var(--danger); background: var(--stale-bg); }
.gps-low   { color: var(--warn); }

/* Hero */
.hero { text-align: center; margin-top: 4px; }
.hero-label { color: var(--muted); font-size: 0.85rem; letter-spacing: 0.5px; }
.hero-value { display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.hero-value .num {
  font-size: clamp(4.5rem, 28vw, 9rem); font-weight: 800; line-height: 1;
  font-variant-numeric: tabular-nums;
}
.hero-value .unit { font-size: 1.4rem; color: var(--muted); }

/* Averages */
.averages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--bg-elev); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.tile-label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; }
.tile-value { display: flex; align-items: baseline; justify-content: center; gap: 4px; margin-top: 2px; }
.tile-value .num { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile-value .unit { font-size: 0.8rem; color: var(--muted); }
.tile-cov { font-size: 0.7rem; color: var(--muted); min-height: 0.9rem; margin-top: 2px; }
.tile.immature .tile-value .num { color: var(--muted); }

/* Supporting readouts */
.readouts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.ro { background: var(--bg-elev); border-radius: var(--radius); padding: 12px 8px; text-align: center; }
.ro-label { color: var(--muted); font-size: 0.78rem; }
.ro-value { display: flex; align-items: baseline; justify-content: center; gap: 4px; margin-top: 4px; }
.ro-value .num { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.ro-value .unit { font-size: 0.8rem; color: var(--muted); }
#vv.climb { color: var(--climb); }
#vv.sink  { color: var(--sink); }

/* c control */
.control { display: flex; align-items: center; gap: 8px; justify-content: center; }
.cbtn {
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: var(--bg-elev); color: var(--fg); font-size: 1.05rem; font-weight: 700;
  font-variant-numeric: tabular-nums; -webkit-tap-highlight-color: transparent; cursor: pointer;
}
.cbtn:active { background: var(--accent); color: var(--on-accent); }
.c-readout { text-align: center; min-width: 88px; }
.c-label { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; }
.c-num { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.caveat { color: var(--muted); font-size: 0.72rem; line-height: 1.4; text-align: center; margin-top: auto; }

/* Overlay */
.overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 20;
}
.overlay[hidden] { display: none; }
.overlay-card { max-width: 360px; text-align: center; }
.overlay-card h1 { font-size: 2.4rem; margin-bottom: 12px; }
.overlay-card p { color: var(--muted); line-height: 1.5; margin-bottom: 24px; }
.primary {
  border: none; background: var(--accent); color: var(--on-accent); font-size: 1.2rem; font-weight: 700;
  padding: 16px 32px; border-radius: 999px; cursor: pointer;
}
.overlay-card.error h1 { color: var(--danger); }
.overlay-theme {
  display: block; margin: 16px auto 0; border: none; background: transparent;
  color: var(--muted); font-size: 0.95rem; text-decoration: underline; cursor: pointer;
}

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--bg-elev); color: var(--fg);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-radius: 999px; box-shadow: 0 4px 16px rgba(0,0,0,0.5); z-index: 30;
}
.toast[hidden] { display: none; }
.toast-btn { border: none; background: var(--accent); color: var(--on-accent); font-weight: 700; padding: 6px 14px; border-radius: 999px; }

/* Phase visibility: hide live UI chrome until tracking */
.phase-idle .statusbar, .phase-idle .hero, .phase-idle .averages,
.phase-idle .readouts, .phase-idle .control, .phase-idle .caveat { visibility: hidden; }

/* Portrait-lock fallback (iOS ignores manifest orientation) */
.rotate-overlay { display: none; }
@media (orientation: landscape) and (max-height: 500px) {
  .rotate-overlay {
    position: fixed; inset: 0; background: var(--bg); z-index: 50;
    display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: 1.4rem;
  }
}
