/* Chrome tokens (light/dark selected, not flipped). The graph plot itself keeps a
 * fixed sky palette — it literally depicts night and day — so only the chrome
 * around it adapts. */
:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --chip: #ffffff;
  --chip-on: #10142e;
  --chip-on-ink: #f2f3f8;
  --overlay: rgba(8, 9, 20, 0.92);
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hairline: #2c2c2a;
    --chip: #1f1f1e;
    --chip-on: #e8e9f2;
    --chip-on-ink: #10142e;
    --overlay: rgba(5, 6, 14, 0.94);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
/* our own gestures everywhere: no double-tap page zoom (taps stay fast), and the
 * video stage handles pinch/pan itself */
button, input, a { touch-action: manipulation; }
/* app, not a document: nothing here is meant to be text-selected */
body { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100vh;    /* fallback for older iOS Safari */
  height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* Species filter chips: one scrollable row; each chip is emoji + name + count.
 * Doubles as the legend — identity is never color-alone, the emoji + name carry it. */
#chips {
  display: flex;
  gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: none;
}
#chips::-webkit-scrollbar { display: none; }
#chips:empty { display: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--chip);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 4px 10px 4px 7px;
  cursor: pointer;
}
.chip img { width: 16px; height: 16px; }
.chip .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.on { background: var(--chip-on); border-color: var(--chip-on); color: var(--chip-on-ink); }
.chip.on .n { color: inherit; opacity: 0.7; }

#stage { position: relative; flex: 1; min-height: 0; touch-action: none; overflow: hidden; }
#graph {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
}
#graph.dragging { cursor: grabbing; }

/* capture markers: glassy circular buttons over the canvas; the wrapper carries
 * the position transform so the button's own transform is free for press/pop */
#markers { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.mkw { position: absolute; left: 0; top: 0; pointer-events: none; will-change: transform; }
.mk {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 42px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(18, 22, 14, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.30);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.30), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(7px) saturate(1.15);
  -webkit-backdrop-filter: blur(7px) saturate(1.15);
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: transform 0.16s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.16s;
  touch-action: none;
}
.mk:active { transform: translate(-50%, -50%) scale(0.82); background: rgba(255, 255, 255, 0.20); }
.mk.pop { animation: mkpop 0.34s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes mkpop {
  0% { transform: translate(-50%, -50%) scale(0.82); }
  55% { transform: translate(-50%, -50%) scale(1.14); }
  100% { transform: translate(-50%, -50%) scale(1); }
}
.mk img { width: 26px; height: 26px; pointer-events: none; }
.mk img + img { margin-left: -13px; }
.mk.lod1 img + img { margin-left: 3px; }   /* room to breathe: icons side by side */
.mk .mkt {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin: 0 4px 0 7px;
  text-align: left;
  line-height: 1.25;
}
.mk .mkt .l1 {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}
.mk .mkt .l2 {
  font-size: 10.5px;
  color: #e2e6d4;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}
.mk .pct {
  font-size: 11px;
  font-weight: 700;
  color: #e8ecd8;
  margin-left: 5px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  font-variant-numeric: tabular-nums;
}
.mk .n {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  margin-left: 4px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  font-variant-numeric: tabular-nums;
}

#empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
  pointer-events: none;
}
#empty[hidden] { display: none; }

/* Desktop hover tooltip */
#tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  padding: 8px;
  max-width: 220px;
}
#tooltip img.t-thumb {
  display: block;
  width: 204px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  background: #0004;
}
#tooltip .t-line { font-size: 12.5px; margin-top: 6px; color: var(--ink); }
#tooltip .t-sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; }

/* ---- Player overlay ---- */
#player {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--overlay);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
#player[hidden] { display: none; }

/* opening animation: backdrop fades while the stage grows out of the tapped
 * marker (JS sets the transform-origin) and the control panel rises */
#player.anim { animation: pfade 0.22s ease-out; }
#player.anim #pStage { animation: pgrow 0.30s cubic-bezier(0.2, 0.9, 0.3, 1.04); }
#player.anim #pPanel { animation: prise 0.30s ease-out; }
@keyframes pfade { from { opacity: 0; } }
@keyframes pgrow { from { transform: scale(0.25); opacity: 0.2; } }
@keyframes prise { from { transform: translateY(26px); opacity: 0; } }

#pClose {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: 10px;
  z-index: 3;
}

#pStage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
  touch-action: none;           /* pinch + pan belong to the video, not the page */
}
#pZoom { width: 100%; height: 100%; display: grid; place-items: center; }
/* both quality copies overlay edge-to-edge; the transform (pinch zoom) rides the
 * wrapper so a quality swap never resets the zoom. The hidden HD element is
 * absolutely positioned so it can never influence layout (an empty <video> has a
 * phantom 300x150 intrinsic size). object-fit letterboxes against transparency —
 * no element background, so no fake black borders. */
#pMedia {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
}
#pMedia video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#pVideoHd { visibility: hidden; }
#pVideoHd.show { visibility: visible; }
#pVideo.hide { visibility: hidden; }

#pPanel {
  flex: none;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: #f2f3f8;
}
#pCaption { display: flex; align-items: center; gap: 10px; }
#pCaption > div { flex: 1; min-width: 0; }
#pTitle { font-size: 15px; font-weight: 650; }
#pSub {
  font-size: 12.5px;
  color: #b8b8c0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* tap the caption to unclamp the details when they don't fit on a phone */
#pCaption > div { cursor: pointer; }
#pSub.expand { white-space: normal; overflow: visible; text-overflow: clip; }
#pQuality {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #b8b8c0;
  border: 1px solid #ffffff38;
  border-radius: 5px;
  padding: 2px 5px;
  opacity: 0;
  transition: opacity 0.25s;
}
#pQuality.on { opacity: 1; color: #fff; border-color: #ffffff85; }

#pScrubRow { display: flex; align-items: center; gap: 10px; }
#pScrubRow input { flex: 1; }
.ptime {
  font-size: 11.5px;
  color: #b8b8c0;
  font-variant-numeric: tabular-nums;
  min-width: 58px;
}
#pDur { text-align: right; }

#pControls { display: flex; justify-content: center; align-items: center; gap: 8px; }
.icon-btn.text-btn { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.icon-btn.alt { border: 1px solid rgba(255, 255, 255, 0.45); }
.icon-btn {
  font: inherit;
  font-size: 17px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: #f2f3f8;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.22); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn.big { width: 58px; height: 58px; }
.icon-btn.big svg { width: 26px; height: 26px; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

/* thin scrubber + speed slider */
input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: var(--track, #ffffff2e);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  margin-top: -5.5px;
  border: none;
}
input[type="range"]::-moz-range-track { height: 3px; border-radius: 2px; background: var(--track, #ffffff2e); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: none; }

/* Roomier on wide screens: player becomes a centered column */
@media (min-width: 900px) {
  #pPanel { max-width: 760px; width: 100%; margin: 0 auto; }
}
