:root, html.light {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  --label: rgba(0, 0, 0, 0.88);
  --secondary: rgba(60, 60, 67, 0.62);
  --bg: #f5f5f7;
  --glass-bg: rgba(255, 255, 255, 0.42);
  --glass-strong: rgba(255, 255, 255, 0.72);
  --menu-bg: rgba(250, 250, 252, 0.96);
  --glass-border: rgba(255, 255, 255, 0.6);
  --glass-hi: rgba(255, 255, 255, 0.75);
  --thumb: rgba(255, 255, 255, 0.95);
  --track: rgba(120, 120, 128, 0.22);
  --accent: #007aff;
  --gray: #8e8e93;
  --warn: #c93400;
  --ease: cubic-bezier(0.3, 0.7, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --label: rgba(255, 255, 255, 0.92);
    --secondary: rgba(235, 235, 245, 0.6);
    --bg: #000;
    --glass-bg: rgba(36, 36, 40, 0.5);
    --glass-strong: rgba(36, 36, 40, 0.78);
    --menu-bg: rgba(40, 40, 44, 0.96);
    --glass-border: rgba(255, 255, 255, 0.14);
    --glass-hi: rgba(255, 255, 255, 0.16);
    --thumb: rgba(255, 255, 255, 0.2);
    --track: rgba(120, 120, 128, 0.36);
    --accent: #0a84ff;
    --gray: #8e8e93;
    --warn: #ffb340;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--label);
  font: 13px/1.3 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}

button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* Liquid Glass material */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(22px) saturate(1.8);
  backdrop-filter: blur(22px) saturate(1.8);
  border: 0.5px solid var(--glass-border);
  box-shadow:
    inset 0 1px 0 var(--glass-hi),
    0 10px 30px rgba(0, 0, 0, 0.12),
    0 1px 3px rgba(0, 0, 0, 0.08);
  /* Only the material fades. Text color never transitions: an interrupted color fade could leave
     text stuck in the other theme (white on the light card, black on the dark one). */
  transition: background-color 0.35s var(--ease), border-color 0.35s var(--ease);
}

/* Stage */
#stage { position: fixed; inset: 0; }
.view { position: absolute; inset: 0; overflow: hidden; }
.view[hidden] { display: none; }

canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

#view-sharpness.dragging { cursor: ew-resize; }

#divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  cursor: ew-resize;
  touch-action: none;
}
/* Invisible grab area around the thin line. */
#divider::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -12px;
  width: 24px;
}
#divider::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -1px;
  width: 2px;
  background: #fff;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.35);
}
#divider:focus-visible { outline: none; }
#divider:focus-visible .knob { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); }

.knob {
  position: absolute;
  top: 74%;
  left: 0;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: transform 0.25s var(--ease), background-color 0.35s var(--ease);
}
#view-sharpness.dragging .knob { transform: translate(-50%, -50%) scale(1.15); }

.tag {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: var(--label);
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  pointer-events: none;
}
#divider .tag { top: 74%; transform: translateY(-50%); }
#tag-a { right: 30px; }
#tag-b { left: 30px; }

/* Motion */
#view-motion { display: flex; flex-direction: column; }
#view-motion[hidden] { display: none; }
.lane { position: relative; flex: 1; overflow: hidden; }
.lane + .lane { border-top: 2px solid #fff; }
.lane .tag { left: 16px; top: 16px; }
.lane:first-child .tag { top: 76px; }

/* Field of view */
#view-fov { background: var(--bg); }
#fov {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 76px;
  bottom: 190px;
  width: calc(100% - 48px);
  height: calc(100% - 266px);
}
#fov text { font-family: var(--font); font-size: 4px; font-weight: 600; }
#fov .w-human { fill: rgba(120, 120, 128, 0.12); }
#fov .w-screen { fill: rgba(120, 120, 128, 0.14); stroke: var(--secondary); stroke-width: 0.5; stroke-dasharray: 2 1.5; }
#fov .w-shared { fill: var(--gray); fill-opacity: 0.22; stroke: var(--gray); stroke-width: 0.6; }
#fov .w-extra { fill: var(--accent); fill-opacity: 0.55; stroke: var(--accent); stroke-width: 0.6; }
#fov .head { fill: #1d1d1f; }
@media (prefers-color-scheme: dark) { #fov .head { fill: #f5f5f7; } }
#fov .t-muted { fill: var(--secondary); }
#fov .t-shared { fill: var(--gray); }
#fov .t-extra { fill: var(--accent); }

/* Toolbar */
.toolbar {
  position: fixed;
  top: 14px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.toolbar > * { pointer-events: auto; }

.segmented {
  position: relative;
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  touch-action: none;
}
.segmented label { position: relative; z-index: 1; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 999px;
}
.segmented input:checked + span { font-weight: 600; }
/* Reserve the bold width so labels don't shift when the selection changes. */
.segmented span::after {
  content: attr(data-text);
  display: block;
  height: 0;
  overflow: hidden;
  visibility: hidden;
  font-weight: 600;
}
.segmented input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); }
.segmented .thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border-radius: 999px;
  background: var(--thumb);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14), inset 0 0.5px 0 rgba(255, 255, 255, 0.6);
}
.segmented.ready .thumb {
  transition: left 0.35s var(--ease), width 0.35s var(--ease), transform 0.25s var(--ease),
    background-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.segmented input:checked + span { cursor: grab; }
/* Held or moving, the thumb lifts into clear glass (iOS 26 Liquid Glass); while dragging it follows the pointer. */
.segmented.pressed .thumb,
.segmented.moving .thumb {
  transform: scale(1.12);
  background: rgba(255, 255, 255, 0.12);
  box-shadow:
    inset 0 0 0 0.5px rgba(255, 255, 255, 0.8),
    inset 0 1px 2px rgba(255, 255, 255, 0.55),
    0 6px 18px rgba(0, 0, 0, 0.18);
}
.segmented.ready.dragging .thumb {
  transition: width 0.25s var(--ease), transform 0.25s var(--ease), background-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.segmented.dragging, .segmented.dragging * { cursor: grabbing; }

.icon-btn {
  position: absolute;
  right: 16px;
  top: 0;
  width: 37px;
  height: 37px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: transform 0.2s var(--ease), background-color 0.35s var(--ease);
}
.icon-btn:active { transform: scale(0.94); }

.popover {
  position: absolute;
  right: 16px;
  top: 48px;
  width: 280px;
  padding: 14px 16px 16px;
  border-radius: 20px;
  background: var(--glass-strong);
  transform-origin: top right;
  animation: pop 0.25s var(--ease);
}
.popover[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: scale(0.94); } }

.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 30px; }
.field + .field { margin-top: 8px; }
.field label, .field > span { font-weight: 500; }
output { color: var(--secondary); font-variant-numeric: tabular-nums; }

/* Pop-up button */
.popup { position: relative; display: inline-flex; align-items: center; gap: 8px; }
.popup .chev { position: absolute; right: 0; width: 8px; height: 13px; pointer-events: none; color: var(--secondary); }
button.popup:active { opacity: 0.6; }
button.popup {
  padding: 2px 18px 2px 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.popup.title { font-size: 17px; font-weight: 600; }

/* Pop-up menu: always lists every item. Opens upward from the cards, downward in settings. */
.picker { position: relative; display: inline-block; }
.menu {
  position: absolute;
  left: -10px;
  bottom: calc(100% + 10px);
  z-index: 10;
  min-width: 250px;
  padding: 6px;
  border-radius: 16px;
  background: var(--menu-bg);
  transform-origin: bottom left;
  animation: pop 0.22s var(--ease);
}
.menu[hidden] { display: none; }
.menu-down {
  left: auto;
  right: -10px;
  bottom: auto;
  top: calc(100% + 8px);
  min-width: 220px;
  transform-origin: top right;
}
.menu-label {
  padding: 6px 12px 3px 30px;
  font-size: 11px;
  font-weight: 600;
  color: var(--secondary);
}
.menu-label:not(:first-child) { margin-top: 4px; border-top: 0.5px solid var(--track); padding-top: 8px; }
.menu-item {
  position: relative;
  padding: 6px 12px 6px 30px;
  border-radius: 9px;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
}
.menu-item[aria-selected="true"]::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 50%;
  width: 10px;
  height: 6px;
  border: solid currentColor;
  border-width: 0 0 2px 2px;
  transform: translateY(-70%) rotate(-45deg);
}
.menu-item:hover, .menu-item:focus { background: var(--accent); color: #fff; }

/* Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 10px 0 0;
  background: transparent;
  cursor: pointer;
  --p: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--track) var(--p));
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--track); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25), 0 0 0 0.5px rgba(0, 0, 0, 0.06);
}
input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

/* Cards */
.cards {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}
.card {
  pointer-events: auto;
  width: min(390px, calc(50% - 8px));
  padding: 14px 18px 16px;
  border-radius: 24px;
}
.sub { margin: 2px 0 0; color: var(--secondary); font-size: 12px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, auto);
  justify-content: space-between;
  gap: 8px;
  margin: 14px 0 0;
}
.stats > div { display: flex; flex-direction: column; transition: opacity 0.3s; }
.stats > div.dim { opacity: 0.38; }
.fov-shared dd { color: var(--gray); }
.fov-extra dd { color: var(--accent); }
.stats dd { order: -1; margin: 0; font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
#name-a, #name-b { display: inline-block; }
.stats dd small { font-size: 12px; font-weight: 500; color: var(--secondary); }
.stats dt { margin-top: 1px; font-size: 11px; color: var(--secondary); }

.warn { margin: 10px 0 0; font-size: 12px; font-weight: 500; color: var(--warn); }
.warn[hidden] { display: none; }

@media (max-width: 760px) {
  .cards { flex-direction: column; gap: 10px; }
  .card { width: 100%; padding: 12px 16px; }
  .segmented span { padding: 7px 11px; }
  .icon-btn { top: 52px; }
  .popover { top: 98px; }
}

@media (prefers-reduced-motion: reduce) {
  .segmented.ready .thumb, .popover, .menu, .knob, .glass, .stats > div, .stats dd { transition: none; animation: none; }
}

/* While the page loads, nothing transitions (see the inline script in index.html). */
.preload *,
.preload *::before,
.preload *::after { transition: none !important; }
