:root {
  --bg: #08070c;
  --panel: #121017;
  --panel-2: #191621;
  --line: #2a2533;
  --text: #ece8f2;
  --dim: #8e8799;
  --ember: #ff5630;
  --ember-soft: #ff8a5c;
  /* The accent as a bare triplet, so rgba(var(--ember-rgb), .3) works. Without it
     every glow and shadow would hardcode the colour and no theme could move it. */
  --ember-rgb: 255,86,48;
  --good: #4ade80;
  --bad: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  cursor: default;
}

kbd {
  font: 600 10px/1 ui-monospace, "Cascadia Mono", monospace;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
  padding: 3px 5px;
  color: var(--dim);
}

.hidden { display: none !important; }
.mono { font-family: ui-monospace, "Cascadia Mono", monospace; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ================================= stage ================================= */

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
  will-change: transform;
}

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0;            /* WebGL draws it; this is only the fallback surface */
  pointer-events: none;
}
#video.fallback-visible { opacity: 1; }

#gl, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom,
      rgba(0,0,0,var(--vig-top, 0.55)) 0%,
      transparent 16%,
      transparent 62%,
      rgba(0,0,0,var(--vig-bottom, 0.82)) 100%);
}

/* This gradient is a plain div, not part of the shader, so each camera look has to
   say how much of it it wants - otherwise "Clean" would still sit in heavy black.
   Driven by the gradient's own alpha rather than the element's opacity: opacity on
   this particular div would not budge from 1, not even from an inline style. */
body[data-look="clean"]         { --vig-top: 0.12; --vig-bottom: 0.20; }
body[data-look="neon"]          { --vig-top: 0.40; --vig-bottom: 0.62; }
body[data-look="interrogation"] { --vig-top: 0.58; --vig-bottom: 0.90; }
body[data-look="grindhouse"]    { --vig-top: 0.66; --vig-bottom: 0.96; }

/* ------------------------------ lab overlay ------------------------------ */

#lab {
  position: absolute;
  top: 62px;
  left: 18px;
  z-index: 6;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(8,7,12,0.72);
  backdrop-filter: blur(8px);
  font: 11px/1.5 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--dim);
  pointer-events: none;
  min-width: 190px;
}

.lab-row { display: flex; justify-content: space-between; gap: 14px; }
.lab-row .lab-v { color: var(--text); }
/* The headline number, and the only one worth reacting to. */
.lab-row:first-child .lab-v { color: var(--ember); font-weight: 700; }

/* ------------------------------- topbar --------------------------------- */

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  z-index: 6;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font: 700 15px/1 "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.16em;
  text-shadow: 0 2px 14px rgba(0,0,0,0.8);
}
.brand .accent { color: var(--ember); }
.brand .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--ember);
  box-shadow: 0 0 12px var(--ember);
  animation: livePulse 2.4s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.82); }
}

.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  font: 600 10px/1 ui-monospace, monospace;
  letter-spacing: 0.12em;
  padding: 6px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(0,0,0,0.5);
  color: var(--dim);
  backdrop-filter: blur(8px);
}
.badge.hybrid { color: #ffd166; border-color: rgba(255,209,102,0.45); }
.badge.local  { color: #7dd3fc; border-color: rgba(125,211,252,0.45); }

.status {
  display: flex;
  align-items: center;
  gap: 7px;
  font: 500 11px/1 "Segoe UI", system-ui, sans-serif;
  color: var(--dim);
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  min-width: 92px;
  transition: color 0.2s;
}
.status.busy { color: var(--ember-soft); }
.status.error { color: var(--bad); }

.spinner {
  width: 9px; height: 9px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.2);
  flex: none;
}
.status.busy .spinner {
  border-top-color: var(--ember);
  border-right-color: var(--ember);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  width: 30px; height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.5);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: rgba(var(--ember-rgb),0.22); border-color: var(--ember); }
.icon-btn.small { width: 26px; height: 26px; font-size: 12px; }

/* ------------------------------- caption -------------------------------- */

#captionWrap {
  position: absolute;
  left: 0; right: 0; bottom: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 8%;
  z-index: 5;
  pointer-events: none;
}

#caption {
  max-width: 900px;
  text-align: center;
  font: 600 clamp(19px, 2.5vw, 31px)/1.32 "Segoe UI", system-ui, sans-serif;
  letter-spacing: -0.012em;
  text-shadow: 0 3px 22px rgba(0,0,0,0.95), 0 1px 3px rgba(0,0,0,1);
  min-height: 1.32em;
}

#caption .w {
  opacity: 0;
  filter: blur(5px);
  display: inline-block;
  transform: translateY(6px);
  transition: opacity 0.16s ease, filter 0.16s ease, transform 0.16s ease;
}
#caption .w.on {
  opacity: 1;
  filter: none;
  transform: none;
}
#caption .w.hot { color: var(--ember-soft); }

#notice {
  font: 500 11px/1.4 "Segoe UI", system-ui, sans-serif;
  color: var(--dim);
  text-align: center;
  max-width: 620px;
  min-height: 1.4em;
}
#notice.warn { color: #ffd166; }
#notice.error { color: var(--bad); }

/* ----------------------------- close the photo ---------------------------- */

/* The roast is written about a photo that stays on screen until this is pressed.
   Top-left, clear of the topbar - the website's zoom-reset pill sits top-right. */
.close-shot {
  position: absolute;
  top: 62px;
  left: 12px;
  z-index: 7;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.close-shot:hover {
  border-color: var(--ember);
  background: rgba(var(--ember-rgb), 0.22);
}
.close-shot:focus-visible { outline: 2px solid var(--ember-soft); outline-offset: 2px; }
.close-shot[hidden] { display: none !important; }

/* ------------------------------ cam error ------------------------------- */

#camError {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  text-align: center;
  background: rgba(8,7,12,0.94);
  z-index: 8;
  padding: 40px;
}
#camError h2 { margin: 0; font-size: 20px; letter-spacing: 0.04em; }
#camError p { margin: 0; color: var(--dim); font-size: 13px; max-width: 460px; line-height: 1.6; }

/* =============================== controls ================================ */

#controls {
  flex: none;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 14px 20px;
  background: linear-gradient(180deg, #0d0b11, #08070c);
  border-top: 1px solid var(--line);
}

.btn {
  font: 600 13px/1 "Segoe UI", system-ui, sans-serif;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 14px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, border-color 0.15s, box-shadow 0.2s;
}
.btn:hover { border-color: #423a52; background: #201c2a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn.primary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 26px;
  font-size: 15px;
  letter-spacing: 0.14em;
  border: none;
  color: #140602;
  background: linear-gradient(135deg, #ff7a4d, var(--ember));
  box-shadow: 0 0 0 rgba(var(--ember-rgb),0.5), 0 6px 22px rgba(var(--ember-rgb),0.32);
}
.btn.primary:hover { box-shadow: 0 0 34px rgba(var(--ember-rgb),0.55), 0 6px 26px rgba(var(--ember-rgb),0.4); }
.btn.primary kbd { background: rgba(0,0,0,0.22); border-color: rgba(0,0,0,0.2); color: rgba(20,6,2,0.7); }
.btn.primary:disabled { background: #3a2e32; color: #8d8189; box-shadow: none; }

.btn.tiny { padding: 7px 10px; font-size: 11px; }
.btn.ghost { background: transparent; }

.link {
  background: none; border: none; padding: 0 8px;
  color: var(--dim); font-size: 11px; cursor: pointer; text-decoration: underline;
}
.link:hover { color: var(--ember); }

/* dials */
.dial { display: flex; align-items: center; gap: 11px; }
.dial-label {
  font: 700 10px/1 ui-monospace, monospace;
  letter-spacing: 0.16em;
  color: var(--dim);
}
.dial-value {
  font: 700 10px/1 ui-monospace, monospace;
  letter-spacing: 0.1em;
  color: var(--ember);
  min-width: 42px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  width: 150px;
  border-radius: 99px;
  background: linear-gradient(90deg, #ffb26b, var(--ember) 60%, #b3210a);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--ember);
  box-shadow: 0 0 12px rgba(var(--ember-rgb),0.7);
  cursor: grab;
}

/* toggles */
.toggles { display: flex; align-items: center; gap: 16px; margin-left: auto; }

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }

.toggle .track {
  position: relative;
  width: 40px; height: 22px;
  border-radius: 99px;
  background: #262130;
  border: 1px solid var(--line);
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.toggle .knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #6b6379;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s;
}
.toggle input:checked + .track {
  background: rgba(var(--ember-rgb),0.26);
  border-color: var(--ember);
  box-shadow: 0 0 14px rgba(var(--ember-rgb),0.3) inset;
}
.toggle input:checked + .track .knob {
  transform: translateX(18px);
  background: var(--ember);
}
.toggle input:focus-visible + .track { outline: 2px solid var(--ember-soft); outline-offset: 2px; }

.toggle-label {
  font: 700 10px/1 ui-monospace, monospace;
  letter-spacing: 0.14em;
  color: var(--dim);
}
.toggle input:checked ~ .toggle-label { color: var(--text); }

/* ================================ panels ================================= */

.panel {
  position: fixed;
  top: 0; right: 0;
  height: 100%;
  width: 400px;
  max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--line);
  transform: translateX(102%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 20;
  display: flex;
  flex-direction: column;
  box-shadow: -24px 0 60px rgba(0,0,0,0.55);
}
.panel.open { transform: none; }

#history { left: 0; right: auto; border-left: none; border-right: 1px solid var(--line);
  transform: translateX(-102%); width: 360px; box-shadow: 24px 0 60px rgba(0,0,0,0.55); }
#history.open { transform: none; }

.panel-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h3 { margin: 0; font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  user-select: text;
}
.panel-body::-webkit-scrollbar { width: 9px; }
.panel-body::-webkit-scrollbar-thumb { background: #2c2637; border-radius: 9px; }

section { margin-bottom: 22px; }
section h4 {
  margin: 0 0 10px;
  font: 700 10px/1 ui-monospace, monospace;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ember);
}

.field { margin-bottom: 12px; }
.field > label {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  color: var(--dim);
}
.row { display: flex; gap: 7px; align-items: center; }
.row > select, .row > input { flex: 1; min-width: 0; }

input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  background: #0c0a11;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  padding: 9px 10px;
  font: 400 12px/1.2 "Segoe UI", system-ui, sans-serif;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--ember); }
select { cursor: pointer; }
option { background: #0c0a11; }
/* The stage direction is a sentence, not a value - let it wrap and grow downward only. */
textarea { resize: vertical; min-height: 44px; }

.hint {
  margin: 6px 0 0;
  font-size: 10.5px;
  line-height: 1.55;
  color: #6f6880;
}
.hint code {
  background: #0c0a11;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, monospace;
  color: var(--ember-soft);
}

.state { font: 600 10px/1 ui-monospace, monospace; }
.state.ok { color: var(--good); }
.state.no { color: #6f6880; }
.state.bad { color: var(--bad); }

.msg { min-height: 16px; font-size: 11px; margin: 4px 0 12px; }
.msg.ok { color: var(--good); }
.msg.bad { color: var(--bad); }

/* ------------------------ settings: mode relevance -----------------------
   Sections are tagged with the modes that use them. Faded, never hidden and
   never disabled: every mode can fall back to the other one's machinery, and
   the renderer writes to all of these elements unconditionally.            */

.used {
  font: 600 9px/1 ui-monospace, monospace;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  margin-left: 8px;
  vertical-align: middle;
}

section[data-uses] { transition: opacity 160ms ease; }
body[data-mode="cloud"]  section[data-uses]:not([data-uses~="cloud"]),
body[data-mode="hybrid"] section[data-uses]:not([data-uses~="hybrid"]),
body[data-mode="local"]  section[data-uses]:not([data-uses~="local"]) { opacity: 0.45; }

/* burn book */
.burn {
  border: 1px solid var(--line);
  border-left: 2px solid var(--ember);
  border-radius: 8px;
  padding: 11px 12px;
  margin-bottom: 9px;
  background: var(--panel-2);
  animation: fadeUp 0.3s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.burn p { margin: 0 0 7px; font-size: 12.5px; line-height: 1.5; }
.burn .meta {
  display: flex; gap: 8px; align-items: center;
  font: 500 9.5px/1 ui-monospace, monospace;
  letter-spacing: 0.06em;
  color: #6f6880;
  text-transform: uppercase;
}

.empty { color: #6f6880; font-size: 12px; text-align: center; margin-top: 30px; }

/* scrim */
#scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 15;
}
#scrim.on { opacity: 1; pointer-events: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* =========================== non-Latin scripts ============================
   The app ships with a Latin-first stack (Segoe UI for the caption), which has no
   CJK or Arabic glyphs. Without these the text
   renders as tofu boxes, or silently falls back to a face with no bold weight.
   Windows 10/11 carry all of the faces named below. */

#caption, .roast-text {
  font-family: "Segoe UI", system-ui,
    "Yu Gothic UI", "Meiryo",                /* Japanese */
    "Microsoft YaHei UI", "Microsoft JhengHei UI",  /* Simplified / Traditional Chinese */
    "Segoe UI Historic", "Segoe UI Emoji",
    "Tahoma",                                 /* Arabic - Segoe UI's coverage is thin */
    sans-serif;
}

/* Arabic reads right to left. Only the text direction changes - the stage, the
   controls and the settings panel stay as they are. */
body[data-lang="ar"] #caption,
body[data-lang="ar"] #historyList .line { direction: rtl; unicode-bidi: isolate; }

/* Chinese and Japanese have no spaces, so the caption reveals per character and
   each one needs to be able to wrap. */
body[data-lang="ja"] #caption .w,
body[data-lang="zh"] #caption .w { margin-right: 0; }
