/*
 * app.css — Air-Gap Transfer visual identity.
 *
 * Cool paper, deep ultramarine ink and one signal blue. The QR stage is
 * always white on every theme: it is a light source for the other camera.
 * The mark is two facing brackets with an arrow crossing the gap between
 * them; reception progress is drawn as a field of QR-like modules.
 * Instrument Sans at its normal width throughout.
 */

/* Instrument Sans (SIL OFL), variable in weight and width, in two subsets:
   browsers fetch the Latin Extended file only for text that needs it. */
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans.woff2") format("woff2-variations"),
       url("../fonts/instrument-sans.woff2") format("woff2");
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("../fonts/instrument-sans-ext.woff2") format("woff2-variations"),
       url("../fonts/instrument-sans-ext.woff2") format("woff2");
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --paper: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #eceef7;
  --line: #d6d9ea;
  --ink: #12143a;
  --ink-2: #545878;
  --signal: #2e2be6;
  --signal-ink: #ffffff;
  --signal-soft: rgba(46, 43, 230, 0.12);
  --ok: #0c8a5c;
  --ok-soft: rgba(12, 138, 92, 0.12);
  --err: #c8261b;
  --err-soft: rgba(200, 38, 27, 0.1);
  --warn: #8f5a00;
  --stage-shadow: 0 1px 0 rgba(18, 20, 58, 0.04), 0 12px 40px -12px rgba(18, 20, 58, 0.22);

  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.5rem;
  --step-3: 2rem;
  --r-s: 8px;
  --r-m: 14px;
  --r-l: 22px;
  --gutter: max(16px, env(safe-area-inset-left));
  --page-width: 1120px;
  --page-top: clamp(24px, 6vh, 64px);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0a0b22;
    --surface: #13153a;
    --surface-2: #1b1e4a;
    --line: #2b2f61;
    --ink: #ecedfb;
    --ink-2: #a2a6cc;
    --signal: #8c8aff;
    --signal-ink: #0a0b22;
    --signal-soft: rgba(140, 138, 255, 0.16);
    --ok: #3fd39c;
    --ok-soft: rgba(63, 211, 156, 0.14);
    --err: #ff7064;
    --err-soft: rgba(255, 112, 100, 0.14);
    --warn: #f0b94a;
    --stage-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 18px 60px -10px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #0a0b22;
  --surface: #13153a;
  --surface-2: #1b1e4a;
  --line: #2b2f61;
  --ink: #ecedfb;
  --ink-2: #a2a6cc;
  --signal: #8c8aff;
  --signal-ink: #0a0b22;
  --signal-soft: rgba(140, 138, 255, 0.16);
  --ok: #3fd39c;
  --ok-soft: rgba(63, 211, 156, 0.14);
  --err: #ff7064;
  --err-soft: rgba(255, 112, 100, 0.14);
  --warn: #f0b94a;
  --stage-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 18px 60px -10px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Room for the scroll bar is always kept, so moving between a short and a
     long page never shifts the layout sideways. */
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }

:focus-visible {
  outline: 3px solid var(--signal);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden { display: none !important; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter) 12px;
  max-width: var(--page-width);
  width: 100%;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 650;
  font-size: var(--step-1);
  letter-spacing: -0.01em;
  white-space: nowrap;
  border-radius: var(--r-s);
}

.brand-mark {
  width: 28px;
  height: 28px;
  color: var(--signal);
}

.topbar-tools {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.tool {
  display: inline-grid;
  place-items: center;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  font-size: var(--step--1);
  letter-spacing: 0.02em;
}
.tool svg { width: 22px; height: 22px; }
.tool:hover { background: var(--surface-2); }
.tool[aria-pressed="true"] { background: var(--signal-soft); color: var(--signal); }

.lang select {
  height: 44px;
  max-width: 10.5em;
  padding: 0 28px 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23888' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 12px center / 10px;
  -webkit-appearance: none;
  appearance: none;
  font-weight: 600;
  font-size: var(--step--1);
  color: var(--ink);
  cursor: pointer;
}
.lang select:hover { background-color: var(--surface-2); }
.lang select option { background: var(--surface); color: var(--ink); }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
}

.view { display: none; }
.view.is-active { display: block; flex: 1; }

/* ---------- Buttons and inputs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 22px;
  border: 1.5px solid transparent;
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn svg { width: 20px; height: 20px; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn-primary { background: var(--signal); color: var(--signal-ink); }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--signal) 88%, var(--ink)); }
.btn-quiet { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-quiet:hover { border-color: var(--ink-2); }
.btn-large { min-height: 56px; padding: 0 28px; font-size: var(--step-1); }

.linkish {
  padding: 0;
  border: 0;
  background: none;
  color: var(--signal);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 32px;
  margin: 0;
  background: transparent;
  touch-action: pan-y;
}
input[type="range"]:disabled { opacity: 0.4; }
input[type="range"]:focus-visible { border-radius: 999px; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(var(--signal), var(--signal)) 0 / var(--fill, 50%) 100% no-repeat, var(--surface-2);
}
input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
}
input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 3px;
  background: var(--signal);
}
/* A plain disc, centered on the 6 px track. */
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -7px;
  border: 0;
  border-radius: 50%;
  background: var(--signal);
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: var(--signal);
}

.fine { color: var(--ink-2); font-size: var(--step--1); }

.banner {
  padding: 12px 16px;
  border-radius: var(--r-m);
  font-size: var(--step--1);
}
.banner-error { background: var(--err-soft); color: var(--err); }

/* ---------- Home ---------- */

/* Home, send, receive and the result share one frame: same width, same
   side and top margins as the top bar, so switching views moves nothing. */
.view-home, .send-pick, .recv-intro, .recv-done {
  width: 100%;
  max-width: var(--page-width);
  margin: 0 auto;
  padding: var(--page-top) var(--gutter) 32px;
}

.display {
  font-size: clamp(2.5rem, 8.5vw, 5rem);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.025em;
  max-width: 13ch;
  text-wrap: balance;
}

.lede {
  margin-top: 20px;
  max-width: 34rem;
  color: var(--ink-2);
  font-size: var(--step-1);
  line-height: 1.45;
  text-wrap: pretty;
}

.paths {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: clamp(28px, 6vh, 56px);
}

.path {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 168px;
  padding: 22px 24px;
  border-radius: var(--r-l);
  text-decoration: none;
  border: 1.5px solid var(--line);
  background: var(--surface);
  transition: border-color 0.15s, transform 0.15s var(--ease);
}
.path:hover { border-color: var(--ink-2); }
.path:active { transform: scale(0.99); }
.path-send { background: var(--signal); border-color: var(--signal); color: var(--signal-ink); }
.path-send:hover { border-color: var(--signal); background: color-mix(in srgb, var(--signal) 90%, var(--ink)); }
.path-icon { width: 30px; height: 30px; }
.path-name {
  align-self: end;
  font-size: clamp(1.75rem, 5vw, 2.5rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.path-hint { margin-top: 8px; font-size: var(--step-0); opacity: 0.82; }

.how {
  margin-top: clamp(40px, 8vh, 80px);
  border-top: 1.5px solid var(--line);
  padding-top: 20px;
}
.how h2 { font-size: var(--step-0); font-weight: 650; }
.how ol {
  list-style: none;
  counter-reset: step;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px 32px;
  margin: 16px 0 0;
  padding: 0;
}
.how li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 2rem 1fr;
  color: var(--ink-2);
  max-width: 36ch;
}
.how li::before {
  content: counter(step);
  color: var(--signal);
  font-weight: 650;
}

.home-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin-top: 40px;
  color: var(--ink-2);
  font-size: var(--step--1);
}
.home-foot a { color: var(--ink-2); text-underline-offset: 3px; }

@media (min-width: 720px) {
  .paths { grid-template-columns: 1.15fr 1fr; gap: 16px; }
  .path { min-height: 240px; padding: 28px 30px; }
  .how ol { grid-template-columns: repeat(3, 1fr); }
}

/* ---------- Send: choose ---------- */

.view-send, .view-receive { width: 100%; }

.send-pick {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "head" "body" "link" "note";
  gap: 16px 24px;
}
.pick-head { grid-area: head; display: grid; gap: 16px; }
/* The file and text panels share one cell: the cell takes the taller of the
   two, so switching tabs never changes the page height. */
.pick-body {
  grid-area: body;
  display: grid;
  grid-template-areas: "panel" "error";
  /* The panel row takes the height of the grid row, so the drop zone (or the
     text area) always matches the receiver card beside it. */
  grid-template-rows: minmax(0, 1fr) auto;
}
#panelFile, #panelText { grid-area: panel; }
#panelFile { display: grid; }
/* Spacing lives on the message, so the empty row adds no height. */
#sendError { grid-area: error; margin-top: 16px; }
.is-inactive { visibility: hidden; }
.pick-note { grid-area: note; }

.title {
  font-size: var(--step-3);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.1;
}

.segmented {
  display: inline-flex;
  justify-self: start;
  padding: 4px;
  border-radius: 999px;
  background: var(--surface-2);
}
.segmented button {
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font-weight: 600;
}
.segmented button[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(18, 20, 58, 0.12);
}

.drop {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 6px;
  min-height: min(46vh, 340px);
  padding: 32px 20px;
  border: 2px dashed var(--line);
  border-radius: var(--r-l);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.drop:hover, .drop.is-over { border-color: var(--signal); background: var(--signal-soft); }
.drop:focus-within { outline: 3px solid var(--signal); outline-offset: 2px; }
.drop-icon {
  width: 56px;
  height: 56px;
  padding: 14px;
  margin-bottom: 8px;
  border-radius: 16px;
  background: var(--signal);
  color: var(--signal-ink);
}
.drop-main { font-size: var(--step-2); font-weight: 650; letter-spacing: -0.015em; }
.drop-sub { color: var(--ink-2); }
.drop.is-busy { pointer-events: none; opacity: 0.6; }

#panelText { display: grid; grid-template-rows: minmax(0, 1fr) auto; gap: 12px; }
#textInput { height: 100%; resize: none; border-radius: var(--r-l); }
#panelText .btn { justify-self: start; }
textarea {
  width: 100%;
  min-height: 180px;
  padding: 14px 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-m);
  background: var(--surface);
  resize: vertical;
  line-height: 1.45;
}
textarea:focus { outline: none; border-color: var(--signal); }

.receiver-link {
  grid-area: link;
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 16px;
  border-radius: var(--r-l);
  background: var(--surface);
  border: 1.5px solid var(--line);
}
.receiver-link canvas {
  flex: none;
  width: 112px;
  height: 112px;
  border-radius: var(--r-s);
  image-rendering: pixelated;
  background: #fff;
}
.receiver-link h2 { font-size: var(--step-0); font-weight: 650; }
.receiver-link p { margin-top: 4px; color: var(--ink-2); font-size: var(--step--1); }

/* Side by side: the receiver card takes exactly the height of the drop
   zone (or of the text panel), its code centered. */
@media (min-width: 900px) {
  .send-pick {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-areas: "head ." "body link" "note .";
  }
  .receiver-link {
    flex-direction: column;
    justify-content: center;
    gap: 20px;
    padding: 24px;
  }
  .receiver-link canvas { width: 160px; height: 160px; }
  .receiver-link-text { align-self: stretch; }
}

/* ---------- Send: live ---------- */

body.is-live .topbar { display: none; }

/* Phones held upright: the page scrolls, the codes take the full width and
   every control follows below them, always shown. */
.send-live {
  display: grid;
  grid-template-rows: auto auto auto;
  grid-template-areas: "bar" "stage" "dock";
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.live-bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 0;
}
.live-file {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 0 6px;
}
.live-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}
.live-size { flex: none; color: var(--ink-2); font-size: var(--step--1); }

.stage-wrap {
  grid-area: stage;
  display: grid;
  place-items: center;
  min-height: 0;
  height: min(100vw, 70dvh);
  padding: 12px;
}
.stage {
  display: grid;
  place-items: center;
  background: #fff;
  border-radius: var(--r-m);
  box-shadow: var(--stage-shadow);
  overflow: hidden;
  cursor: zoom-in;
}
.stage canvas { display: block; width: 100%; height: 100%; }
.stage.is-link { cursor: default; }

.dock {
  grid-area: dock;
  padding: 8px 20px 24px;
  container-type: inline-size;
}
.dock-grid { display: grid; gap: 24px 32px; align-items: start; }
.dock-col { display: grid; gap: 14px; align-content: start; min-width: 0; }
/* A wide enough panel shows its sections side by side. */
@container (min-width: 420px) {
  .dock-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
.control { display: grid; gap: 2px; }
.control-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.control-head label { font-weight: 650; }
.control-head output { color: var(--ink-2); font-size: var(--step--1); text-align: right; }
.control-ends {
  display: flex;
  justify-content: space-between;
  color: var(--ink-2);
  font-size: 0.75rem;
}
.dock-foot {
  display: flex;
  align-items: center;
  gap: 14px;
}
.dock-foot .btn { min-height: 44px; padding: 0 18px; }
.dock-stats { color: var(--ink-2); font-size: var(--step--1); line-height: 1.35; }
.dock-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  align-items: baseline;
  font-size: var(--step--1);
}
.keys { color: var(--ink-2); }
.note { color: var(--warn); font-size: var(--step--1); }

.send-live.is-paused .stage { opacity: 0.35; }

@media not (pointer: fine) {
  .keys { display: none; }
}

/* Landscape screens: the codes on the left, a wide control panel on the
   right, the whole view fitting the window. */
@media (min-aspect-ratio: 5/4) and (min-width: 640px) {
  .send-live {
    grid-template-columns: minmax(0, 1fr) clamp(380px, 48vw, 720px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "bar bar" "stage dock";
    height: 100dvh;
  }
  .stage-wrap { height: auto; }
  .dock { min-height: 0; overflow-y: auto; padding: 16px 28px 24px 12px; }
}

/* Full screen (or its CSS stand-in on iPhone): the stage is all there is */
.send-live:fullscreen, .send-live.is-full { background: #000; }
.send-live:fullscreen .live-bar, .send-live.is-full .live-bar,
.send-live:fullscreen .dock, .send-live.is-full .dock { display: none; }
.send-live:fullscreen, .send-live.is-full {
  grid-template-areas: "stage";
  grid-template-rows: minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
}
.send-live.is-full { position: fixed; inset: 0; z-index: 10; }
.send-live:fullscreen, .send-live.is-full { height: 100dvh; }
.send-live:fullscreen .stage-wrap, .send-live.is-full .stage-wrap { height: auto; }
.send-live:fullscreen .stage, .send-live.is-full .stage { cursor: zoom-out; border-radius: 0; box-shadow: none; }

/* ---------- Calibration sheet ---------- */

.sheet {
  width: min(560px, calc(100vw - 32px));
  padding: 24px;
  border: 0;
  border-radius: var(--r-l);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.45);
}
.sheet::backdrop { background: rgba(10, 11, 34, 0.45); }
.sheet h2 { font-size: var(--step-2); font-weight: 650; letter-spacing: -0.015em; }
.sheet > p { margin-top: 8px; color: var(--ink-2); }
.calib-bar {
  height: 54px;
  margin: 20px 0 8px;
  max-width: 100%;
  border-radius: 6px;
  background: var(--signal);
}
.sheet-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Receive ---------- */

.recv-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 32px 24px;
  align-content: start;
}
.intro-main {
  display: grid;
  gap: 20px;
  justify-items: start;
  align-content: start;
}
.intro-main > * { max-width: 40rem; }
.recv-intro .lede { margin-top: 0; }

/* Receive settings: always shown, beside the introduction on wide screens. */
.settings-card {
  align-self: start;
  padding: 24px;
  border-radius: var(--r-l);
  background: var(--surface);
  border: 1.5px solid var(--line);
}
.settings-card h2 { font-size: var(--step-0); font-weight: 650; }
.settings-body { display: grid; gap: 16px; margin-top: 16px; }
.settings-card .fields { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
/* Same right column as the receiver card of the send page. */
@media (min-width: 900px) {
  .recv-intro { grid-template-columns: minmax(0, 1fr) 300px; }
}

.tips {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
  color: var(--ink-2);
  font-size: var(--step--1);
}
.tips li { display: grid; grid-template-columns: 18px 1fr; }
.tips li::before {
  content: "";
  width: 6px;
  height: 6px;
  margin-top: 0.55em;
  background: var(--signal);
}

.recv-live {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100dvh;
}

.viewfinder {
  position: relative;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
.viewfinder video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.reticle {
  position: absolute;
  inset: 12%;
  max-width: min(76vw, 76vh);
  max-height: min(76vw, 76vh);
  margin: auto;
  aspect-ratio: 1;
  pointer-events: none;
  --c: rgba(255, 255, 255, 0.9);
  background:
    linear-gradient(var(--c), var(--c)) top left / 28px 3px,
    linear-gradient(var(--c), var(--c)) top left / 3px 28px,
    linear-gradient(var(--c), var(--c)) top right / 28px 3px,
    linear-gradient(var(--c), var(--c)) top right / 3px 28px,
    linear-gradient(var(--c), var(--c)) bottom left / 28px 3px,
    linear-gradient(var(--c), var(--c)) bottom left / 3px 28px,
    linear-gradient(var(--c), var(--c)) bottom right / 28px 3px,
    linear-gradient(var(--c), var(--c)) bottom right / 3px 28px;
  background-repeat: no-repeat;
  transition: transform 0.2s var(--ease);
}
.recv-live.is-hit .reticle { --c: #8c8aff; transform: scale(0.985); }

.cam-tools {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.tool-glass {
  background: rgba(10, 11, 34, 0.55);
  color: #fff;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.tool-glass:hover { background: rgba(10, 11, 34, 0.75); }
.zoom {
  flex: 1;
  max-width: 280px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 44px;
  border-radius: 999px;
  background: rgba(10, 11, 34, 0.55);
  color: #fff;
  font-size: var(--step--1);
  font-weight: 600;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.recv-panel {
  display: grid;
  gap: 12px;
  padding: 14px var(--gutter) max(16px, env(safe-area-inset-bottom));
  background: var(--paper);
}
.recv-head { display: flex; align-items: center; gap: 8px; }
.recv-file { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.recv-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.recv-size { flex: none; color: var(--ink-2); font-size: var(--step--1); }

.mosaic-wrap {
  display: grid;
  place-items: center;
  height: clamp(56px, 12vh, 200px);
  padding: 10px;
  border-radius: var(--r-m);
  background: var(--surface);
  border: 1.5px solid var(--line);
}
#mosaic {
  display: block;
  max-width: 100%;
  max-height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.recv-progress { display: flex; align-items: baseline; gap: 12px; height: 2.25rem; }
.recv-pct {
  font-size: var(--step-3);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1;
}
.recv-eta { color: var(--ink-2); }

.signal { display: flex; align-items: center; gap: 12px; }
.bars { display: inline-flex; align-items: flex-end; gap: 3px; height: 18px; flex: none; }
.bars i { width: 5px; background: var(--line); border-radius: 1px; }
.bars i:nth-child(1) { height: 30%; }
.bars i:nth-child(2) { height: 55%; }
.bars i:nth-child(3) { height: 78%; }
.bars i:nth-child(4) { height: 100%; }
.signal[data-level="poor"] .bars i:nth-child(-n+1),
.signal[data-level="fair"] .bars i:nth-child(-n+2),
.signal[data-level="good"] .bars i:nth-child(-n+3),
.signal[data-level="excellent"] .bars i { background: var(--signal); }
.signal[data-level="poor"] .bars i:nth-child(1) { background: var(--err); }
.signal[data-level="poor"] .signal-text { color: var(--err); }
.signal[data-level="lost"] .signal-text { color: var(--warn); }
.signal-text { font-weight: 600; line-height: 1.35; }
/* Fixed heights (two lines of advice, one of figures), whatever the text,
   so the panel never moves while receiving. */
.signal-text { min-height: calc(2 * 1.35em); }
.signal-meta {
  color: var(--ink-2);
  font-size: var(--step--1);
  line-height: 1.5;
  height: 1.5em;
  margin-top: -6px;
  padding-left: 38px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.details { color: var(--ink-2); font-size: var(--step--1); }
.details-title { font-size: var(--step--1); font-weight: 650; color: var(--ink); }
.details dl {
  display: grid;
  /* Two pairs per row under the camera on phones; one in the side panel. */
  grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr);
  gap: 2px 16px;
  margin: 8px 0 0;
}
.details dt { color: var(--ink-2); }
.details dd:last-of-type { grid-column: 2 / -1; }   /* the decoder name is the longest value */
.details dd {
  margin: 0;
  color: var(--ink);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

@media (min-aspect-ratio: 5/4) and (min-width: 700px) {
  .recv-live { grid-template-columns: minmax(0, 1fr) clamp(300px, 32vw, 400px); grid-template-rows: 1fr; }
  .recv-panel { align-content: start; padding: 24px; overflow-y: auto; }
  .details dl { grid-template-columns: max-content minmax(0, 1fr); }
  .mosaic-wrap { height: clamp(120px, 30vh, 280px); }
}

/* ---------- Receive: done ---------- */

.recv-done {
  display: grid;
  gap: 24px;
  align-content: start;
}
.recv-done > * { max-width: 600px; }
.verdict { display: grid; gap: 8px; justify-items: start; }
.verdict-icon {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  margin-bottom: 8px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--ink-2);
}
.verdict-icon svg { width: 34px; height: 34px; }
.verdict[data-state="ok"] .verdict-icon { background: var(--ok); color: #fff; }
.verdict[data-state="bad"] .verdict-icon { background: var(--err); color: #fff; }
.verdict p { color: var(--ink-2); max-width: 40ch; }
.verdict[data-state="ok"] .verdict-icon svg { animation: pop 0.45s var(--ease) both; }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }

.file-card {
  display: grid;
  gap: 4px;
  padding: 18px 20px;
  border-radius: var(--r-l);
  background: var(--surface);
  border: 1.5px solid var(--line);
}
.file-name { font-weight: 650; font-size: var(--step-1); overflow-wrap: anywhere; }
.file-meta { color: var(--ink-2); }
.hash {
  margin-top: 8px;
  color: var(--ink-2);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.75rem;
  overflow-wrap: anywhere;
}
.text-out { min-height: 160px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Scripts without the Latin display treatment ---------- */

/* Negative tracking only suits the Latin face; Chinese, Japanese and Korean
   fall back to system fonts. */
:lang(ja) :is(.display, .title, .path-name, .recv-pct),
:lang(zh-Hans) :is(.display, .title, .path-name, .recv-pct),
:lang(ko) :is(.display, .title, .path-name, .recv-pct) {
  letter-spacing: 0;
  line-height: 1.15;
}
:lang(ja), :lang(zh-Hans) { line-break: strict; }
:lang(ko) { word-break: keep-all; }

/* ---------- Panels, fields and details ---------- */

.panel { display: grid; gap: 10px; }
.panel-title { font-size: var(--step-0); font-weight: 650; }
.panel-body { display: grid; gap: 14px; }

.fields {
  display: grid;
  /* A column never gets narrower than its list box: long options wrap the
     grid to fewer columns instead of overlapping the next one. */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 110px), 1fr));
  gap: 12px 16px;
}
.field { display: grid; gap: 4px; min-width: 0; font-size: var(--step--1); color: var(--ink-2); }
.field select { width: 100%; min-width: 0; text-overflow: ellipsis; }
.field-wide { grid-column: 1 / -1; }
select {
  min-height: 40px;
  padding: 0 34px 0 14px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23888' stroke-width='1.6'/%3E%3C/svg%3E") no-repeat right 14px center / 10px;
  -webkit-appearance: none;
  appearance: none;
  color: var(--ink);
  font-size: var(--step-0);
  cursor: pointer;
}
select:hover { border-color: var(--ink-2); }
.lang select { min-height: 0; border: 0; }

.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--signal);
}

.specs {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 16px;
  margin: 0;
  font-size: var(--step--1);
}
.specs dt { color: var(--ink-2); }
.specs dd { margin: 0; overflow-wrap: anywhere; }
.specs .hash { margin: 0; font-size: 0.6875rem; line-height: 1.4; }

.btn-small { min-height: 38px; padding: 0 16px; font-size: var(--step--1); }
.export-actions, .link-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.link-actions { margin-top: 12px; }


/* Over the camera view, so its appearance moves nothing in the panel. */
.nosignal {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  max-width: 440px;
  padding: 12px 16px;
  border-radius: var(--r-m);
  background: rgba(10, 11, 34, 0.72);
  color: #fff;
  font-size: var(--step--1);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.nosignal-title { font-weight: 650; margin-bottom: 4px; }
.nosignal ol { margin: 0; padding-left: 1.2em; display: grid; gap: 2px; }

.preview { border-radius: var(--r-l); overflow: hidden; background: var(--surface-2); }
.preview img, .preview video { display: block; max-width: 100%; max-height: 60vh; margin: 0 auto; }
.preview audio { display: block; width: 100%; }

/* ---------- Motion preferences ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
