/*
 * One stylesheet, dark, phone-first.
 *
 * Design tokens are the ones named in the plan. Two rules are load-bearing:
 *
 *   1. The wipe is built with `clip-path: inset(...)`. Never `width` plus
 *      `overflow: hidden`: that resizes the layer instead of revealing it, so
 *      the copy scales as the handle moves.
 *   2. Every interactive target is at least 44px in both axes.
 */

:root {
  --bg: #0b0d10;
  --panel: #14181d;
  --panel-2: #1b2027;
  --line: #2a313a;
  --fg: #e8edf2;
  --muted: #93a0ad;
  --accent: #ff7a3d;
  --accent-dim: #b8532a;
  --ok: #4ec9a0;
  --warn: #ffcf5c;
  --danger: #ff6b6b;

  --hit: 44px;
  --radius: 10px;
  --radius-sm: 6px;
  --gap: 14px;
  --pad: 14px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

html {
  background: var(--bg);
  /* A vertical drag must scroll the page, never bounce it. */
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  /* Kill the 300 ms double-tap zoom on every control. */
  touch-action: manipulation;
  overscroll-behavior: none;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

h1,
h2,
h3 {
  margin: 0 0 6px;
  line-height: 1.2;
  font-weight: 650;
}

h1 {
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.05rem;
}

p {
  margin: 0 0 10px;
}

/* ---------------------------------------------------------------- chrome -- */

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 calc(var(--pad) + env(safe-area-inset-left)) 0
    calc(var(--pad) + env(safe-area-inset-right));
}

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(180deg, var(--bg) 72%, rgba(11, 13, 16, 0));
  padding: calc(12px + env(safe-area-inset-top)) 0 10px;
}

.top__row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.top__sub {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0;
}

.nav {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--hit);
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--fg);
  text-decoration: none;
  font-size: 0.9rem;
}

.nav a[aria-current="page"] {
  border-color: var(--accent-dim);
  color: var(--accent);
}

.banner {
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 12px 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.banner strong {
  color: var(--fg);
}

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  vertical-align: 1px;
}

.tag--approx {
  border-color: var(--warn);
  color: var(--warn);
}

.tag--ok {
  border-color: var(--ok);
  color: var(--ok);
}

.tag--bad {
  border-color: var(--danger);
  color: var(--danger);
}

/* ---------------------------------------------------------------- layout -- */

.grid {
  display: grid;
  gap: var(--gap);
  grid-template-columns: 1fr;
  margin: 14px 0 24px;
}

@media (min-width: 760px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.card__body {
  padding: 12px var(--pad) var(--pad);
}

.card__title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.card__credit {
  color: var(--muted);
  font-size: 0.78rem;
}

/* ----------------------------------------------------------------- chips -- */

/* Wrapping, not a horizontal scroller. A hidden scrollbar with no fade and no
   half-visible chip gives the user nothing to tell them that LRD and LAB are
   there at all. Wrapping shows every preset on every width. */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 4px;
  margin: 8px 0;
}

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: var(--hit);
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--fg);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip:hover {
  border-color: var(--muted);
}

.chip[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #14100d;
  font-weight: 650;
}

.chip:focus-visible,
.btn:focus-visible,
.nav a:focus-visible,
.wipe__handle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* -------------------------------------------------------------- controls -- */

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--hit);
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--fg);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #14100d;
  font-weight: 650;
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

input[type="range"] {
  width: 100%;
  min-height: var(--hit);
  accent-color: var(--accent);
  background: transparent;
}

label.field {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 2px;
}

/* ------------------------------------------------------------------ wipe -- */

/*
 * Two stacked layers. The "before" layer fills the box. The "after" layer sits
 * on top and is *clipped* from the left, so the handle uncovers it without
 * rescaling either image. `overflow: hidden` here is only for the rounded
 * corners; it is not what makes the wipe work.
 */
.wipe {
  --wipe: 50%;
  position: relative;
  overflow: hidden;
  background: #05070a;
  aspect-ratio: 4 / 3;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.wipe__layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}

.wipe__layer--after {
  clip-path: inset(0 0 0 var(--wipe));
}

.wipe__badge {
  position: absolute;
  bottom: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(5, 7, 10, 0.72);
  color: var(--fg);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  pointer-events: none;
}

.wipe__badge--before {
  left: 8px;
}

.wipe__badge--after {
  right: 8px;
  color: var(--accent);
}

.wipe__handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--wipe);
  width: var(--hit);
  margin-left: calc(var(--hit) / -2);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: ew-resize;
  touch-action: none;
}

.wipe__handle::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: var(--accent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}

.wipe__handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid rgba(0, 0, 0, 0.6);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.wipe__handle:active::after {
  transform: scale(0.94);
}

/* --------------------------------------------------------------- metrics -- */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 6px 10px;
  margin: 10px 0 0;
  font-size: 0.78rem;
}

.metrics div {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  border-bottom: 1px dotted var(--line);
  padding-bottom: 2px;
}

.metrics dt {
  color: var(--muted);
}

.metrics dd {
  margin: 0;
  font-family: var(--mono);
}

.note {
  color: var(--muted);
  font-size: 0.78rem;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
  color: var(--muted);
}

code,
kbd {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
}

.foot {
  color: var(--muted);
  font-size: 0.78rem;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 8px;
}

/* -------------------------------------------------------------- camera app -- */

/*
 * The camera is the app: the stage is the viewport, not a box in a page. The
 * controls float over the picture — a cogwheel top right, the shutter centred
 * at the bottom, and the last shot in the bottom-left corner. Nothing is in
 * the flow, so there is nothing to scroll and no fullscreen button to press.
 */
body.is-camera {
  padding: 0;
  overflow: hidden;
}

.cam__stage {
  position: fixed;
  inset: 0;
  background: #000;
  /* `clip`, not `hidden`. `hidden` still makes the stage a scroll container,
     so anything that calls `scrollIntoView` on a control inside it — the
     smoke test does — scrolls the whole overlay out of place. */
  overflow: hidden;
  overflow: clip;
}

/*
 * The video is covered, not hidden: `display: none` can stop a browser from
 * decoding frames at all. `contain`, not `cover`, because cropping a rock-art
 * panel to fill the screen would hide the edge the pigment is on.
 */
.cam__video,
.cam__gl {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

/* The shutter flash: a white sheet over the picture, gone in a tenth of a
   second. It carries no pointer events, so a second tap still reaches the
   shutter underneath. */
.cam__stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 8;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s linear;
}

.cam__stage.is-flash::after {
  opacity: 0.8;
  transition: none;
}

.cam__hud {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  right: calc(64px + env(safe-area-inset-right));
  z-index: 3;
  pointer-events: none;
  font-size: 0.78rem;
  color: var(--muted);
}

.cam__status,
.cam__err {
  margin: 0 0 4px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

.cam__err {
  color: var(--danger);
}

/* -- the floating controls ------------------------------------------------ */

.cam__cog,
.cam__shots,
.cam__shutter {
  -webkit-tap-highlight-color: transparent;
}

.cam__cog {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top));
  right: calc(8px + env(safe-area-inset-right));
  z-index: 4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--hit);
  height: var(--hit);
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(11, 13, 16, 0.55);
  color: var(--fg);
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.cam__cog[aria-expanded="true"] {
  color: var(--accent);
  border-color: var(--accent-dim);
}

.cam__shots {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left));
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--hit);
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(11, 13, 16, 0.55);
  color: var(--fg);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.cam__shots.is-empty {
  padding: 0 14px;
}

.cam__shots-thumb {
  display: block;
  height: 38px;
  width: auto;
  border-radius: 8px;
  object-fit: cover;
  background: var(--panel-2);
}

.cam__shots-count {
  font-family: var(--mono);
  font-size: 0.78rem;
}

.cam__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

/* A red disc inside a white ring, which is what a shutter looks like. */
.cam__shutter {
  pointer-events: auto;
  width: 72px;
  height: 72px;
  padding: 0;
  border-radius: 50%;
  border: 4px solid #f2f4f6;
  background: #e0403c;
  box-shadow:
    0 4px 18px rgba(0, 0, 0, 0.55),
    inset 0 0 0 2px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  transition: transform 0.08s ease;
}

.cam__shutter:active {
  transform: scale(0.92);
}

.cam__shutter.is-busy {
  background: #7d2a28;
  cursor: progress;
}

.cam__shutter:focus-visible,
.cam__cog:focus-visible,
.cam__shots:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* -- the settings, shots and adjust panels -------------------------------- */

/*
 * Every panel slides in from the right over the picture. Closed, each is parked
 * past the right edge, so it cannot swallow a tap meant for the shutter. The
 * blur keeps the live view readable underneath without hiding it.
 */
.cam__sheet,
.cam__panel,
.cam__adjust {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 6;
  height: 100%;
  width: min(360px, 90vw);
  padding: calc(12px + env(safe-area-inset-top)) 14px
    calc(16px + env(safe-area-inset-bottom));
  background: rgba(11, 13, 16, 0.86);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.45);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateX(105%);
  transition: transform 0.22s ease;
}

.cam__panel,
.cam__adjust {
  width: min(440px, 94vw);
}

.cam__sheet.is-open,
.cam__panel.is-open,
.cam__adjust.is-open {
  transform: translateX(0);
}

/*
 * The computed still, at the sensor's own aspect ratio. Full width, height from
 * the ratio set inline by `setPreview`; a square crop would hide the frame the
 * stretch is meant to reveal.
 */
.cam__preview {
  display: block;
  width: 100%;
  height: auto;
  margin: 2px 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #05070a;
}

.cam__adjust-note {
  color: var(--warn);
}

.cam__sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.cam__sheet-head h2 {
  margin: 0;
}

.cam__sheet-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 10px;
}

.cam__provenance {
  display: inline-block;
}

.cam__field {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cam__gain-value {
  min-width: 3.6rem;
  text-align: right;
  font-family: var(--mono);
}

/* -- the shots panel ------------------------------------------------------ */

.shots__list {
  display: grid;
  gap: 10px;
}

.shot {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

/*
 * The shot at the sensor's own aspect ratio, spanning the whole tile. The
 * `aspect-ratio` is set inline from the stored dimensions; fixing a square here
 * would crop the edges of the frame, which is where the faint pigment is.
 */
.shot__thumb {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
  background: #05070a;
}

.shot__meta {
  min-width: 0;
}

.shot__facts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

.shot__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.shot__actions .btn {
  padding: 0 12px;
  font-size: 0.82rem;
}

.shot__danger {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.5);
}

.shot__danger.is-armed {
  background: var(--danger);
  border-color: var(--danger);
  color: #1a0c0c;
  font-weight: 650;
}

.is-off {
  opacity: 0.45;
}

@media (prefers-reduced-motion: reduce) {
  .cam__sheet,
  .cam__panel,
  .cam__adjust,
  .cam__shutter {
    transition: none;
  }
}

.hidden {
  display: none !important;
}

.err {
  color: var(--danger);
  font-size: 0.85rem;
}

.stat-line {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
}

/* The live readout is rewritten four times a second, and its text changes
   width every time — a frame time of 12.4 ms becomes 9.1 ms. Wrapped, that
   changes the number of lines, and with it the page height, so the controls
   below it jump several times a second. One line of constant height, scrolled
   sideways when it overflows, removes the shift. */
.stat-line--readout {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  scrollbar-width: none;
  min-height: 1.2rem;
}

.stat-line--readout::-webkit-scrollbar {
  display: none;
}
