:root {
  --abyss: #020a14;
  --ink: #dbeafe;
  --muted: #8fb3cf;
  --faint: #86a5c2;
  --cyan: #22d3ee;
  --cyan-soft: rgba(34, 211, 238, 0.35);
  /* opaque enough for --faint text to keep 4.5:1 even over a white sky */
  --glass: rgba(3, 14, 28, 0.85);
  --glass-2: rgba(6, 22, 42, 0.9);
  --glass-border: rgba(56, 205, 235, 0.26);
  --glass-border-lt: rgba(120, 230, 255, 0.5);
  --accent: #2dd4bf;
  --warn: #fbbf24;
  --danger: #f87171;
  --danger-deep: #ef4444;
  --dock-bottom: max(16px, env(safe-area-inset-bottom, 0px));
  --pop-bottom: calc(var(--dock-bottom) + 104px);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--abyss);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, select, input { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
[hidden] { display: none !important; }
b { font-weight: 650; }
kbd {
  font: 600 10px var(--mono); padding: 1px 5px; border-radius: 4px; margin-left: 4px;
  border: 1px solid rgba(255,255,255,0.25); background: rgba(255,255,255,0.08);
}

#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#gl:active { cursor: grabbing; }
#gl.crosshair { cursor: crosshair; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > :not(.hint, .alert, .frozen, .beacon) { pointer-events: auto; }

/* ---------- glass ---------- */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.3);
  backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45), inset 0 0 28px rgba(40, 200, 255, 0.05), 0 0 0 1px rgba(0,0,0,0.25);
}

/* ---------- brand + stats ---------- */
.brand { position: absolute; top: 16px; left: 16px; padding: 9px 14px 8px; }
.brand h1 { font-size: 15px; font-weight: 650; letter-spacing: 0.3px; line-height: 1.25; }
.brand p { font-size: 11px; color: var(--muted); }

.stats { position: absolute; top: 16px; right: 16px; display: flex; gap: 2px; padding: 5px; }
.stat { padding: 4px 11px; min-width: 76px; border-right: 1px solid rgba(56,205,235,0.14); }
.stat:last-child { border-right: none; }
.stat .k { display: block; font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.9px; color: var(--faint); }
.stat .v { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stat .v b { font-size: 15px; color: var(--ink); }
.stat.ratio { min-width: 118px; }
.stat.ratio.hot .v b { color: var(--warn); }
.stat.ratio.rogue .v b { color: var(--danger); }
.meter { height: 4px; border-radius: 2px; background: rgba(20, 50, 80, 0.9); margin-top: 3px; position: relative; overflow: hidden; }
.meter .fill { position: absolute; inset: 0 auto 0 0; width: 0%; background: var(--accent); border-radius: 2px; transition: width 90ms linear, background 200ms; }
.meter .tick { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--danger); left: 80%; }

/* ---------- alert, frozen, beacon, hint ---------- */
.alert {
  position: absolute; top: 90px; left: 50%; transform: translateX(-50%);
  display: none; z-index: 25; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
.alert.show { display: block; animation: alertFlash 0.55s ease-in-out 3; }
.alert .banner {
  position: relative; z-index: 1; text-align: center; padding: 9px 26px;
  background: rgba(60, 8, 12, 0.72); border: 1px solid var(--danger-deep); border-radius: 14px;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: 0 0 40px rgba(239, 68, 68, 0.5), inset 0 0 20px rgba(239,68,68,0.15);
}
.alert .title { font-size: 15px; font-weight: 750; letter-spacing: 2px; text-transform: uppercase; color: var(--danger); }
.alert .title::before { content: "⚠ "; }
.alert .sub { font-size: 12px; color: #fca5a5; margin-top: 1px; font-variant-numeric: tabular-nums; }
.alert::before, .alert::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 90px; height: 90px; margin: -45px 0 0 -45px;
  border-radius: 50%; border: 2px solid rgba(248, 113, 113, 0.75); opacity: 0;
  animation: sonar 1.7s ease-out infinite;
}
.alert::after { animation-delay: 0.85s; }
@keyframes sonar { 0% { transform: scale(0.5); opacity: 0.9; } 100% { transform: scale(3.2); opacity: 0; } }
@keyframes alertFlash { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.frozen {
  position: absolute; top: 158px; left: 50%; transform: translateX(-50%);
  font-size: 10.5px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--warn);
  background: rgba(40, 28, 4, 0.7); border: 1px solid rgba(251, 191, 36, 0.4); border-radius: 999px;
  padding: 3px 12px; display: none; pointer-events: none; z-index: 24;
  width: max-content; max-width: calc(100vw - 32px); text-align: center;
}
.frozen.show { display: block; }

.beacon {
  position: absolute; width: 14px; height: 14px; margin: -7px 0 0 -7px; pointer-events: none;
  border-radius: 50%; background: #fca5a5; box-shadow: 0 0 14px #ef4444; z-index: 20;
}
.beacon::after {
  content: ""; position: absolute; inset: -12px; border: 2px solid var(--danger);
  border-radius: 50%; animation: beaconPulse 1.1s ease-out infinite;
}
@keyframes beaconPulse { 0% { transform: scale(0.4); opacity: 1; } 100% { transform: scale(1.7); opacity: 0; } }

.hint {
  position: absolute; left: 50%; bottom: calc(var(--pop-bottom) + 18px); transform: translateX(-50%);
  padding: 6px 14px; font-size: 12px; color: var(--muted); white-space: nowrap; pointer-events: none;
  transition: opacity 0.8s ease; border-radius: 999px;
}
.hint.fade { opacity: 0; visibility: hidden; transition: opacity 0.8s ease, visibility 0s 0.8s; }

/* ?fps readout: a debug overlay above everything, top centre */
.perf {
  position: absolute; top: 2px; left: 50%; transform: translateX(-50%); z-index: 60; pointer-events: none;
  font: 11px var(--mono); color: var(--ink); background: rgba(3, 14, 28, 0.9); padding: 2px 8px; border-radius: 6px; white-space: nowrap;
}

/* ---------- buoy readout ---------- */
.buoy-readout { position: absolute; top: 76px; left: 16px; padding: 8px 12px 6px; width: 246px; }
.buoy-readout .row { display: flex; align-items: baseline; gap: 8px; font-size: 12px; }
.buoy-readout .row.sub { margin-top: -2px; }
.buoy-readout .k { font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.9px; color: var(--faint); }
.buoy-readout .v { color: var(--muted); font-variant-numeric: tabular-nums; }
.buoy-readout .v b { color: var(--ink); font-size: 13px; }
.buoy-readout canvas { display: block; width: 100%; height: 46px; margin-top: 4px; }
.mini {
  margin-left: auto; font-size: 10.5px; color: var(--muted); padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--glass-border);
}
.mini:hover { color: var(--ink); border-color: var(--glass-border-lt); }

/* ---------- dock ---------- */
.dock {
  position: absolute; left: 50%; bottom: var(--dock-bottom); transform: translateX(-50%); z-index: 30;
}
.dock ul { display: flex; align-items: flex-end; gap: 13px; list-style: none; padding: 0 10px; }
.dock li {
  position: relative;
  --lift: calc(var(--d) * var(--d) * 4.5px);
  transform: translateY(calc(-1 * var(--lift)));
  animation: dockRise 0.75s cubic-bezier(0.2, 0.9, 0.25, 1.1) both;
  animation-delay: calc(80ms + var(--i) * 55ms);
}
@keyframes dockRise {
  from { transform: translateY(calc(40px - var(--lift))); opacity: 0; }
  to { transform: translateY(calc(-1 * var(--lift))); opacity: 1; }
}
.dock-btn {
  position: relative; width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; color: #bfe9ff;
  background: radial-gradient(circle at 35% 28%, rgba(60, 160, 210, 0.35), rgba(4, 20, 40, 0.72) 60%);
  border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.12), 0 0 0 0 var(--cyan-soft);
  transition: box-shadow 0.25s, border-color 0.25s, color 0.25s, background 0.25s;
  animation: bob 4.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * -0.6s);
}
.dock-btn svg { width: 24px; height: 24px; filter: drop-shadow(0 0 6px rgba(34, 211, 238, 0.55)); }
.dock-btn svg[fill=""], .ic-pause, .ic-play { fill: currentColor; }
.dock-btn:hover, .dock-btn[aria-expanded="true"], .dock-btn[aria-pressed="true"] {
  color: #ffffff; border-color: var(--glass-border-lt);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255,255,255,0.18), 0 0 22px var(--cyan-soft);
}
.dock-btn[aria-expanded="true"], .dock-btn[aria-pressed="true"] {
  background: radial-gradient(circle at 35% 28%, rgba(34, 211, 238, 0.5), rgba(6, 40, 70, 0.85) 62%);
}
.dock-btn::after {
  content: ""; position: absolute; inset: -2px; border-radius: 50%; pointer-events: none;
  border: 2px solid rgba(120, 230, 255, 0.8); opacity: 0; transform: scale(0.7);
}
.dock-btn.ping::after { animation: ping 0.7s ease-out forwards; }
@keyframes ping { 0% { opacity: 0.9; transform: scale(0.7); } 100% { opacity: 0; transform: scale(1.9); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

#btn-pause .ic-play, #btn-pause[aria-pressed="true"] .ic-pause { display: none; }
#btn-pause[aria-pressed="true"] .ic-play { display: block; }
#btn-click .ic-buoy, #btn-click.buoy .ic-splash { display: none; }
#btn-click.buoy .ic-buoy { display: block; }

/* tooltips: air bubbles rising off the icons, tilted outward along the fan */
.tip {
  position: absolute; bottom: calc(100% + 10px); left: 50%; white-space: nowrap; pointer-events: none;
  padding: 5px 12px; font-size: 11.5px; font-weight: 550; color: var(--ink);
  border-radius: 999px; border: 1px solid var(--glass-border-lt);
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,0.22), rgba(20, 90, 130, 0.35) 40%, rgba(4, 22, 44, 0.85) 100%);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: 0 8px 22px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.28), 0 0 14px rgba(34,211,238,0.25);
  --ang: calc(var(--d) * 8deg);
  transform-origin: 50% 140%;
  transform: translateX(-50%) rotate(var(--ang)) translateY(8px) scale(0.75);
  opacity: 0; transition: opacity 0.18s, transform 0.18s;
}
.tip::before {
  content: ""; position: absolute; left: 50%; bottom: -9px; width: 6px; height: 6px; margin-left: -3px;
  border-radius: 50%; border: 1px solid var(--glass-border-lt); background: rgba(120, 230, 255, 0.25);
}
.dock-btn:hover + .tip, .dock-btn:focus-visible + .tip {
  opacity: 1;
  transform: translateX(-50%) rotate(var(--ang)) translateY(0) scale(1);
  animation: bubbleRise 2.8s ease-in-out 0.2s infinite;
}
.dock-btn[aria-expanded="true"] + .tip { display: none; }
@keyframes bubbleRise {
  0%, 100% { transform: translateX(-50%) rotate(var(--ang)) translateY(0) scale(1); }
  35% { transform: translateX(-50%) rotate(calc(var(--ang) + 2deg)) translateY(-3px) scale(1.02, 0.98); }
  70% { transform: translateX(-50%) rotate(calc(var(--ang) - 1.5deg)) translateY(-1px) scale(0.99, 1.02); }
}

/* ---------- popovers ---------- */
.backdrop { position: absolute; inset: 0; z-index: 38; background: rgba(2, 10, 20, 0.35); }
.popover {
  position: absolute; bottom: var(--pop-bottom); left: var(--x, 50%); z-index: 40;
  width: min(370px, calc(100vw - 32px)); max-height: min(64vh, 600px, calc(100vh - var(--pop-bottom) - 96px));
  display: flex; flex-direction: column;
  background: var(--glass-2);
  -webkit-backdrop-filter: blur(18px) saturate(1.3); backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid var(--glass-border); border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), inset 0 0 40px rgba(40, 200, 255, 0.05), 0 0 0 1px rgba(0,0,0,0.3);
  transform-origin: 50% 100%;
  transform: translateX(-50%);
  animation: popIn 0.28s cubic-bezier(0.2, 0.9, 0.25, 1.15) both;
}
.popover.wide-pop { width: min(440px, calc(100vw - 32px)); }
@keyframes popIn {
  from { transform: translateX(-50%) translateY(10px) scale(0.92); opacity: 0; }
  to { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}
.popover > header, .drawer > header {
  position: relative; overflow: hidden; flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px; padding: 11px 16px;
  border-bottom: 1px solid rgba(56, 205, 235, 0.16);
}
/* caustic stripes sweep behind the header text: faint enough for --faint to keep 4.5:1 */
.popover > header::before, .drawer > header::before {
  content: ""; position: absolute; inset: -60% -30%; pointer-events: none;
  background: repeating-linear-gradient(112deg, transparent 0 22px, rgba(120, 230, 255, 0.04) 22px 31px, transparent 31px 52px);
  animation: caustic 11s linear infinite;
}
@keyframes caustic { from { transform: translateX(-60px); } to { transform: translateX(60px); } }
.popover h2, .drawer h2 { position: relative; font-size: 13px; font-weight: 650; letter-spacing: 0.4px; text-transform: uppercase; color: var(--cyan); }
.popover .count { position: relative; font-size: 11px; color: var(--faint); }
.popover > .body { overflow-y: auto; padding: 12px 16px 16px; overscroll-behavior: contain; }
.popover .note { font-size: 11.5px; color: var(--faint); margin-top: 10px; }
.icon-btn { margin-left: auto; color: var(--muted); font-size: 15px; padding: 0 4px; line-height: 1; position: relative; }
.icon-btn:hover { color: var(--ink); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: rgba(14, 60, 90, 0.35); border: 1px solid var(--glass-border); border-radius: 10px;
  padding: 7px 13px; font-size: 12.5px; font-weight: 600; color: var(--ink);
  transition: border-color 120ms, background 120ms;
}
.btn:hover { border-color: var(--glass-border-lt); background: rgba(20, 80, 120, 0.45); }
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.seg { display: flex; border: 1px solid var(--glass-border); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; padding: 8px 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { color: #fff; background: rgba(34, 211, 238, 0.2); box-shadow: inset 0 0 18px rgba(34,211,238,0.15); }

/* ---------- controls ---------- */
.ctl { margin-bottom: 9px; }
.ctl label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 1px; }
.ctl output { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.row-ctl { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0 4px; }
.row-ctl label { margin: 0; }
select {
  background: rgba(6, 30, 52, 0.9); border: 1px solid var(--glass-border); border-radius: 8px; padding: 5px 8px; font-size: 12.5px;
}
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 24px; background: transparent; cursor: pointer;
  --c: var(--cyan);
}
input[type="range"]:disabled { opacity: 0.45; cursor: not-allowed; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='6' viewBox='0 0 24 6'%3E%3Cpath d='M0 3Q6 -0.5 12 3T24 3' fill='none' stroke='rgba(140,225,255,0.55)' stroke-width='1.3'/%3E%3C/svg%3E") repeat-x center / 24px 6px,
    linear-gradient(90deg, rgba(34, 211, 238, 0.28), rgba(34, 211, 238, 0.08));
}
input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 3px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='6' viewBox='0 0 24 6'%3E%3Cpath d='M0 3Q6 -0.5 12 3T24 3' fill='none' stroke='rgba(140,225,255,0.55)' stroke-width='1.3'/%3E%3C/svg%3E") repeat-x center / 24px 6px,
    linear-gradient(90deg, rgba(34, 211, 238, 0.28), rgba(34, 211, 238, 0.08));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; margin-top: -5px;
  background: radial-gradient(circle at 35% 30%, #ffffff, #d6f1ff 45%, #86d7f7 100%);
  border: 1.5px solid var(--c);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6), 0 0 12px color-mix(in srgb, var(--c) 55%, transparent);
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffffff, #d6f1ff 45%, #86d7f7 100%);
  border: 1.5px solid var(--c);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6), 0 0 12px color-mix(in srgb, var(--c) 55%, transparent);
}

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 12.5px; color: var(--muted); padding: 6px 0; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle i {
  position: relative; flex: 0 0 auto; width: 34px; height: 19px; border-radius: 999px;
  background: rgba(20, 50, 80, 0.9); border: 1px solid var(--glass-border); transition: background 0.2s;
}
.toggle i::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, #b9e8ff 55%, #7dd3fc); transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.5);
}
.toggle input:checked + i { background: rgba(34, 211, 238, 0.45); }
.toggle input:checked + i::after { transform: translateX(15px); }
.toggle input:focus-visible + i { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* train cards */
.card {
  --c: var(--cyan);
  position: relative; border: 1px solid rgba(56, 205, 235, 0.18); border-left: 3px solid var(--c);
  border-radius: 12px; padding: 9px 12px 8px; margin-bottom: 9px; background: rgba(4, 18, 34, 0.5);
}
/* switched off: its toggle and sliders still work, so no group opacity (it would
   drop the text under 4.5:1); only the name and the colour stripe go grey */
.card.off { border-left-color: #5b6b7c; }
.card.off .name { color: var(--faint); }
.card input[type="range"] { --c: var(--c); }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.card-head .name { font-weight: 650; font-size: 12.5px; color: var(--c); }
.card-head .meta { font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.card-head .toggle { margin-left: auto; padding: 0; }
.card-head .remove { font-size: 13px; color: var(--faint); padding: 0 2px; line-height: 1; }
.card-head .remove:hover { color: var(--danger); }
.card .ctl { margin-bottom: 4px; }
.card .ctl label { font-size: 11.5px; }
.card input[type="range"] { height: 20px; }

/* ---------- physics prose ---------- */
.prose h3 { font-size: 12.5px; font-weight: 650; color: var(--accent); margin: 14px 0 3px; }
.prose p { font-size: 12.5px; color: #b6cbe0; margin-bottom: 6px; }
.prose .eq {
  font-family: var(--mono); font-size: 11.5px; background: rgba(2, 12, 26, 0.8);
  border: 1px solid rgba(56, 205, 235, 0.18); border-radius: 8px; padding: 6px 9px; margin: 6px 0; overflow-x: auto; white-space: nowrap;
}
.tip-box, .prose .tip {
  background: rgba(13, 43, 44, 0.7); border: 1px solid #1c5f57; border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 8px 11px; font-size: 12.5px; color: #b8ece4; margin: 4px 0 8px;
  position: static; opacity: 1; transform: none; animation: none; white-space: normal; pointer-events: auto;
  box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none;
}
.prose .tip::before { display: none; }
.prose .tip b { color: var(--accent); }

/* ---------- 2D drawer ---------- */
.drawer {
  position: absolute; left: 16px; right: 16px; bottom: var(--pop-bottom); height: 250px; z-index: 35;
  display: flex; flex-direction: column; border-radius: 16px; overflow: hidden;
  animation: drawerUp 0.35s cubic-bezier(0.2, 0.9, 0.25, 1) both;
}
@keyframes drawerUp { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.drawer > header { padding: 8px 14px; }
.drawer .legend { position: relative; display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-left: 8px; }
.drawer .legend span { display: inline-flex; align-items: center; gap: 5px; }
.drawer .legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.drawer canvas { flex: 1 1 0; min-height: 0; width: 100%; height: auto; display: block; }

.nogl { position: absolute; top: 22%; left: 50%; transform: translateX(-50%); padding: 18px 22px; width: min(420px, calc(100vw - 32px)); text-align: center; z-index: 36; }
.nogl h2 { font-size: 15px; margin-bottom: 6px; }
.nogl p { font-size: 12.5px; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .buoy-readout { top: 190px; }
}
@media (max-width: 720px) {
  .stats { top: auto; right: auto; left: 16px; top: 70px; max-width: calc(100vw - 32px); overflow-x: auto; gap: 0; }
  .stat { min-width: 66px; padding: 3px 9px; }
  .stat.ratio { min-width: 100px; }
  .buoy-readout { top: 240px; width: calc(100vw - 32px); }
  .alert { top: 140px; width: calc(100vw - 32px); }
  .alert .banner { padding: 8px 14px; }
  .frozen { top: 204px; }
  .dock ul { gap: 7px; padding: 0 4px; }
  .dock li { --lift: calc(var(--d) * var(--d) * 3px); }
  .dock-btn { width: 44px; height: 44px; }
  .dock-btn svg { width: 21px; height: 21px; }
  .hint { font-size: 11px; white-space: normal; text-align: center; width: calc(100vw - 48px); }
  .drawer { height: 200px; left: 8px; right: 8px; }
}
@media (max-width: 640px) {
  .popover, .popover.wide-pop {
    left: 0 !important; right: 0; bottom: 0; width: auto; max-height: 74vh; transform: none;
    border-radius: 18px 18px 0 0; border-bottom: none; z-index: 40;
    animation: sheetUp 0.3s cubic-bezier(0.2, 0.9, 0.25, 1) both;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .popover > .body { padding-bottom: 20px; }
  @keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
  /* the dock spans the screen: no outward tilt, and the end bubbles grow inward
     from their button's outer edge (translate cancels the translateX(-50%)),
     tails kept over the 44 px buttons' centres */
  .tip { --ang: 0deg; }
  .dock li:first-child .tip { left: 0; translate: 50%; }
  .dock li:last-child .tip { left: auto; right: 0; translate: 50%; }
  .dock li:first-child .tip::before { left: 21px; }
  .dock li:last-child .tip::before { left: auto; right: 18px; }
}

/* narrowest phones (320 px): 7 x 42 px buttons fit with the tooltips' end bubbles on screen */
@media (max-width: 359px) {
  .dock ul { gap: 3px; padding: 0 2px; }
  .dock-btn { width: 42px; height: 42px; }
  .dock li:first-child .tip::before { left: 20px; }
  .dock li:last-child .tip::before { right: 17px; }
}

/* touch screens have no Space key to hint at */
@media (pointer: coarse) {
  .tip kbd { display: none; }
}

/* short (landscape phone) viewports: no room for the sparkline, the hint or a tall fallback panel */
@media (max-height: 480px) {
  .buoy-readout canvas { display: none; }
  .buoy-readout { top: 90px; left: auto; right: 16px; width: 246px; padding-bottom: 8px; }
  .hint { display: none; }
  .drawer { height: 150px; }
  /* the free corner beside the dock, below the drawer: the top belongs to the brand and stats */
  .nogl { top: auto; bottom: var(--dock-bottom); left: 16px; transform: none; width: 118px; padding: 8px 10px; }
  .nogl h2 { font-size: 13px; margin: 0; }
  .nogl p { display: none; }
}
/* 630-720 px wide and short: the stats go back up beside the brand, clear of the 2D drawer
   (300 px leaves the brand's 278 px and keeps the ~324 px stats on one row from 630 up) */
@media (min-width: 630px) and (max-width: 720px) and (max-height: 480px) {
  .stats { top: 16px; left: auto; right: 16px; max-width: calc(100vw - 300px); }
}
/* under 630 px wide and short the corner beside the dock is too narrow (the first dock
   button starts left of x 134 up to ~620 px): a compact tag at the top right, above the drawer */
@media (max-width: 629px) and (max-height: 480px) {
  .nogl { bottom: auto; top: 16px; left: auto; right: 16px; width: auto; padding: 6px 10px; }
  .nogl h2 { font-size: 12px; line-height: 1.25; white-space: nowrap; }
}
/* under 470 px the top row has no room beside the brand: the tag sits centred in the
   band between the 2D drawer and the dock's fan (whose raised buttons reach ~59 px up),
   under the dock's tooltips */
@media (max-width: 469px) and (max-height: 480px) {
  .nogl { top: auto; right: auto; bottom: calc(var(--dock-bottom) + 64px); left: 50%; transform: translateX(-50%); z-index: 29; }
}
/* desktop, 481-640 px tall: the fallback panel sits just above the 2D drawer (which opens by itself) */
@media (min-width: 721px) and (min-height: 481px) and (max-height: 640px) {
  .nogl { top: auto; bottom: calc(var(--pop-bottom) + 258px); }
}
/* too short for the full panel between the stats and the drawer: the heading only, under the brand */
@media (min-width: 721px) and (min-height: 481px) and (max-height: 589px) {
  .nogl { left: 16px; transform: none; width: auto; padding: 6px 10px; }
  .nogl h2 { font-size: 13px; line-height: 1.25; margin: 0; }
  .nogl p { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dock li, .dock-btn, .dock-btn.ping::after, .popover, .drawer, .tip, .dock-btn:hover + .tip, .dock-btn:focus-visible + .tip,
  .alert.show, .alert::before, .alert::after, .beacon::after, .popover > header::before, .drawer > header::before { animation: none !important; }
  .alert::before, .alert::after { display: none; }
  .tip { transition: opacity 0.1s; }
}
