/* ============================================================================
   SERIES DIRECTOR — "Film Lab"
   A darkened colour-grading suite: warm near-black, tungsten amber, and the
   clips laid out as real 35mm frames with sprocket holes.
   ========================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Bai+Jamjuree:wght@400;500;600;700&family=Chakra+Petch:wght@500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

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

:root {
  /* Surfaces — warm blacks, the colour of a room lit by a single lamp */
  --ink:        #100c0a;
  --panel:      #17120f;
  --panel-2:    #1f1814;
  --panel-3:    #2a211b;
  --rail:       #14100d;

  /* Lines */
  --line:       #2e241d;
  --line-soft:  #241c17;
  --line-hot:   #4a3728;

  /* Type */
  --text:       #f4ece2;
  --text-2:     #c3b3a3;
  --text-dim:   #8a7969;
  --text-faint: #5f5348;

  /* Accents — tungsten lamp + its teal complement (the classic film grade) */
  --amber:      #f2a049;
  --amber-hot:  #ffb867;
  --amber-deep: #b8702a;
  --teal:       #4fc7c0;
  --teal-deep:  #2b7d78;

  /* Semantic */
  --ok:         #6fc98a;
  --warn:       #e8b44a;
  --err:        #e8685f;

  /* Type stacks — Thai-capable throughout, with OS fallbacks for offline */
  --font-body:    'Bai Jamjuree', 'Leelawadee UI', 'Noto Sans Thai', 'Segoe UI', sans-serif;
  --font-display: 'Chakra Petch', 'Bai Jamjuree', 'Leelawadee UI', 'Segoe UI', sans-serif;
  --font-mono:    'IBM Plex Mono', 'Cascadia Mono', 'Consolas', monospace;

  /* Rhythm */
  --r-sm: 4px;
  --r:    8px;
  --r-lg: 14px;

  --rail-w: 400px;
  --topbar-h: 56px;

  --shadow-lift: 0 12px 32px -12px rgba(0, 0, 0, .8);
  --shadow-deep: 0 24px 64px -20px rgba(0, 0, 0, .9);

  --ease: cubic-bezier(.22, .61, .36, 1);
}

/* ------------------------------------------------------------------ base */

*, *::before, *::after { box-sizing: border-box; }

/* Class-based `display` rules out-specify the UA sheet's [hidden] rule, so
   anything we toggle with .hidden = true would otherwise stay on screen. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;               /* the two panes scroll, not the page */
}

/* Film grain — a still photographic texture over everything. Sits above the
   background, below all content, and never eats a click. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Lamp glow from the top-left — the single light source of the room */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 500px at 12% -8%, rgba(242, 160, 73, .10), transparent 62%),
    radial-gradient(700px 600px at 100% 110%, rgba(79, 199, 192, .06), transparent 58%);
}

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

/* Scrollbars, dressed down */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 3px solid var(--ink);
}
::-webkit-scrollbar-thumb:hover { background: var(--line-hot); }

/* --------------------------------------------------------------- topbar */

.topbar {
  position: relative;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: linear-gradient(var(--rail), #120e0c);
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}

/* A tally lamp: the little red light that says "we are rolling" */
.tally {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(242, 160, 73, .16), 0 0 14px var(--amber);
  flex: none;
}
.tally.rolling { animation: tally-pulse 1.4s var(--ease) infinite; }
@keyframes tally-pulse {
  0%, 100% { opacity: 1;  box-shadow: 0 0 0 3px rgba(242,160,73,.16), 0 0 14px var(--amber); }
  50%      { opacity: .45; box-shadow: 0 0 0 6px rgba(242,160,73,.05), 0 0 4px var(--amber); }
}

.wordmark small {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: .04em;
  color: var(--text-faint);
  text-transform: none;
}

.topbar-btn {
  font: inherit;
  font-size: 13px;
  color: var(--text-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  padding: 7px 13px;
  cursor: pointer;
  text-decoration: none;
  transition: background .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease);
}
.topbar-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }

.topbar-btn.accent {
  background: linear-gradient(var(--amber), var(--amber-deep));
  border-color: var(--amber-hot);
  color: #1a1005;
  font-weight: 600;
}
.topbar-btn.accent:hover { background: linear-gradient(var(--amber-hot), var(--amber)); }

/* Remaining shared-pool credits. Turns amber when it starts to run out and
   red once it is gone, so the limit is visible before it bites. */
.quota-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .02em;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 4px 11px;
  white-space: nowrap;
}
.quota-chip.low  { color: var(--warn); border-color: rgba(232,180,74,.45); }
.quota-chip.out  { color: var(--err);  border-color: rgba(232,104,95,.45); }
.quota-chip.free { color: var(--teal); border-color: rgba(79,199,192,.4); }

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

.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  height: calc(100vh - var(--topbar-h));
}

/* ------------------------------------------------------- left rail: brief */

/* Column layout: the fields scroll, the generate button stays put. Doing this
   with flex rather than position:sticky keeps the button pinned to the true
   bottom edge regardless of how tall the form grows. */
.rail {
  background: var(--rail);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rail-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 20px 28px;
}

.rail-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}

.rail-head h1 {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: .01em;
  margin: 0;
}

.rail-sub {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 22px;
}

/* Section label — small caps rule, like a slate field */
.field-label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 8px;
}
.field-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
}
.field-label .req { color: var(--amber); letter-spacing: 0; }

.field { margin-bottom: 22px; }

/* ------------------------------------------------------------- controls */

input[type=text], input[type=number], input[type=email],
input[type=password], textarea, select {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px 12px;
  transition: border-color .16s var(--ease), background .16s var(--ease), box-shadow .16s var(--ease);
}
textarea { resize: vertical; min-height: 92px; line-height: 1.65; }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--amber-deep);
  background: var(--panel-2);
  box-shadow: 0 0 0 3px rgba(242, 160, 73, .11);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }

select {
  appearance: none;
  cursor: pointer;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a7969' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.hint { font-size: 12px; color: var(--text-faint); margin-top: 6px; line-height: 1.5; }

/* ---------------------------------------------------------- genre chips */

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font: inherit;
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 6px 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .16s var(--ease);
}
.chip:hover { border-color: var(--line-hot); color: var(--text); transform: translateY(-1px); }
.chip[aria-pressed="true"] {
  background: linear-gradient(var(--amber), var(--amber-deep));
  border-color: var(--amber-hot);
  color: #1a1005;
  font-weight: 600;
  box-shadow: 0 3px 14px -4px rgba(242, 160, 73, .55);
}

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

.btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 9px 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: all .16s var(--ease);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--panel-3); border-color: var(--line-hot); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(var(--amber), var(--amber-deep));
  border-color: var(--amber-hot);
  color: #1a1005;
  font-weight: 700;
  box-shadow: 0 6px 22px -8px rgba(242, 160, 73, .65);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(var(--amber-hot), var(--amber));
  border-color: #ffd0a0;
}

.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }

.btn-teal {
  background: linear-gradient(var(--teal), var(--teal-deep));
  border-color: #7fe0da; color: #04211f; font-weight: 600;
}
.btn-teal:hover:not(:disabled) { filter: brightness(1.1); }

.btn-lg { width: 100%; padding: 13px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* Spinner shown inside a busy button */
.btn.busy { pointer-events: none; opacity: .8; }
.btn.busy::before {
  content: '';
  width: 13px; height: 13px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------ characters */

.char {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 12px;
  margin-bottom: 9px;
  position: relative;
}
.char-top {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 9px;
}
.char-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: .1em;
  color: var(--ink);
  background: var(--text-dim);
  border-radius: var(--r-sm);
  padding: 2px 6px;
  flex: none;
}
.char-tag.lead { background: var(--amber); }
.char-x {
  margin-left: auto;
  background: none; border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: var(--r-sm);
}
.char-x:hover { color: var(--err); background: var(--panel-3); }
.char textarea { min-height: 58px; font-size: 13px; }
.char input { font-size: 13px; padding: 8px 10px; }

/* Reference face + fields, side by side */
.char-body { display: flex; gap: 10px; align-items: flex-start; }
.char-fields { flex: 1; min-width: 0; }

/* The uploaded face. Portrait ratio, because that is what the models want. */
.char-face {
  position: relative;
  flex: none;
  width: 62px;
  height: 82px;
  border-radius: var(--r);
  border: 1px dashed var(--line-hot);
  background: var(--panel-2);
  cursor: pointer;
  overflow: hidden;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--text-faint);
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.char-face:hover { border-color: var(--amber-deep); color: var(--amber); background: var(--panel-3); }
.char-face.has { border-style: solid; border-color: var(--amber-deep); }
.char-face img { width: 100%; height: 100%; object-fit: cover; display: block; }

.face-x {
  position: absolute;
  top: 3px; right: 3px;
  width: 17px; height: 17px;
  border: none;
  border-radius: 50%;
  background: rgba(12, 8, 6, .82);
  color: var(--text-2);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.face-x:hover { background: var(--err); color: #fff; }

/* -------------------------------------------------- sticky generate bar */

.rail-cta {
  flex: none;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line);
  background: linear-gradient(var(--panel), var(--rail));
}

/* ------------------------------------------------------ right: the stage */

.stage {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 30px 80px;
}

.stage-head {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.stage-head h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  letter-spacing: .01em;
}
.stage-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-dim);
  letter-spacing: .03em;
  margin-bottom: 3px;
}
.stage-meta b { color: var(--teal); font-weight: 500; }

.stage-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.stage-rule {
  height: 1px;
  background: linear-gradient(90deg, var(--line-hot), var(--line) 30%, transparent);
  margin: 16px 0 22px;
}

/* --------------------------------------------------------- empty state */

.empty {
  height: 100%;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 4px;
}
.empty-strip {
  display: flex;
  gap: 5px;
  margin-bottom: 22px;
  opacity: .5;
}
.empty-strip i {
  display: block;
  width: 34px; height: 52px;
  border-radius: 3px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  animation: shimmer 2.6s var(--ease) infinite;
}
.empty-strip i:nth-child(2) { animation-delay: .18s; }
.empty-strip i:nth-child(3) { animation-delay: .36s; }
.empty-strip i:nth-child(4) { animation-delay: .54s; }
.empty-strip i:nth-child(5) { animation-delay: .72s; }
@keyframes shimmer {
  0%, 100% { background: var(--panel-2); border-color: var(--line); }
  50%      { background: var(--panel-3); border-color: var(--line-hot); }
}
.empty h3 {
  font-family: var(--font-display);
  font-size: 17px; font-weight: 600;
  margin: 0 0 4px; color: var(--text-2);
}
.empty p { color: var(--text-faint); margin: 0; font-size: 13.5px; max-width: 42ch; }

/* ======================================================== THE FILMSTRIP */

.strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 14px;
}

/* One 35mm frame, held vertically — sprockets run down both long edges. */
.frame {
  --sprocket: rgba(0, 0, 0, .55);
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px);
  animation: frame-in .5s var(--ease) forwards;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), transform .18s var(--ease);
}
@keyframes frame-in { to { opacity: 1; transform: none; } }

.frame:hover {
  border-color: var(--line-hot);
  box-shadow: var(--shadow-lift);
  transform: translateY(-2px);
}
.frame.open {
  border-color: var(--amber-deep);
  box-shadow: 0 0 0 1px var(--amber-deep), var(--shadow-deep);
  grid-column: 1 / -1;
  transform: none;
}

/* Sprocket holes — repeating notches down the left and right gutters */
.frame::before, .frame::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 11px;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0 7px,
    var(--sprocket) 7px 16px
  );
  background-clip: content-box;
  padding: 6px 3px;
  pointer-events: none;
  opacity: .8;
}
.frame::before { left: 0; }
.frame::after  { right: 0; }
.frame.open::before, .frame.open::after { opacity: .35; }

.frame-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px 12px 22px;
  cursor: pointer;
  user-select: none;
}

/* Frame counter — the big mono number punched into the film edge */
.frame-no {
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 500;
  line-height: 1;
  color: var(--amber);
  letter-spacing: -.02em;
  flex: none;
  min-width: 30px;
}
.frame.open .frame-no { color: var(--amber-hot); }

.frame-id { min-width: 0; flex: 1; }
.frame-beat {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.frame-tech {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.frame-caret {
  flex: none;
  color: var(--text-faint);
  font-size: 11px;
  transition: transform .22s var(--ease), color .18s var(--ease);
}
.frame.open .frame-caret { transform: rotate(180deg); color: var(--amber); }

/* Role stripe down the left edge — colour-codes the story beat */
.frame-role {
  position: absolute;
  left: 11px; top: 0; bottom: 0;
  width: 2px;
  background: var(--line-hot);
}
.frame-role[data-role="establishing"] { background: var(--teal); }
.frame-role[data-role="conflict"],
.frame-role[data-role="peak"]         { background: var(--err); }
.frame-role[data-role="twist"]        { background: var(--amber); }
.frame-role[data-role="close"]        { background: var(--ok); }

/* ------------------------------------------------------- frame: opened */

.frame-body {
  display: none;
  padding: 4px 22px 20px;
  border-top: 1px solid var(--line-soft);
  margin-top: 2px;
}
.frame.open .frame-body { display: block; animation: body-in .3s var(--ease); }
@keyframes body-in { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }

.frame-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 232px;
  gap: 18px;
  padding-top: 14px;
}
@media (max-width: 1180px) { .frame-grid { grid-template-columns: 1fr; } }

.spec {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  margin-bottom: 14px;
}
.spec dt { color: var(--text-faint); letter-spacing: .06em; text-transform: uppercase; font-size: 10px; padding-top: 2px; }
.spec dd { margin: 0; color: var(--text-2); }

/* A prompt block styled as a strip of edge-code */
.prompt {
  background: #0b0806;
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--amber-deep);
  border-radius: var(--r-sm);
  margin-bottom: 10px;
  overflow: hidden;
}
.prompt.vdo { border-left-color: var(--teal-deep); }

.prompt-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  background: rgba(255, 255, 255, .022);
  border-bottom: 1px solid var(--line-soft);
}
.prompt-tag {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--amber);
}
.prompt.vdo .prompt-tag { color: var(--teal); }
.prompt-len { font-family: var(--font-mono); font-size: 10px; color: var(--text-faint); }
.prompt-bar .btn-row { margin-left: auto; gap: 5px; }

.prompt pre {
  margin: 0;
  padding: 11px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.72;
  color: #cfe6c8;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 210px;
  overflow-y: auto;
}
.prompt.vdo pre { color: #bfe4e6; }

/* Still preview pane inside an open frame */
.still {
  background: #0b0806;
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  min-height: 168px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  text-align: center;
}
.still img {
  width: 100%;
  border-radius: var(--r-sm);
  display: block;
  box-shadow: var(--shadow-lift);
}
.still-hint { font-size: 12px; color: var(--text-faint); }

.fix-out:not(:empty) { margin-top: 12px; }

/* ------------------------------------------------------------- notices */

.note {
  border-radius: var(--r);
  padding: 10px 13px;
  font-size: 13px;
  border: 1px solid;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  line-height: 1.55;
}
.note.info    { background: rgba(79,199,192,.07);  border-color: rgba(79,199,192,.28);  color: #a5e2df; }
.note.success { background: rgba(111,201,138,.07); border-color: rgba(111,201,138,.28); color: #a9dcb8; }
.note.warn    { background: rgba(232,180,74,.07);  border-color: rgba(232,180,74,.28);  color: #ecd09a; }
.note.error   { background: rgba(232,104,95,.07);  border-color: rgba(232,104,95,.30);  color: #f0aaa4; }
.note + .note { margin-top: 8px; }

/* -------------------------------------------------------------- panels */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
  margin-bottom: 14px;
}
.panel > h3 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-2);
  margin: 0 0 13px;
}

/* --------------------------------------------------------- progress bar */

.meter {
  height: 5px;
  background: var(--panel-3);
  border-radius: 99px;
  overflow: hidden;
  margin: 10px 0 8px;
}
.meter > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--amber-deep), var(--amber-hot));
  transition: width .4s var(--ease);
}
.meter-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

/* ---------------------------------------------------------- list rows */

.rows { display: flex; flex-direction: column; gap: 6px; }

.rowitem {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px 13px;
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.rowitem:hover { border-color: var(--line-hot); background: var(--panel-2); }
.rowitem-main { min-width: 0; flex: 1; }
.rowitem-title {
  font-weight: 600; font-size: 13.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rowitem-meta {
  font-family: var(--font-mono);
  font-size: 10.5px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------------------------------------------------------- the drawer */

.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(6, 4, 3, .74);
  backdrop-filter: blur(3px);
  opacity: 0;
  animation: fade-in .2s var(--ease) forwards;
}
@keyframes fade-in { to { opacity: 1; } }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 41;
  width: min(480px, 92vw);
  background: var(--rail);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-deep);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  animation: drawer-in .3s var(--ease) forwards;
}
@keyframes drawer-in { to { transform: none; } }

.drawer-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 {
  font-family: var(--font-display);
  font-size: 15px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  margin: 0; flex: 1;
}
.drawer-body { overflow-y: auto; padding: 18px 20px 40px; flex: 1; }

.drawer-section { margin-bottom: 24px; }
.drawer-section > h3 {
  font-family: var(--font-display);
  font-size: 10.5px; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--text-dim);
  margin: 0 0 9px;
  display: flex; align-items: center; gap: 9px;
}
.drawer-section > h3::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, var(--line), transparent);
}

.icon-btn {
  background: none; border: 1px solid var(--line);
  color: var(--text-dim);
  width: 30px; height: 30px;
  border-radius: var(--r);
  cursor: pointer; font-size: 15px; line-height: 1;
  display: grid; place-items: center;
  transition: all .16s var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--line-hot); background: var(--panel-2); }

/* ---------------------------------------------------------- the modal */

.modal {
  position: fixed;
  z-index: 42;
  top: 50%; left: 50%;
  transform: translate(-50%, -48%);
  width: min(560px, 94vw);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line-hot);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-deep);
  padding: 22px;
  animation: modal-in .24s var(--ease) forwards;
}
@keyframes modal-in { to { transform: translate(-50%, -50%); } }

.modal h2 {
  font-family: var(--font-display);
  font-size: 16px; font-weight: 700;
  letter-spacing: .04em;
  margin: 0 0 16px;
  display: flex; align-items: center; gap: 10px;
}
.modal h2 .icon-btn { margin-left: auto; }

/* Archetype picker grid */
.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 8px;
}
.pick {
  text-align: left;
  font: inherit;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 11px 12px;
  cursor: pointer;
  transition: all .16s var(--ease);
}
.pick:hover {
  border-color: var(--amber-deep);
  background: var(--panel-3);
  transform: translateY(-2px);
}
.pick b { display: block; font-size: 13px; margin-bottom: 2px; }
.pick span { font-size: 11.5px; color: var(--text-faint); line-height: 1.45; display: block; }

/* ----------------------------------------------------------- toasts */

#toasts {
  position: fixed;
  z-index: 60;
  right: 18px; bottom: 18px;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--panel-2);
  border: 1px solid var(--line-hot);
  border-left: 3px solid var(--amber);
  border-radius: var(--r);
  padding: 11px 15px;
  font-size: 13px;
  max-width: 340px;
  box-shadow: var(--shadow-deep);
  animation: toast-in .28s var(--ease);
}
.toast.success { border-left-color: var(--ok); }
.toast.error   { border-left-color: var(--err); }
.toast.warn    { border-left-color: var(--warn); }
.toast.out     { animation: toast-out .25s var(--ease) forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateX(24px); } }
@keyframes toast-out { to   { opacity: 0; transform: translateX(24px); } }

/* ------------------------------------------------------------ details */

details.fold { margin-top: 10px; }
details.fold > summary {
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 7px 0;
  list-style: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: '▸ '; color: var(--amber); }
details.fold[open] > summary::before { content: '▾ '; }
details.fold > summary:hover { color: var(--text); }

/* ------------------------------------------------------------- chat */

.chat-msg {
  border-radius: var(--r);
  padding: 10px 13px;
  margin-bottom: 8px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.chat-msg.user { border-left: 2px solid var(--teal); }
.chat-msg.assistant { border-left: 2px solid var(--amber); }
.chat-msg b {
  font-family: var(--font-display);
  font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-dim); display: block; margin-bottom: 4px;
}
.chat-msg pre {
  margin: 0; white-space: pre-wrap; font-family: var(--font-body);
  font-size: 13px; line-height: 1.65; color: var(--text-2);
}

/* ----------------------------------------------------------- utility */

.mono { font-family: var(--font-mono); }
.dim  { color: var(--text-dim); }
.faint{ color: var(--text-faint); }
.mt   { margin-top: 12px; }
.center-col { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; }
.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;
}

/* --------------------------------------------------------- responsive */

@media (max-width: 1000px) {
  body { overflow: auto; }
  .shell { grid-template-columns: 1fr; height: auto; }
  .rail {
    border-right: none;
    border-bottom: 1px solid var(--line);
    display: block;
  }
  .rail-scroll { overflow: visible; padding-bottom: 4px; }
  .rail-cta { border-top: none; background: none; padding: 6px 20px 22px; }
  .stage { overflow: visible; padding: 22px 18px 60px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .frame { opacity: 1; transform: none; }
}
