/* Lab — shared UI for Slava's in-browser AI tools.
   All colours / fonts live in tokens below: recolour the whole lab by editing :root. */

:root {
  --bg: #0b0b0c;
  --surface: #141416;
  --surface-2: #1c1c1f;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f1f0ec;
  --muted: #8e8d89;
  --accent: #f1f0ec;          /* primary button fill */
  --accent-ink: #0b0b0c;      /* text on primary button */
  --rec: #ff453a;
  --ok: #8fd19e;
  --warn: #f0c36a;

  --font-ui: 'Manrope', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Unbounded', 'Manrope', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --radius: 16px;
  --radius-sm: 10px;
  --gutter: clamp(16px, 4vw, 40px);
  --maxw: 1240px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}
a { color: inherit; }
button { font: inherit; color: inherit; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter); }

/* ---------- header ---------- */
.lab-header { padding: clamp(18px, 3vw, 32px) 0 clamp(14px, 2vw, 22px); }
.crumbs { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--text); }
.lab-header h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(22px, 3.4vw, 38px);
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
}
.lead { color: var(--muted); max-width: 64ch; margin: 0; }
.privacy { display: inline-flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; color: var(--muted); }
.privacy::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }

/* ---------- stage ---------- */
.stage {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  min-height: 220px;
}
.stage canvas { display: block; width: 100%; height: auto; max-height: 74vh; max-height: 74dvh; object-fit: contain; }
.stage-msg {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 24px; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.stage-msg[hidden] { display: none; }
.stage-msg .box { max-width: 420px; }
.stage-msg .title { font-weight: 600; font-size: 16px; margin-bottom: 6px; }
.stage-msg .sub { color: var(--muted); font-size: 13px; }
.source-note { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-size: 13px; color: var(--muted); padding-top: 10px; }
.source-note[hidden] { display: none; }
.stats[hidden] { display: none; }
.stats {
  position: absolute; right: 12px; bottom: 10px; font-family: var(--font-mono); font-size: 11px;
  color: rgba(255, 255, 255, 0.55); pointer-events: none; text-shadow: 0 1px 2px #000;
}

/* ---------- controls ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; justify-content: space-between; padding: 16px 0; }
.group { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-right: 4px; }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.seg button {
  border: 0; background: transparent; padding: 8px 12px; border-radius: 9px; cursor: pointer;
  color: var(--muted); font-weight: 500; font-size: 14px; white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed='true'] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 12px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; font-size: 14px;
  text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(0.92); }
.btn .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--rec); }
.btn.recording { border-color: var(--rec); color: var(--rec); }
.btn.recording .dot { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.15; } }

.field { display: inline-flex; align-items: center; gap: 8px; }
.input {
  min-height: 42px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px; width: min(420px, 100%);
}
.input:focus, .btn:focus-visible, .seg button:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
input[type='range'] { -webkit-appearance: none; appearance: none; width: 140px; height: 4px; border-radius: 4px; background: var(--line-strong); outline-offset: 6px; }
input[type='range']::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--text); border: 0; cursor: pointer; }
input[type='range']::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--text); border: 0; cursor: pointer; }
.check { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); cursor: pointer; }
.check input[type='checkbox'] { accent-color: var(--text); width: 16px; height: 16px; }

.hint { font-size: 13px; color: var(--muted); }
.notes { border-top: 1px solid var(--line); margin-top: 8px; padding: 18px 0 40px; display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.notes b { color: var(--text); font-weight: 600; }

/* ---------- progress ---------- */
.progress { width: min(320px, 80vw); height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; margin: 14px auto 8px; }
.progress > i { display: block; height: 100%; width: 0%; background: var(--text); transition: width .2s; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--text); animation: spin .8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); border: 1px solid var(--line-strong); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- result modal ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.72); }
.modal[hidden] { display: none; }
.modal-card { width: min(860px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.modal-media { background: #000; display: grid; place-items: center; }
.modal-media img, .modal-media video { display: block; max-width: 100%; max-height: 64vh; max-height: 64dvh; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px; align-items: center; }
.modal-actions .meta { margin-right: auto; font-size: 13px; color: var(--muted); }

@media (max-width: 640px) {
  .controls { gap: 12px; }
  .controls > .group { width: 100%; }
  .seg { width: 100%; }
  .seg button { flex: 1 1 auto; padding: 8px 8px; font-size: 13px; }
  .group .btn { flex: 1 1 auto; }
  .stage { border-radius: 12px; }
  .input { width: 100%; }
}
