/* Wireframe shared styles — DESIGN.md token-backed dark theme */
:root {
  --ink: var(--color-body);
  --ink-2: var(--color-muted-strong);
  --ink-3: var(--color-muted);
  --line: var(--color-hairline-on-dark);
  --line-2: color-mix(in srgb, var(--color-hairline-on-dark) 72%, var(--color-canvas-dark));
  --paper: var(--color-surface-card-dark);
  --paper-2: var(--color-canvas-dark);
  --paper-3: var(--color-surface-elevated-dark);
  --accent: var(--color-muted-strong);
  --tag: var(--color-surface-elevated-dark);
  --radius: var(--radius-lg);
  --shadow: var(--shadow-raised);
  --mono: var(--font-mono);
  --rail-w: 384px;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html, body {
  margin: 0; height: 100%;
  background: var(--paper-2); color: var(--ink);
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* stylish thin scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--color-muted) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--color-muted); border-radius: var(--radius-lg); border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--color-muted-strong); }

/* ============ shell ============ */
.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.app-row { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.toast {
  position: fixed; right: var(--space-md); bottom: var(--space-md); z-index: 80;
  max-width: min(360px, calc(100vw - 32px)); padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--button-primary-bg); border-radius: var(--radius-lg); background: var(--button-primary-bg);
  color: var(--button-primary-fg); font-size: var(--type-caption-size); font-weight: 700; line-height: var(--type-caption-line-height); box-shadow: 0 var(--space-xs) var(--space-lg) color-mix(in srgb, var(--color-canvas-dark) 28%, transparent);
}
.toast-enter {
  transition: opacity .24s ease-out, transform .24s ease-out;
}
.toast-enter-start {
  opacity: 0;
  transform: translateY(var(--space-sm));
}
.toast-enter-end {
  opacity: 1;
  transform: translateY(0);
}
.p-login{min-height:100vh;display:grid;place-items:center;padding:clamp(var(--space-lg),6vw,var(--space-xxl));background:var(--color-canvas-dark);color:var(--ink);}
.p-login__panel{width:min(100%,440px);padding:var(--space-xl);border:1px solid var(--line);border-radius:var(--radius-xl);background:var(--paper);box-shadow:none;}
.p-login__brand{display:flex;justify-content:center;align-items:center;margin:0 0 var(--space-xs);}
.p-login__logo{display:block;width:min(52%,170px);height:auto;}
.p-login__logo{filter:invert(1) brightness(1.45) contrast(.92);opacity:.92;}
.p-login__appname{margin:0 0 var(--space-lg);text-align:center;font-size:var(--type-title-sm-size);font-weight:var(--type-title-sm-weight);line-height:var(--type-title-sm-line-height);color:var(--ink);}
.p-login__note{margin:0 0 var(--space-lg);color:var(--ink-2);font-size:var(--type-body-md-size);line-height:var(--type-body-md-line-height);text-align:center;}
.p-login__actions{display:grid;gap:var(--space-sm);}
.p-login__google{width:100%;min-height:46px;display:inline-flex;align-items:center;justify-content:center;gap:var(--space-xs);border:1px solid var(--button-primary-bg);border-radius:var(--button-primary-radius);background:var(--button-primary-bg);color:var(--button-primary-fg);font-size:var(--type-button-size);font-weight:var(--type-button-weight);line-height:var(--type-button-line-height);text-decoration:none;}
.p-login__google:hover{background:var(--button-primary-bg-active);border-color:var(--button-primary-bg-active);}
.p-login__google:focus-visible{outline:none;box-shadow:var(--focus-ring);}
.p-login__google-mark{width:22px;height:22px;display:inline-grid;place-items:center;border-radius:var(--radius-full);background:color-mix(in srgb,var(--color-on-primary) 10%,transparent);color:var(--color-on-primary);font-weight:700;line-height:1;}
.p-login__meta{margin:var(--space-md) 0 0;color:var(--ink-3);font-size:var(--type-caption-size);line-height:var(--type-caption-line-height);text-align:center;}
.p-login__error{margin:var(--space-xs) 0 0;color:var(--color-error);font-size:var(--type-caption-size);line-height:var(--type-caption-line-height);text-align:center;}
@media(max-width:900px){.p-login{padding:var(--space-lg);}.p-login__panel{padding:var(--space-lg);}}

/* far-left icon nav */
.iconrail {
  flex: 0 0 60px; background: var(--color-canvas-dark);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-xs);
  padding: var(--space-sm) var(--space-xs);
}
.ir-btn {
  width: 100%; border: 0; background: transparent; border-radius: var(--radius-lg);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-xxs);
  padding: var(--space-xs) var(--space-xxs); color: var(--ink-3);
  font-size: var(--type-caption-size); font-weight: var(--type-caption-weight); line-height: var(--type-caption-line-height);
}
.ir-btn:hover { background: var(--paper-2); color: var(--ink-2); }
.ir-btn.on { background: var(--paper-3); color: var(--ink); }

/* workspace */
.workspace { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

/* header (full width) */
.header {
  flex: 0 0 auto; height: 58px; display: flex; align-items: center; gap: var(--space-sm);
  padding: 0 var(--space-md); background: var(--paper); border-bottom: 1px solid var(--line); z-index: 6;
}
.app > .header {
  height: 64px;
  gap: var(--space-sm);
  padding: 0 var(--space-md);
  background: var(--color-canvas-dark);
  font-size: var(--type-nav-link-size);
  font-weight: var(--type-nav-link-weight);
  line-height: var(--type-nav-link-line-height);
}
.hd-brand { display: flex; align-items: center; gap: var(--space-sm); min-width: 0; }
.hd-mark {
  width: 30px; height: 30px; border-radius: var(--radius-lg); background: var(--color-primary);
  color: var(--color-on-primary); display: grid; place-items: center; font-size: var(--type-title-sm-size); flex: 0 0 auto;
}
.app > .header .hd-mark { width: 32px; height: 32px; border-radius: var(--radius-md); }
.hd-logo { font-weight: 700; font-size: var(--type-title-sm-size); letter-spacing: .01em; white-space: nowrap; }
.app > .header .hd-logo { font-weight: var(--type-title-sm-weight); font-size: var(--type-title-sm-size); line-height: var(--type-title-sm-line-height); letter-spacing: 0; }
.header .spacer { flex: 1; }
.hd-user {
  display: inline-flex; align-items: center; gap: var(--space-xxs); max-width: 220px;
  color: var(--ink-2); font-size: var(--type-caption-size); font-weight: 600;
}
.app > .header .hd-user {
  gap: var(--space-xs);
  font-size: var(--type-nav-link-size);
  font-weight: var(--type-nav-link-weight);
  line-height: var(--type-nav-link-line-height);
}
.hd-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ buttons ============ */
.btn {
  border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  font-size: var(--type-button-size); font-weight: var(--type-button-weight); line-height: var(--type-button-line-height); padding: var(--space-xs) var(--space-sm); border-radius: var(--radius-lg);
  display: inline-flex; align-items: center; gap: var(--space-xs); white-space: nowrap; text-decoration: none;
}
.btn:not(:disabled):hover { background: var(--paper-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--button-primary-bg); color: var(--button-primary-fg); border-color: var(--button-primary-bg); }
.btn.primary:not(:disabled):hover { background: var(--button-primary-bg-active); border-color: var(--button-primary-bg-active); }
.btn.primary:disabled { background: var(--color-primary-disabled); border-color: var(--color-primary-disabled); color: var(--color-muted); opacity: 1; }
.btn.danger { border-color: var(--color-error); color: var(--color-error); }
.btn.danger:not(:disabled):hover { background: var(--surface-error); }
.btn.sm { padding: var(--space-xxs) var(--space-xs); font-size: var(--type-caption-size); font-weight: 600; border-radius: var(--radius-md); }
.btn.lg { padding: var(--space-sm) var(--space-md); font-size: var(--type-body-lg-size); border-radius: var(--radius-lg); }
.btn.icon-only { width: 32px; height: 30px; padding: 0; justify-content: center; gap: 0; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--paper-3); }
.btn.block { width: 100%; justify-content: center; padding: var(--space-sm); }
.icon-btn {
  border: 0; background: transparent; color: var(--ink-3); border-radius: var(--radius-md);
  width: 28px; height: 28px; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--paper-3); color: var(--ink); }
.icon-btn.lg { width: 36px; height: 36px; color: var(--ink-2); }
.app .btn,
.sg-page .btn {
  font-size: var(--type-button-size);
  font-weight: var(--type-button-weight);
  line-height: var(--type-button-line-height);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
}
.app .btn.primary,
.sg-page .btn.primary {
  border-radius: var(--button-primary-radius);
}
.app .btn.sm,
.sg-page .btn.sm {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--type-caption-size);
  border-radius: var(--radius-md);
}
.app .btn.lg,
.sg-page .btn.lg {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--type-button-size);
  border-radius: var(--radius-lg);
}
.app .btn.block,
.sg-page .btn.block {
  padding: var(--space-sm);
}
.app .icon-btn,
.sg-page .icon-btn {
  border-radius: var(--radius-md);
}
.app > .header .btn.sm {
  font-size: var(--type-caption-size);
  font-weight: 600;
  line-height: var(--type-caption-line-height);
  text-decoration: none;
}
.app .btn:focus-visible,
.sg-page .btn:focus-visible,
.icon-btn:focus-visible,
.plot-drag-handle:focus-visible,
.plot-toggle:focus-visible,
.ir-btn:focus-visible,
.wf-item:focus-visible,
.set-btn:focus-visible,
.add-row:focus-visible,
.dz-add:focus-visible,
.vt-btn:focus-visible,
.pj-card:focus-visible,
.pj-row:focus-visible,
.pj-edit:focus-visible,
.editor-title-button:focus-visible,
.editor-title-input:focus-visible,
.choice-row:focus-visible,
.ratio-card:focus-visible,
.chip:focus-visible,
.stepper button:focus-visible,
.asset-choice:focus-visible,
.asset-del:focus-visible,
.seg button:focus-visible,
.switch:focus-visible {
  outline: none;
  border-color: var(--color-info);
  box-shadow: var(--focus-ring);
}

/* ============ split: rail + board ============ */
.split { flex: 1; min-height: 0; display: flex; position: relative; }
.panel-rail {
  flex: 0 0 var(--rail-w); width: var(--rail-w);
  background: var(--paper); overflow: hidden;
  transition: flex-basis .22s ease, width .22s ease;
}
.panel-rail.collapsed { flex-basis: 0; width: 0; }
.resizer { flex: 0 0 6px; cursor: col-resize; position: relative; background: transparent; z-index: 3; }
.resizer::after { content: ""; position: absolute; left: 2px; top: 0; bottom: 0; width: 1px; background: var(--line); transition: background .12s, width .12s; }
.resizer:hover::after, .resizer.on::after { background: var(--ink-3); width: 2px; left: 1.5px; }
.rail-inner { width: var(--rail-w); height: 100%; overflow-y: auto; padding: var(--space-md) var(--space-md) var(--space-lg); }
.seclabel {
  font-size: var(--type-caption-size); font-weight: 700; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .07em; margin: 0 0 var(--space-xs);
}

.board-area { flex: 1; min-width: 0; overflow-y: auto; padding: var(--space-lg) var(--space-lg) var(--space-xl); }
.board-wrap { max-width: 1040px; margin: 0 auto; }
.editor-head {
  max-width: 1040px; margin: 0 auto var(--space-md); display: flex; align-items: center; gap: var(--space-xs) var(--space-sm);
  min-width: 0; padding: 0; border: 0; border-radius: 0;
  background: transparent; box-shadow: none;
}
.editor-title { flex: 1 1 auto; min-width: 0; }
.editor-title h1 {
  margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--type-title-md-size); font-weight: var(--type-title-md-weight); line-height: var(--type-title-md-line-height);
}
.editor-title-button {
  max-width: 100%; padding: 0; border: 0; background: transparent; color: inherit;
  font: inherit; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: text;
}
.editor-title-input {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper);
  color: var(--ink); font-family: inherit; font-size: var(--type-title-md-size); font-weight: var(--type-title-md-weight);
  line-height: var(--type-title-md-line-height); padding: var(--space-xxs) var(--space-xs); outline: none;
}
.editor-head .spacer { flex: 1 1 24px; min-width: 0; }
.editor-head .btn { flex: 0 0 auto; }

/* ============ composer ============ */
.composer { display: flex; flex-direction: column; }
.composer .ctabs { display: flex; gap: var(--space-xxs); margin-bottom: var(--space-sm); background: var(--paper-3); padding: var(--space-xxs); border-radius: var(--radius-lg); }
.composer .ctabs button {
  flex: 1; border: 0; background: transparent; font-size: var(--type-caption-size); font-weight: var(--type-caption-weight); line-height: var(--type-caption-line-height);
  color: var(--ink-3); padding: var(--space-xs) var(--space-sm); border-radius: var(--radius-md); white-space: nowrap;
}
.composer .ctabs button.on { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-flat-card); }
.field {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-lg); resize: none;
  font-family: inherit; font-size: var(--type-body-lg-size); color: var(--ink); background: var(--paper-2);
  outline: none; line-height: var(--type-body-lg-line-height); padding: var(--space-sm);
}
.field::placeholder { color: var(--ink-3); }
.field:focus { border-color: var(--color-info); box-shadow: var(--focus-ring); }
.composer-foot { margin-top: var(--space-md); display: flex; flex-direction: column; gap: var(--space-xs); }
.settings-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-xs); }
.set-btn { padding: var(--space-xs) var(--space-xxs); }
.set-btn {
  border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-lg);
  padding: var(--space-xs); font-size: var(--type-caption-size); font-weight: var(--type-caption-weight); line-height: var(--type-caption-line-height); color: var(--ink-2);
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: var(--space-xxs); white-space: nowrap; min-width: 0;
}
.set-btn:hover { background: var(--paper-2); color: var(--ink); }
.set-lab { display: flex; align-items: center; gap: var(--space-xxs); max-width: 100%; color: var(--ink-2); font-size: var(--type-caption-size); font-weight: var(--type-caption-weight); line-height: var(--type-caption-line-height); }
.set-lab svg { flex: 0 0 auto; }
.set-val { max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-3); font-size: var(--type-caption-size); font-weight: 400; line-height: var(--type-caption-line-height); }
.rail-settings { display: flex; flex-direction: column; gap: var(--space-sm); margin-top: var(--space-md); }
.rail-divider { height: 1px; background: var(--line); margin: 0 0 var(--space-xxs); }
.rail-settings .set-btn { min-width: 0; }
.rail-settings .set-val { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* ============ scene accordion (input) ============ */
.acc { display: flex; flex-direction: column; gap: var(--space-xs); }
.acc-item { border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--paper); overflow: hidden; }
.acc-item.open { box-shadow: none; }
.acc-head { display: flex; align-items: center; gap: var(--space-xs); padding: var(--space-sm); cursor: pointer; }
.acc-head:hover { background: var(--paper-2); }
.grip { color: var(--line); cursor: grab; display: grid; place-items: center; }
.grip:active { cursor: grabbing; }
.acc-no {
  flex: 0 0 auto; width: 21px; height: 21px; border-radius: 50%;
  background: var(--paper-3); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: var(--type-caption-size); font-weight: 700; color: var(--ink-2);
}
.acc-title { flex: 1; font-size: var(--type-body-sm-size); font-weight: 600; line-height: var(--type-body-sm-line-height); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-chev { color: var(--ink-3); display: grid; place-items: center; }
.acc-chev svg { transition: transform .18s; }
.acc-body { padding: var(--space-xxs) var(--space-sm) var(--space-sm); display: flex; flex-direction: column; gap: var(--space-sm); border-top: 1px solid var(--line-2); }
.fld { display: flex; flex-direction: column; gap: var(--space-xs); }
.fld-lab { font-size: var(--type-caption-size); font-weight: var(--type-caption-weight); line-height: var(--type-caption-line-height); color: var(--ink-3); display: flex; align-items: center; gap: var(--space-xxs); }
.fld textarea {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-lg); resize: vertical;
  font-family: var(--mono); font-size: var(--type-body-lg-size); line-height: var(--type-body-lg-line-height); color: var(--ink-2);
  background: var(--paper-2); outline: none; padding: var(--space-xs);
}
.fld textarea:focus { border-color: var(--color-info); box-shadow: var(--focus-ring); }
.acc-foot { display: flex; }
.plot-box { margin-top: var(--space-md); display: flex; flex-direction: column; gap: var(--space-xs); }
.story-actions { margin-top: var(--space-sm); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs); }
.original-story { margin-top: var(--space-xs); display: flex; flex-direction: column; gap: var(--space-xs); }
.original-story-panel { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-xs); }
.original-story-text {
  width: 100%; border: 1px solid var(--line); border-radius: var(--radius-lg); resize: vertical;
  font-family: var(--mono); font-size: var(--type-body-lg-size); line-height: var(--type-body-lg-line-height); color: var(--ink-3);
  background: var(--paper-3); outline: none; padding: var(--space-xs);
}
.original-story-text:focus { border-color: var(--color-info); box-shadow: var(--focus-ring); }
.plot-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-xs); }
.plot-head-buttons { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: var(--space-xs); }
.plot-list { display: flex; flex-direction: column; gap: var(--space-xs); }
.plot-row {
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--paper-2); overflow: hidden;
}
.plot-row.open { border-color: var(--ink-3); }
.plot-row-head {
  display: grid;
  grid-template-columns: var(--space-lg) var(--space-lg) minmax(0, 1fr) calc(var(--space-lg) + var(--space-xs));
  align-items: center; gap: var(--space-xs); padding: var(--space-xs);
}
.plot-drag-handle {
  width: var(--space-lg); height: var(--space-lg); border: 0; border-radius: var(--radius-md);
  background: transparent; color: var(--ink-3); display: grid; place-items: center;
  padding: 0; cursor: grab;
}
.plot-drag-handle:hover { background: var(--paper-3); color: var(--ink-2); }
.plot-drag-handle:active { cursor: grabbing; }
.plot-no {
  width: 24px; height: 24px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--paper-3); color: var(--ink-3); display: grid; place-items: center;
  font-size: var(--type-caption-size); font-weight: 700;
}
.plot-row input {
  min-width: 0; width: 100%; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--paper-2); color: var(--ink-2); font: inherit; font-size: var(--type-body-lg-size); line-height: var(--type-body-lg-line-height);
  padding: var(--space-xs); outline: none;
}
.plot-row input:disabled,
.plot-detail textarea:disabled { cursor: not-allowed; opacity: .72; }
.plot-row input:focus { border-color: var(--color-info); box-shadow: var(--focus-ring); }
.plot-toggle {
  width: calc(var(--space-lg) + var(--space-xs)); height: calc(var(--space-lg) + var(--space-xs));
  border: 0; border-radius: var(--radius-md); background: transparent; color: var(--ink-3);
  display: grid; place-items: center; padding: 0;
}
.plot-toggle:hover { background: var(--paper-3); color: var(--ink-2); }
.plot-toggle svg { transition: transform .18s ease; }
.plot-toggle.open svg { transform: rotate(180deg); }
.plot-detail {
  border-top: 1px solid var(--line-2); padding: var(--space-sm);
  background: var(--paper); display: flex; flex-direction: column; gap: var(--space-sm);
}
.plot-row-foot { display: flex; justify-content: flex-end; }
.plot-field { display: flex; flex-direction: column; gap: var(--space-xs); }
.plot-field-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-xs); }
.compose-btn { flex: 0 0 auto; }
.ref-box {
  border: 1px solid var(--line-2); border-radius: var(--radius-lg); background: var(--paper-2);
  padding: var(--space-sm); display: flex; flex-direction: column; gap: var(--space-xs);
}
.ref-head { display: flex; align-items: center; gap: var(--space-xs); min-width: 0; }
.ref-style { margin-left: auto; font-size: var(--type-caption-size); color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-group { display: flex; flex-direction: column; gap: var(--space-xxs); }
.ref-label { font-size: var(--type-caption-size); font-weight: 700; color: var(--ink-3); }
.ref-list { display: flex; flex-wrap: wrap; gap: var(--space-xxs); }
.ref-chip {
  min-width: 0; max-width: 100%; border: 1px solid var(--line); background: var(--paper);
  border-radius: var(--radius-lg); padding: var(--space-xxs) var(--space-xs); display: inline-flex; align-items: center;
  gap: var(--space-xxs); color: var(--ink-2); font-size: var(--type-caption-size); font-weight: 700;
  transition: background-color .16s ease, border-color .16s ease, color .16s ease;
}
.ref-chip:hover { border-color: var(--accent); background: var(--paper-3); color: var(--ink); }
.ref-chip:focus-visible { outline: none; border-color: var(--color-info); box-shadow: var(--focus-ring); }
.ref-chip:disabled { cursor: not-allowed; opacity: .56; }
.ref-chip.on {
  border-color: var(--button-primary-bg); background: var(--button-primary-bg); color: var(--button-primary-fg);
}
.ref-chip.on:hover {
  border-color: var(--button-primary-bg-active); background: var(--button-primary-bg-active); color: var(--button-primary-fg);
}
.ref-check {
  width: calc(var(--space-sm) + var(--space-xxs)); height: calc(var(--space-sm) + var(--space-xxs));
  border-radius: var(--radius-full); background: var(--button-primary-fg); color: var(--button-primary-bg);
  display: inline-grid; place-items: center; flex: 0 0 auto; opacity: 0; transform: scale(.8);
  transition: opacity .16s ease, transform .16s ease;
}
.ref-chip.on .ref-check { opacity: 1; transform: scale(1); }
.ref-chip.on .ref-thumb { background: color-mix(in srgb, var(--button-primary-fg) 16%, transparent); color: var(--button-primary-fg); }
.ref-chip span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-thumb { width: 22px; height: 22px; border-radius: var(--radius-sm); background: var(--paper-3); display: grid; place-items: center; color: var(--ink-3); flex: 0 0 auto; overflow: hidden; }
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref-empty { font-size: var(--type-caption-size); color: var(--ink-3); line-height: var(--type-caption-line-height); }
.ref-select { min-height: 40px; padding: var(--space-xs) var(--space-sm); border-radius: var(--radius-lg); font-size: var(--type-body-lg-size); line-height: var(--type-body-lg-line-height); }
.ref-select:focus { border-color: var(--color-info); box-shadow: var(--focus-ring); }
.add-row {
  display: flex; align-items: center; gap: var(--space-xs); justify-content: center;
  border: 1px dashed var(--line); border-radius: var(--radius-lg); padding: var(--space-sm);
  color: var(--ink-3); font-size: var(--type-caption-size); font-weight: var(--type-caption-weight); line-height: var(--type-caption-line-height); background: transparent; width: 100%;
}
.add-row:hover { color: var(--ink-2); border-color: var(--ink-3); }

/* ============ dropzone ============ */
.dropzone { border: 1px dashed var(--line); border-radius: var(--radius-lg); background: var(--paper-2); padding: var(--space-sm); }
.dropzone.disabled { opacity: .72; }
.dz-head { display: flex; align-items: center; gap: var(--space-xs); font-size: var(--type-caption-size); color: var(--ink-2); font-weight: var(--type-caption-weight); line-height: var(--type-caption-line-height); margin-bottom: var(--space-xs); }
.dz-add { width: 42px; border-radius: var(--radius-lg); border: 1px dashed var(--line); background: var(--paper); display: grid; place-items: center; color: var(--ink-3); }
.dz-add:hover { color: var(--ink); border-color: var(--ink-3); }
.dz-actions { margin-top: var(--space-xs); display: flex; flex-wrap: wrap; gap: var(--space-xs); }

/* ============ panel workflow ============ */
.workflow-nav { margin-top: var(--space-md); display: flex; flex-direction: column; gap: var(--space-xs); }
.wf-item {
  width: 100%; border: 1px solid var(--line); background: var(--paper);
  border-radius: var(--radius-lg); padding: var(--space-sm); display: flex; align-items: center; gap: var(--space-xs);
  text-align: left; color: var(--ink-2);
}
.wf-item:hover { background: var(--paper-2); color: var(--ink); }
.wf-item.dim { opacity: .55; }
.wf-item span {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--type-body-sm-size); font-weight: 700;
}
.wf-item b {
  flex: 0 0 auto; font-size: var(--type-caption-size); color: var(--ink-3);
  background: var(--paper-3); border-radius: var(--radius-pill); padding: 3px var(--space-xs);
}
.flow-panels { max-width: 1040px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--space-md); }
.flow-panel {
  border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper);
  box-shadow: none; padding: var(--space-md); scroll-margin-top: var(--space-md);
}
.flow-head { display: flex; align-items: center; gap: var(--space-xs); margin-bottom: var(--space-sm); }
.flow-head h2 { margin: 0; font-size: var(--type-title-sm-size); font-weight: var(--type-title-sm-weight); line-height: var(--type-title-sm-line-height); }
.flow-head .count { font-family: var(--font-number); font-size: var(--type-caption-size); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.flow-settings { margin-top: var(--space-md); }
.flow-panel-controls .flow-settings { margin-top: 0; }
.flow-actions { margin-top: var(--space-md); display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs); }
.flow-note { flex: 1 1 240px; min-width: 0; font-size: var(--type-caption-size); color: var(--ink-3); line-height: var(--type-caption-line-height); }
.flow-empty {
  border: 1px dashed var(--line); border-radius: var(--radius-lg); background: var(--paper-2);
  color: var(--ink-3); font-size: var(--type-caption-size); line-height: var(--type-caption-line-height); padding: var(--space-sm); margin-bottom: var(--space-md);
}
.split-loading {
  margin-top: var(--space-md); border: 1px solid var(--line-2); border-radius: var(--radius-lg);
  background: var(--paper-2); padding: var(--space-sm); display: flex; align-items: center; gap: var(--space-xs);
  font-size: var(--type-caption-size); font-weight: 700; color: var(--ink-2);
}
.split-loading .gen-spinner { width: 18px; height: 18px; border-width: 2px; }
.candidate-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-sm); margin-bottom: var(--space-md);
}
@media (max-width: 900px) {
  .candidate-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .candidate-grid { grid-template-columns: repeat(1, minmax(0, 1fr)); }
}
.candidate-card {
  position: relative; min-width: 0; border: 1px solid var(--line);
  border-radius: var(--radius-lg); background: var(--paper-2); padding: var(--space-sm); display: flex;
  flex-direction: column; gap: var(--space-xs);
}
.candidate-thumb {
  position: relative; aspect-ratio: 16/10; border: 1px solid var(--line-2); border-radius: var(--radius-lg);
  background: var(--paper-3); display: grid; place-items: center; color: var(--ink-3); overflow: hidden;
}
.candidate-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.candidate-thumb img.candidate-zoom { cursor: zoom-in; }
.candidate-thumb img,
.candidate-thumb > svg { transition: opacity .2s; }
.candidate-thumb.is-generating img,
.candidate-thumb.is-generating > svg { opacity: .3; }
.candidate-thumb .gen-overlay { z-index: 2; gap: 0; }
.candidate-thumb .gen-spinner { width: 22px; height: 22px; border-width: 2px; }
.candidate-upload-badge {
  position: absolute; right: 7px; bottom: 7px; z-index: 3;
  width: 24px; height: 24px; border: 1px solid var(--line); border-radius: var(--radius-pill);
  background: var(--paper); color: var(--ink);
  display: grid; place-items: center; opacity: 0; transform: translateY(2px);
  pointer-events: none; transition: opacity .16s ease, transform .16s ease;
}
.candidate-card:hover .candidate-upload-badge { opacity: 1; transform: translateY(0); }
.candidate-body { display: flex; flex-direction: column; gap: var(--space-xxs); min-width: 0; }
.candidate-body b { font-size: var(--type-body-sm-size); font-weight: 600; line-height: var(--type-body-sm-line-height); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.candidate-body p { margin: 0; min-height: 3.1em; font-size: var(--type-caption-size); line-height: var(--type-caption-line-height); color: var(--ink-2); }
.candidate-name-input,
.candidate-desc-input {
  width: 100%; min-width: 0; border: 1px solid transparent; border-radius: var(--radius-md);
  background: transparent; color: var(--ink); font-family: inherit; outline: none;
}
.candidate-name-input { font-size: var(--type-body-lg-size); font-weight: 700; line-height: var(--type-body-lg-line-height); padding: var(--space-xxs); }
.candidate-desc-input {
  min-height: 4.4em; resize: vertical; font-size: var(--type-body-sm-size); line-height: var(--type-body-sm-line-height);
  color: var(--ink-2); padding: var(--space-xxs);
}
.candidate-name-input:focus,
.candidate-desc-input:focus { border-color: var(--color-info); background: var(--paper); box-shadow: var(--focus-ring); }
.candidate-remove {
  position: absolute; top: var(--space-xs); right: var(--space-xs); z-index: 2;
  background: var(--paper); border: 1px solid var(--line);
}
.kind-badge {
  position: absolute; top: var(--space-xs); left: var(--space-xs); z-index: 1;
  font-size: var(--type-caption-size); font-weight: 700; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-pill); padding: 3px var(--space-xs);
}
.kind-prop,
.kind-bg { color: var(--ink); }
.asset-inline {
  border: 1px dashed var(--line); border-radius: var(--radius-lg); background: var(--paper-2);
  padding: var(--space-sm); display: flex; flex-direction: column; gap: var(--space-xs);
}
.asset-inline .dz-actions { margin-top: 0; }
.asset-inline.disabled { opacity: .72; }
.fld textarea.drop-ready,
.candidate-card.drop-ready,
.asset-inline.drop-ready {
  border-color: var(--color-info); border-style: dashed;
  background: color-mix(in srgb, var(--color-info) 10%, var(--paper-2));
  box-shadow: var(--focus-ring);
}
.scene-add { margin-top: var(--space-md); }
.scene .stitle { display: flex; align-items: center; gap: var(--space-xs); min-width: 0; }
.scene .stitle .grip { color: var(--ink-3); }
.scene-edit-body { max-height: min(72vh, 720px); overflow-y: auto; }
.fade-up { animation: fade-up .28s ease-out both; animation-delay: var(--stagger-delay, 0ms); }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .fade-up { animation: none; }
}

/* ============ board head ============ */
.board-head { display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-xs) var(--space-sm); min-width: 0; margin-bottom: var(--space-md); }
.board-head h2 { flex: 0 0 auto; font-size: var(--type-title-sm-size); line-height: var(--type-title-sm-line-height); margin: 0; font-weight: var(--type-title-sm-weight); }
.board-head .count { flex: 0 0 auto; font-family: var(--font-number); font-size: var(--type-caption-size); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.board-head .spacer { flex: 1 1 24px; min-width: 0; }
.board-head .view-toggle,
.board-head .board-image-toggle,
.board-head .btn { flex: 0 0 auto; }
.board-image-toggle {
  min-height: 32px; padding: 0 var(--space-xs);
  border-radius: var(--radius-lg); background: var(--paper-3);
}
.view-toggle { display: flex; gap: var(--space-xxs); background: var(--paper-3); padding: var(--space-xxs); border-radius: var(--radius-lg); }
.vt-btn {
  border: 0; background: transparent; color: var(--ink-3); border-radius: var(--radius-md);
  width: 30px; height: 28px; display: grid; place-items: center;
}
.vt-btn:hover { color: var(--ink-2); }
.vt-btn.on { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-flat-card); }

/* ============ scenes ============ */
.scene { position: relative; }
.scenes.strip { display: flex; flex-direction: column; gap: var(--space-sm); }
.scenes.strip .scene {
  display: grid; grid-template-columns: 320px 1fr;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: none;
}
.scenes.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--card-min, 260px), 1fr)); gap: var(--space-sm); }
.scenes.grid .scene {
  display: flex; flex-direction: column; background: var(--paper);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: none;
}
.panel { position: relative; width: 100%; align-self: start; background: var(--paper-3); border-right: 1px solid var(--line); aspect-ratio: 4/3; min-height: 180px; display: grid; place-items: center; }
.scenes.grid .panel { border-right: 0; border-bottom: 1px solid var(--line); aspect-ratio: 4/3; min-height: 0; }
.scene-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.scene-img.is-generating { opacity: .3; transition: opacity .2s; }
.scene-no {
  position: absolute; top: var(--space-xs); left: var(--space-xs); z-index: 2;
  min-width: 28px; height: 28px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-canvas-dark) 68%, transparent);
  color: var(--ink); font-family: var(--font-number); font-size: var(--type-caption-size);
  font-weight: 700; font-variant-numeric: tabular-nums;
}
.scenes.image-only .script { display: none; }
.gen-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-sm);
  pointer-events: none; overflow: hidden;
}
.gen-overlay::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(115deg, transparent 30%, color-mix(in srgb, var(--ink) 16%, transparent) 50%, transparent 70%);
  background-size: 220% 100%;
  animation: gen-sweep 1.1s linear infinite;
}
.gen-spinner {
  position: relative; width: 34px; height: 34px;
  border: 3px solid var(--line); border-top-color: var(--ink);
  border-radius: 50%; animation: gen-spin .7s linear infinite;
}
.btn-spinner {
  width: 14px; height: 14px;
  border: 2px solid color-mix(in srgb, currentColor 36%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: gen-spin .7s linear infinite;
  flex: 0 0 auto;
}
.gen-label {
  position: relative; font-size: var(--type-caption-size); font-weight: 700; letter-spacing: .06em;
  color: var(--ink-2); animation: gen-pulse 1.1s ease-in-out infinite;
}
@keyframes gen-spin { to { transform: rotate(360deg); } }
@keyframes gen-sweep { 0% { background-position: 220% 0; } 100% { background-position: -220% 0; } }
@keyframes gen-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
.panel .ph { width: 100%; height: 100%; background: var(--paper-3); }
@keyframes ph-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.panel .ph--generating {
  background: linear-gradient(110deg,
    var(--paper-3) 20%,
    var(--paper-2) 40%,
    var(--paper) 50%,
    var(--paper-2) 60%,
    var(--paper-3) 80%
  );
  background-size: 220% 100%;
  animation: ph-shimmer 1.1s linear infinite;
}

.script { position: relative; padding: var(--space-md); display: flex; flex-direction: column; gap: var(--space-xs); min-width: 0; }
.script .stitle { padding-right: calc(var(--space-lg) + var(--space-md)); font-size: var(--type-body-md-size); font-weight: 700; line-height: var(--type-body-md-line-height); }
.tags { display: flex; flex-wrap: wrap; gap: var(--space-xxs); }
.tag { font-size: var(--type-caption-size); font-weight: 600; color: var(--ink-2); background: var(--tag); border-radius: var(--radius-sm); padding: var(--space-xxs) var(--space-xs); white-space: nowrap; }
.script .lines { display: flex; flex-direction: column; gap: var(--space-xxs); }
.script .line { font-size: var(--type-body-md-size); line-height: var(--type-body-md-line-height); color: var(--ink-2); }
.script .line.dim { color: var(--ink-3); }
.script .line b { color: var(--ink); font-weight: 700; }
/* 状況説明: top border, no box, no heading */
.situation {
  margin-top: var(--space-xxs); padding-top: var(--space-sm); border-top: 1px solid var(--line-2);
  font-size: var(--type-caption-size); line-height: var(--type-caption-line-height); color: var(--ink-3);
}
.scene-actions { display: flex; gap: var(--space-xs); margin-top: var(--space-xxs); }
.scene-drag-handle {
  position: absolute; top: var(--space-xs); right: var(--space-xs); z-index: 2;
  width: calc(var(--space-lg) + var(--space-xxs)); height: calc(var(--space-lg) + var(--space-xxs));
  border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper-3);
  color: var(--ink); display: grid; place-items: center; cursor: grab;
}
.scene-drag-handle:hover { background: var(--paper-2); }
.scene-drag-handle:active { cursor: grabbing; }

/* ============ projects page ============ */
.projects { flex: 1; overflow-y: auto; padding: var(--space-lg) var(--space-xl); }
.pj-head { display: flex; align-items: center; gap: var(--space-sm); margin-bottom: var(--space-md); }
.pj-head h2 { margin: 0; font-size: var(--type-title-md-size); font-weight: var(--type-title-md-weight); line-height: var(--type-title-md-line-height); }
.pj-head .count { font-family: var(--font-number); font-size: var(--type-caption-size); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.pj-head .spacer { flex: 1; }
.pj-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-md); }
@media (max-width: 1024px) {
  .pj-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .pj-grid { grid-template-columns: repeat(1, minmax(0, 1fr)); }
}
.pj-card {
  border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-xl); padding: 0;
  text-align: left; overflow: hidden; display: flex; flex-direction: column;
}
.pj-card:hover { border-color: var(--ink-3); box-shadow: none; }
.pj-card:hover .pj-edit { opacity: 1; }
.pj-card.new { border-style: dashed; align-items: center; justify-content: center; min-height: 180px; color: var(--ink-3); gap: var(--space-xs); cursor: pointer; }
.pj-card.new:hover { color: var(--ink); border-color: var(--ink-3); }
.pj-thumb { position: relative; width: 100%; aspect-ratio: 16/9; overflow: hidden; background: var(--paper-3); display: grid; place-items: center; color: var(--ink-3); border: 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.pj-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.pj-card.new .pj-thumb { aspect-ratio: auto; background: transparent; border: 0; }
.pj-foot { display: flex; align-items: center; gap: var(--space-xs); padding: var(--space-sm) var(--space-sm) var(--space-xxs); }
.pj-title-line { display: flex; align-items: center; gap: var(--space-xs); min-width: 0; width: 100%; }
.pj-name { font-size: var(--type-title-sm-size); font-weight: var(--type-title-sm-weight); line-height: var(--type-title-sm-line-height); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pj-meta { font-family: var(--font-number); font-size: var(--type-caption-size); color: var(--ink-3); padding: 0 var(--space-sm) var(--space-sm); font-variant-numeric: tabular-nums; }
.pj-card.new .pj-name { padding: 0; flex: none; }
.pj-edit {
  flex: 0 0 auto; width: 40px; height: 40px; border: 0; background: transparent; border-radius: var(--radius-md);
  color: var(--ink-3); display: grid; place-items: center; opacity: 0; transition: opacity .12s;
}
.pj-edit:hover { background: var(--paper-3); color: var(--ink); }
.pj-edit svg { width: 20px; height: 20px; }
.pj-rename {
  flex: 1; min-width: 0; border: 1px solid var(--accent); border-radius: var(--radius-md); outline: none;
  font-family: inherit; font-size: var(--type-body-lg-size); line-height: var(--type-body-lg-line-height); font-weight: 700; color: var(--ink); padding: var(--space-xxs) var(--space-xs); background: var(--paper);
}
.pj-rename:focus { border-color: var(--color-info); box-shadow: var(--focus-ring); }
.pj-actions { display: flex; gap: var(--space-xs); padding: 0 var(--space-sm) var(--space-sm); }
.pj-actions .btn.icon-only,
.pj-row .btn.icon-only {
  width: 40px; height: 40px; border-color: transparent; background: transparent;
}
.pj-actions .btn.icon-only:hover,
.pj-row .btn.icon-only:hover { background: var(--paper-3); border-color: transparent; }
.pj-actions .btn.icon-only.danger:hover,
.pj-row .btn.icon-only.danger:hover { background: var(--surface-error); }
.pj-actions .btn.icon-only svg,
.pj-row .btn.icon-only svg { width: 20px; height: 20px; }

/* list view */
.pj-list { display: flex; flex-direction: column; gap: var(--space-xs); }
.pj-row {
  display: flex; align-items: center; gap: var(--space-lg); padding: var(--space-md);
  border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-lg); text-align: left;
}
.pj-row:hover { border-color: var(--ink-3); box-shadow: none; }
.pj-row:hover .pj-edit { opacity: 1; }
.pj-row.new { border-style: dashed; color: var(--ink-3); cursor: pointer; }
.pj-row.new:hover { color: var(--ink); border-color: var(--ink-3); }
.pj-rthumb { flex: 0 0 auto; width: 240px; height: 160px; border: 0; border-radius: var(--radius-lg); background: var(--paper-3); display: grid; place-items: center; color: var(--ink-3); cursor: pointer; overflow: hidden; }
.pj-rthumb img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: inherit; overflow: hidden; }
.pj-rthumb svg { width: 56px; height: 56px; }
.pj-row.new .pj-rthumb { background: transparent; }
.pj-rmain { flex: 1; min-width: 0; align-self: stretch; display: flex; flex-direction: column; justify-content: center; gap: var(--space-xxs); }
.pj-rmain .pj-name { flex: none; }
.pj-rmain .pj-meta { padding: 0; }

@media (max-width: 760px) {
  .board-head { gap: var(--space-xs); }
  .board-head .spacer { display: none; }
  .board-head .view-toggle { margin-left: auto; }
  .board-head .btn {
    flex: 1 1 148px;
    justify-content: center;
    min-width: 0;
    max-width: 100%;
    white-space: normal;
    text-align: center;
  }
  .pj-row { gap: var(--space-sm); padding: var(--space-sm); }
  .pj-rthumb { width: 168px; height: 112px; }
  .pj-rthumb svg { width: 42px; height: 42px; }
}

/* ============ PDF modal ============ */
.overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--color-canvas-dark) 85%, transparent); display: grid; place-items: center; z-index: 50; padding: var(--space-md); }
.modal { width: 520px; max-width: 100%; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-xl); box-shadow: none; overflow: hidden; }
.modal.sm { width: 420px; }
.modal.md { width: calc(var(--space-section) * 7); }
.modal.wide { width: 720px; }
.modal.lightbox {
  position: relative;
  width: min(calc(var(--space-section) * 12), 100%);
  max-height: calc(100vh - var(--space-xl));
  padding: var(--space-md);
  display: grid;
  gap: var(--space-sm);
  overflow: hidden;
}
.lightbox-frame {
  min-height: 240px;
  display: grid;
  place-items: center;
}
.lightbox-frame img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  display: block;
  border-radius: var(--radius-lg);
}
.lightbox-close {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  z-index: 2;
  background: var(--paper);
  border: 1px solid var(--line);
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  width: 40px;
  height: 40px;
  transform: translateY(-50%);
  background: var(--paper);
  border: 1px solid var(--line);
}
.lightbox-nav.prev { left: var(--space-sm); }
.lightbox-nav.next { right: var(--space-sm); }
.lightbox-nav.prev svg { transform: rotate(90deg); }
.lightbox-nav.next svg { transform: rotate(-90deg); }
.lightbox-caption {
  min-height: 1.4em;
  color: var(--ink-2);
  font-size: var(--type-caption-size);
  line-height: var(--type-caption-line-height);
  text-align: center;
}
.m-split { display: grid; grid-template-columns: 1fr 300px; }
.m-split .m-body { border-right: 1px solid var(--line); }
.m-preview {
  background: var(--paper-2); padding: var(--space-md); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--space-sm);
}
.pv-cap, .pv-meta { font-family: var(--font-number); font-size: 10.5px; font-weight: 700; color: var(--ink-3); letter-spacing: 0; font-variant-numeric: tabular-nums; }
.pv-meta { font-weight: 600; }
.pv-page {
  background: var(--paper); border: 1px solid var(--line); box-shadow: none;
  padding: var(--space-sm); display: flex; flex-direction: column; gap: var(--space-xs);
}
.pv-title { flex: 0 0 auto; height: 6px; width: 55%; background: var(--ink); opacity: .85; border-radius: var(--radius-xs); }
.pv-grid { flex: 1; display: grid; gap: 6px; width: 100%; min-height: 0; overflow: hidden; }
.pv-grid.list .pv-cell { flex-direction: row; align-items: stretch; gap: 6px; }
.pv-grid.list .pv-img { width: 34%; flex: 0 0 34%; min-height: 0; }
.pv-grid.list .pv-lines { flex: 1; justify-content: center; }
.pv-cell { display: flex; flex-direction: column; gap: 3px; min-height: 0; min-width: 0; overflow: hidden; }
.pv-img { position: relative; flex: 1; background: var(--paper-3); border: 1px solid var(--line-2); border-radius: var(--radius-sm); display: grid; place-items: center; color: var(--ink-3); min-height: 0; }
.pv-no { position: absolute; top: 2px; left: 2px; background: var(--paper-3); color: var(--ink); font-size: 7px; font-weight: 700; line-height: 1; padding: 2px 3px; border-radius: var(--radius-xs); }
.pv-lines { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.pv-line { height: 3px; border-radius: var(--radius-xs); background: var(--ink-3); opacity: .55; }
.pv-line.title { height: 4px; background: var(--ink); opacity: .85; }
.pv-line.dim { background: var(--line); opacity: 1; }
.pv-line.w90 { width: 90%; }
.pv-line.w70 { width: 70%; }
.pv-line.w50 { width: 50%; }
.ratio-grid { display: flex; gap: var(--space-xs); }
.ratio-card {
  flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-lg);
  padding: var(--space-sm) var(--space-xs); display: flex; flex-direction: column; align-items: center; gap: var(--space-xs);
  color: var(--ink-2);
}
.ratio-card.on { border-color: var(--accent); background: var(--paper-2); color: var(--ink); }
.ratio-ico { height: 32px; display: flex; align-items: center; justify-content: center; }
.ratio-box { border: 1.5px solid currentColor; border-radius: var(--radius-sm); background: var(--paper-3); }
.ratio-lab { font-size: var(--type-caption-size); font-weight: 700; }
.modal .m-head { padding: var(--space-md); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: var(--space-xs); }
.modal .m-head h3 { margin: 0; font-size: var(--type-title-sm-size); font-weight: var(--type-title-sm-weight); line-height: var(--type-title-sm-line-height); }
.modal .m-body { padding: var(--space-md); display: flex; flex-direction: column; gap: var(--space-md); }
.modal .m-foot { padding: var(--space-sm) var(--space-md); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: var(--space-xs); }
.choice-stack { display: flex; flex-direction: column; gap: var(--space-xs); }
.choice-row {
  width: 100%; text-align: left; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--paper); padding: var(--space-sm); display: flex; flex-direction: column; gap: var(--space-xxs);
}
.choice-row:hover { background: var(--paper-2); }
.choice-row b { font-size: var(--type-body-sm-size); color: var(--ink); }
.choice-row span { font-size: var(--type-caption-size); color: var(--ink-3); line-height: var(--type-caption-line-height); }
.gate-image {
  width: 100%; max-height: 56vh; object-fit: contain; display: block;
  background: var(--paper-3); border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.gate-empty {
  min-height: 180px; display: grid; place-items: center; border: 1px dashed var(--line);
  border-radius: var(--radius-lg); background: var(--paper-2); color: var(--ink-3); font-size: var(--type-caption-size);
}
.opt-row { display: flex; flex-direction: column; gap: var(--space-xs); }
.opt-row > .lab { font-size: var(--type-caption-size); font-weight: 700; color: var(--ink-2); }
.opt-row .hint { font-size: var(--type-caption-size); color: var(--ink-3); line-height: var(--type-caption-line-height); }
.preset-chips { display: flex; gap: var(--space-xxs); flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-md); padding: var(--space-xs) var(--space-sm); font-size: var(--type-caption-size); font-weight: 700; color: var(--ink-2); }
.chip:hover { background: var(--paper-2); }
.chip.on { border-color: var(--accent); background: var(--paper-2); color: var(--ink); }
.stepper-row { display: flex; gap: var(--space-md); margin-top: var(--space-xxs); }
.stepper { display: flex; align-items: center; gap: var(--space-xs); }
.stepper > span { font-size: var(--type-caption-size); font-weight: 700; color: var(--ink-2); }
.stepper button { width: 26px; height: 26px; border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-md); font-size: var(--type-button-size); color: var(--ink-2); display: grid; place-items: center; }
.stepper button:hover { background: var(--paper-2); color: var(--ink); }
.stepper b { min-width: 18px; text-align: center; font-family: var(--font-number); font-size: var(--type-number-sm-size); font-variant-numeric: tabular-nums; }
.am-drop {
  border: 1px dashed var(--line); border-radius: var(--radius-lg); background: var(--paper-2);
  aspect-ratio: 16/8; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-xs); color: var(--ink-3); font-size: var(--type-caption-size); cursor: pointer; overflow: hidden;
}
.am-drop:hover { border-color: var(--ink-3); color: var(--ink-2); }
.am-preview { width: 100%; height: calc(100% - 26px); object-fit: contain; display: block; }
.asset-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: var(--space-xs); }
.asset-tile { position: relative; min-width: 0; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--paper); overflow: hidden; }
.asset-choice { width: 100%; padding: 0; text-align: left; color: var(--ink-2); }
.asset-choice:hover { background: var(--paper-2); }
.asset-choice.on { border-color: var(--accent); background: var(--paper-2); color: var(--ink); }
.asset-upload { display: block; cursor: pointer; border-style: dashed; }
.asset-upload:hover { border-color: var(--ink-3); }
.asset-upload .asset-img { color: var(--ink-3); }
.style-gallery { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.asset-img { aspect-ratio: 1/1; background: var(--paper-3); display: grid; place-items: center; color: var(--ink-3); }
.asset-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.asset-name { display: block; padding: var(--space-xs); font-size: var(--type-caption-size); font-weight: 700; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-del {
  position: absolute; top: var(--space-xxs); right: var(--space-xxs); width: 24px; height: 24px;
  border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--paper);
  color: var(--ink-2); display: grid; place-items: center;
}
.asset-del:hover { color: var(--ink); background: var(--paper-3); }
.u-visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.field[type="text"] { font-family: inherit; }
input.field { padding: var(--space-xs) var(--space-sm); }
.seg { display: flex; gap: var(--space-xxs); }
.seg.wrap { flex-wrap: wrap; }
.seg button { border: 1px solid var(--line); background: var(--paper); border-radius: var(--radius-lg); padding: var(--space-xs) var(--space-sm); font-size: var(--type-caption-size); font-weight: var(--type-caption-weight); color: var(--ink-2); display: flex; align-items: center; gap: var(--space-xs); white-space: nowrap; }
.seg button.on { border-color: var(--accent); background: var(--paper-2); color: var(--ink); }
.orient-ico { border: 1.5px solid currentColor; border-radius: var(--radius-xs); }
.toggle-row { display: flex; align-items: center; gap: var(--space-xs); font-size: var(--type-body-sm-size); color: var(--ink-2); }
.switch { width: 38px; height: 22px; border-radius: var(--radius-xl); background: var(--line); position: relative; transition: background .15s; flex: 0 0 auto; border: 0; }
.switch.on { background: var(--color-primary); }
.switch i { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--color-on-dark); transition: transform .15s; }
.switch.on i { background: var(--color-on-primary); transform: translateX(16px); }
.share-add { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: var(--space-xs); align-items: start; }
.share-add .field { min-height: 36px; }
.collab-list { display: flex; flex-direction: column; gap: var(--space-xs); }
.collab-row {
  display: flex; align-items: center; gap: var(--space-xs); min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--paper-2); padding: var(--space-xs);
}
.collab-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.collab-main b, .collab-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collab-main b { font-size: var(--type-body-sm-size); }
.collab-main small { font-size: var(--type-caption-size); color: var(--ink-3); }
@media (max-width: 620px) {
  .share-add { grid-template-columns: 1fr; }
}

/* ============ admin dashboard ============ */
.admin-app { min-height: 100vh; display: flex; flex-direction: column; background: var(--paper-2); }
.admin-header { position: sticky; top: 0; }
.admin-app > .admin-header {
  height: 64px;
  gap: var(--space-sm);
  padding: 0 var(--space-md);
  background: var(--color-canvas-dark);
  font-size: var(--type-nav-link-size);
  font-weight: var(--type-nav-link-weight);
  line-height: var(--type-nav-link-line-height);
}
.admin-app > .admin-header .hd-mark { width: 32px; height: 32px; border-radius: var(--radius-md); }
.admin-app > .admin-header .hd-logo { font-size: var(--type-title-sm-size); font-weight: var(--type-title-sm-weight); line-height: var(--type-title-sm-line-height); letter-spacing: 0; }
.admin-app > .admin-header .btn.sm {
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  font-size: var(--type-nav-link-size);
  font-weight: var(--type-nav-link-weight);
  line-height: var(--type-nav-link-line-height);
}
.admin-app .btn.primary {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
}
.admin-app .btn.primary:hover {
  background: var(--paper-3);
  border-color: var(--line);
}
.admin-main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: var(--space-lg) var(--space-lg) var(--space-xl);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
.admin-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-md);
}
.admin-title h1 { margin: 0; font-size: var(--type-title-lg-size); font-weight: var(--type-title-lg-weight); line-height: var(--type-title-lg-line-height); }
.admin-title .seclabel { margin-bottom: var(--space-xxs); }
.admin-tabs {
  display: flex;
  gap: var(--space-xxs);
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  background: var(--paper-3);
  border-radius: var(--radius-lg);
  padding: var(--space-xxs);
}
.admin-tabs button {
  border: 0;
  background: transparent;
  color: var(--ink-3);
  border-radius: var(--radius-md);
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--type-caption-size);
  font-weight: 700;
  line-height: var(--type-caption-line-height);
  white-space: nowrap;
}
.admin-tabs button.on { background: var(--paper); color: var(--ink); box-shadow: none; }
.admin-tabs button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.admin-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--paper);
  box-shadow: none;
  padding: var(--space-md);
}
.admin-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}
.admin-panel-head h2 { margin: 0 0 var(--space-xxs); font-size: var(--type-title-sm-size); font-weight: var(--type-title-sm-weight); line-height: var(--type-title-sm-line-height); }
.admin-panel-head p { margin: 0; max-width: 760px; color: var(--ink-3); font-size: var(--type-caption-size); line-height: var(--type-caption-line-height); }
.admin-filter-row { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: var(--space-xs); }
.admin-date-field {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--ink-3);
  font-size: var(--type-caption-size);
  font-weight: 700;
  line-height: var(--type-caption-line-height);
}
.admin-date-field input,
.admin-date-field select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: var(--type-body-lg-size);
  line-height: var(--type-body-lg-line-height);
  padding: var(--space-xs);
}
.admin-date-field input:focus,
.admin-date-field select:focus { outline: none; border-color: var(--color-info); box-shadow: var(--focus-ring); }
.admin-error {
  margin: 0;
  border: 1px solid var(--color-error);
  border-radius: var(--radius-lg);
  background: var(--surface-error);
  color: var(--color-error);
  padding: var(--space-sm);
  font-size: var(--type-caption-size);
  line-height: var(--type-caption-line-height);
  font-weight: 700;
}
.admin-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}
.admin-stat {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--paper-3);
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}
.admin-stat span { color: var(--ink-3); font-size: var(--type-caption-size); line-height: var(--type-caption-line-height); font-weight: 700; }
.admin-stat b { font-family: var(--font-number); font-size: var(--type-title-lg-size); line-height: var(--type-title-lg-line-height); font-variant-numeric: tabular-nums; }
.admin-grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-sm);
}
.admin-subpanel {
  min-width: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-lg);
  background: var(--paper-2);
  padding: var(--space-sm);
}
.admin-subpanel-wide { grid-column: 1 / -1; }
.admin-subpanel h3 { margin: 0 0 var(--space-sm); font-size: var(--type-body-sm-size); font-weight: var(--type-title-sm-weight); line-height: var(--type-body-sm-line-height); }
.admin-table-wrap { width: 100%; overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; min-width: 620px; }
.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line-2);
  padding: var(--space-xs);
  text-align: left;
  vertical-align: top;
  font-size: var(--type-caption-size);
  line-height: var(--type-caption-line-height);
}
.admin-table th { color: var(--ink-3); font-weight: 700; white-space: nowrap; }
.admin-panel[x-show="tab === 'usage'"] .admin-table td:nth-child(n+2),
.admin-panel[x-show="tab === 'generations'"] .admin-table td:first-child,
.admin-panel[x-show="tab === 'generations'"] .admin-table td:nth-child(8) { font-family: var(--font-number); font-variant-numeric: tabular-nums; }
.admin-table tr.is-error td { background: var(--surface-error); }
.admin-error-cell { max-width: 320px; color: var(--color-error); }
.admin-bar {
  display: block;
  width: 120px;
  height: var(--space-xs);
  border-radius: var(--radius-pill);
  background: var(--paper-3);
  overflow: hidden;
}
.admin-bar i { display: block; height: 100%; min-width: 0; background: var(--color-info); border-radius: inherit; }
.admin-status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--paper-2);
  color: var(--ink-2);
  padding: 2px var(--space-xs);
  font-size: var(--type-caption-size);
  font-weight: 700;
  white-space: nowrap;
}
.admin-status.status-error { border-color: var(--color-error); background: var(--surface-error); color: var(--color-error); }
.admin-status.status-done { border-color: var(--color-success); background: var(--surface-success); color: var(--color-success); }
.admin-status.status-running,
.admin-status.status-queued { border-color: var(--line); background: var(--paper-3); color: var(--ink-2); }
.admin-log-list { display: flex; flex-direction: column; gap: var(--space-sm); }
.admin-log-row {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--paper);
  overflow: hidden;
}
.admin-log-summary {
  width: 100%;
  border: 0;
  background: var(--paper-2);
  color: var(--ink);
  padding: var(--space-sm);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  text-align: left;
}
.admin-log-summary:hover { background: var(--paper-3); }
.admin-log-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.admin-log-main b,
.admin-log-main small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-log-main b { font-size: var(--type-body-sm-size); line-height: var(--type-body-sm-line-height); }
.admin-log-main small { color: var(--ink-3); font-size: var(--type-caption-size); }
.admin-log-preview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  border-top: 1px solid var(--line-2);
  background: var(--line-2);
}
.admin-log-preview p {
  min-width: 0;
  margin: 0;
  background: var(--paper);
  padding: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
}
.admin-log-preview b,
.admin-log-block b { color: var(--ink-3); font-size: var(--type-caption-size); }
.admin-log-preview span {
  color: var(--ink-2);
  font-size: var(--type-body-sm-size);
  line-height: var(--type-body-sm-line-height);
  overflow-wrap: anywhere;
}
.admin-log-entry {
  border-top: 1px solid var(--line-2);
  padding: var(--space-sm);
  display: grid;
  gap: var(--space-sm);
}
.admin-log-block {
  min-width: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--radius-lg);
  background: var(--paper-2);
  padding: var(--space-sm);
}
.admin-log-block pre {
  margin: var(--space-xxs) 0 0;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: var(--type-caption-size);
  line-height: var(--type-caption-line-height);
  color: var(--ink-2);
}
.admin-empty {
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  background: var(--paper-2);
  color: var(--ink-3);
  padding: var(--space-sm);
  font-size: var(--type-caption-size);
  line-height: var(--type-caption-line-height);
}
@media (max-width: 840px) {
  .admin-main { padding: var(--space-md) var(--space-sm) var(--space-xl); }
  .admin-title,
  .admin-panel-head { align-items: stretch; flex-direction: column; }
  .admin-filter-row { justify-content: flex-start; }
  .admin-stats,
  .admin-grid-two,
  .admin-log-preview { grid-template-columns: 1fr; }
  .admin-table { min-width: 760px; }
}
