/* Lens engine v1: the piece frame (stage, controls, parameter panel). Used by page, embed, theater and standalone views.
   Colors are tokens; dark by default, light with the system setting, either forced by ?theme=dark|light (data-theme). */
:root {
  --lens-bg: #050608;
  --lens-stage: #000;
  --lens-ink: #e9edf2;
  --lens-soft: #9aa5b2;
  --lens-line: #20262e;
  --lens-btn: #11151b;
  --lens-btn-hover: #1a2029;
  --lens-accent: #f2f4f7;
  --lens-accent-ink: #050608;
  --lens-focus: #8fd3ff;
  --lens-caption-bg: rgba(0, 0, 0, .62);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --lens-bg: #f4f5f7; --lens-stage: #fbfbfc; --lens-ink: #11151b; --lens-soft: #56606c; --lens-line: #d7dce2;
    --lens-btn: #ffffff; --lens-btn-hover: #eef1f4; --lens-accent: #11151b; --lens-accent-ink: #ffffff; --lens-focus: #1b6fb8;
    --lens-caption-bg: rgba(255, 255, 255, .78); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --lens-bg: #f4f5f7; --lens-stage: #fbfbfc; --lens-ink: #11151b; --lens-soft: #56606c; --lens-line: #d7dce2;
  --lens-btn: #ffffff; --lens-btn-hover: #eef1f4; --lens-accent: #11151b; --lens-accent-ink: #ffffff; --lens-focus: #1b6fb8;
  --lens-caption-bg: rgba(255, 255, 255, .78); color-scheme: light;
}

.lens-piece { color: var(--lens-ink); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.lens-stage { position: relative; width: 100%; background: var(--lens-stage); overflow: hidden; border-radius: 10px; outline: none; touch-action: manipulation; }
.lens-stage:focus-visible { box-shadow: 0 0 0 3px var(--lens-focus); }
.lens-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.lens-caption { position: absolute; left: 50%; bottom: 6%; transform: translateX(-50%); max-width: min(86%, 46em); padding: .45em .9em; border-radius: 8px;
  background: var(--lens-caption-bg); color: var(--lens-ink); font-size: clamp(13px, 2.1vw, 19px); line-height: 1.4; text-align: center; pointer-events: none;
  backdrop-filter: blur(4px); transition: opacity .4s ease; }
.lens-caption[hidden] { display: block; opacity: 0; }
.lens-big { position: absolute; left: 50%; top: 50%; width: 72px; height: 72px; margin: -36px 0 0 -36px; border-radius: 50%; border: 1px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.45); color: #fff; cursor: pointer; display: grid; place-items: center; backdrop-filter: blur(6px); }
.lens-big svg { width: 34px; height: 34px; margin-left: 4px; }
.lens-big[hidden] { display: none; }

.lens-bar { display: flex; align-items: center; gap: 8px; padding: 8px 2px 4px; flex-wrap: wrap; }
.lens-spacer { flex: 1; }
.lens-btn, .lens-seg button { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--lens-line);
  background: var(--lens-btn); color: var(--lens-ink); font: inherit; cursor: pointer; }
.lens-btn:hover, .lens-seg button:hover { background: var(--lens-btn-hover); }
.lens-btn svg { width: 18px; height: 18px; }
.lens-btn:focus-visible, .lens-seg button:focus-visible, .lens-big:focus-visible, .lens-scrub:focus-visible, .lens-param input:focus-visible { outline: 2px solid var(--lens-focus); outline-offset: 2px; }
.lens-calm[aria-pressed="true"] { background: var(--lens-accent); color: var(--lens-accent-ink); border-color: var(--lens-accent); }
.lens-seg { display: inline-flex; border: 1px solid var(--lens-line); border-radius: 9px; overflow: hidden; }
.lens-seg button { border: 0; border-radius: 0; }
.lens-seg button[aria-pressed="true"] { background: var(--lens-accent); color: var(--lens-accent-ink); }
.lens-scrub { flex: 1 1 140px; min-width: 100px; accent-color: var(--lens-accent); }
.lens-scrub:disabled { opacity: .35; }
.lens-time { font: 12px ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--lens-soft); min-width: 7.5em; }
.lens-params { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 18px; padding: 6px 2px 2px; }
.lens-params[hidden] { display: none; }
.lens-param { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; color: var(--lens-soft); }
.lens-param input { grid-column: 1 / -1; width: 100%; accent-color: var(--lens-accent); }
.lens-param output { font: 12px ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--lens-ink); }

/* Embed: the frame is the whole page, so the stage fills what is left after the bar. */
.lens-view-embed .lens-stage { border-radius: 0; }
.lens-view-embed .lens-bar { padding: 4px 6px; gap: 6px; }
.lens-view-embed .lens-btn span { display: none; }

/* Theater: the stage is the viewport and the bar floats over it, fading when idle. */
.lens-view-theater { position: fixed; inset: 0; }
.lens-view-theater .lens-stage { position: absolute; inset: 0; height: 100%; border-radius: 0; aspect-ratio: auto; }
.lens-view-theater .lens-bar, .lens-view-theater .lens-params { position: absolute; left: 50%; transform: translateX(-50%); width: min(920px, calc(100% - 24px)); z-index: 3;
  background: color-mix(in srgb, var(--lens-bg) 82%, transparent); border: 1px solid var(--lens-line); border-radius: 12px; padding: 6px 8px; backdrop-filter: blur(8px);
  transition: opacity .5s ease; }
.lens-view-theater .lens-bar { bottom: 14px; }
.lens-view-theater .lens-caption { bottom: 96px; }
.lens-view-theater[data-mode="play"] .lens-caption { bottom: 150px; }
.lens-view-theater .lens-params { bottom: 66px; }
.lens-idle .lens-view-theater .lens-bar, .lens-idle .lens-view-theater .lens-params { opacity: 0; pointer-events: none; }
.lens-idle { cursor: none; }

.lens-piece:fullscreen { background: var(--lens-stage); display: flex; flex-direction: column; }
.lens-piece:fullscreen .lens-stage { flex: 1; aspect-ratio: auto !important; border-radius: 0; }

@media (prefers-reduced-motion: reduce) { .lens-caption { transition: none; } }
