:root {
  --bg: rgba(12, 16, 32, 0.62);
  --bg-strong: rgba(12, 16, 32, 0.82);
  --border: rgba(255, 255, 255, 0.10);
  --text: #eef2ff;
  --muted: #94a3c4;
  --accent: #4cc9f0;
  --accent-2: #ffb703;
  --radius: 18px;
  --panel-w: 372px;
  --gap: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #05070f;
  font-family: "Inter", system-ui, sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#cesiumContainer { position: fixed; inset: 0; }
#cesiumContainer .cesium-viewer-bottom { display: none; }

#vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(3, 5, 15, 0.55) 100%);
}

.glass {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }

button { font-family: inherit; color: inherit; cursor: pointer; }

/* ---------- Logbook panel ---------- */
#logbook {
  position: fixed; top: var(--gap); left: var(--gap); bottom: var(--gap);
  width: var(--panel-w);
  display: flex; flex-direction: column;
  padding: 20px;
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.brand-mark {
  width: 46px; height: 46px; border-radius: 14px; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7b6cf6 55%, var(--accent-2));
  box-shadow: 0 8px 24px rgba(76, 201, 240, 0.35);
}
.brand-mark svg { width: 26px; height: 26px; fill: #fff; transform: rotate(45deg); }
.brand-title { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.brand-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.brand-sub span { font-family: "JetBrains Mono", monospace; color: var(--accent); font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px; padding: 10px 6px; text-align: center;
}
.stat-value { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 3px; }

.progress { margin: 16px 0 14px; }
.progress-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 7px; }
.progress-head span:last-child { color: var(--text); font-weight: 600; }
.progress-bar { height: 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.progress-fill {
  height: 100%; width: 0; border-radius: 99px;
  background: linear-gradient(90deg, var(--accent), #7b6cf6, var(--accent-2));
  box-shadow: 0 0 12px rgba(76, 201, 240, 0.6);
  transition: width 1.2s cubic-bezier(.2, .8, .2, 1);
}

.journey-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 11px; border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
  font-size: 13.5px; font-weight: 600;
  transition: all .2s;
}
.journey-btn svg { width: 17px; height: 17px; fill: currentColor; }
.journey-btn:hover { background: rgba(255, 255, 255, 0.1); }
.journey-btn.active {
  background: linear-gradient(135deg, rgba(76, 201, 240, 0.25), rgba(123, 108, 246, 0.25));
  border-color: rgba(76, 201, 240, 0.5);
}

.section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--muted); margin: 18px 2px 10px; font-weight: 600;
}

.flight-list {
  flex: 1; overflow-y: auto; margin: 0 -8px; padding: 0 8px 4px;
  position: relative;
}
.flight-list::-webkit-scrollbar { width: 6px; }
.flight-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.12); border-radius: 9px; }

/* Timeline spine */
.flight-card { position: relative; padding-left: 26px; margin-bottom: 12px; }
.flight-card::before {
  content: ""; position: absolute; left: 7px; top: 22px; bottom: -14px; width: 2px;
  background: linear-gradient(var(--c), rgba(255, 255, 255, 0.08));
}
.flight-card:last-child::before { display: none; }
.flight-card .node {
  position: absolute; left: 0; top: 14px; width: 16px; height: 16px; border-radius: 50%;
  background: #0b1020; border: 3px solid var(--c);
  box-shadow: 0 0 12px var(--c);
}

.card-body {
  border-radius: 14px; padding: 13px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  cursor: pointer; transition: all .2s;
}
.card-body:hover { background: rgba(255, 255, 255, 0.08); transform: translateX(2px); }
.flight-card.active .card-body {
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 22%, transparent), rgba(255, 255, 255, 0.04));
  border-color: color-mix(in srgb, var(--c) 60%, transparent);
}

.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.lesson { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--c); }
.lesson .tail {
  margin-left: 8px; padding: 1px 7px; border-radius: 99px; letter-spacing: 0.04em;
  font-family: "JetBrains Mono", monospace; font-size: 10.5px; color: var(--text);
  background: color-mix(in srgb, var(--c) 18%, transparent); border: 1px solid color-mix(in srgb, var(--c) 40%, transparent);
}
.card-date { font-size: 15px; font-weight: 700; margin-top: 2px; }
.card-route { font-size: 12px; color: var(--muted); margin-top: 2px; font-family: "JetBrains Mono", monospace; }
.tag {
  font-size: 10.5px; font-weight: 600; padding: 3px 8px; border-radius: 99px; white-space: nowrap;
  background: rgba(255, 255, 255, 0.08); color: var(--text);
}
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.badge {
  font-size: 10.5px; font-weight: 600; padding: 3px 8px; border-radius: 99px;
  background: rgba(255, 183, 3, 0.14); color: #ffd166; border: 1px solid rgba(255, 183, 3, 0.25);
}

.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.chip { font-size: 11px; color: var(--muted); }
.chip b { display: block; font-size: 14px; color: var(--text); font-weight: 700; }

.spark { width: 100%; height: 34px; margin-top: 8px; display: block; }

/* Lessons whose track hasn't been downloaded yet */
.flight-card.unloaded .chip b { color: var(--muted); }
.flight-card.unloaded .card-route { color: color-mix(in srgb, var(--c) 70%, var(--muted)); }
.spark-placeholder {
  border-radius: 6px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.03), color-mix(in srgb, var(--c) 18%, transparent), rgba(255, 255, 255, 0.03));
  background-size: 200% 100%;
  opacity: 0.5;
}
.flight-card.loading .spark-placeholder { opacity: 1; animation: shimmer 1.2s linear infinite; }
.flight-card.loading .node { animation: pulse 1s ease-in-out infinite alternate; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: 0 0; } }
@keyframes pulse { to { box-shadow: 0 0 2px var(--c); } }

.notes { margin-top: 8px; }
.notes textarea {
  width: 100%; resize: vertical; min-height: 54px;
  background: rgba(0, 0, 0, 0.25); color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 10px;
  padding: 8px 10px; font: 12.5px/1.4 "Inter", sans-serif;
  display: none;
}
.flight-card.active .notes textarea { display: block; }
.notes textarea:focus { outline: none; border-color: var(--c); }

/* ---------- HUD ---------- */
#hud {
  position: fixed; top: var(--gap); right: var(--gap);
  display: grid; grid-template-columns: repeat(4, auto); gap: 4px;
  padding: 10px 12px; z-index: 5; transition: all .35s;
}
.hud-item { padding: 4px 12px; min-width: 96px; }
.hud-item + .hud-item { border-left: 1px solid rgba(255, 255, 255, 0.08); }
.hud-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); }
.hud-value { font-family: "JetBrains Mono", monospace; font-size: 24px; font-weight: 700; margin-top: 2px; }
.hud-value small { font-family: "Inter"; font-size: 11px; color: var(--muted); margin-left: 4px; font-weight: 500; }

#camModes {
  position: fixed; top: 96px; right: var(--gap);
  display: flex; padding: 5px; gap: 4px; border-radius: 13px; z-index: 5; transition: all .35s;
}
#camModes button, .speeds button {
  border: 0; background: transparent; padding: 7px 13px; border-radius: 9px;
  font-size: 12.5px; font-weight: 600; color: var(--muted); transition: all .2s;
}
#camModes button:hover, .speeds button:hover { color: var(--text); background: rgba(255, 255, 255, 0.06); }
#camModes button.active, .speeds button.active { color: #0b1020; background: var(--text); }

/* ---------- Map tools: search, layers, compass ---------- */
#mapTools {
  --tool: 44px;
  position: fixed; top: var(--gap); right: var(--gap); z-index: 7;
  display: flex; flex-direction: column; gap: 8px; transition: top .35s;
}
body.flight-open #mapTools { top: 150px; }
.tool { position: relative; }
.tool-btn {
  width: var(--tool); height: var(--tool); padding: 0; border-radius: 13px;
  display: grid; place-items: center; color: var(--text); transition: background .2s, color .2s;
}
.tool-btn svg { width: 20px; height: 20px; fill: currentColor; }
.tool-btn:hover { background: var(--bg-strong); }
.tool.open > .tool-btn { background: var(--text); color: #0b1020; }
.compass svg { width: 40px; height: 40px; }
.compass.north { opacity: .78; }

.tool-panel, .search-panel {
  position: absolute; top: 0; right: calc(100% + 10px);
  border-radius: 16px; padding: 12px; background: var(--bg-strong);
  opacity: 0; pointer-events: none; transform: translateX(8px); transition: opacity .2s, transform .2s;
}
.tool.open > .tool-panel, .tool.open > .search-panel { opacity: 1; pointer-events: auto; transform: none; }

.search-panel { width: 340px; padding: 6px; }
.search-row { display: flex; align-items: center; gap: 6px; padding: 0 2px 0 8px; }
.search-icon { width: 18px; height: 18px; fill: var(--muted); flex: none; }
#searchInput {
  flex: 1; min-width: 0; height: 36px; border: 0; outline: 0; background: transparent;
  color: var(--text); font: 500 14px "Inter", sans-serif;
}
#searchInput::placeholder { color: var(--muted); }
#searchInput::-webkit-search-cancel-button { display: none; }
.search-close {
  width: 34px; height: 34px; flex: none; border: 0; border-radius: 10px; background: transparent;
  display: grid; place-items: center; color: var(--muted);
}
.search-close:hover { background: rgba(255, 255, 255, 0.07); color: var(--text); }
.search-close svg { width: 18px; height: 18px; fill: currentColor; }
.search-results { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
.search-results:not(:empty) { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 4px; }
.search-results li {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px;
  font-size: 13.5px; cursor: pointer; min-height: 40px;
}
.search-results li svg { width: 16px; height: 16px; fill: var(--muted); flex: none; }
.search-results li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-results li:hover, .search-results li.active { background: rgba(255, 255, 255, 0.08); }
.search-results li.msg { color: var(--muted); cursor: default; background: none; }
.search-credit { display: none; align-items: center; justify-content: flex-end; gap: 8px; padding: 6px 8px 2px; font-size: 10px; color: var(--muted); }
.search-credit.show { display: flex; }
.search-credit img { height: 14px; width: auto; vertical-align: middle; }
.search-credit a { color: var(--muted); }

#layersPanel { width: 330px; }
.tp-title { font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); margin: 2px 4px 8px; }
.tp-title + .seg, .tp-title + .opts { margin-bottom: 14px; }
.opts { margin-bottom: 0 !important; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg button, .opts button {
  border: 1px solid transparent; background: rgba(255, 255, 255, 0.05); border-radius: 11px;
  text-align: left; transition: background .2s, border-color .2s;
}
.seg button { padding: 9px 10px; min-height: 52px; display: flex; align-items: center; }
.seg b { display: block; font-size: 12.5px; line-height: 1.3; }
.seg small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.opts { display: grid; gap: 4px; }
.opts button { display: flex; align-items: center; gap: 10px; padding: 6px 8px; min-height: 44px; font-size: 13px; font-weight: 500; }
.seg button:hover, .opts button:hover { background: rgba(255, 255, 255, 0.09); }
.seg button.active, .opts button.active { border-color: var(--accent); background: rgba(76, 201, 240, 0.14); }
.opts button.unavailable { display: none; }
.sw {
  width: 30px; height: 30px; border-radius: 8px; flex: none; display: grid; place-items: center;
  font: 800 11px "Inter", sans-serif; font-style: normal; color: #fff; text-shadow: 0 1px 2px #000;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.sw-labels { background: repeating-linear-gradient(135deg, rgba(255,255,255,.06) 0 4px, transparent 4px 8px); }
.sw-roadmap { background: linear-gradient(160deg, #e8eef3 0 40%, #fbd36b 40% 46%, #cfe6c4 46% 70%, #9cc9f2 70%); }
.sw-sat { background: linear-gradient(150deg, #3d5a3a, #6b7d4c 45%, #8c8a6a 60%, #2f4c63); }
.sw-none { background: linear-gradient(135deg, transparent 46%, rgba(255,255,255,.45) 46% 54%, transparent 54%); }

/* ---------- Player ---------- */
#player {
  position: fixed; left: calc(var(--panel-w) + var(--gap) * 2); right: var(--gap); bottom: 46px;
  padding: 14px 18px 12px; z-index: 5; transition: all .35s;
}
.player-row { display: flex; align-items: center; gap: 14px; }
.play-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 0; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), #7b6cf6);
  box-shadow: 0 8px 22px rgba(76, 201, 240, 0.4);
  transition: transform .15s;
}
.play-btn:hover { transform: scale(1.06); }
.play-btn svg { width: 22px; height: 22px; fill: #fff; }
.play-btn .icon-pause { display: none; }
.play-btn.playing .icon-play { display: none; }
.play-btn.playing .icon-pause { display: block; }
.player-meta { flex: 1; min-width: 0; }
.player-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-time { font-family: "JetBrains Mono", monospace; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.player-time .dot { margin: 0 8px; opacity: .5; }
.speeds { display: flex; gap: 2px; background: rgba(255, 255, 255, 0.05); padding: 4px; border-radius: 12px; }

.chart-wrap { position: relative; margin-top: 12px; }
#chart { width: 100%; height: 92px; display: block; cursor: ew-resize; touch-action: none; }
.chart-legend { position: absolute; top: 2px; right: 4px; display: flex; gap: 12px; font-size: 10.5px; color: var(--muted); pointer-events: none; }
.chart-legend span::before { content: ""; display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.lg-alt::before { background: var(--accent); }
.lg-spd::before { background: rgba(255, 255, 255, 0.7); }

/* ---------- Credits (attribution must remain visible) ---------- */
#credits {
  position: fixed; right: var(--gap); bottom: 8px; left: calc(var(--panel-w) + var(--gap) * 2);
  z-index: 4; text-align: right; font-size: 10.5px; color: rgba(255, 255, 255, 0.7);
}
#credits .cesium-credit-logoContainer img { height: 18px; vertical-align: middle; }
#credits a { color: rgba(255, 255, 255, 0.8); }

/* ---------- Loader / modal / toast ---------- */
#loader {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: radial-gradient(circle at 50% 40%, #121a3a, #05070f 70%);
  transition: opacity .8s;
}
#loader.done { opacity: 0; pointer-events: none; }
.loader-card { text-align: center; }
.loader-plane {
  width: 84px; height: 84px; margin: 0 auto 22px; border-radius: 50%;
  display: grid; place-items: center; position: relative;
}
.loader-plane::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.08); border-top-color: var(--accent);
  animation: spin 1.1s linear infinite;
}
.loader-plane svg { width: 34px; height: 34px; fill: #fff; transform: rotate(45deg); }
.loader-title { font-size: 20px; font-weight: 800; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(3, 5, 15, 0.6); transition: opacity .3s; }
.modal-card { width: min(440px, 92vw); padding: 26px; background: var(--bg-strong); }
.modal-title { font-size: 18px; font-weight: 800; }
.modal-card p { color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.modal-card input {
  width: 100%; padding: 12px 14px; border-radius: 12px; margin: 6px 0 14px;
  background: rgba(0, 0, 0, 0.35); border: 1px solid var(--border); color: var(--text);
  font: 13px "JetBrains Mono", monospace;
}
.modal-card input:focus { outline: none; border-color: var(--accent); }
.modal-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 12px; font-weight: 700; font-size: 14px;
  background: linear-gradient(135deg, var(--accent), #7b6cf6); color: #fff;
}

#toast {
  position: fixed; top: 24px; left: 50%; transform: translate(-50%, -20px); z-index: 70;
  background: rgba(220, 38, 38, 0.9); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 13px; font-weight: 500; opacity: 0; transition: all .3s; pointer-events: none; max-width: 80vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  :root { --panel-w: 300px; }
  #hud { grid-template-columns: repeat(2, auto); }
  #camModes { top: 150px; }
  body.flight-open #mapTools { top: 204px; }
}

/* ================================================================
   Phones
   Portrait: logbook becomes a bottom sheet (peek / half / full).
   Landscape: logbook is a collapsible side panel.
   ================================================================ */
.sheet-handle, .mobile-only, .notes-toggle { display: none; }
@media (hover: none) { .card-body:hover { transform: none; background: rgba(255, 255, 255, 0.04); } }

.sheet-handle {
  border: 0; background: transparent; width: 100%; padding: 8px 4px 10px; margin: -6px 0 4px;
  align-items: center; gap: 10px; font-size: 13px; color: var(--muted); text-align: left;
  touch-action: none; position: relative; flex: none;
}
.sheet-handle .grip {
  position: absolute; top: 0; left: 50%; width: 38px; height: 4px; margin-left: -19px;
  border-radius: 9px; background: rgba(255, 255, 255, 0.25);
}
.sheet-handle #sheetSummary { flex: 1; padding-top: 6px; }
.sheet-handle #sheetSummary b { color: var(--text); font-weight: 700; }
.sheet-handle .chev { width: 18px; height: 18px; fill: currentColor; margin-top: 6px; transition: transform .3s; }

.icon-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 0; flex: none;
  place-items: center; background: rgba(255, 255, 255, 0.06); color: var(--muted);
}
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
.icon-btn.active { background: var(--text); color: #0b1020; }

.scrub {
  position: relative; height: 22px; margin-top: 8px; cursor: ew-resize; touch-action: none;
}
.scrub::before, #scrubFill {
  content: ""; position: absolute; left: 0; top: 9px; height: 4px; border-radius: 9px;
}
.scrub::before { right: 0; background: rgba(255, 255, 255, 0.12); }
#scrubFill { width: 0; background: linear-gradient(90deg, var(--accent), #7b6cf6); }
#scrubFill::after {
  content: ""; position: absolute; right: -7px; top: -5px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 10px var(--accent);
}

/* ---------- Shared phone rules (portrait + landscape) ---------- */
@media (max-width: 600px), (max-height: 500px) and (min-width: 601px) {
  .sheet-handle { display: flex; }
  .icon-btn.mobile-only { display: grid; }
  .scrub.mobile-only { display: block; }
  body.chart-open .scrub { display: none; }
  .chart-wrap { display: none; }
  body.chart-open .chart-wrap { display: block; margin-top: 8px; }
  #chart { height: 72px; }

  /* Single active button; tapping it cycles. */
  #camModes button:not(.active), #speeds button:not(.active) { display: none; }
  #camModes button.active::after, #speeds button.active::after { content: " ↻"; opacity: .55; }
  #camModes button, .speeds button { min-height: 36px; padding: 7px 12px; }

  #clockTime, .player-time .dot { display: none; }
  .player-title { font-size: 14px; }
  .player-time { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #sheetSummary { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .player-row { gap: 10px; }
  .play-btn { width: 40px; height: 40px; }
  .play-btn svg { width: 19px; height: 19px; }
  #player { padding: 10px 12px 6px; }

  #hud { grid-template-columns: repeat(4, 1fr); padding: 6px 4px; gap: 0; }
  .hud-item { min-width: 0; padding: 2px 8px; }
  .hud-label { font-size: 8.5px; letter-spacing: 0.08em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hud-value { font-size: 16px; }
  .hud-value small { font-size: 9px; margin-left: 2px; }

  .glass, .glass button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
  .notes textarea { user-select: text; -webkit-user-select: text; font-size: 16px; }
  .flight-card.active .notes textarea { display: none; }
  .flight-card.notes-open .notes textarea { display: block; margin-top: 6px; }
  .flight-card.active .notes-toggle {
    display: inline-block; border: 0; border-radius: 9px; padding: 6px 10px; font-size: 12px; font-weight: 600;
    background: rgba(255, 255, 255, 0.07); color: var(--text);
  }
  .journey-btn { min-height: 42px; }

  #credits {
    font-size: 9px; line-height: 16px; height: 16px; white-space: nowrap; overflow: hidden;
    opacity: .75; text-shadow: 0 1px 3px rgba(0, 0, 0, .8);
    transition: opacity .25s, visibility .25s;
  }
  #credits img { height: 12px !important; width: auto !important; vertical-align: middle; }
  #credits .cesium-widget-credits { display: flex !important; align-items: center; justify-content: center; gap: 6px; height: 16px; }
  #logbook.dragging { transition: none !important; }
}

/* ---------- Portrait phone: bottom sheet ---------- */
@media (max-width: 600px) {
  :root {
    --gap: 8px;
    --safe-t: env(safe-area-inset-top, 0px);
    --safe-b: env(safe-area-inset-bottom, 0px);
    --sheet-h: calc(60px + var(--safe-b));
  }
  body[data-sheet="half"] { --sheet-h: calc(min(380px, 54dvh) + var(--safe-b)); }
  body[data-sheet="full"] { --sheet-h: calc(100dvh - var(--safe-t) - 92px); }

  #logbook {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: var(--sheet-h);
    border-radius: 22px 22px 0 0; border-bottom: 0;
    padding: 12px 14px calc(10px + var(--safe-b));
    overflow: hidden; overflow: clip; z-index: 6;
    transition: height .35s cubic-bezier(.2, .8, .2, 1), transform .3s cubic-bezier(.2, .8, .2, 1);
    overscroll-behavior: contain;
  }
  body:not([data-sheet="peek"]) .sheet-handle .chev { transform: rotate(180deg); }
  body[data-sheet="peek"] #logbook > :not(.sheet-handle) { visibility: hidden; }

  .brand { margin-bottom: 12px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
  .brand-title { font-size: 17px; }
  .stats { grid-template-columns: repeat(2, 1fr); }

  /* Half: horizontally swipeable cards only */
  body[data-sheet="half"] .brand,
  body[data-sheet="half"] .stats,
  body[data-sheet="half"] .progress,
  body[data-sheet="half"] .section-title { display: none; }
  body[data-sheet="half"] .journey-btn { margin: 2px 0 10px; }
  body[data-sheet="half"] .flight-list {
    display: flex; gap: 10px; overflow-x: auto; overflow-y: hidden;
    scroll-snap-type: x mandatory; margin: 0 -14px; padding: 0 14px 6px; scroll-padding: 0 14px;
  }
  body[data-sheet="half"] .flight-list::-webkit-scrollbar { display: none; }
  body[data-sheet="half"] .flight-card {
    flex: 0 0 84%; padding-left: 0; margin-bottom: 0; scroll-snap-align: center;
    overflow-y: auto; overscroll-behavior: contain;
  }
  body[data-sheet="half"] .flight-card { scrollbar-width: none; }
  body[data-sheet="half"] .flight-card::-webkit-scrollbar { display: none; }
  body[data-sheet="half"] .flight-card::before,
  body[data-sheet="half"] .flight-card .node { display: none; }

  body[data-sheet="full"] #player { opacity: 0; pointer-events: none; }

  #hud { left: var(--gap); right: var(--gap); top: calc(var(--safe-t) + var(--gap)); }
  #camModes { top: calc(var(--safe-t) + 64px); right: var(--gap); padding: 4px; }
  /* Attribution: one quiet line between the player and the sheet. */
  #credits { top: auto; left: var(--gap); right: var(--gap); bottom: calc(64px + var(--safe-b)); text-align: center; }
  body:not([data-sheet="peek"]) #credits { opacity: 0; visibility: hidden; }
  #player { left: var(--gap); right: var(--gap); bottom: calc(var(--sheet-h) + 22px); }
  #toast { top: calc(var(--safe-t) + 12px); }

  /* Map tools: a row under the HUD on the left (camera modes sit on the right). */
  #mapTools { --tool: 42px; flex-direction: row; right: auto; left: var(--gap); top: calc(var(--safe-t) + var(--gap)); }
  body.flight-open #mapTools { top: calc(var(--safe-t) + 64px); }
  body[data-sheet="full"] #mapTools { opacity: 0; pointer-events: none; }
  .tool-panel { right: auto; left: 0; top: calc(100% + 8px); transform: translateY(-6px); }
  #layersPanel { width: min(330px, calc(100vw - 16px)); max-height: calc(100dvh - var(--safe-t) - 140px); overflow-y: auto; }
  /* Search takes over the top of the screen as a full-width bar. */
  .search-panel {
    position: fixed; top: calc(var(--safe-t) + var(--gap)); left: var(--gap); right: var(--gap); width: auto;
    transform: translateY(-6px); z-index: 20;
  }
  #searchInput { height: 40px; font-size: 16px; }
  .search-results { max-height: 45dvh; }
  .search-results li { min-height: 46px; font-size: 14.5px; }
}

/* ---------- Landscape phone: collapsible side panel ---------- */
@media (max-height: 500px) and (min-width: 601px) {
  :root {
    --gap: 8px; --panel-w: 280px;
    --safe-l: env(safe-area-inset-left, 0px);
    --safe-r: env(safe-area-inset-right, 0px);
  }
  #logbook {
    left: calc(var(--safe-l) + var(--gap)); padding: 10px 12px;
    transition: width .3s, height .3s, bottom .3s;
  }
  #logbook .brand { display: none; }
  .stats { gap: 5px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat { padding: 7px 4px; min-width: 0; }
  .stat-value { font-size: 14px; }
  .stat-label { font-size: 8px; letter-spacing: 0.04em; }
  .progress { margin: 10px 0; }
  .section-title { margin: 10px 2px 6px; }
  .sheet-handle .chev { transform: rotate(-90deg); }
  body[data-sheet="full"] .sheet-handle .chev { transform: rotate(90deg); }

  body[data-sheet="peek"] #logbook { width: 320px; bottom: auto; height: 46px; padding: 6px 12px; overflow: hidden; }
  body[data-sheet="peek"] #logbook > :not(.sheet-handle) { display: none; }
  body[data-sheet="peek"] .sheet-handle .grip { display: none; }
  body[data-sheet="peek"] .sheet-handle { margin: 0; padding: 4px 0; }
  body[data-sheet="peek"] .sheet-handle #sheetSummary,
  body[data-sheet="peek"] .sheet-handle .chev { padding-top: 0; margin-top: 0; }

  #hud { right: calc(var(--safe-r) + var(--gap)); top: var(--gap); width: min(360px, 46vw); }
  #camModes { top: 62px; right: calc(var(--safe-r) + var(--gap)); padding: 4px; }
  #credits { top: auto; bottom: 2px; left: calc(var(--safe-l) + var(--gap)); right: calc(var(--safe-r) + var(--gap)); }
  #credits .cesium-widget-credits { justify-content: flex-end; }
  #player {
    bottom: 20px; right: calc(var(--safe-r) + var(--gap));
    left: calc(var(--safe-l) + var(--panel-w) + var(--gap) * 2);
  }
  body[data-sheet="peek"] #player { left: calc(var(--safe-l) + var(--gap)); }

  #mapTools { --tool: 40px; gap: 6px; right: calc(var(--safe-r) + var(--gap)); }
  body.flight-open #mapTools { top: 110px; }
  .compass svg { width: 36px; height: 36px; }
  /* Popovers anchor to the top of the screen so they fit the short viewport. */
  .tool-panel, .search-panel {
    position: fixed; top: var(--gap); right: calc(var(--safe-r) + var(--gap) + 50px);
    max-height: calc(100dvh - var(--gap) * 2); overflow-y: auto; z-index: 20;
  }
  #layersPanel { width: 340px; padding: 10px; }
  .tp-title { margin-bottom: 6px; }
  .tp-title + .seg { margin-bottom: 10px; }
  .seg button { min-height: 40px; padding: 5px 10px; }
  .opts { gap: 3px; }
  .opts button { min-height: 36px; padding: 3px 6px; font-size: 12px; gap: 8px; }
  .sw { width: 26px; height: 26px; }
  .search-panel { width: min(380px, calc(100vw - 80px)); }
  .search-results { max-height: calc(100dvh - 120px); }
}