/*
 * Signalbox follows the Inapse design system (inapse-site DESIGN.md) in the dialect QRMagic Studio uses
 * for app screens ("At the Workbench", qrmagic docs/studio-design.md): monochrome paper and ink, colour
 * only for state and always beside a word, square corners, 1px hairlines, Space Grotesk to read and
 * JetBrains Mono for addresses, amounts, file names and short status words. The video carries the
 * picture; the chrome stays quiet.
 *
 * Fonts: Space Grotesk and JetBrains Mono, SIL Open Font License 1.1 (static/fonts/OFL-*.txt).
 */
@font-face {
  font-family: 'Space Grotesk';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('/static/fonts/space-grotesk-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('/static/fonts/jetbrains-mono-latin.woff2') format('woff2');
}

:root {
  /* Each colour is light-dark(light, dark); theme.js sets data-theme when the person chose the other. */
  color-scheme: light dark;
  --ink: light-dark(#0a0a0a, #f2f2ef);
  --body: light-dark(#111111, #ededea);
  --paper: light-dark(#ffffff, #0f0f0e);
  --muted: light-dark(#f7f7f6, #1c1c1b);
  --hairline: light-dark(#e6e6e2, #2b2b29);
  --border: light-dark(#d0d0cc, #6a6a64);
  --text2: light-dark(#5a5a5a, #b3b3ad);
  --ok: light-dark(#15803d, #4ade80);
  --warn: light-dark(#b45309, #fbbf24);
  --danger: light-dark(#dc2626, #f87171);
  /* An ink field with a job: the video's frame and the status line. */
  --field: light-dark(#0a0a0a, #1b1b1a);
  --on-field: light-dark(#ffffff, #f2f2ef);
  --on-field-danger: #f87171;
  --field-edge: light-dark(transparent, #2b2b29);
  /* The paper a QR code is shown on: the same in both themes. */
  --page: #ffffff;
  --sans: 'Space Grotesk', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --topbar-h: 45px;
}
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--body);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  caret-color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p, dl, dd { margin: 0; }

/* The parts the browser draws carry the system too: focus, selection, the caret, scrollbars. */
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
::selection { background: var(--ink); color: var(--paper); }
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* A drawn icon: 16px on a 24 grid, a 2-unit stroke in the text's colour, square ends and mitred corners. */
.icon {
  display: block;
  flex: none;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

/* ── Top bar ───────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: var(--topbar-h);
  padding: env(safe-area-inset-top) 16px 0;
  background: var(--paper);
  border-bottom: 1px solid var(--hairline);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 6px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1;
  white-space: nowrap;
  color: var(--ink);
}
/* The mark: an ink tile with the four signal bars drawn in paper lines, as Inapse draws its own. */
.logo-mark { display: block; flex: none; }
.logo-mark .tile { fill: var(--ink); }
.logo-mark .bar { fill: none; stroke: var(--paper); stroke-width: 0.9; }

/* The three places: words with a small icon, the chosen one in ink over a 2px ink underline. */
.views { display: flex; gap: 20px; align-self: stretch; margin-left: 8px; }
.views button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  margin-bottom: -1px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
}
.views button:hover { color: var(--ink); }
.views button.on { color: var(--ink); border-bottom-color: var(--ink); }
.views button:focus-visible { outline-offset: -2px; }
.spacer { flex: 1; }

/* Tools the bar keeps at hand: gray at rest, ink under the pointer, named in their tooltips. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  background: none;
  border: 0;
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
}
.chip:hover { color: var(--ink); }
.wallet-chip { font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.theme-switch .sun { display: none; }
:root[data-scheme-shown='dark'] .theme-switch .moon { display: none; }
:root[data-scheme-shown='dark'] .theme-switch .sun { display: block; }

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 8px 16px;
  border-bottom: 1px solid var(--hairline);
  font-size: 13px;
}

/* ── Controls ──────────────────────────────────────────────────────────── */

/* A secondary action is an outline; the one action a panel exists for is a black fill (.primary). */
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
button:hover:not(:disabled), .button:hover { border-color: var(--ink); }
.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 84%, var(--paper)); }
button:disabled { cursor: default; background: var(--muted); border-color: var(--hairline); color: var(--text2); }
/* Small or reversible: Dismiss, a quiet extra. */
button.link {
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--text2);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
button.link:hover:not(:disabled) { color: var(--ink); }
button.link:disabled { background: none; opacity: 0.5; }

/* A button is as wide as its words. */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* Choose video: the file field stays reachable by keyboard; its label is the button. */
.picker { position: relative; }
.picker input[type='file'] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
  opacity: 0;
}
.picker:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ── Fields ────────────────────────────────────────────────────────────── */

label { font-size: 12px; color: var(--text2); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
input, select, textarea {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--paper);
  color: var(--body);
  font-size: 13px;
  accent-color: var(--ink);
}
input:not([type='file']):focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 0;
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}
input[readonly], textarea[readonly] { background: var(--muted); border-color: var(--hairline); }
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text2); opacity: 1; }
input[type='file'] { padding: 0; border: 0; background: none; color: var(--text2); font-size: 13px; }
input[type='file']::file-selector-button {
  margin-right: 10px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
input[type='file']:hover::file-selector-button { border-color: var(--ink); }
/* A field with its one button at its end: the address and Copy. */
.field-row { display: flex; align-items: stretch; gap: 8px; }
.field-row > input { flex: 1; }
.field-row > button { flex: none; }
/* A unit inside the field's end: USDT, %. */
.affixed { position: relative; display: flex; }
.affixed input { padding-right: 52px; }
.affix {
  position: absolute;
  top: 50%;
  right: 9px;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text2);
  pointer-events: none;
}
.hint { font-size: 12px; color: var(--text2); }
.hint.warn { color: var(--warn); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; }

/* ── Type and state ────────────────────────────────────────────────────── */

.mono { font-family: var(--mono); overflow-wrap: anywhere; }
.num { font-variant-numeric: tabular-nums; }
.small { font-size: 12px; }
.muted { color: var(--text2); }
.ink { color: var(--ink); }
.lede { color: var(--text2); max-width: 62ch; }
.object-title { font-size: 15px; font-weight: 500; color: var(--ink); overflow-wrap: anywhere; }

/* A status word (mono) or sentence (sans) after a drawn 8px dot in the state's colour. */
.state, .status { font-size: 12px; color: var(--text2); }
.state { font-family: var(--mono); }
.state::before, .status::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin: -2px 6px 0 0;
  border-radius: 50%;
  background: currentColor;
  vertical-align: middle;
}
.state.muted::before { background: none; box-shadow: inset 0 0 0 1.5px currentColor; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.danger { color: var(--danger); }

/* A label column and its values: payout, referrer. */
.holds { display: grid; grid-template-columns: fit-content(40%) minmax(0, 1fr); gap: 4px 12px; font-size: 13px; }
.holds:not(:has(> div:not([hidden]))) { display: none; }
.holds > div { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; }
.holds dt { font-size: 12px; color: var(--text2); }
.holds dd { color: var(--body); overflow-wrap: anywhere; }
.holds dd.mono, .holds .mono { font-size: 12px; color: var(--ink); }

/* ── Watch ─────────────────────────────────────────────────────────────── */

.watch {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 30vw, 380px);
  min-height: calc(100dvh - var(--topbar-h));
}
.center { display: flex; flex-direction: column; min-width: 0; }

/* The video's name and its state, with the one thing to do to it. */
.designbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  min-height: 45px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--hairline);
}
.design-name { font-size: 15px; font-weight: 500; color: var(--ink); overflow-wrap: anywhere; }
.designbar .status { white-space: nowrap; }

.canvas { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--muted); }
.canvas.empty { align-items: center; justify-content: center; }

/* Nothing open yet: what a Signalbox file is and how to open one. */
.empty-state { width: min(560px, 100%); padding: 56px 24px; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.empty-state h2 { font-size: 24px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.2; color: var(--ink); }
.empty-state .actions { margin-top: 4px; }
#empty-actions-slot .picker { background: var(--ink); border-color: var(--ink); color: var(--paper); }
#empty-actions-slot .picker:hover { background: color-mix(in srgb, var(--ink) 84%, var(--paper)); }
#empty-actions-slot .picker:has(input:disabled) { background: var(--muted); border-color: var(--hairline); color: var(--text2); cursor: default; }

.stage { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 24px; }
.screen {
  position: relative;
  width: min(100%, calc((100dvh - 210px) * 16 / 9));
  aspect-ratio: 16 / 9;
  background: var(--field);
  border: 1px solid var(--field-edge);
}
.screen video { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }

/* The link a file carries in its timed text, over the picture, with where it goes. */
.timed-link {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 20px);
  padding: 4px 8px;
  background: var(--paper);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
}
.timed-link:hover { border-color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }
.timed-link-host { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text2); font-size: 12px; }

/* Under the picture: the file, then what else can be opened. */
.stagebar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 6px 16px;
  border-top: 1px solid var(--hairline);
  background: var(--paper);
  font-size: 12px;
}
.stage-info { flex: 1 1 12rem; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--text2); }
.stagebar .actions { gap: 6px; }
.stagebar .actions .button, .stagebar .actions button { padding: 3px 10px; font-size: 12px; }

/* ── Inspector ─────────────────────────────────────────────────────────── */

.inspector { min-width: 0; border-left: 1px solid var(--hairline); }
.panel { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--hairline); }
.panel h3 { font-size: 13px; font-weight: 500; color: var(--ink); }
.panel.list-panel { padding-bottom: 0; }
.panel .list { margin: 2px -16px 0; }
.price-row { display: flex; flex-direction: column; gap: 2px; }
.price { display: flex; align-items: baseline; gap: 6px; font-size: 24px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.15; color: var(--ink); font-variant-numeric: tabular-nums; }
.price .unit { font-family: var(--mono); font-size: 12px; font-weight: 400; letter-spacing: 0; color: var(--text2); }

/* ── Lists ─────────────────────────────────────────────────────────────── */

.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--hairline); }
.row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  padding: 9px 16px;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  background: none;
  color: var(--body);
  font-size: 14px;
  text-align: left;
}
.list > li:last-child > .row { border-bottom: 0; }
button.row:hover:not(:disabled) { background: var(--muted); }
button.row:focus-visible { outline-offset: -2px; }
button.row:disabled { background: none; color: var(--body); opacity: 0.6; }
.row.on { background: var(--muted); box-shadow: inset 2px 0 0 var(--ink); }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--ink); }
.row-meta { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: var(--mono); font-size: 12px; color: var(--text2); }
.row .actions { flex: none; gap: 6px; }
.row .actions .button, .row .actions button { padding: 3px 10px; font-size: 12px; }
.start .list { border-bottom: 1px solid var(--hairline); }
.start .row { padding-left: 0; padding-right: 0; }

/* ── Publish and Wallet: a column, as a form reads well ────────────────── */

.start { display: flex; justify-content: center; padding: 48px 24px 112px; }
.start-body { width: min(600px, 100%); display: flex; flex-direction: column; gap: 18px; }
.start-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.start h2 { font-size: 24px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.2; color: var(--ink); }
.group { display: flex; flex-direction: column; gap: 10px; padding-top: 16px; border-top: 1px solid var(--hairline); }
.group h3 { font-size: 13px; font-weight: 500; color: var(--ink); }
.subform { padding-top: 12px; border-top: 1px solid var(--hairline); }

/* The wallet's two balances, side by side, sharing their rules. */
.figures { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--hairline); }
.figure { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; min-width: 0; }
.figure + .figure { border-left: 1px solid var(--hairline); }
.figure dt { font-size: 12px; color: var(--text2); }
.figure dd { font-size: 24px; font-weight: 500; letter-spacing: -0.01em; line-height: 1.2; color: var(--ink); overflow-wrap: anywhere; }

/* What the wallet has earned: one row each, as a table reads. */
.ledger { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; column-gap: 16px; }
.ledger > div { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; align-items: baseline; padding: 6px 0; }
.ledger > div + div { border-top: 1px solid var(--hairline); }
.ledger dt { color: var(--body); }
.ledger dd { font-size: 13px; text-align: right; }
.ledger dd.muted { font-size: 12px; }
.ledger dd.num { font-family: var(--mono); font-size: 12px; color: var(--ink); }

.deposit { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 16px; }
.wallet-qr { flex: none; padding: 6px; background: var(--page); border: 1px solid var(--hairline); image-rendering: pixelated; }
.deposit-info { flex: 1 1 16rem; min-width: 0; display: flex; flex-direction: column; gap: 8px; }

/* ── The status line ───────────────────────────────────────────────────── */

/* Always in the page for screen readers, drawn only when it has something to say. */
.toast {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: baseline;
  gap: 14px;
  width: max-content;
  max-width: min(440px, calc(100vw - 32px));
  padding: 10px 12px 10px 16px;
  background: var(--field);
  border: 1px solid var(--field-edge);
  color: var(--on-field);
  font-size: 13px;
}
.toast:has(#notice:empty) { padding: 0; border: 0; }
.toast:has(#notice:empty) #notice-close { display: none; }
.toast button.link { flex: none; color: var(--on-field); }
.toast :focus-visible { outline-color: var(--on-field); }
.toast.error #notice::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin: -2px 8px 0 0;
  border-radius: 50%;
  background: var(--on-field-danger);
  vertical-align: middle;
}

/* ── Narrow windows ────────────────────────────────────────────────────── */

@media (max-width: 980px) {
  .topbar { flex-wrap: wrap; gap: 4px 12px; padding: calc(8px + env(safe-area-inset-top)) 16px 0; }
  /* The places take the bar's last row, their underline on its edge. */
  .views { order: 10; flex-basis: 100%; margin-left: 0; gap: 0; }
  .views button { flex: 1; justify-content: center; padding: 8px 0; }
  .watch { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .inspector { border-left: 0; border-top: 1px solid var(--hairline); }
  .stage { padding: 16px; }
  .screen { width: 100%; }
  .empty-state { padding: 40px 16px; }
  .start { padding: 32px 16px 112px; }
}
@media (max-width: 640px) {
  .brand { gap: 8px; font-size: 15px; }
  .logo-mark { width: 24px; height: 24px; }
  .row2 { grid-template-columns: 1fr; }
  .stage { padding: 0; }
  .screen { border: 0; }
}
/* Touch: targets a finger can hit, and text fields a phone does not zoom into. */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
  button:not(.link, .chip, .views button), .button, select, input:not([type='checkbox'], [type='radio'], [type='range'], [type='file']) { min-height: 44px; }
  .stagebar .actions .button, .stagebar .actions button, .row .actions .button, .row .actions button { min-height: 36px; }
  button.link { min-height: 24px; }
  .chip { min-width: 44px; min-height: 44px; justify-content: center; }
  .row { min-height: 44px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
