/* memson — vanilla cream design system v2
   Warm layered paper, espresso ink, caramel accent. All legacy class
   names are preserved; tokens drive everything so feature pages from
   parallel work inherit the system automatically. */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600;9..144,700&family=Schibsted+Grotesk:wght@400;500;600;700&display=swap');

/* ---------- tokens ---------- */

:root {
  /* surfaces: sunken < paper < raised */
  --paper: #faf5ec;
  --paper-deep: #f3ecdd;       /* sunken */
  --card: #fffdf8;             /* raised */
  --card-hi: rgba(255, 255, 255, .9);

  /* ink */
  --ink: #2b2420;
  --ink-soft: #8a7f72;
  --ink-faint: #b8ad9e;

  /* lines & accents */
  --line: #e6dcc9;
  --line-soft: #efe7d6;
  --accent: #b8865b;
  --accent-ink: #6f4e2e;
  --accent-soft: #f1e2d0;
  --good: #4e7a4e;
  --good-soft: #e9f0e4;
  --good-line: #d3e0cb;
  --bad: #a3502e;
  --bad-soft: #f6e3da;
  --bad-line: #ecd0c2;

  /* elevation: key light + ambient, warm-tinted */
  --shadow-s: 0 1px 2px rgba(67, 50, 30, .07);
  --shadow: 0 1px 2px rgba(67, 50, 30, .06), 0 8px 24px rgba(67, 50, 30, .07);
  --shadow-lift: 0 2px 4px rgba(67, 50, 30, .08), 0 16px 40px rgba(67, 50, 30, .13);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);

  /* shape & rhythm */
  --radius-s: 8px;
  --radius: 12px;
  --radius-l: 16px;
  --gap: 18px;

  /* type scale */
  --text-s: 13px;
  --text: 14.5px;
  --text-l: 17px;
  --display: "Fraunces", Georgia, serif;
  --body: "Schibsted Grotesk", system-ui, sans-serif;
}

* { box-sizing: border-box; }

::selection { background: var(--accent-soft); color: var(--accent-ink); }

html { scrollbar-color: var(--line) transparent; }

body {
  font-family: var(--body);
  font-size: var(--text);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 80% -10%, var(--paper-deep), transparent 60%),
    var(--paper);
  margin: 0;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* fine grain so the cream feels like paper, not a void */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .35;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.42 0 0 0 0 0.35 0 0 0 0 0.26 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

main { max-width: 860px; margin: 0 auto; padding: 26px 18px 110px; position: relative; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-s); }

/* ---------- app shell ---------- */

nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 18px;
  background: color-mix(in srgb, var(--paper) 80%, transparent);
  backdrop-filter: blur(12px) saturate(1.1);
  border-bottom: 1px solid var(--line);
}
nav .brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-right: 14px;
}
nav .brand::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background:
    radial-gradient(7px 7px at 7px 8px, var(--card) 45%, transparent 46%),
    linear-gradient(135deg, var(--accent), var(--accent-ink));
  box-shadow: var(--shadow-s);
}
nav a {
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 500;
  font-size: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  transition: color .15s ease, background .15s ease;
}
nav a:hover { color: var(--ink); background: var(--paper-deep); }
nav a.here { color: var(--ink); background: var(--paper-deep); font-weight: 600; }
nav .lang { margin-left: auto; display: flex; gap: 2px; font-size: var(--text-s); }
nav .lang a { padding: 4px 9px; }
nav .lang a.active { color: var(--ink); font-weight: 700; background: var(--paper-deep); }

h1 {
  font-family: var(--display);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 26px 0 6px;
}
h1 + .muted { margin-top: 0; }
h2 { font-family: var(--display); font-size: 19px; margin: 4px 0 12px; letter-spacing: -0.01em; }

/* ---------- cards ---------- */

.card {
  position: relative;
  background: linear-gradient(var(--card-hi), transparent 28px), var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: var(--gap) 0;
  box-shadow: var(--shadow);
  transition: transform .25s ease, box-shadow .25s ease, border-color .25s ease;
  animation: rise .5s ease both;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.card:nth-of-type(1) { animation-delay: .03s; }
.card:nth-of-type(2) { animation-delay: .08s; }
.card:nth-of-type(3) { animation-delay: .13s; }
.card:nth-of-type(4) { animation-delay: .18s; }
.card:nth-of-type(5) { animation-delay: .23s; }
.card:nth-of-type(n+6) { animation-delay: .27s; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* two-column card grid on wide screens (videos / refs) */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  margin: var(--gap) 0;
  align-items: start;
}
.cards-grid > .card { margin: 0; }
@media (min-width: 900px) {
  .cards-grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .card, .banner { animation: none; }
  .card:hover { transform: none; }
  * { transition-duration: .01ms !important; }
}

/* ---------- media ---------- */

video {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: var(--radius-s);
  background: #1a1512;
  box-shadow: var(--shadow);
  display: block;
}
.video-shell { position: relative; width: fit-content; margin: 10px 0; }

.muted { color: var(--ink-soft); font-size: var(--text-s); }

/* ---------- status pills & chips ---------- */

.status {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  border-radius: 999px;
  padding: 2.5px 10px;
  background: var(--paper-deep);
  color: var(--accent-ink);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.status.generated, .status.uploaded { background: var(--good-soft); color: var(--good); border-color: var(--good-line); }
.status.failed { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.status.pending { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--line); }

pre.caption {
  background: var(--paper-deep);
  border: 1px dashed var(--line);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: var(--text);
  margin: 10px 0 6px;
}

/* ---------- buttons ---------- */

button, input[type=submit] {
  font: inherit;
  font-weight: 600;
  font-size: var(--text);
  padding: 8px 18px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
button:hover { background: var(--paper-deep); transform: translateY(-1px); box-shadow: var(--shadow); }
button:active { transform: translateY(0); }
button.primary {
  background: linear-gradient(rgba(255,255,255,.12), transparent 45%), var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
button.primary:hover { background: linear-gradient(rgba(255,255,255,.16), transparent 45%), #463a31; }
button:disabled { opacity: .45; cursor: default; transform: none; box-shadow: none; }
button.small { padding: 5px 13px; font-size: var(--text-s); }

/* tiny utility button (copy etc.) */
.copy-btn {
  border: 1px solid var(--line);
  color: var(--ink-soft);
  background: var(--card);
  font-size: 12px;
  padding: 4px 12px;
}
.copy-btn:hover { color: var(--ink); border-color: var(--accent); }

/* decision buttons: semantic tints that invert on hover */
button.approve, button.reject {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: .01em;
}
button .glyph {
  display: inline-grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  transition: background .18s ease, color .18s ease;
}
button.approve { background: var(--good-soft); border-color: var(--good-line); color: var(--good); }
button.approve .glyph { background: var(--good); color: var(--good-soft); }
button.approve:hover { background: var(--good); border-color: var(--good); color: #fff;
                       box-shadow: 0 4px 14px rgba(78, 122, 78, .3); }
button.approve:hover .glyph { background: #fff; color: var(--good); }
button.reject { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad); }
button.reject .glyph { background: var(--bad); color: var(--bad-soft); }
button.reject:hover { background: var(--bad); border-color: var(--bad); color: #fff;
                      box-shadow: 0 4px 14px rgba(163, 80, 46, .3); }
button.reject:hover .glyph { background: #fff; color: var(--bad); }

/* ---------- forms ---------- */

input[type=text], input[type=password], input[type=search], textarea, input[type=file] {
  font: inherit;
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  margin: 4px 0 14px;
  background: var(--card);
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
textarea { min-height: 76px; resize: vertical; }

input[type=file] {
  border: 1px dashed color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--paper-deep) 60%, var(--card));
  padding: 8px;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: var(--text);
}
input[type=file]:hover { border-color: var(--accent); background: var(--paper-deep); }
input[type=file]::file-selector-button {
  font: inherit;
  font-size: var(--text);
  font-weight: 600;
  padding: 7px 16px;
  margin-right: 12px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(184, 134, 91, .3);
  transition: background .18s ease, transform .15s ease, box-shadow .18s ease;
}
input[type=file]::file-selector-button:hover {
  background: var(--accent-ink);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(111, 78, 46, .35);
}
label { font-size: var(--text); color: var(--accent-ink); font-weight: 500; }

select {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  background: var(--card);
  color: var(--ink);
  margin: 4px 6px 10px 6px;
}

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.banner {
  border: 1px solid var(--good-line);
  background: var(--good-soft);
  color: var(--good);
  border-radius: var(--radius-s);
  padding: 10px 14px;
  margin: 14px 0;
  font-size: var(--text);
  animation: rise .4s ease both;
}
.error-banner { border-color: var(--bad-line); background: var(--bad-soft); color: var(--bad); }

.tags { font-size: var(--text-s); color: var(--ink-soft); }
.tags a { color: inherit; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--paper);
  font-size: var(--text-s);
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-lift);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- empty states ---------- */

.empty {
  text-align: center;
  padding: 46px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-l);
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--paper-deep) 40%, transparent);
}
.empty::before {
  content: "◌";
  display: block;
  font-size: 34px;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

/* ---------- skeleton shimmer (busy cards) ---------- */

.shimmer {
  position: relative;
  overflow: hidden;
}
.shimmer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%,
              color-mix(in srgb, var(--card-hi) 70%, transparent) 50%,
              transparent 65%);
  animation: shimmer 1.6s ease-in-out infinite;
  pointer-events: none;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- maker editor ---------- */

/* numbered step rail — pure CSS counters, no template changes needed */
main { counter-reset: step; }
.card.step { padding-left: 24px; }
.card.step > h2 { display: flex; align-items: center; gap: 10px; }
.card.step > h2::before {
  counter-increment: step;
  content: counter(step);
  font-family: var(--body);
  font-size: 12px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--paper-deep);
  color: var(--accent-ink);
  border: 1px solid var(--line);
  flex: none;
}
.card.step.busy { border-color: var(--accent); }
.card.step.busy > h2::before { background: var(--accent); color: #fff; border-color: var(--accent); }

fieldset.scene {
  border: 1px dashed var(--line);
  border-radius: var(--radius-s);
  padding: 12px 14px;
  margin: 14px 0;
}
fieldset.scene legend {
  font-family: var(--display);
  font-size: var(--text);
  color: var(--accent-ink);
  padding: 0 8px;
}

.models { display: grid; gap: 10px; margin: 8px 0 16px; }
.model-option {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  align-items: baseline;
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
  font-size: var(--text);
}
.model-option:hover { border-color: var(--accent); }
.model-option.chosen, .model-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--paper-deep);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.model-option input { accent-color: var(--accent); }
.model-name { font-weight: 700; }
.model-cost { color: var(--accent-ink); font-size: var(--text-s); white-space: nowrap; }
.model-desc { grid-column: 2 / 4; color: var(--ink-soft); font-size: var(--text-s); }

.frames { display: flex; gap: 14px; flex-wrap: wrap; margin: 12px 0; }
.frame {
  width: 180px;
  text-align: center;
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 6px;
  transition: border-color .2s ease, transform .2s ease;
}
.frame img {
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
  display: block;
  margin-bottom: 8px;
  transition: transform .25s ease;
}
.frame:hover img { transform: scale(1.02); }
.frame.chosen { border-color: var(--accent); background: var(--paper-deep); }
.frame:hover { transform: translateY(-2px); }
.frame button { font-size: var(--text-s); padding: 5px 12px; }
.frame.chosen button { background: var(--accent); border-color: var(--accent); color: #fff; }

.prompt-area { min-height: 170px; font-size: var(--text); line-height: 1.55; }
details > summary { cursor: pointer; margin: 8px 0; }

.feedback { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.feedback textarea { min-height: 54px; }
details.chat { margin-top: 8px; }
details.chat summary { cursor: pointer; }
details.chat p { margin: 4px 0 0 12px; }

.step.busy { border-color: var(--accent); }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }

.char-sheet {
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: var(--text-s);
  margin: 8px 0 12px;
  line-height: 1.5;
}
.scene-area { min-height: 110px; }

.draft-bar { display: flex; gap: 12px; align-items: center; margin: 0 0 16px; flex-wrap: wrap; }
.draft-switch { display: flex; gap: 8px; align-items: center; font-size: var(--text-s); color: var(--ink-soft); }
.draft-switch select { max-width: 320px; }

.sound-profile {
  font-size: var(--text-s);
  background: var(--paper-deep);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 7px 10px;
  line-height: 1.5;
}

/* remix editor */
.remix-card { border-left: 3px solid var(--accent); }
.remix-timeline { padding-left: 20px; margin: 6px 0 10px; font-size: var(--text-s); }
.remix-timeline li { margin: 3px 0; }
.mech-chip {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  margin: 2px 3px;
  font-size: 12px;
  background: var(--paper-deep);
}
.chosen-direction { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }

/* ---------- login ---------- */

.login-box {
  max-width: 360px;
  margin: 14vh auto;
  text-align: left;
  padding: 28px 28px 24px;
  border-radius: var(--radius-l);
}
.login-box::before {
  content: "";
  display: block;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  margin-bottom: 14px;
  background:
    radial-gradient(13px 13px at 14px 16px, var(--card) 45%, transparent 46%),
    linear-gradient(135deg, var(--accent), var(--accent-ink));
  box-shadow: var(--shadow);
}
.login-box h1 { font-size: 36px; margin: 0 0 4px; }
.login-box .sub { color: var(--ink-soft); font-size: var(--text-s); margin: 0 0 18px; }
.error { color: var(--bad); font-size: var(--text); margin: 4px 0 10px; }

/* ---------- docs ---------- */

.docs p, .docs li { font-size: var(--text); line-height: 1.55; }
.docs ol, .docs ul { padding-left: 22px; margin: 8px 0; }
.docs li { margin: 5px 0; }
.docs li::marker { color: var(--ink-soft); }

/* ---------- refs ---------- */

.toolbar { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.toolbar form.grow { display: flex; gap: 8px; flex: 1; min-width: 240px; }
.toolbar input[type=search] { flex: 1; margin: 0; }
.metrics { display: flex; gap: 14px; font-size: var(--text); margin: 6px 0; font-variant-numeric: tabular-nums; }
.metrics span { white-space: nowrap; }
.card-dim { opacity: .65; }
.manual-upload { margin: 10px 0; }
.manual-upload summary { cursor: pointer; color: var(--ink-soft); font-size: var(--text); }
.busy-banner { display: flex; gap: 8px; align-items: center; }

/* ---------- trends dashboard ---------- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 14px 0 20px; }
.stat-tile {
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-tile b { font-family: var(--display); font-size: 26px; font-variant-numeric: tabular-nums; }
.stat-tile span { color: var(--ink-soft); font-size: 12px; }
.trend-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 40%) 1fr auto; gap: 8px; align-items: center; margin: 6px 0; font-size: var(--text-s); }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: color-mix(in srgb, var(--ink) 6%, transparent); border-radius: 99px; height: 8px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .6s cubic-bezier(.16,1,.3,1); }
.convergence { border-left: 3px solid var(--accent); }
.idea-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 12px 0;
  background: color-mix(in srgb, var(--card) 55%, transparent);
}
.idea-card .appeal { font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--accent); }
.meta-trend { font-style: italic; color: var(--ink-soft); margin: 4px 0; }

.spark { flex: none; }
.spark polyline { fill: none; stroke: var(--good); stroke-width: 2;
                  stroke-linecap: round; stroke-linejoin: round; }

/* ---------- videos filter chips ---------- */

.filter-chips { display: flex; gap: 8px; margin: 12px 0 4px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: var(--text-s);
  text-decoration: none;
  color: var(--ink-soft);
  background: var(--card);
  transition: all .15s ease;
}
.chip b { color: var(--ink); font-weight: 600; }
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.active b { color: #fff; }

/* ---------- mobile ---------- */

@media (max-width: 560px) {
  nav { gap: 2px; padding: 10px 12px; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav .brand { font-size: 16px; margin-right: 8px; }
  nav a { font-size: var(--text-s); padding: 5px 9px; }
  h1 { font-size: 28px; }
  .stat-tile b { font-size: 21px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar form.grow { min-width: 0; }
  video { max-width: 100%; }
}

/* ---------- midnight espresso (manual + system default) ----------
   JS in <head> resolves localStorage.theme | system preference into
   html[data-theme]; the toggle in the nav flips and persists it. */

:root[data-theme="dark"] {
    --paper: #1c1714;
    --paper-deep: #251f1a;
    --card: #2a231d;
    --card-hi: rgba(255, 252, 245, .045);
    --ink: #f0e7da;
    --ink-soft: #a3978a;
    --ink-faint: #6b6157;
    --line: #3a3128;
    --line-soft: #332b23;
    --accent: #c89a6c;
    --accent-ink: #e3c39d;
    --accent-soft: #3c2f22;
    --good: #93b88b;
    --good-soft: #2a3326;
    --good-line: #3d4d38;
    --bad: #d98d68;
    --bad-soft: #3a2a21;
    --bad-line: #54382a;
    --shadow-s: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, .4), 0 16px 40px rgba(0, 0, 0, .5);
  }
}
[data-theme="dark"] body::before { opacity: .22; }
[data-theme="dark"] button.primary { background: linear-gradient(rgba(255,255,255,.1), transparent 45%), var(--accent); color: #221a12; border-color: var(--accent); }
[data-theme="dark"] button.primary:hover { background: linear-gradient(rgba(255,255,255,.16), transparent 45%), var(--accent-ink); }
[data-theme="dark"] button, [data-theme="dark"] input[type=submit] { border-color: var(--line); }
[data-theme="dark"] .chip.active { color: #221a12; }
[data-theme="dark"] .chip.active b { color: #221a12; }
[data-theme="dark"] input[type=file]::file-selector-button { color: #221a12; }
[data-theme="dark"] button.approve:hover, [data-theme="dark"] button.reject:hover { color: #1c1714; }
[data-theme="dark"] button.approve:hover .glyph { background: #1c1714; }
[data-theme="dark"] button.reject:hover .glyph { background: #1c1714; }
[data-theme="dark"] #toast { background: var(--ink); color: var(--paper); }

/* ---------- channel switcher ---------- */

.channel-menu { position: relative; margin-right: 6px; }
.channel-menu > summary {
  list-style: none;
  cursor: pointer;
  font-size: var(--text-s);
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  white-space: nowrap;
}
.channel-menu > summary::-webkit-details-marker { display: none; }
.channel-menu[open] > summary { border-color: var(--accent); }
.channel-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 210px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lift);
  padding: 6px;
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.channel-pop a {
  padding: 7px 11px;
  border-radius: var(--radius-s);
  color: var(--ink);
  text-decoration: none;
  font-size: var(--text);
  white-space: nowrap;
}
.channel-pop a:hover { background: var(--paper-deep); }
.channel-pop a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.channel-pop a.manage { border-top: 1px solid var(--line); margin-top: 4px; color: var(--ink-soft); }

/* ---------- theme toggle ---------- */

.theme-toggle {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-soft);
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 15px;
  line-height: 1;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--accent); }

/* ---------- left drawer (maker draft history) ---------- */

.drawer-scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 9, .4);
  backdrop-filter: blur(2px);
  z-index: 30;
  opacity: 0;
  transition: opacity .25s ease;
}
.drawer-scrim.open { opacity: 1; }
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(330px, 86vw);
  background: var(--card);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-lift);
  z-index: 31;
  transform: translateX(-102%);
  transition: transform .28s cubic-bezier(.16, 1, .3, 1);
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; }
.drawer-x { border: none; background: none; box-shadow: none; font-size: 16px;
            color: var(--ink-soft); padding: 4px 8px; }
.drawer-x:hover { color: var(--ink); background: var(--paper-deep); transform: none; box-shadow: none; }
.drawer-list { overflow-y: auto; padding: 10px 12px 20px; }
.drawer-item {
  display: block;
  text-decoration: none;
  color: var(--ink);
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  padding: 9px 11px;
  margin: 4px 0;
  transition: background .15s ease, border-color .15s ease;
}
.drawer-item:hover { background: var(--paper-deep); }
.drawer-item.active { border-color: var(--accent); background: var(--paper-deep); }
.drawer-item .drawer-label {
  display: block;
  color: var(--ink-soft);
  font-size: var(--text-s);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

/* frame workshop */
.model-checks { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0; }
.model-check { display: flex; gap: 6px; align-items: center; border: 1px solid var(--line);
               border-radius: 99px; padding: 5px 12px; font-size: 13px; cursor: pointer;
               background: var(--card); }
.model-check:has(input:checked) { border-color: var(--accent);
                                  box-shadow: 0 0 0 1px var(--accent) inset; }
.model-check.disabled { opacity: .45; cursor: not-allowed; }
.frame-badges { display: flex; gap: 6px; margin: 4px 0; justify-content: center; }
.frame-actions { display: flex; gap: 6px; justify-content: center; margin-top: 4px; }
.frame-actions button { padding: 3px 10px; font-size: 12px; }

.render-check { align-items: center; margin: 8px 0; }
.render-thumb { width: 72px; height: 128px; object-fit: cover;
                border-radius: 10px; border: 2px solid var(--accent); }

/* motion swap */
.char-pick { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0; }
.char-option { display: flex; flex-direction: column; align-items: center;
               gap: 4px; cursor: pointer; }
.char-option img { width: 64px; height: 114px; object-fit: cover;
                   border-radius: 8px; border: 2px solid transparent; }
.char-option:has(input:checked) img { border-color: var(--accent); }
.char-option input { position: absolute; opacity: 0; }

/* character lab */
.char-portrait { cursor: pointer; }
.char-portrait input { position: absolute; opacity: 0; }
.char-portrait:has(input:checked) img { outline: 3px solid var(--accent); }
.char-roster-img { width: 100%; max-width: 200px; border-radius: 12px;
                   aspect-ratio: 9/16; object-fit: cover; }

/* saga */
.saga-layout { display: grid; grid-template-columns: 200px 1fr; gap: 18px; }
.saga-side { display: flex; flex-direction: column; gap: 6px; }
.saga-pill { display: block; padding: 8px 12px; border-radius: 10px;
             border: 1px solid var(--line); text-decoration: none;
             color: var(--ink); background: var(--card); font-size: 14px; }
.saga-pill.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.saga-new summary { cursor: pointer; color: var(--ink-soft); padding: 8px 0; font-size: 14px; }
.saga-ep video { max-width: 240px; }
@media (max-width: 640px) { .saga-layout { grid-template-columns: 1fr; } }

/* saga redesign */
.saga-top { gap: 12px; align-items: center; flex-wrap: wrap; }
.saga-switch { font-size: 15px; padding: 6px 10px; border-radius: 10px; }
.btn-like { cursor: pointer; display: inline-block; padding: 7px 13px;
            border: 1px solid var(--line); border-radius: 99px; font-size: 14px;
            background: var(--card); list-style: none; }
.btn-like::-webkit-details-marker { display: none; }
.saga-new-pop, .saga-settings { position: relative; }
.pop-form { display: flex; flex-direction: column; gap: 6px; margin-top: 8px;
            padding: 12px; border: 1px solid var(--line); border-radius: 12px;
            background: var(--card); }
.saga-head { display: flex; gap: 12px; align-items: flex-start;
             background: var(--paper-deep); border: 1px solid var(--line);
             border-radius: 14px; padding: 14px 16px; margin: 12px 0; }
.saga-head-main { flex: 1; }
.saga-head h2 { margin: 0 0 4px; }
.saga-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
/* composer: the one focused next-episode action */
.composer { display: flex; gap: 14px; align-items: flex-start;
            border: 2px solid var(--accent); }
.composer-num { font-family: "Fraunces", serif; font-size: 34px; font-weight: 700;
                color: var(--accent); line-height: 1; min-width: 44px; text-align: center; }
.composer-body { flex: 1; }
.composer-body h2 { margin: 0 0 8px; }
/* episode timeline */
.ep-card { display: flex; gap: 14px; }
.ep-rail { display: flex; flex-direction: column; align-items: center; gap: 6px;
           min-width: 54px; }
.ep-num { font-family: "Fraunces", serif; font-weight: 700; font-size: 18px; }
.ep-stage { font-size: 11px; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.stage-scripted { background: var(--paper-deep); color: var(--ink-soft); }
.stage-rendering { background: #f3e8d0; color: var(--accent-ink); }
.stage-rendered  { background: #e9f0e4; color: var(--good); }
.stage-posted    { background: var(--accent); color: #fff; }
.ep-body { flex: 1; min-width: 0; }
.ep-comment { font-weight: 600; }
.ep-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.copy-line { display: flex; gap: 8px; align-items: center; margin: 5px 0;
             font-size: 13px; }
.copy-tag { color: var(--ink-soft); min-width: 56px; text-transform: uppercase;
            font-size: 11px; letter-spacing: .04em; }
.copy-line code { flex: 1; background: var(--paper-deep); padding: 5px 9px;
                  border-radius: 8px; overflow-x: auto; white-space: nowrap; }
.copy-btn { padding: 4px 9px; }

/* submit spinner */
.spin { display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* actionable empty states */
.empty { text-align: center; color: var(--ink-soft); padding: 36px 18px; }
.empty .cta { display: inline-block; margin-top: 12px; padding: 9px 18px;
              border-radius: 99px; background: var(--accent); color: #fff;
              text-decoration: none; font-weight: 600; }
.empty .cta:hover { background: var(--accent-ink); }

/* account-type picker */
.type-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; margin: 6px 0 12px; }
.type-option { display: flex; flex-direction: column; gap: 3px; cursor: pointer;
               border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
               background: var(--card); }
.type-option:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.type-option input { position: absolute; opacity: 0; }
.type-name { font-weight: 600; font-size: 14px; }
.type-desc { font-size: 12px; color: var(--ink-soft); line-height: 1.4; }

.post-form input { margin-bottom: 6px; font-size: 13px; }

.spend { font-size: 13px; color: var(--ink-soft); margin: 4px 0; }
.spend.over { color: var(--bad); font-weight: 600; }

/* character studio — three focused panes */
.studio-top { align-items: center; }
.studio-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; align-items: start; }
.studio-pane { display: flex; flex-direction: column; }
.studio-sub { font-family: "Fraunces", serif; font-size: 15px; margin: 14px 0 6px; }
.studio-save { margin-top: 12px; gap: 8px; }
.studio-save input { flex: 1; }
.studio-thread { max-height: 260px; overflow-y: auto; margin-top: 10px;
                 display: flex; flex-direction: column; gap: 6px; }
.chat-you { background: var(--paper-deep); border-radius: 10px; padding: 6px 10px; font-size: 13px; }
.chat-agent { color: var(--ink-soft); font-size: 13px; padding: 2px 4px; }
.studio-versions { display: flex; flex-direction: column; gap: 6px; }
.version-row { align-items: center; font-size: 13px; }
.version-row .muted { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ephemeral ref poster: first extracted frame instead of the purged video */
.ref-thumb {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
  display: block;
  transition: transform .2s ease;
}
a:hover > .ref-thumb { transform: scale(1.015); }
