:root {
  --bg: #070825;
  --panel: rgba(10, 14, 40, 0.78);
  --panel-solid: #0c1130;
  --accent: #19e0ff;
  --accent-2: #7c5cff;
  --text: #eaf2ff;
  --muted: #9fb0d6;
  --good: #43e07a;
  --bad: #ff6b5e;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
#cesiumContainer { position: fixed; inset: 0; }
.hidden { display: none !important; }

/* --- top bar --------------------------------------------------------------*/
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: linear-gradient(to bottom, rgba(7, 8, 37, 0.85), rgba(7, 8, 37, 0));
  pointer-events: none;
}
.topbar a, .topbar button { pointer-events: auto; }
.brand {
  font-weight: 800; letter-spacing: 0.5px; text-decoration: none; color: var(--text);
  display: flex; align-items: center; gap: 8px; font-size: 16px;
}
.brand .dot { width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand small { color: var(--muted); font-weight: 500; }
.flight-title { margin-left: auto; text-align: right; max-width: 50vw; }
.flight-title .t { font-weight: 700; }
.flight-title .s { color: var(--muted); font-size: 13px; }

/* --- camera buttons (top-right) ------------------------------------------*/
.camgroup {
  position: fixed; top: 64px; right: 16px; z-index: 20;
  display: flex; flex-direction: column; gap: 8px;
}
.camgroup button {
  background: var(--panel); color: var(--text); border: 1px solid rgba(255,255,255,0.1);
  padding: 9px 12px; border-radius: 10px; cursor: pointer; font-size: 13px;
  backdrop-filter: blur(8px); min-width: 96px; text-align: left;
}
.camgroup button.active { border-color: var(--accent); color: var(--accent); }
.camgroup button:hover { border-color: var(--accent); }

/* --- instruments (left) ---------------------------------------------------*/
.instruments {
  position: fixed; top: 64px; left: 16px; z-index: 20;
  display: flex; flex-direction: column; gap: 8px; width: 150px;
}
.gauge {
  background: var(--panel); border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius); padding: 10px 12px; backdrop-filter: blur(8px);
}
.gauge .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.gauge .value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.gauge .unit { font-size: 12px; color: var(--muted); font-weight: 600; }
.gauge.vario .value.up { color: var(--good); }
.gauge.vario .value.down { color: var(--bad); }

/* --- bottom control bar ---------------------------------------------------*/
.controls {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 20; width: min(880px, calc(100vw - 32px));
  background: var(--panel); border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px);
  padding: 12px 16px; display: flex; align-items: center; gap: 14px;
}
.controls button.play {
  width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #04121a; font-size: 18px; font-weight: 900;
  display: grid; place-items: center; flex: none;
}
.controls .time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; min-width: 64px; }
.scrubber { flex: 1; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px;
  border-radius: 4px; background: rgba(255,255,255,0.15); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--accent); cursor: pointer; box-shadow: 0 0 8px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border: none; border-radius: 50%; background: var(--accent); cursor: pointer;
}
.controls select {
  background: var(--panel-solid); color: var(--text); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 13px;
}

/* --- drop overlay ---------------------------------------------------------*/
.dropzone {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at center, rgba(12,17,48,0.85), rgba(7,8,37,0.96));
}
.dropcard {
  text-align: center; padding: 40px 44px; border-radius: 20px;
  border: 2px dashed rgba(255,255,255,0.22); background: var(--panel);
  max-width: 520px; box-shadow: var(--shadow);
}
.dropcard.dragover { border-color: var(--accent); background: rgba(25,224,255,0.08); }
.dropcard h1 { margin: 0 0 6px; font-size: 26px; }
.dropcard p { color: var(--muted); margin: 6px 0 22px; line-height: 1.5; }
.btn {
  display: inline-block; cursor: pointer; border: none; border-radius: 12px;
  padding: 12px 20px; font-size: 15px; font-weight: 700; text-decoration: none;
}
.btn.primary { background: var(--accent); color: #04121a; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid rgba(255,255,255,0.25); margin-left: 10px; }
.dropcard .err { color: var(--bad); margin-top: 14px; min-height: 18px; }

/* --- url input + recents (browser logbook) -------------------------------*/
.url-row { display: flex; gap: 8px; margin-top: 18px; }
.url-row input {
  flex: 1; background: #060a22; color: var(--text); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px; padding: 11px 13px; font-size: 14px;
}
.url-row .btn { padding: 11px 16px; margin: 0; }
.recents { margin-top: 18px; text-align: left; }
.recents h4 {
  margin: 0 0 8px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px;
  display: flex; justify-content: space-between; align-items: center;
}
.recents h4 button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 11px; }
.recents h4 button:hover { color: var(--bad); }
.recent-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.07); margin-bottom: 7px;
  cursor: pointer;
}
.recent-item:hover { border-color: var(--accent); background: rgba(25,224,255,0.07); }
.recent-item .ri-icon { font-size: 16px; }
.recent-item .ri-main { flex: 1; min-width: 0; }
.recent-item .ri-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item .ri-meta { font-size: 12px; color: var(--muted); }
.recent-item .ri-x { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 4px; }
.recent-item .ri-x:hover { color: var(--bad); }

/* --- pilot roster (group replay) -----------------------------------------*/
.roster {
  position: fixed; left: 16px; bottom: 18px; z-index: 21; width: 210px;
  background: var(--panel); border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px);
  padding: 8px 10px; max-height: 46vh; overflow: auto;
}
.roster-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px;
  margin-bottom: 8px;
}
.roster-add {
  cursor: pointer; color: var(--accent); font-weight: 700; letter-spacing: 0;
  text-transform: none; font-size: 12px; padding: 2px 6px; border-radius: 8px;
  border: 1px solid rgba(25,224,255,0.35);
}
.roster-add:hover { background: rgba(25,224,255,0.1); }
.roster-item {
  display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 10px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.07);
  margin-bottom: 6px; cursor: pointer;
}
.roster-item:hover { border-color: rgba(255,255,255,0.25); }
.roster-item.focused { border-color: var(--accent); background: rgba(25,224,255,0.08); }
.roster-item .chip { width: 12px; height: 12px; border-radius: 50%; flex: none;
  box-shadow: 0 0 8px currentColor; }
.roster-item .rn { flex: 1; min-width: 0; font-weight: 600; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.roster-item .rd { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.roster-item .rx { background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 0 2px; }
.roster-item .rx:hover { color: var(--bad); }

/* --- altitude profile + inline legend ------------------------------------*/
.profile-wrap {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%);
  z-index: 19; width: min(880px, calc(100vw - 32px)); height: 96px;
  background: var(--panel); border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius); box-shadow: var(--shadow); backdrop-filter: blur(10px);
  padding: 6px 12px 8px;
}
.profile-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px;
}
.profile-head small { text-transform: none; letter-spacing: 0; opacity: 0.7; }
.profile-wrap canvas { width: 100%; height: 64px; display: block; cursor: pointer; }
.legend-inline { display: flex; align-items: center; gap: 6px; }
.legend-bar {
  display: inline-block; height: 8px; width: 90px; border-radius: 4px;
  background: linear-gradient(to right, #ff6b3c, #e6e6b4, #2be64a);
}
.legend-labels { display: inline-flex; gap: 6px; }

.loading {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(7,8,37,0.7); color: var(--text); font-size: 16px;
}

/* --- slide-in panel (stats) ----------------------------------------------*/
.panel {
  position: fixed; top: 64px; right: 16px; z-index: 30; width: 280px;
  background: var(--panel-solid); border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,0.08);
  font-weight: 700;
}
.panel-head .x {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 16px;
}
.panel-head .x:hover { color: var(--text); }
.panel-body { padding: 6px 14px 14px; }
.stat-row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 14px; }
.stat-row:last-child { border-bottom: none; }
.stat-row .k { color: var(--muted); }
.stat-row .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-section { color: var(--accent); font-size: 11px; text-transform: uppercase;
  letter-spacing: 1px; margin: 12px 0 2px; }

/* --- modal (share) -------------------------------------------------------*/
.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(4, 6, 24, 0.6); backdrop-filter: blur(3px); padding: 20px;
}
.modal-card {
  width: min(560px, 100%); background: var(--panel-solid);
  border: 1px solid rgba(255,255,255,0.12); border-radius: var(--radius); box-shadow: var(--shadow);
}
.modal-body { padding: 16px; }
.modal-body p { color: var(--muted); line-height: 1.5; margin: 0 0 12px; }
.modal-body label { display: block; font-size: 12px; color: var(--muted); margin: 14px 0 6px;
  text-transform: uppercase; letter-spacing: 0.5px; }
.copyfield { display: flex; gap: 8px; }
.copyfield input, .copyfield textarea {
  flex: 1; background: #060a22; color: var(--text); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 9px 11px; font-size: 13px; font-family: ui-monospace, monospace;
}
.copyfield textarea { resize: vertical; min-height: 64px; }
.copyfield button {
  background: var(--accent); color: #04121a; border: none; border-radius: 8px;
  padding: 0 14px; font-weight: 700; cursor: pointer; white-space: nowrap;
}

/* --- embed mode ----------------------------------------------------------*/
.embed-badge {
  display: none; position: fixed; top: 10px; left: 12px; z-index: 25;
  align-items: center; gap: 7px; text-decoration: none; color: var(--text);
  background: var(--panel); border: 1px solid rgba(255,255,255,0.12);
  padding: 6px 11px; border-radius: 999px; font-size: 13px; font-weight: 700; backdrop-filter: blur(8px);
}
.embed-badge .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 10px var(--accent); }
body.embed .topbar { display: none; }
body.embed .embed-badge { display: flex; }
body.embed #shareBtn, body.embed #statsBtn, body.embed #saveBtn { display: none; }
body.embed .roster-add { display: none; } /* no adding pilots inside an embed */

/* --- account + auth/save forms -------------------------------------------*/
.acct-btn {
  pointer-events: auto; margin-left: 14px; flex: none;
  background: var(--panel); color: var(--text); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
  backdrop-filter: blur(8px); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.acct-btn:hover { border-color: var(--accent); color: var(--accent); }
.auth-actions { display: flex; gap: 10px; margin-top: 18px; }
.auth-actions .btn { flex: 1; text-align: center; }
.auth-msg { margin-top: 12px; min-height: 18px; font-size: 13px; color: var(--muted); }
.auth-msg.err { color: var(--bad); }
.auth-msg.ok { color: var(--good); }
.vis-sel {
  width: 100%; background: #060a22; color: var(--text); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; padding: 10px 11px; font-size: 14px; cursor: pointer;
}

@media (max-width: 640px) {
  .instruments { flex-direction: row; flex-wrap: wrap; width: auto; right: 16px; }
  .gauge { flex: 1 1 40%; }
  .camgroup { top: 64px; right: 16px; flex-direction: row; flex-wrap: wrap; justify-content: flex-end; max-width: 60vw; }
  .camgroup button { min-width: 0; }
  /* Hide the profile graph on small screens to keep the controls usable. */
  .profile-wrap { display: none !important; }
  /* Roster moves up out of the way of the bottom controls. */
  .roster { bottom: auto; top: 64px; left: 16px; width: 150px; max-height: 38vh; }
}
