/* Mio Studio — film / Shimokitazawa editorial
   Warm paper · ink · wine. Not purple-AI. */

:root {
  --bg: #f3efe6;
  --bg-deep: #ebe4d6;
  --ink: #1c1814;
  --ink-soft: #4a433a;
  --muted: #5c564c; /* AA-friendlier than #7a7166 */
  --focus: #8b3a3a;
  --line: #d9d0c0;
  --panel: #faf7f1;
  --panel-2: #fffdf8;
  --wine: #8b3a3a;
  --wine-deep: #6e2c2c;
  --cream: #e8d9b8;
  --ok: #2f6b4f;
  --warn: #9a6b1f;
  --bad: #a33a3a;
  --running: #3d5a80;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(40, 30, 16, 0.08);
  --font: "DM Sans", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  --display: "Instrument Serif", "Songti SC", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 480px at 0% 0%, #efe6d4 0%, transparent 55%),
    radial-gradient(700px 400px at 100% 10%, #e7ddd0 0%, transparent 50%),
    var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* Keyboard focus — all interactive surfaces */
:where(
  a, button, input, textarea, select, summary,
  [role="button"], [role="tab"], [tabindex]:not([tabindex="-1"])
):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
:where(button, .chip, .seg-btn, .step, .run, .char-card, .depth-card, .outfit-card):focus:not(:focus-visible) {
  outline: none;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--cream);
  border-radius: 0 0 8px 0;
  font-weight: 650;
}
.skip-link:focus {
  left: 0;
  outline-offset: 0;
}

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

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.wrap-break {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.gate-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0 0 8px;
  min-height: 1.2em;
}
.gate-hint.warn { color: var(--warn); }

.toast-host {
  position: fixed;
  inset-inline-end: 16px;
  inset-block-end: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  border: 1px solid #333;
}
.toast.err { background: #4a1f1f; border-color: #7a3030; }
.toast.ok { background: #1e3a2c; border-color: #2f6b4f; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .depth-card:hover { transform: none; }
}

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 18px 48px;
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
  padding-bottom: max(48px, env(safe-area-inset-bottom));
  min-height: 100%;
}

/* Mobile bar — hidden on desktop */
.mobile-bar {
  display: flex; /* always: jobs as drawer */
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.mobile-jobs-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 14px;
}
.mobile-jobs-label { font-weight: 650; }
.job-count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}
.job-count:empty,
.job-count[data-empty="1"] {
  display: none;
}
.drawer-scrim {
  display: none;
}
.rail-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.rail-close {
  display: none;
}

/* Top */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--display);
  font-size: 1.35rem;
  display: grid; place-items: center;
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}
.brand p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.balance {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--wine);
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #e0cfc0;
  background: #faf4ec;
}
.user-chip {
  font-size: 0.78rem;
  color: var(--ink-soft);
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  font: inherit;
}
.auth-card {
  max-width: 420px;
  margin-bottom: 18px;
}
.health {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.health.ok { color: var(--ok); border-color: #b7d4c4; background: #f0f7f3; }
.health.bad { color: var(--bad); border-color: #e0b4b4; background: #faf0f0; }

/* Layout — workspace full width; jobs always in drawer (saves space) */
.main {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  align-items: start;
}

/* Jobs toggle always visible (was mobile-only) */
.mobile-bar {
  display: flex;
}

/* Rail = off-canvas drawer on all breakpoints */
.drawer-scrim {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(28, 24, 20, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
body.drawer-open .drawer-scrim {
  opacity: 1;
  pointer-events: auto;
}
body.drawer-open {
  overflow: hidden;
}

/* Rail */
.rail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0;
  border-left: none;
  border-top: none;
  border-bottom: none;
  padding: 16px 12px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  box-shadow: 8px 0 32px rgba(40, 30, 16, 0.18);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(300px, 86vw);
  max-height: none;
  z-index: 850;
  overflow: auto;
  overscroll-behavior: contain;
  transform: translateX(-105%);
  transition: transform 0.22s ease;
}
body.drawer-open .rail {
  transform: translateX(0);
}
.rail-close {
  display: inline-flex !important;
  min-height: 36px;
}
.rail-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding: 0 4px;
}
.rail-head h2 {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.runs { display: flex; flex-direction: column; gap: 6px; }
.run {
  text-align: left;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 12px 10px;
  min-height: 44px;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.run:hover { background: var(--bg-deep); }
.run.active {
  background: #fff;
  border-color: var(--line);
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}
.run .rid {
  display: none; /* hide random hex; title is primary */
}
.run .rtitle {
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.run .rstatus { margin-top: 6px; }
.run .rmeta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Workspace */
.workspace {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  min-height: 640px;
  min-height: min(640px, calc(100vh - 140px));
  min-width: 0;
  overflow-x: hidden;
  box-shadow: var(--shadow);
  padding: 22px 24px 28px;
}
.empty-workspace {
  max-width: 420px;
  padding: 48px 12px 32px;
}
.empty-kicker {
  margin: 0 0 8px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--wine);
  font-weight: 600;
}
.empty-workspace h2 {
  margin: 0 0 10px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 2.2rem;
  letter-spacing: -0.02em;
}
.lede {
  margin: 0 0 22px;
  color: var(--ink-soft);
  font-size: 0.98rem;
}

/* Steps */
.steps {
  display: flex;
  gap: 4px;
  margin-bottom: 22px;
  padding: 4px;
  background: var(--bg-deep);
  border-radius: 999px;
  width: fit-content;
  max-width: 100%;
  flex-wrap: wrap;
}
.step {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.step span {
  width: 22px; height: 22px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.06);
  display: grid; place-items: center;
  font-size: 0.72rem;
}
.step.is-active {
  background: var(--panel-2);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.step.is-active span { background: var(--ink); color: var(--cream); }
.step.is-done { color: var(--ok); }
.step.is-done span { background: #cfe5d9; color: var(--ok); }

.panel-head h2 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.65rem;
}
.panel-head p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 48ch;
}

/* Depth strip */
.depth-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.depth-card {
  border: 1.5px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: border-color 0.15s, transform 0.15s;
}
.depth-card:hover { border-color: #b8ad98; transform: translateY(-1px); }
.depth-card.selected {
  border-color: var(--wine);
  box-shadow: 0 0 0 1px var(--wine);
}
.depth-card .thumb {
  aspect-ratio: 9/12;
  background: #1c1814;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.depth-card .thumb img,
.depth-card .thumb video,
.depth-card .thumb .depth-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none; /* clicks go to card button */
}
.depth-card .thumb .ph {
  color: #9a9084;
  font-size: 0.75rem;
  padding: 8px;
  text-align: center;
}
.depth-card.selected .thumb video {
  outline: none;
}
.ready .body video {
  max-width: 100%;
  max-height: 220px;
  display: block;
  background: #1c1814;
}
.depth-card .meta {
  padding: 8px 9px 10px;
}
.depth-url-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
#video-style-block {
  margin-bottom: 14px;
}
.start-type-block {
  text-align: left;
  max-width: 420px;
  margin: 0 auto 16px;
}
.compose-type-bar {
  margin: 0 0 14px;
  font-size: 0.8rem;
  color: var(--muted);
}
#video-style-hint {
  margin: 8px 0 0;
  font-size: 0.82rem;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  margin: 10px 0 14px;
}
.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--wine);
}
.depth-ingest-preview {
  margin-top: 10px;
  max-width: 220px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #1c1814;
}
.depth-ingest-preview video {
  width: 100%;
  display: block;
  max-height: 280px;
  object-fit: contain;
  background: #1c1814;
}
.depth-ingest-preview .cap,
.depth-ingest-preview .muted {
  padding: 6px 10px;
  font-size: 0.75rem;
  margin: 0;
  background: var(--panel);
}
.depth-card .name {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.depth-card .sub {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Look */
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  background: var(--bg-deep);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 16px;
  max-width: 100%;
}
.seg-btn {
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 14px;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
}
.seg-btn.is-on {
  background: var(--panel-2);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.outfit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.outfit-card {
  border: 1.5px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}
.outfit-card.selected {
  border-color: var(--wine);
  box-shadow: 0 0 0 1px var(--wine);
}
.outfit-card .thumb {
  position: relative;
  aspect-ratio: 9/14;
  background: #ddd5c6;
  overflow: hidden;
}
.outfit-card .thumb img {
  width: 100%; height: 100%; object-fit: cover;
}
.outfit-card .name {
  padding: 7px 8px 9px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Character */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.char-card {
  border: 1.5px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
}
.char-card.selected {
  border-color: var(--wine);
  box-shadow: 0 0 0 1px var(--wine);
}
.char-card .thumb {
  position: relative;
  aspect-ratio: 1;
  background: #ddd5c6;
  overflow: hidden;
}
.char-card .thumb img {
  width: 100%; height: 100%; object-fit: cover;
}
.char-card .name {
  padding: 7px 8px 9px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.opt-groups {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  max-height: 52vh;
  overflow: auto;
  padding-right: 4px;
}
.opt-group h4 {
  margin: 0 0 8px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}
.opt-group .chip-row { margin-bottom: 0; }
.char-gen-preview {
  position: relative;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  max-width: 280px;
  background: #1c1814;
}
.char-gen-preview img {
  width: 100%;
  display: block;
}
.char-gen-preview .zoom-wrap {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
}
.char-gen-preview .zoom-wrap img {
  width: 100%;
  height: auto;
  display: block;
}
.zoom-wrap,
.media.media-zoom,
.zoom-host {
  position: relative;
  display: block;
  width: 100%;
}
.thumb .zoom-wrap img,
.char-card .thumb img,
.outfit-card .thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.media .zoom-wrap img,
.media.media-zoom img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.zoom-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: rgba(20, 16, 12, 0.58);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.zoom-btn:hover,
.zoom-btn:focus-visible {
  background: rgba(20, 16, 12, 0.82);
  outline: 2px solid rgba(255, 255, 255, 0.55);
  outline-offset: 1px;
}
.zoom-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}
.char-gen-preview .cap {
  padding: 6px 10px;
  font-size: 0.75rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.35);
  color: rgba(255, 255, 255, 0.75);
}
.selected-outfit-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eef6f1;
  border: 1px solid #c5ddcf;
  font-size: 0.88rem;
}
.selected-outfit-bar strong {
  font-weight: 650;
  color: var(--ok);
}
.ready-cards.three {
  grid-template-columns: 1fr 1fr 1fr;
}
.ready-cards.refs-layout {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
  grid-template-columns: 1fr;
}
.ref-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.ref-card .lab {
  background: color-mix(in srgb, var(--wine) 8%, var(--panel-2));
  color: var(--wine);
}
.ref-card .lab-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px 6px 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--wine) 8%, var(--panel-2));
}
.ref-card .lab-row .lab {
  border: none;
  background: transparent;
  padding: 2px 10px;
}
.ref-card .lab-row .btn {
  flex-shrink: 0;
  margin-right: 8px;
}
.ref-card .body {
  position: relative;
}
.motion-card .body {
  min-height: 180px;
}
@media (max-width: 720px) {
  .ready-cards.three { grid-template-columns: 1fr; }
  .ref-pair { grid-template-columns: 1fr; }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 16px;
}
.modal[hidden] { display: none !important; }
.modal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(28, 24, 20, 0.5);
}
.modal-panel {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 14px 16px 18px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.modal-head h3 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.25rem;
}
.modal-outfit-grid {
  max-height: 48vh;
  overflow: auto;
  margin: 10px 0;
}
body.modal-open,
body.lightbox-open {
  overflow: hidden;
}

/* Lightbox — must use vh/dvh, never % of auto-height parent (tall 9:16 would overflow) */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
.lightbox[hidden] { display: none !important; }
.lightbox-scrim {
  position: absolute;
  inset: 0;
  background: rgba(12, 10, 8, 0.88);
}
.lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 2;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.lightbox-close:hover { background: rgba(255,255,255,0.22); }
.lightbox-body {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  /* fit inside viewport with padding + close button room */
  width: min(960px, calc(100vw - 24px));
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.lightbox-body img {
  display: block;
  /* hard cap to viewport — % of parent fails when parent height is content-sized */
  max-width: min(960px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  max-height: calc(100dvh - 48px);
  width: auto;
  height: auto;
  margin: 0 auto;
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.45);
  object-fit: contain;
  background: #1c1814;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}
.chip {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 10px 14px;
  min-height: 44px;
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chip:hover, .chip.on {
  border-color: var(--wine);
  color: var(--wine);
  background: #f8efef;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 500;
}
.field input,
.field textarea {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 400;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
}
.field textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  resize: vertical;
  min-height: 140px;
}
.field input:focus,
.field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--wine) 35%, transparent);
  border-color: var(--wine);
}
.field em { font-style: normal; font-weight: 400; }

.row-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.hint { font-size: 0.8rem; color: var(--muted); }
.hint.warn { color: var(--warn); }

.field-block {
  margin: 16px 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
}
.subhead {
  margin: 0 0 10px;
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--ink-soft);
}
.subhead em {
  font-style: normal;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.8rem;
}
.field-block .outfit-grid {
  max-height: 280px;
  overflow: auto;
  margin-bottom: 8px;
}
#video-prompt-ta,
#jv-video-prompt {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  min-height: 140px;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.panel-actions.between { justify-content: space-between; }

.advanced {
  margin: 8px 0 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--bg);
}
.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}
.advanced[open] summary { margin-bottom: 10px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  margin: 4px 0 8px;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  min-height: 44px;
  font: inherit;
  font-weight: 650;
  font-size: 0.9rem;
  cursor: pointer;
  transition: filter 0.12s, opacity 0.12s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn.is-busy {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}
.chip[aria-pressed="true"],
.seg-btn[aria-pressed="true"] {
  border-color: var(--wine);
  color: var(--wine);
  background: #f8efef;
}
.seg-btn[aria-pressed="true"] {
  background: var(--panel-2);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.char-card[aria-pressed="true"],
.depth-card[aria-pressed="true"],
.outfit-card[aria-pressed="true"] {
  border-color: var(--wine);
  box-shadow: 0 0 0 1px var(--wine);
}
.run[aria-current="true"] {
  background: #fff;
  border-color: var(--line);
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}
.step[aria-current="step"] {
  background: var(--panel-2);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.btn.primary {
  background: var(--wine);
  color: #faf6f0;
}
.btn.primary:hover:not(:disabled) { background: var(--wine-deep); }
.btn.secondary {
  background: var(--ink);
  color: var(--cream);
}
.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn.sm {
  padding: 8px 12px;
  min-height: 36px;
  font-size: 0.8rem;
}
.msg { min-height: 1.2em; font-size: 0.88rem; color: var(--muted); margin: 10px 0 0; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--ok); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, monospace; }

/* Ready cards step 3 */
.ready-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 640px) {
  .ready-cards { grid-template-columns: 1fr; }
}
.ready {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--panel-2);
}
.ready .lab {
  padding: 8px 10px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  font-weight: 600;
}
.ready .body {
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1c1814;
}
.ready .body img,
.ready .body video {
  max-width: 100%;
  max-height: 220px;
  display: block;
}
.ready .body .ph {
  color: #9a9084;
  font-size: 0.84rem;
  padding: 20px;
  text-align: center;
}
.ready .cap {
  padding: 8px 10px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

/* Job view */
.job-view {
  min-width: 0;
  overflow-x: hidden;
}
.job-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  min-width: 0;
}
.job-head h2,
.job-id {
  overflow-wrap: anywhere;
}
.job-id { margin: 0; font-size: 0.72rem; color: var(--muted); }
.job-head h2 {
  margin: 4px 0 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.55rem;
}
.job-progress {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 18px;
  min-width: 0;
}
.job-progress .badge.failed {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.job-chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.job-chip.muted {
  font-weight: 550;
  color: var(--muted);
}
.job-run {
  background: linear-gradient(180deg, #fffdf8 0%, #f6f0e6 100%);
}
.job-run-top {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.job-run-pulse {
  width: 12px;
  height: 12px;
  margin-top: 6px;
  border-radius: 999px;
  background: var(--wine);
  box-shadow: 0 0 0 0 rgba(139, 58, 58, 0.45);
  animation: job-pulse 1.6s ease-out infinite;
  flex-shrink: 0;
}
@keyframes job-pulse {
  0% { box-shadow: 0 0 0 0 rgba(139, 58, 58, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(139, 58, 58, 0); }
  100% { box-shadow: 0 0 0 0 rgba(139, 58, 58, 0); }
}
.job-run-kicker {
  margin: 0 0 2px;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
}
.job-run h3.job-run-title,
.job-run-title {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.35rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}
.job-run-sub {
  margin: 6px 0 0;
  font-size: 0.84rem;
  color: var(--ink-soft);
}
.job-steps {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 0;
  padding: 0;
}
.job-steps li {
  position: relative;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  background: var(--bg-deep);
  color: var(--muted);
}
.job-steps li.is-done {
  background: #dceee4;
  color: var(--ok);
}
.job-steps li.is-current {
  background: #e8d9b8;
  color: var(--wine-deep);
}
.job-steps li.is-failed {
  background: #f3dede;
  color: var(--bad);
}
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  background: var(--bg-deep);
  color: var(--muted);
}
.badge.running { background: #e4eaf3; color: var(--running); }
.badge.awaiting_prompt,
.badge.awaiting_outfit,
.badge.awaiting_approval { background: #f5ead0; color: var(--warn); }
.badge.completed { background: #dceee4; color: var(--ok); }
.badge.failed { background: #f3dede; color: var(--bad); }
.badge.queued { background: var(--bg-deep); color: var(--muted); }

.job-body { display: grid; gap: 16px; }
.stage {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  background: var(--panel-2);
}
.stage h3 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.stage-media {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 200px));
  gap: 14px;
  align-items: start;
}
.stage-media > div {
  min-width: 0;
}
.media {
  background: #1c1814;
  border-radius: 10px;
  overflow: hidden;
  min-height: 0;
  display: block;
  position: relative;
}
/* Never let a lone preview (outside the asset grid) go full-bleed */
.stage > .media,
.stage > .media-zoom {
  max-width: 140px;
  aspect-ratio: 3 / 4;
}
.stage-media .media {
  aspect-ratio: 3 / 4;
}
.stage-media .media-face {
  aspect-ratio: 1 / 1;
}
.stage-media .media-look {
  aspect-ratio: 3 / 4;
}
.stage-media .media-film {
  aspect-ratio: 9 / 16;
}
.job-final {
  display: flex;
  justify-content: center;
  margin: 10px 0;
}
.job-final video {
  width: 100%;
  max-width: 320px;
  max-height: 72vh;
  object-fit: contain;
  border-radius: 10px;
  background: #1c1814;
  display: block;
}
.media img, .media video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #1c1814;
}
.stage-media .media-face img {
  object-fit: cover;
}
.media .ph { color: #8a8074; font-size: 0.82rem; padding: 16px; text-align: center; }
.stage .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.captions { display: grid; gap: 10px; }
.caption {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--bg);
}
.caption.is-rec {
  border-color: #c5ddcf;
  background: #f6faf7;
}
.caption .tone {
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 8px;
}
.fail-banner {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f8eeee;
  border: 1px solid #e8cfcf;
  overflow: hidden;
  min-width: 0;
}
.fail-banner .fail-msg,
.job-fail .fail-msg {
  margin: 0 0 10px;
  color: var(--bad);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.fail-banner .fail-msg { margin: 0; }
.job-body,
.stage {
  min-width: 0;
}
.stage textarea,
.stage input[type="text"] {
  max-width: 100%;
  box-sizing: border-box;
}
.job-fail .fail-raw {
  margin: 0 0 12px;
  font-size: 0.78rem;
  color: var(--muted);
}
.job-fail .fail-raw pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.75rem;
  color: var(--ink-soft);
}
.caption pre {
  margin: 0 0 10px;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.5;
}
.caption .tone { font-size: 0.75rem; color: var(--wine); margin-bottom: 6px; font-weight: 600; }
.caption pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 0.9rem;
}
.job-logs {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.job-logs summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}
.logs {
  margin: 10px 0 0;
  background: #1c1814;
  color: #d4cbb8;
  border-radius: 10px;
  padding: 12px;
  max-height: 200px;
  overflow: auto;
  font-size: 0.72rem;
  white-space: pre-wrap;
  font-family: ui-monospace, Menlo, monospace;
}

/* ── Responsive: tablet / mobile (workspace already full-width) ── */
@media (max-width: 900px) {
  .workspace {
    padding: 18px 18px 24px;
    min-height: 520px;
  }
}

/* ── Desktop: jobs still drawer, no sidebar ── */

@media (max-width: 820px) {
  .shell {
    padding: 12px 12px 32px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(32px, env(safe-area-inset-bottom));
  }

  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
    padding-bottom: 12px;
  }
  .brand h1 { font-size: 1.3rem; }
  .brand p {
    font-size: 0.68rem;
    letter-spacing: 0.02em;
  }
  .brand-mark { width: 36px; height: 36px; font-size: 1.15rem; }
  .top-actions {
    width: 100%;
    justify-content: flex-start;
    gap: 8px;
  }
  .balance,
  .user-chip,
  .health {
    font-size: 0.72rem;
    padding: 8px 10px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }
  .user-chip { max-width: min(140px, 40vw); }
  .health {
    white-space: normal;
    max-width: 100%;
    line-height: 1.25;
  }
  .mobile-bar .btn {
    min-height: 44px;
  }

  .workspace {
    min-height: auto;
    border-radius: 14px;
    padding: 16px 14px 22px;
  }

  .empty-workspace {
    padding: 28px 4px 20px;
    max-width: none;
  }
  .empty-workspace h2 {
    font-size: clamp(1.6rem, 7vw, 2rem);
  }

  .steps {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    border-radius: 14px;
    padding: 3px;
  }
  .step {
    justify-content: center;
    padding: 10px 4px;
    font-size: 0.78rem;
    gap: 4px;
    min-width: 0;
  }
  .step span {
    width: 20px;
    height: 20px;
  }

  .panel-head h2 {
    font-size: 1.4rem;
  }
  .panel-head p {
    font-size: 0.88rem;
  }

  .seg {
    display: flex;
    width: 100%;
  }
  .seg-btn {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
    font-size: 0.82rem;
  }

  .depth-strip {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
  }
  .outfit-grid,
  .char-grid {
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
  }

  .field input,
  .field textarea {
    font-size: 16px; /* prevent iOS zoom on focus */
    padding: 12px;
  }

  .panel-actions {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
    position: sticky;
    bottom: 0;
    margin-left: -14px;
    margin-right: -14px;
    margin-bottom: -8px;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--panel) 70%, color-mix(in srgb, var(--panel) 85%, transparent));
    border-top: 1px solid var(--line);
    z-index: 5;
  }
  .panel-actions .btn {
    width: 100%;
  }
  .panel-actions.between {
    flex-direction: column-reverse;
  }

  .row-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .row-actions .btn {
    width: 100%;
  }

  .selected-outfit-bar {
    flex-wrap: wrap;
  }

  .char-gen-preview {
    max-width: 100%;
  }

  .opt-groups {
    max-height: 48vh;
  }

  .job-head {
    flex-direction: column;
    align-items: flex-start;
  }
  .job-head h2 {
    font-size: 1.3rem;
  }
  .stage-media {
    grid-template-columns: repeat(2, minmax(0, 180px));
  }

  .toast-host {
    inset-inline-end: 12px;
    inset-block-end: max(12px, env(safe-area-inset-bottom));
    max-width: min(360px, calc(100vw - 24px));
  }

  .auth-card {
    max-width: none;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .steps {
    grid-template-columns: repeat(2, 1fr);
  }
  .step {
    font-size: 0.8rem;
  }
  .brand p { display: none; }
}

/* Landscape phones: keep drawer usable */
@media (max-width: 820px) and (orientation: landscape) {
  .rail {
    width: min(280px, 70vw);
  }
  .workspace {
    min-height: auto;
  }
  .opt-groups {
    max-height: 40vh;
  }
}

/* Prefer reduced motion: instant drawer */
@media (prefers-reduced-motion: reduce) {
  .rail,
  .drawer-scrim {
    transition: none !important;
  }
}

/* 新增：Post/Set 內容預覽樣式 */
.generated-content-preview {
  margin-top: 24px;
  padding: 20px;
  background: var(--surface-2);
  border-radius: 12px;
  border: 1px solid var(--border-1);
}

.generated-content-preview h3 {
  margin: 0 0 16px 0;
  font-size: 1.1rem;
  color: var(--text-1);
}

.content-preview {
  margin-top: 20px;
}

/* 內容類型選擇提示 */
#content-type-hint {
  margin-top: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}

/* 場景描述面板樣式 */
#set-frames-block {
  margin-top: 24px;
  padding: 16px;
  background: var(--surface-2);
  border-radius: 8px;
  border: 1px solid var(--border-1);
}

#set-frames-block .subhead {
  margin-bottom: 12px;
}

#set-num-frames {
  width: 100%;
  max-width: 200px;
  padding: 8px 12px;
  font-size: 1rem;
}
