/* ──────────────────────────────────────────────
   theater.css — Onecarat Product Theater
   Page layout uses shared.css tokens. The pseudo app
   (.demo-app) carries its own tokens copied from the
   real app's theme/core.css, editor.css, menu.css and
   ai-process/aiProcess.css (OnecaratEditorPhase1).
   ────────────────────────────────────────────── */

/* Demo-only tokens (shared.css stays untouched) */
:root {
  --spot-dim: 0.6;                 /* overwritten from scenes.js config */
  --demo-w: 960px;                 /* logical size of the pseudo app; scaled to fit */
  --demo-h: 500px;
  --theater-max: 1180px;
}

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

/* ── Intro (real H1 + lead, outside the demo) ── */

.theater-intro {
  text-align: center;
  padding-top: 8px;
}

.theater-intro .tag { margin-bottom: 12px; }

.theater-intro h1 {
  margin-bottom: 8px;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
}

.theater-lead {
  color: var(--muted);
  max-width: 60ch;
  margin: 0 auto;
}

/* ── Theater block ── */

/* width also follows the viewport height so the whole app + caption stays in view */
.theater {
  width: min(72vw, var(--theater-max), calc((100vh - 480px) * 960 / 500));
  min-width: min(640px, 100%);
  margin: 28px auto 0;
}

.theater-topline {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 16px;
  min-height: 34px;
}

/* Step list = table of contents, not a player control */
.theater-steps {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  counter-reset: step;
}

.theater-steps li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.theater-steps li + li::before {
  content: "";
  width: 28px;
  height: 1px;
  background: var(--border);
}

.theater-step {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 4px 14px 4px 6px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.35s ease, background-color 0.35s ease, border-color 0.35s ease;
}

.theater-step-num {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  font-size: 0.75rem;
  font-weight: 650;
  transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease;
}

.theater-step:hover { color: var(--text); }

.theater-step[aria-current="step"] {
  color: var(--accent-dark);
  background: var(--accent-light);
  font-weight: 600;
}

.theater-step[aria-current="step"] .theater-step-num {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.theater-demo-tag {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.74rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ── Stage: the pseudo app sits on the page, no player chrome ── */

.theater-stage {
  position: relative;
  /* height is set from JS (scale × --demo-h) */
}

.demo-scaler {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--demo-w);
  height: var(--demo-h);
  transform-origin: 0 0;
  /* the frame is only a soft edge so the app blends into the page */
  border-radius: 12px;
  box-shadow:
    0 0 0 1px var(--border),
    0 24px 60px -28px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}

@media (prefers-color-scheme: dark) {
  .demo-scaler {
    box-shadow:
      0 0 0 1px var(--border),
      0 24px 60px -24px rgba(0, 0, 0, 0.6);
  }
}

/* scene-3 loupe: page-level callout above the status bar */
.theater-loupe {
  position: absolute;
  z-index: 2;
  left: 0;
  top: 0;
  padding: 8px 16px;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: clamp(0.9rem, 1.2vw, 1.05rem);
  font-weight: 600;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

.theater-loupe::after {
  content: "";
  position: absolute;
  left: var(--arrow-x, 50%);
  bottom: -7px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  background: var(--surface);
  border-right: 1.5px solid var(--accent);
  border-bottom: 1.5px solid var(--accent);
  transform: rotate(45deg);
}

.theater-loupe.is-on { opacity: 1; }

/* ── Under the stage: caption + quiet pause control ── */

.theater-under {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-top: 22px;
  min-height: 44px;
}

.theater-caption {
  margin: 0;
  font-size: clamp(1.05rem, 1.6vw, 1.3rem);
  font-weight: 600;
  letter-spacing: 0.01em;
  text-align: center;
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.theater-caption.is-out {
  opacity: 0;
  transform: translateY(4px);
}

.theater-toggle {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px 4px 10px;
  font: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}

.theater-toggle:hover { color: var(--text); border-color: var(--muted); }

.theater-toggle[aria-pressed="true"] {
  color: var(--accent-dark);
  border-color: var(--accent);
  background: var(--accent-light);
}

/* two bars = pause, small triangle = play; drawn with borders, no icon font */
.theater-toggle-icon {
  width: 8px;
  height: 9px;
  border-left: 2.5px solid currentColor;
  border-right: 2.5px solid currentColor;
}

.theater-toggle[aria-pressed="true"] .theater-toggle-icon {
  border-right: 0;
  border-left: 0;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 8px solid currentColor;
}

.theater.is-reduced .theater-toggle { display: none; }

/* ══════════════════════════════════════════════
   Pseudo app — values from the real app's CSS
   ══════════════════════════════════════════════ */

.demo-app {
  /* theme/core.css */
  --a-accent: #0d9488;
  --a-surface: #f8fafc;
  --a-raised: #ffffff;
  --a-border: #e2e8f0;
  --a-text: #0f172a;
  --a-muted: #64748b;
  --a-on-accent: #ffffff;
  --a-sel: rgba(13, 148, 136, 0.22);
  /* Monaco base themes the app builds on (monacoSetup.ts: "vs" / "vs-dark") */
  --a-editor-fg: #000000;
  --a-editor-bg: #fffffe;

  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--a-surface);
  color: var(--a-text);
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  line-height: normal;
  cursor: default;
  user-select: none;
  transition: opacity 0.5s ease;
}

@media (prefers-color-scheme: dark) {
  .demo-app {
    --a-accent: #2dd4bf;
    --a-surface: #0f172a;
    --a-raised: #1e293b;
    --a-border: #334155;
    --a-text: #e2e8f0;
    --a-muted: #94a3b8;
    --a-on-accent: #042f2e;
    --a-sel: rgba(45, 212, 191, 0.24);
    --a-editor-fg: #d4d4d4;
    --a-editor-bg: #1e1e1e;
  }
}

.demo-app.is-faded { opacity: 0; }

/* spotlight: regions outside the focus are dimmed, never blacked out */
.demo-app [data-r] { transition: opacity 0.45s ease; }
.demo-app [data-r].is-dim { opacity: var(--spot-dim); }

.d-spacer { flex: 1; }

/* menu.css .menubar-row / .menubar-trigger ; editor.css .toolbar-btn */
.d-menubar {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--a-raised);
  border-bottom: 1px solid var(--a-border);
  padding: 2px 8px 2px 0;
  font-size: 12.5px;
}

.d-menus { display: flex; }

.d-menus span {
  padding: 4px 12px;
  color: var(--a-text);
}

.d-toolbar { display: flex; gap: 4px; }

.d-toolbar span {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--a-text);
}

/* editor.css .tabbar / .tab */
.d-tabbar {
  display: flex;
  align-items: stretch;
  background: var(--a-raised);
  border-bottom: 1px solid var(--a-border);
  min-height: 32px;
}

.d-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px 0 12px;
  font-size: 12px;
  color: var(--a-muted);
  border-right: 1px solid var(--a-border);
  white-space: nowrap;
}

.d-tab-active {
  color: var(--a-text);
  background: var(--a-surface);
  box-shadow: inset 0 -2px 0 var(--a-accent);
}

.d-tab-dirty {
  color: var(--a-accent);
  margin-right: 4px;
  font-size: 9px;
  vertical-align: 1px;
}

.d-tab-dirty.is-hidden { display: none; }

.d-tab-close {
  color: var(--a-muted);
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
}

.d-tab-new {
  display: flex;
  align-items: center;
  padding: 0 10px;
  color: var(--a-muted);
  font-size: 13px;
}

/* Editor body: monacoOptions.ts simpleOptions — 16px / 26px, Cascadia Code,
   word wrap on. Line numbers are a user option (View menu); shown here. */
.d-main {
  flex: 1;
  min-height: 0;
  display: flex;
}

.d-editor {
  flex: 1;
  min-width: 0;
  background: var(--a-editor-bg);
  color: var(--a-editor-fg);
  padding: 12px 0 8px;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 16px;
  line-height: 26px;
  overflow: hidden;
}

.d-line {
  display: grid;
  grid-template-columns: 52px 1fr;
}

.d-ln {
  text-align: right;
  padding-right: 18px;
  color: var(--a-muted);
  opacity: 0.75;
  font-size: 14px;
}

.d-line.is-current .d-ln { color: var(--a-text); opacity: 1; }

.d-tx {
  white-space: pre-wrap;
  word-break: break-word;
  padding-right: 28px;
  min-height: 26px;
  transition: opacity 0.45s ease;
}

.d-ln { transition: opacity 0.45s ease; }
.d-editor.focus-selection .d-line:not(.is-selected) .d-tx,
.d-editor.focus-selection .d-ln { opacity: calc(var(--spot-dim) * 0.75); }

.d-sel {
  background: var(--a-sel);
  border-radius: 2px;
}

.d-sel-eol::after {
  content: " ";
  background: var(--a-sel);
}

.d-caret {
  display: inline-block;
  width: 0;
  height: 20px;
  margin-right: -2px;
  border-left: 2px solid var(--a-text);
  vertical-align: -4px;
}

.demo-app.caret-blink .d-caret { animation: d-blink 1.06s steps(1) infinite; }
.demo-app.is-paused *, .demo-app.is-paused *::after { animation-play-state: paused !important; }

@keyframes d-blink {
  50% { opacity: 0; }
}

/* editor.css .statusbar */
.d-statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 12px;
  font-size: 11px;
  color: var(--a-muted);
  background: var(--a-raised);
  border-top: 1px solid var(--a-border);
  white-space: nowrap;
}

.d-sb-item { position: relative; }

.d-sb-select::after {
  content: "";
  display: inline-block;
  margin-left: 5px;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-top: 4px solid currentColor;
  vertical-align: 2px;
  opacity: 0.7;
}

/* soft ring for the scene-3 pulse (transform/opacity only) */
.d-sb-llm::after {
  content: "";
  position: absolute;
  inset: -4px -8px;
  border-radius: 6px;
  box-shadow: 0 0 0 2px var(--a-accent);
  opacity: 0;
  transform: scale(1.15);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.d-sb-llm.is-pulsed::after { opacity: 0.85; transform: scale(1); }
.d-sb-llm.is-pulsed { color: var(--a-text); }

/* menu.css .menubar-dropdown / .menubar-item */
.d-ctx {
  position: absolute;
  z-index: 20;
  min-width: 230px;
  background: var(--a-raised);
  border: 1px solid var(--a-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  padding: 4px;
  display: flex;
  flex-direction: column;
  font-size: 12.5px;
  transform-origin: 0 0;
  animation: d-pop 0.12s ease-out;
}

.d-ctx[hidden] { display: none; }

.d-ctx-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 5px 12px;
  border-radius: 5px;
  color: var(--a-text);
  white-space: nowrap;
}

.d-ctx-item.is-disabled { opacity: 0.45; }

.d-ctx-item.is-focused {
  background: var(--a-accent);
  color: var(--a-on-accent);
}

.d-ctx-short {
  font-size: 11px;
  color: var(--a-muted);
}

.d-ctx-item.is-focused .d-ctx-short { color: inherit; opacity: 0.75; }

.d-ctx-sep {
  height: 1px;
  background: var(--a-border);
  margin: 4px 6px;
}

@keyframes d-pop {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

/* ai-process/aiProcess.css — centered modal */
.d-wiz-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.25);
  animation: d-fade 0.18s ease-out;
}

@media (prefers-color-scheme: dark) {
  .d-wiz-overlay { background: rgba(226, 232, 240, 0.12); }
}

.d-wiz-overlay[hidden] { display: none; }
.d-wiz-overlay.is-closing { opacity: 0; transition: opacity 0.18s ease-in; }

@keyframes d-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.d-wiz-panel {
  position: relative;
  width: 600px;
  height: 452px;
  display: flex;
  flex-direction: column;
  background: var(--a-raised);
  border: 1px solid var(--a-border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.d-wiz-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--a-border);
}

.d-wiz-title {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--a-accent);
}

.d-wiz-close {
  color: var(--a-muted);
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
}

.d-wiz-input {
  display: flex;
  flex-direction: column;
  flex: 1 1 30%;
  min-height: 0;
  padding: 8px 14px 0;
}

.d-wiz-input.is-shrunk {
  flex: 0 0 auto;
  max-height: 22%;
}

.d-wiz-caption {
  font-size: 11px;
  color: var(--a-muted);
  margin-bottom: 4px;
}

.d-wiz-input-text {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--a-muted);
  border: 1px solid var(--a-border);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--a-surface);
}

.d-wiz-tiers { padding: 8px 14px 2px; }

.d-chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-bottom: 6px;
}

.d-chip-row-sub { padding-left: 10px; }

.d-tier-label {
  font-size: 11px;
  color: var(--a-muted);
  min-width: 58px;
}

.d-chip {
  border: 1px solid var(--a-border);
  border-radius: 999px;
  background: var(--a-surface);
  color: var(--a-muted);
  font-size: 12px;
  padding: 3px 11px;
}

.d-chip-fn { font-weight: 600; }

.d-chip.is-active {
  background: var(--a-accent);
  border-color: var(--a-accent);
  color: var(--a-on-accent);
}

.d-wiz-panel.is-running .d-chip { opacity: 0.6; }
.d-wiz-panel.is-running .d-chip.is-active { opacity: 1; }

.d-wiz-result {
  flex: 1 1 40%;
  min-height: 0;
  overflow: hidden;
  margin: 4px 14px;
  border: 1px solid var(--a-border);
  border-radius: 8px;
  background: var(--a-surface);
  padding: 8px 10px;
}

.d-wiz-result-text {
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.d-wiz-placeholder {
  font-size: 12px;
  color: var(--a-muted);
}

.d-wiz-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px 12px;
}

/* core.css .btn (small) */
.d-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12px;
}

.d-btn-primary { background: var(--a-accent); color: var(--a-on-accent); }
.d-btn-ghost { color: var(--a-muted); }

.d-wiz-resizer {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 18px;
  height: 18px;
  background: linear-gradient(135deg, transparent 50%, color-mix(in srgb, var(--a-accent) 45%, transparent) 50%);
  border-bottom-right-radius: 12px;
}

/* ── Pseudo mouse cursor (transform-only motion) ── */
.d-cursor {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 50;
  width: 16px;
  height: 24px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  will-change: transform;
}

.d-cursor.is-visible { opacity: 1; }

.d-cursor svg {
  display: block;
  fill: #ffffff;
  stroke: #0f172a;
  stroke-width: 1.2;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.3));
  transition: transform 0.09s ease;
  transform-origin: 1px 1px;
}

.d-cursor.is-pressed svg { transform: scale(0.88); }

.d-click-ring {
  position: absolute;
  left: -11px;
  top: -11px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--a-accent);
  opacity: 0;
  transform: scale(0.3);
}

.d-cursor.is-clicked .d-click-ring {
  animation: d-ring 0.45s ease-out;
}

@keyframes d-ring {
  0% { opacity: 0.8; transform: scale(0.3); }
  100% { opacity: 0; transform: scale(1.3); }
}

/* ── Responsive (standalone theater page) ── */

@media (max-width: 1279px) {
  .theater { width: min(86vw, var(--theater-max), calc((100vh - 480px) * 960 / 500)); }
}

/* ≤1023px: only "does not break". The whole app scales down; the step list
   and controls stack so nothing overlaps. */
@media (max-width: 1023px) {
  .theater { width: auto; min-width: 0; margin: 24px 16px 0; }
  .theater-topline { flex-direction: column; gap: 8px; }
  .theater-demo-tag { position: static; transform: none; }
  .theater-loupe { white-space: normal; max-width: 90%; }
  .theater-steps { flex-wrap: wrap; justify-content: center; }
  .theater-steps li + li::before { width: 12px; }
  .theater-under { flex-direction: column; gap: 12px; }
  .theater-toggle { position: static; transform: none; }
}

/* ── Menubar dropdown, tabs, log view, callout rows ── */

.d-tabs { display: flex; }

/* menu.css .menubar-trigger-open */
.d-menus span.is-open {
  background: var(--a-accent);
  color: var(--a-on-accent);
}

.d-drop { animation: none; }

/* network.log opened in the editor: same editor, long line wraps */
.d-editor.is-log .d-tx { word-break: break-all; }

.loupe-rows {
  display: grid;
  grid-template-columns: auto auto;
  gap: 4px 18px;
  margin: 0;
  font-size: 0.92em;
}

.loupe-rows dt { color: var(--muted); font-weight: 500; }
.loupe-rows dd { margin: 0; font-weight: 650; }

/* callout under its anchor: arrow on top */
.theater-loupe.is-below::after {
  bottom: auto;
  top: -7px;
  transform: rotate(225deg);
}

/* ── Phone: a narrower app layout, not a shrunken desktop ── */
@media (max-width: 640px) {
  :root {
    --demo-w: 480px;
    --demo-h: 540px;
  }
  .d-toolbar,
  .d-sb-font,
  .d-sb-select { display: none; }
  .d-menus span { padding: 4px 9px; }
  .d-wiz-panel {
    width: calc(100% - 20px);
    height: calc(100% - 24px);
  }
  .d-ctx { min-width: 0; }
  .d-ctx-short { display: none; }
  .theater-topline { align-items: stretch; }
  .theater-steps {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    max-width: 100%;
    padding-bottom: 4px;
    scrollbar-width: none;
  }
  .theater-step { white-space: nowrap; }
}
