:root {
  --bg: #0d0f12;
  --panel: #15181d;
  --line: #262b33;
  --text: #e7ebf0;
  --muted: #8b95a3;
  --accent: #4f9dff;
  --danger: #ff6b6b;
  --ok: #43d17c;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* A class that sets `display` outranks the UA's [hidden] rule, so state the
   intent once and let every hidden element mean it. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overflow: hidden;
}

/* ------------------------------------------------------------- top bar */

.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px 8px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand { font-weight: 600; letter-spacing: .2px; white-space: nowrap; }

.session {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.session.active { color: var(--text); }

.counter {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.counter span { font-size: 22px; font-weight: 600; }
.counter small { color: var(--muted); }

/* The window controls of the app: one row, one size, no labels competing
   with the album name for the middle of the bar. */
.tools {
  display: flex;
  gap: 4px;
  padding-left: 4px;
  border-left: 1px solid var(--line);
}

button.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: var(--muted);
}

button.icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button.icon:hover { color: var(--text); }
button.icon.on { border-color: var(--accent); color: var(--accent); }

/* --------------------------------------------------------------- stage */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  flex: 1;
  min-height: 0;
}

.viewport {
  position: relative;
  display: grid;
  place-items: center;
  background: #000;
  overflow: hidden;
}

/* Sized by layoutPreview() so a rotated feed still fits the viewport. */
#video {
  display: block;
  transform-origin: center;
}

#video.mirror { transform: scaleX(-1); }
#video.rot-90 { transform: rotate(90deg); }
#video.rot-180 { transform: rotate(180deg); }
#video.rot-270 { transform: rotate(270deg); }
#video.mirror.rot-90 { transform: rotate(90deg) scaleY(-1); }
#video.mirror.rot-180 { transform: rotate(180deg) scaleX(-1); }
#video.mirror.rot-270 { transform: rotate(270deg) scaleY(-1); }

/* The preview wears the same tone curve the capture will bake in, so what
   you frame is what lands on disk. Keep these in step with LOOKS in app.js. */
#video.look-gray { filter: grayscale(1); }
#video.look-doc { filter: grayscale(1) contrast(1.45) brightness(1.06); }

.guides {
  position: absolute;
  pointer-events: none;
  background:
    linear-gradient(to right, transparent calc(33.33% - 1px), rgba(255,255,255,.25) 33.33%, transparent calc(33.33% + 1px)),
    linear-gradient(to right, transparent calc(66.66% - 1px), rgba(255,255,255,.25) 66.66%, transparent calc(66.66% + 1px)),
    linear-gradient(to bottom, transparent calc(33.33% - 1px), rgba(255,255,255,.25) 33.33%, transparent calc(33.33% + 1px)),
    linear-gradient(to bottom, transparent calc(66.66% - 1px), rgba(255,255,255,.25) 66.66%, transparent calc(66.66% + 1px));
}

.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.flash.fire { animation: flash .18s ease-out; }

@keyframes flash {
  from { opacity: .85; }
  to { opacity: 0; }
}

/* What the shutter is set to do, without opening a panel to find out. */
.badges {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: calc(100% - 24px);
  pointer-events: none;
}

.badges span {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .55);
  color: var(--muted);
  font-size: 11px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.badges span.hot { color: var(--accent); }

.hint {
  position: absolute;
  bottom: 18px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: var(--muted);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* --------------------------------------------------------------- panel */

.panel {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Every section is content-sized and the panel is what scrolls. An earlier
   version let the Recent block flex-grow from a zero basis, which squeezed it
   under its own thumbnails and painted them over the block below. */
.block {
  flex: none;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}

.block[open] { padding-bottom: 14px; }

.block > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 -16px;
  padding: 11px 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  list-style: none;
  -webkit-user-select: none;
  user-select: none;
}

.block > summary::-webkit-details-marker { display: none; }
.block > summary:hover { color: var(--text); }

.block > summary::after {
  content: "";
  width: 6px;
  height: 6px;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg) translate(-1px, 1px);
  transition: transform .15s ease;
}

.block[open] > summary::after { transform: rotate(45deg); }

/* A folded section still says what it is set to, so nothing has to be opened
   just to check. */
.summary-tag {
  padding: 1px 7px;
  border-radius: 999px;
  background: #232a34;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .02em;
  text-transform: none;
}

.summary-tag:empty { display: none; }
.block[open] .summary-tag { opacity: .5; }

.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }

.field { display: block; margin-bottom: 10px; }
.field > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.field b { color: var(--text); font-variant-numeric: tabular-nums; }

input[type="text"], select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f1216;
  color: var(--text);
  font: inherit;
}

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

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  cursor: pointer;
}

.check input { accent-color: var(--accent); }

button {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1d222a;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:hover { border-color: #3a424f; }
button.primary { border-color: transparent; background: var(--accent); color: #06121f; font-weight: 600; }

/* One control, three mutually exclusive answers — a row of radio buttons
   would cost three lines and read as three separate questions. */
.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  flex: 1;
  padding: 7px 4px;
  border: 0;
  border-radius: 0;
  background: #0f1216;
  color: var(--muted);
  font-size: 12px;
}

.segmented button + button { border-left: 1px solid var(--line); }
.segmented button:hover { color: var(--text); background: #171c22; }
.segmented button.on { background: var(--accent); color: #06121f; font-weight: 600; }

.path, .actual {
  margin: 8px 0 0;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  word-break: break-all;
}

.queue {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #2a3140;
  color: var(--accent);
  font-size: 10px;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

/* `contain`, not `cover`: a cropped thumbnail of a page of text tells you
   nothing about the page. This shows the whole shot, and a click opens it. */
.thumb {
  position: relative;
  aspect-ratio: var(--thumb-aspect, 3 / 4);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #000;
  overflow: hidden;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.thumb i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 4px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .75));
  color: #cfd6df;
  font: 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  font-style: normal;
  text-align: center;
}

.thumb:hover { border-color: var(--accent); }
.thumb.failed { border-color: var(--danger); opacity: .55; }

.keys {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  color: var(--muted);
  font-size: 12px;
}

kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #1d222a;
  color: var(--text);
  font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 30;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 8px;
  background: #22282f;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}

.toast.error { background: var(--danger); color: #2b0000; }
.toast.ok { background: var(--ok); color: #05230f; }

@media (max-width: 860px) {
  .stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: 1fr auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
}

/* ------------------------------------------------------------- triggers */

.sub {
  margin: 10px 0 4px;
  padding-left: 12px;
  border-left: 2px solid var(--line);
}

.note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

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

.meter {
  position: relative;
  height: 8px;
  margin-bottom: 12px;
  border-radius: 4px;
  background: #0f1216;
  overflow: hidden;
}

.meter i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width .05s linear;
}

.meter b {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--danger);
}

.listening { color: var(--ok); }

.tag {
  padding: 1px 6px;
  border-radius: 999px;
  background: #3a2f16;
  color: #e8b84b;
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.banner {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  padding: 10px 16px;
  background: var(--danger);
  color: #2b0000;
  font-weight: 500;
  text-align: center;
}

.check + .field { margin-top: 14px; }

/* Depletes over the minimum-interval window, so a swallowed press reads as
   "not yet" rather than "the app missed it". */
.cooldown {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: var(--accent);
  pointer-events: none;
}

/* Captures the server would not take are held, never silently dropped. */
.failed {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--danger);
  color: #2b0000;
}

.failed button {
  border-color: rgba(0, 0, 0, .35);
  background: rgba(0, 0, 0, .12);
  color: #2b0000;
  font-weight: 600;
}

/* Peak-hold marker: shows how loud the last sound actually was, so the
   threshold can be parked just under it. */
.meter u {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
  opacity: .8;
}

button.wide { width: 100%; margin-top: 10px; }
button:disabled { opacity: .45; cursor: default; }

/* --------------------------------------------------------------- review */

/* minmax(0, 1fr) rather than 1fr: a bare 1fr floors the row at the content's
   own height, and the content here is a full-resolution page — the stage grew
   past the window and took the filmstrip off the bottom of the screen. */
.review {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #07090b;
}

.review header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.review header .grow { flex: 1; }
.review header kbd { margin-left: 4px; }
.review header strong { font-weight: 600; }

#review-title {
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#review-status { color: var(--muted); font-variant-numeric: tabular-nums; }
#review-status.saving { color: var(--accent); }
#review-status.saved { color: var(--ok); }

.zoomer {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.zoomer button {
  min-width: 32px;
  padding: 6px 8px;
  border: 0;
  border-radius: 0;
  background: #1d222a;
  color: var(--muted);
}

.zoomer button + button { border-left: 1px solid var(--line); }
.zoomer button:hover { color: var(--text); }
#zoom-reset { min-width: 62px; font-variant-numeric: tabular-nums; font-size: 12px; }

.review-stage {
  overflow: auto;
  overscroll-behavior: contain;
  background:
    repeating-conic-gradient(#0b0e11 0% 25%, #0e1216 0% 50%) 50% / 22px 22px;
}

.review-stage.pannable { cursor: grab; }
.review-stage.panning { cursor: grabbing; }

/* min-width/height keep the page centred while it is smaller than the stage
   and let it push out scrollbars once it is not — which `place-items: center`
   alone cannot do without clipping the top-left of an over-sized image. */
.review-pan {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 100%;
  min-height: 100%;
  padding: 16px;
}

#review-canvas {
  display: block;
  border-radius: 3px;
  background: #000;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .6);
}

.review-strip {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  overflow-x: auto;
}

.review-strip img {
  height: 76px;
  width: auto;
  flex: none;
  border: 2px solid transparent;
  border-radius: 4px;
  background: #000;
  cursor: pointer;
}

.review-strip img.current { border-color: var(--accent); }

#connect-row button { margin-top: 0; }
#connect-row .note { margin-top: 8px; }

/* Offered, never forced: an update must not swap the app out mid-session. */
.update {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
