:root {
  --room: #17130F;
  --panel: #221C17;
  --panel-2: #2B241E;
  --line: #3A3129;
  --text: #EDE3D1;
  --muted: #8C7F70;
  --tungsten: #F2B33D;
  --tungsten-ink: #2A1E05;
  --slate: #6FB7C4;
  --danger: #E0694F;
  --ok: #8FBF7A;
  --display: "Avenir Next Condensed", "Roboto Condensed", "Arial Narrow", "Helvetica Neue", sans-serif-condensed, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius-s: 6px;
  --radius-m: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--room); color: var(--text); font: 15px/1.5 var(--body); }
a { color: var(--slate); }
button, input, textarea, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--tungsten); outline-offset: 2px; }
img { display: block; max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; background: linear-gradient(to right, var(--panel) 279px, var(--line) 279px, var(--line) 280px, var(--room) 280px); }
.rail { background: var(--panel); display: flex; flex-direction: column; min-height: 100vh; position: sticky; top: 0; max-height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 12px; }
.brand-mark { width: 26px; height: 26px; border: 2.5px solid var(--tungsten); border-radius: 3px; position: relative; }
.brand-mark::before, .brand-mark::after { content: ""; position: absolute; left: 0; right: 0; height: 2px; background: var(--tungsten); }
.brand-mark::before { top: 5px; } .brand-mark::after { bottom: 5px; }
.brand-name { font: 600 22px/1 var(--display); letter-spacing: .01em; }
.tabs { display: flex; gap: 4px; padding: 0 12px 12px; }
.tab { flex: 1; padding: 8px 10px; border: 1px solid var(--line); background: transparent; border-radius: var(--radius-s); cursor: pointer; color: var(--muted); }
.tab[aria-current="page"] { background: var(--panel-2); color: var(--text); border-color: var(--muted); }
.rail-list { overflow-y: auto; flex: 1; padding: 4px 8px 12px; }
.rail-new { margin: 0 12px 10px; }
.rail-item { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 6px; border: 0; border-radius: var(--radius-s); background: transparent; cursor: pointer; }
.rail-item:hover { background: var(--panel-2); }
.rail-item[aria-current="true"] { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--tungsten); }
.rail-thumb { width: 40px; height: 52px; border-radius: 4px; background: var(--room) center/cover no-repeat; border: 1px solid var(--line); }
.rail-title { font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-sub { color: var(--muted); font-size: 13px; }
.rail-foot { border-top: 1px solid var(--line); padding: 12px 16px; font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rail-foot strong { color: var(--text); font-weight: 600; }
.linkish { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 0; }
.main { padding: 28px clamp(16px, 4vw, 48px) 80px; max-width: 1180px; width: 100%; }
.menu-toggle { display: none; }

/* ---------- type ---------- */
h1, h2, h3 { font-family: var(--display); font-weight: 600; letter-spacing: .005em; margin: 0; }
h1 { font-size: clamp(34px, 5vw, 52px); line-height: 1; }
h2 { font-size: 26px; line-height: 1.1; margin-bottom: 12px; }
h3 { font-size: 19px; line-height: 1.2; margin-bottom: 8px; }
.lede { color: var(--muted); max-width: 62ch; margin: 10px 0 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.section { margin-top: 36px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- controls ---------- */
.btn { border: 1px solid var(--line); background: var(--panel-2); padding: 9px 16px; border-radius: var(--radius-s); cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--tungsten); color: var(--tungsten-ink); border-color: var(--tungsten); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.quiet { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
a.btn { text-decoration: none; color: var(--text); display: inline-block; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.cost { font-weight: 400; opacity: .8; margin-left: 6px; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; }
input[type=text], input[type=password], textarea, select {
  width: 100%; background: var(--room); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 14px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--text); }

/* ---------- builder ---------- */
.builder { display: grid; grid-template-columns: 1fr 300px; gap: 28px; align-items: start; }
.groups { display: grid; gap: 22px; }
.group-title { font-weight: 600; margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; }
.group-title .hint { font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 6px 13px; cursor: pointer; font-size: 14px; }
.chip:hover { border-color: var(--muted); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--room); border-color: var(--text); }
.chip.random[aria-pressed="true"] { background: transparent; color: var(--tungsten); border-color: var(--tungsten); border-style: dashed; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; padding: 0; position: relative; }
.swatch[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 3px var(--room), 0 0 0 5px var(--text); }
.swatch.random { background: conic-gradient(#f5d6ba, #8d5524, #3b2219, #e6c35c, #9a3324, #5b8bb0, #f5d6ba); }
.swatch-wrap { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.picked { font-size: 13px; color: var(--muted); }
.side { position: sticky; top: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px; }
.side .btn { width: 100%; margin-top: 10px; }
.side-summary { font-size: 13px; color: var(--muted); max-height: 220px; overflow: auto; margin: 8px 0 4px; }
.side-summary b { color: var(--text); font-weight: 600; }

/* ---------- casting ---------- */
.cast-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.look { position: relative; border-radius: var(--radius-s); overflow: hidden; border: 2px solid transparent; background: var(--panel); cursor: pointer; padding: 0; text-align: left; }
.look img { aspect-ratio: 9 / 16; object-fit: cover; width: 100%; }
.look:hover { border-color: var(--muted); }
.look[aria-pressed="true"] { border-color: var(--tungsten); }
.look .tag { position: absolute; left: 8px; bottom: 8px; background: rgba(23,19,15,.85); padding: 3px 9px; border-radius: 999px; font-size: 13px; }
.char-head { display: grid; grid-template-columns: 220px 1fr; gap: 28px; align-items: start; }
.hero { border-radius: var(--radius-m); overflow: hidden; background: var(--panel); border: 1px solid var(--line); aspect-ratio: 9 / 16; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 0; }
.hero img { width: 100%; height: 100%; object-fit: cover; }
.sheets { display: grid; grid-template-columns: 2fr 2fr 1fr; gap: 12px; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.sheet img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.sheet.portrait img { aspect-ratio: 3 / 4; }
.sheet .cap { padding: 7px 10px; font-size: 13px; color: var(--muted); }
.card-md { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px 22px; max-width: 72ch; }

/* ---------- markdown ---------- */
.md h1, .md h2, .md h3 { margin: 18px 0 8px; font-size: 22px; }
.md h1:first-child, .md h2:first-child, .md h3:first-child { margin-top: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 20px; }
.md li { margin: 3px 0; }
.md table { border-collapse: collapse; width: 100%; margin: 8px 0 14px; font-size: 14px; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.md th { color: var(--muted); font-weight: 600; }
.md strong { color: #fff6e6; }
.table-wrap { overflow-x: auto; }

/* ---------- contact sheet (the one bold element) ---------- */
.contact { background: #0d0a08; border-radius: var(--radius-m); padding: 0 14px; position: relative; overflow: hidden; }
.contact::before, .contact::after { content: ""; position: absolute; left: 0; right: 0; height: 14px;
  background-image: radial-gradient(ellipse 5px 3.5px at center, var(--room) 92%, transparent 100%); background-size: 22px 14px; background-repeat: repeat-x; opacity: .9; }
.contact::before { top: 2px; } .contact::after { bottom: 2px; }
.strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; padding: 26px 0; }
.frame { background: var(--panel); border-radius: 4px; overflow: hidden; display: flex; flex-direction: column; }
.frame-img { position: relative; aspect-ratio: 9 / 16; background: #1b1612; display: grid; place-items: center; color: var(--muted); font-size: 13px; text-align: center; padding: 0; }
.frame-img img, .frame-img video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.frame-no { position: absolute; top: 6px; left: 8px; font: 600 15px/1 var(--display); color: var(--tungsten); text-shadow: 0 1px 2px #000; z-index: 1; }
.frame-ref { position: absolute; top: 6px; right: 8px; font-size: 12px; background: rgba(13,10,8,.8); color: var(--slate); padding: 2px 7px; border-radius: 999px; z-index: 1; }
.frame-body { padding: 10px 11px 12px; display: grid; gap: 6px; font-size: 13.5px; }
.frame-body .what { color: var(--text); }
.frame-body .meta { color: var(--muted); font-size: 12.5px; }
.frame details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.frame textarea { min-height: 80px; font-size: 13px; margin-top: 6px; }
.frame .row { margin-top: 4px; }

/* ---------- steps (a real sequence) ---------- */
.steps { display: flex; gap: 0; margin: 22px 0 6px; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; width: fit-content; max-width: 100%; }
.step { padding: 8px 16px; color: var(--muted); font-size: 14px; border-right: 1px solid var(--line); white-space: nowrap; }
.step:last-child { border-right: 0; }
.step.on { color: var(--text); background: var(--panel-2); }
.step.doneish { color: var(--ok); }

/* ---------- jobs ---------- */
.job { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-m); padding: 14px 16px; margin: 18px 0; }
.job.error { border-color: var(--danger); }
.job-head { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--slate); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }
.bar { height: 6px; background: var(--room); border-radius: 999px; overflow: hidden; margin: 10px 0 8px; }
.bar > i { display: block; height: 100%; background: var(--slate); width: 0; transition: width .4s; }
.job-log { font-size: 12.5px; color: var(--muted); max-height: 74px; overflow: hidden; white-space: pre-wrap; }
.job.error .job-log { color: var(--danger); }

.video-wrap { display: grid; grid-template-columns: minmax(220px, 340px) 1fr; gap: 28px; align-items: start; }
.video-wrap video { width: 100%; aspect-ratio: 9 / 16; background: #000; border-radius: var(--radius-m); }
.banner { border-left: 3px solid var(--tungsten); background: var(--panel); padding: 10px 14px; border-radius: 0 var(--radius-s) var(--radius-s) 0; margin: 14px 0; }
.empty { border: 1px dashed var(--line); border-radius: var(--radius-m); padding: 34px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); }
.pick-cast { display: flex; flex-wrap: wrap; gap: 10px; }
.cast-chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 4px; background: var(--panel); cursor: pointer; }
.cast-chip img, .cast-chip .ph { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--room); }
.cast-chip[aria-pressed="true"] { border-color: var(--tungsten); background: var(--panel-2); }
.transcripts { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-s); }
.tr { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; width: 100%; background: transparent; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.tr:last-child { border-bottom: 0; }
.tr[aria-pressed="true"] { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--tungsten); }
.tr .folder { color: var(--muted); font-size: 12.5px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 28px; }
.login h1 { font-size: 40px; margin-bottom: 18px; display: flex; gap: 12px; align-items: center; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; }

#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--room); padding: 10px 16px; border-radius: var(--radius-s); font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); z-index: 10; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--danger); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .builder { grid-template-columns: 1fr; }
  .side { position: static; }
  .char-head { grid-template-columns: 1fr; }
  .char-head .hero { max-width: 260px; }
  .sheets { grid-template-columns: 1fr 1fr; }
  .video-wrap { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; background: var(--room); }
  .rail { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 5; transform: translateX(-102%); transition: transform .2s; }
  .rail.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.5); }
  .menu-toggle { display: inline-flex; margin-bottom: 14px; }
  .main { padding: 16px 16px 80px; }
  .strip { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .cast-grid { grid-template-columns: repeat(2, 1fr); }
  .sheets { grid-template-columns: 1fr; }
}

/* models check */
.table-wrap { overflow-x: auto; margin: 16px 0; }
table.models { width: 100%; border-collapse: collapse; font-size: 14px; }
table.models th { text-align: left; font-weight: 600; color: var(--muted); padding: 8px 12px 8px 0; border-bottom: 1px solid var(--line); }
table.models td { padding: 12px 12px 12px 0; vertical-align: top; border-bottom: 1px solid var(--line); }
.status { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 13px; white-space: nowrap; }
.s-ok { background: rgba(143,191,122,.16); color: var(--ok); }
.s-problem { background: rgba(224,105,79,.18); color: var(--danger); }
.s-unknown { background: var(--panel-2); color: var(--muted); }
