/* Register the tint color so WebKit can interpolate the computed color of
   the invisible Safari chrome samplers instead of switching it instantly. */
@property --safari-chrome-color {
  syntax: '<color>';
  inherits: true;
  initial-value: #fff;
}
:root {
  color-scheme: light;
  --page-bg: #fff;
  --viewer-bg: #fff;
  --text-primary: #111;
  --text-secondary: #666;
  --tabs-bg: #f4f4f5;
  --tab-active-bg: #fff;
  --tab-shadow: #00000014;
  --placeholder-bg: #f5f5f5;
  --spinner-track: #ddd;
  --spinner-head: #777;
  --focus-ring: #777;
  --button-bg: #fff;
  --button-text: #111;
  --button-border: #ccc;
  background: var(--page-bg);
  color: var(--text-primary);
  font-family: system-ui, sans-serif;
  --viewer-spring-duration: 270ms;
  --viewer-color-duration: 180ms;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page-bg: #111113;
    --viewer-bg: #000;
    --text-primary: #f5f5f7;
    --text-secondary: #b4b4bd;
    --tabs-bg: #242427;
    --tab-active-bg: #38383d;
    --tab-shadow: #00000055;
    --placeholder-bg: #242428;
    --spinner-track: #55555c;
    --spinner-head: #bdbdc5;
    --focus-ring: #c8c8d0;
    --button-bg: #303035;
    --button-text: #f5f5f7;
    --button-border: #73737d;
  }
}
* { box-sizing: border-box; }
/* Older Safari reads theme-color; Safari 26 samples viewport-edge elements.
   Extend to the physical edges, then keep content outside iPhone safe areas. */
body {
  margin: 0;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
  padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  background: var(--page-bg);
  --safari-chrome-color: var(--page-bg);
  /* Fade both the page and Safari's sampled edge color between states. */
  transition: background-color var(--viewer-color-duration) ease-in-out,
              --safari-chrome-color var(--viewer-color-duration) ease-in-out;
}
body[data-viewer-open="true"] { overflow: hidden; overscroll-behavior: none; background: var(--viewer-bg); --safari-chrome-color: var(--viewer-bg); }
/* Paintless, persistent edge samplers override Safari's stale fullscreen tint.
   A transparent or display:none box is not eligible for WebKit color sampling. */
.safari-chrome-sample {
  position: fixed;
  z-index: 2147483647;
  pointer-events: none;
  background-color: var(--safari-chrome-color);
  background-clip: text;
  -webkit-background-clip: text;
}
.safari-chrome-sample--top, .safari-chrome-sample--bottom {
  left: 0;
  right: 0;
  height: 0;
}
.safari-chrome-sample--top { top: 0; }
.safari-chrome-sample--bottom { bottom: 0; }
.safari-chrome-sample--left, .safari-chrome-sample--right {
  top: 0;
  bottom: 0;
  height: 100vh;
  height: 100dvh;
  width: 0;
}
.safari-chrome-sample--left { left: 0; }
.safari-chrome-sample--right { right: 0; }
@supports (-webkit-touch-callout: none) {
  @media (hover: none) and (pointer: coarse) {
    .safari-chrome-sample--top, .safari-chrome-sample--bottom { height: 11px; }
    .safari-chrome-sample--left, .safari-chrome-sample--right { width: 11px; }
    html[data-chrome-sample-refresh] .safari-chrome-sample--top,
    html[data-chrome-sample-refresh] .safari-chrome-sample--bottom { height: 12px; }
    html[data-chrome-sample-refresh] .safari-chrome-sample--left,
    html[data-chrome-sample-refresh] .safari-chrome-sample--right { width: 12px; }
  }
}
.tabs { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 24px; border-radius: 10px; background: var(--tabs-bg); }
.tabs button { min-height: 40px; padding: 0 18px; border: 0; border-radius: 7px; background: transparent; color: var(--text-secondary); font: inherit; font-size: 14px; cursor: pointer; }
.tabs button[aria-selected="true"] { background: var(--tab-active-bg); color: var(--text-primary); box-shadow: 0 1px 3px var(--tab-shadow); }
.tabs button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.cameras { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.camera { position: relative; min-width: 0; }
.camera-media { position: relative; border-radius: 12px; }
/* A single named media box in the old/new snapshots lets the browser morph
   between its grid rect and its fixed fullscreen-fallback rect. */
@supports (view-transition-name: camera-viewer) {
  .camera-media[data-view-transition="true"] { view-transition-name: camera-viewer; }
  ::view-transition-group(camera-viewer) {
    animation-duration: var(--viewer-spring-duration);
    /* Fallback for browsers without CSS linear() easing. */
    animation-timing-function: cubic-bezier(.18, .9, .25, 1);
    /* Damped spring: gentle ~4% overshoot, then settle at the target.
       Sampled from a mass-spring-damper curve; works on Safari 17.2+. */
    animation-timing-function: linear(
      0, .092, .288, .503, .692, .837, .936, .996, 1.027, 1.038,
      1.037, 1.03, 1.022, 1.014, 1.008, 1.004, 1.001, .999, .999, .999, 1
    );
  }
  /* Cross-fade snapshots while respecting the OS-selected viewer background. */
  ::view-transition-old(root), ::view-transition-new(root) {
    animation-duration: var(--viewer-color-duration);
    animation-timing-function: ease-in-out;
  }

}
/* Desktop grid/detail transitions animate the original live camera via FLIP,
   without any duplicated View Transition snapshots or geometry overshoot. */
.camera-media[data-zooming="true"],
.camera-media[data-slide-in="true"] { will-change: transform; }
@media (prefers-reduced-motion: reduce) {
  body { transition: none; }
  ::view-transition-group(camera-viewer),
  ::view-transition-old(root), ::view-transition-new(root) {
    animation-duration: 0.01ms;
  }
}
/* Cover native mobile play chrome without hiding the video from autoplay. */
.camera:not([data-state="playing"]) .camera-media::before { content: ""; position: absolute; inset: 0; z-index: 1; border-radius: inherit; background: var(--placeholder-bg); pointer-events: none; }
.camera:not([data-state="playing"]) .camera-media:fullscreen::before,
.camera:not([data-state="playing"]) .camera-media[data-expanded="true"]::before { background: var(--viewer-bg); }
.camera[data-state="error"] .camera-media::before { background: var(--placeholder-bg); }
.camera[data-state="error"] .camera-media:fullscreen::before,
.camera[data-state="error"] .camera-media[data-expanded="true"]::before {
  background: var(--placeholder-bg);
  inset: 50% auto auto 50%; transform: translate(-50%, -50%); border-radius: 0;
  width: min(100%, calc(100dvh * var(--camera-ratio, 1.7777778)));
  height: min(100%, calc(100vw / var(--camera-ratio, 1.7777778)));
}
.view-toggle { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; padding: 0; border: 0; border-radius: inherit; background: transparent; cursor: zoom-in; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.view-toggle[aria-pressed="true"] { cursor: default; }
.view-toggle[data-dismiss-target="true"] { cursor: zoom-out; }
.view-toggle[data-camera-center="true"] { cursor: default; }
/* Desktop previous/next is drawn in the cursor itself: no floating hover
   badge obscures the live stream. Keep a pointer fallback for unsupported SVG. */
@media (hover: hover) and (pointer: fine) {
  .camera-media[data-expanded="true"] .view-toggle[data-nav-direction="previous"] {
    cursor: url("/cursors/previous.svg") 2 2, pointer;
  }
  .camera-media[data-expanded="true"] .view-toggle[data-nav-direction="next"] {
    cursor: url("/cursors/next.svg") 2 2, pointer;
  }
}
/* Shortcut-triggered focus is programmatic; Tab navigation still gets a ring. */
.view-toggle[data-shortcut-focus="true"]:focus-visible,
.tabs button[data-shortcut-focus="true"]:focus-visible { outline: none; }
/* Handle camera pinch zoom, panning and swipes locally so a tap can reset zoom. */
.camera-media[data-expanded="true"] .view-toggle,
.camera-media:fullscreen .view-toggle { touch-action: none; }
body[data-viewer-zoomed="true"] .camera-media .view-toggle { cursor: zoom-out; }
.view-toggle:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -3px; }
.spinner { display: none; position: absolute; z-index: 2; top: 50%; left: 50%; width: 20px; height: 20px; border: 2px solid var(--spinner-track); border-top-color: var(--spinner-head); border-radius: 50%; transform: translate(-50%, -50%); animation: spin .8s linear infinite; pointer-events: none; }
.camera[data-state="loading"] .spinner { display: block; }
@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
h2 { margin: 10px 0 0; font-size: 14px; font-weight: 500; }
video, .mjpeg-frame { display: block; width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; background: var(--placeholder-bg); object-fit: contain; }
.mjpeg-frame { display: flex; align-items: center; justify-content: center; }
.mjpeg-crop { position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; border-radius: inherit; }
.mjpeg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
#cucharas-image { transform: scale(1.08); transform-origin: bottom left; }
.camera-media:fullscreen, .camera-media[data-expanded="true"] { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; border-radius: 0; background: var(--viewer-bg); }
/* Fit the live video to the browser viewport (not the OS display) and keep
   its aspect ratio. The browser toolbar/window decorations remain visible. */
.camera-media[data-expanded="true"] { position: fixed; inset: 0; z-index: 1000; height: 100vh; height: 100dvh; overscroll-behavior: none; }
.camera-media:fullscreen video, .camera-media[data-expanded="true"] video { width: 100%; height: 100%; border-radius: 0; background: var(--viewer-bg); }
.camera-media:fullscreen .mjpeg-frame, .camera-media[data-expanded="true"] .mjpeg-frame { flex-shrink: 0; width: min(100%, calc(100dvh * 16 / 9)); border-radius: 0; background: var(--viewer-bg); }
.camera-media::backdrop { background: var(--viewer-bg); }
.retry { position: absolute; z-index: 3; top: 50%; left: 50%; transform: translate(-50%, -50%); padding: 8px 16px; border: 1px solid var(--button-border); border-radius: 8px; background: var(--button-bg); color: var(--button-text); font: inherit; cursor: pointer; }
.status { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }
@media (max-width: 700px) {
  .tabs { display: flex; width: fit-content; margin-inline: auto; }
  .cameras { grid-template-columns: 1fr; }
}
