/* NoirRP — Literary Dark-Mode Roleplay & Uncensored Image Studio (>= 375px mobile-first) */

[hidden] {
  display: none !important;
}

:root {
  --bg-root: #09090d;
  --bg-elevated: #111119;
  --bg-card: #161622;
  --bg-input: #0d0d14;
  --bg-hover: #1f1f30;
  --border: #26263a;
  --border-focus: #a855f7;
  --text-main: #f1edf8;
  --text-prose: #ede8f6;
  --text-action: #c4badc;
  --text-quote: #fff8ed;
  --text-muted: #958ea8;
  --accent: #c084fc;
  --accent-strong: #9333ea;
  --accent-soft: rgba(192, 132, 252, 0.14);
  --zdr-green: #34d399;
  --zdr-bg: rgba(52, 211, 153, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.15);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --topbar-h: 56px;
  --mobnav-h: 60px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-root);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.86em;
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
}

.muted {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.muted-xs {
  color: var(--text-muted);
  font-size: 0.8rem;
}

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

/* Buttons & Pills */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  min-height: 38px;
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: #3a3a58;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #9333ea, #7e22ce);
  border-color: #a855f7;
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #a855f7, #8b2be2);
}

.btn-ghost {
  background: transparent;
}

.btn-cloak {
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(148, 163, 184, 0.3);
  color: #e2e8f0;
}

.btn-danger {
  background: var(--danger-bg);
  border-color: rgba(248, 113, 113, 0.45);
  color: #fecaca;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 0.83rem;
  min-height: 34px;
}

.btn-xs {
  padding: 4px 9px;
  font-size: 0.78rem;
  min-height: 28px;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-hover);
}

.chip-btn {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 32px;
  white-space: nowrap;
}

.chip-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text-main);
}

.link-btn {
  background: none;
  border: none;
  padding: 2px 4px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  flex-shrink: 0;
}

.pill-zdr {
  background: var(--zdr-bg);
  color: var(--zdr-green);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.pill-accent {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(192, 132, 252, 0.35);
}

/* Inputs & Forms */
.field,
.field-compact {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field > span,
.field-compact > span,
.label-split > span:first-child {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

.label-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="search"],
input[type="number"],
select,
textarea {
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-main);
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
}

textarea {
  resize: vertical;
}

.input-compact {
  padding: 5px 9px;
  font-size: 0.82rem;
  height: 34px;
  max-width: 100%;
}

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 0.86rem;
  color: var(--text-main);
  cursor: pointer;
  padding: 4px 0;
}

.checkbox-field input[type="checkbox"] {
  margin-top: 3px;
  width: 16px;
  height: 16px;
  accent-color: var(--accent-strong);
  flex-shrink: 0;
}

.input-with-btn {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.input-with-btn input {
  flex: 1;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

/* Boss-Key Cloak Screen (Harmless Neutral Scratchpad) */
.cloak-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #101216;
  color: #d4d8df;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.cloak-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid #22262e;
  background: #14171d;
  gap: 10px;
}

.cloak-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.cloak-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
}

.cloak-sub,
.cloak-meta {
  font-size: 0.78rem;
  color: #7c8594;
}

.cloak-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cloak-body {
  flex: 1;
  display: flex;
  padding: 14px;
  min-height: 0;
}

.cloak-textarea {
  width: 100%;
  height: 100%;
  border: 1px solid #22262e;
  background: #0d0f13;
  color: #cfd5de;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.6;
  padding: 14px;
  border-radius: 8px;
  resize: none;
}

/* Vault Gate */
.vault-gate {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 10%, rgba(147, 51, 234, 0.14), transparent 55%), var(--bg-root);
}

.gate-topbar {
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
}

.brand-badge,
.brand-name {
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand-badge span,
.brand-name span {
  color: var(--accent);
}

.gate-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.gate-icon {
  font-size: 1.8rem;
  color: var(--accent);
}

#vaultForm {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.alert-error {
  background: var(--danger-bg);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fecaca;
}

/* App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  padding-top: env(safe-area-inset-top);
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.02rem;
}

.brand-glyph {
  color: var(--accent);
}

.desktop-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-root);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.nav-tab {
  padding: 6px 14px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
}

.nav-tab.active {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

.workspace {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

/* Stories Workspace */
#view-stories {
  display: flex;
  overflow: hidden;
}

.story-sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 0.96rem;
}

.story-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.story-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  min-width: 0;
}

.story-item:hover {
  background: var(--bg-card);
}

.story-item.active {
  background: var(--bg-card);
  border-color: rgba(192, 132, 252, 0.45);
}

.avatar-sm {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-card);
}

.story-item-info {
  flex: 1;
  min-width: 0;
}

.story-item-title {
  font-size: 0.88rem;
  font-weight: 500;
}

.story-item-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.story-item-del {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.65;
}

.story-item-del:hover {
  opacity: 1;
  color: var(--danger);
  background: var(--danger-bg);
}

.story-stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-root);
}

.story-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  background: rgba(17, 17, 25, 0.92);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.story-header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.story-title-group {
  min-width: 0;
}

.story-title-group h2 {
  font-size: 0.96rem;
}

.story-sub {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.story-header-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

#storyQuickModel {
  max-width: 200px;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px 20px;
  gap: 12px;
  max-width: 460px;
  margin: 0 auto;
}

.empty-glyph {
  font-size: 2.2rem;
  color: var(--accent);
}

.empty-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 6px;
}

/* Message Thread */
.message-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px;
}

.message-list {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.msg-card.msg-user {
  background: #141322;
  border-color: #2d2948;
}

.msg-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.msg-author {
  font-weight: 600;
  font-size: 0.86rem;
  color: var(--accent);
}

.msg-user .msg-author {
  color: #93c5fd;
}

.msg-model-tag {
  font-size: 0.73rem;
  color: var(--text-muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.director-fold {
  border: 1px dashed #342f4f;
  background: rgba(168, 85, 247, 0.05);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.director-fold summary {
  cursor: pointer;
  font-weight: 500;
  color: #b794f4;
  user-select: none;
}

.director-fold pre {
  margin: 6px 0 2px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: inherit;
  color: #cfc8e2;
}

.msg-prose {
  color: var(--text-prose);
  font-size: 0.98rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.msg-prose p + p {
  margin-top: 11px;
}

.rp-action {
  color: var(--text-action);
  font-style: italic;
}

.rp-quote {
  color: var(--text-quote);
}

/* Inline Story Illustrations */
.msg-media-box {
  margin-top: 4px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0b0b11;
  max-width: 420px;
}

.msg-media-img {
  display: block;
  width: 100%;
  max-height: 460px;
  object-fit: contain;
  cursor: zoom-in;
  background: #07070b;
}

.msg-media-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 0.76rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  gap: 6px;
}

.msg-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  flex-wrap: wrap;
}

.sib-nav {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 6px;
}

.sib-btn {
  background: none;
  border: none;
  color: var(--text-main);
  cursor: pointer;
  padding: 2px 5px;
  font-size: 0.78rem;
}

.sib-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.turn-btns {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.turn-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.77rem;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.turn-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border);
}

/* Composer Dock */
.composer-dock {
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stream-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--accent);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulseAnim 1.1s infinite ease-in-out;
}

@keyframes pulseAnim {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}

.composer-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

#composerInput {
  flex: 1;
  min-height: 46px;
  max-height: 180px;
  line-height: 1.5;
}

.composer-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.composer-subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  flex-wrap: wrap;
}

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

/* Right Story Inspector */
.story-inspector {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inspector-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
}

.inspector-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-block {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.branch-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.branch-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.branch-meta {
  font-size: 0.74rem;
  color: var(--accent);
  font-weight: 600;
}

.branch-snip {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

/* Imagine Studio Workspace */
.studio-layout {
  max-width: 1360px;
  margin: 0 auto;
  padding: 18px 14px 32px;
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  min-width: 0;
}

.card-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.advanced-fold {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  background: rgba(255, 255, 255, 0.015);
}

.advanced-fold summary {
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-muted);
}

.fold-body {
  margin-top: 11px;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.workbench-actions {
  display: flex;
  gap: 8px;
}

.studio-gallery-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-pills,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.gallery-search {
  width: 220px;
  max-width: 100%;
}

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

.gallery-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.gallery-img-wrap {
  aspect-ratio: 3 / 4;
  background: #08080c;
  overflow: hidden;
  position: relative;
}

.gallery-img-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}

.gallery-fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(9, 9, 13, 0.72);
  color: #cbd5e1;
  cursor: pointer;
}

.gallery-fav-btn.fav {
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.5);
}

.gallery-meta {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex: 1;
}

.gallery-prompt {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  flex: 1;
}

.gallery-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  flex-wrap: wrap;
}

/* Cast & Settings Containers */
.container-wide {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 14px 36px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.container-narrow {
  max-width: 780px;
  margin: 0 auto;
  padding: 18px 14px 40px;
}

.subtab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

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

.char-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  min-width: 0;
}

.char-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar-lg {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-card);
}

.char-desc {
  font-size: 0.84rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  flex: 1;
}

.tag-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.tag-chip {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.stack-list,
.stack-cards {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.list-row-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.key-status {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.key-status.configured {
  color: var(--zdr-green);
}

.ios-install-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.settings-save-bar {
  display: flex;
  justify-content: flex-end;
}

.file-btn {
  cursor: pointer;
}

/* Modals, Lightbox, & Toasts */
.modal-overlay,
.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(5, 5, 9, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-card {
  width: 100%;
  max-width: 620px;
  max-height: 90dvh;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lightbox-overlay {
  flex-direction: column;
  z-index: 600;
  background: rgba(4, 4, 7, 0.94);
}

.lightbox-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 6px 12px;
}

.lightbox-caption {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.lightbox-stage {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-stage img {
  max-width: 100%;
  max-height: 84dvh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.toast-region {
  position: fixed;
  bottom: 76px;
  right: 16px;
  z-index: 700;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}

.toast {
  background: #1d1c2d;
  border: 1px solid #3d395e;
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.toast-error {
  border-color: rgba(248, 113, 113, 0.55);
  color: #fecaca;
}

/* Mobile Responsive (< 900px down to 375px) */
.mobile-only {
  display: none;
}

.drawer-backdrop {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 35;
}

@media (max-width: 960px) {
  .studio-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .desktop-tabs {
    display: none;
  }

  .mobile-only {
    display: inline-flex;
  }

  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    height: calc(var(--mobnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-elevated);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 30;
  }

  .mob-tab {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 0.72rem;
    cursor: pointer;
  }

  .mob-tab.active {
    color: var(--accent);
    font-weight: 600;
  }

  .mob-ic {
    font-size: 1.05rem;
    line-height: 1;
  }

  .story-sidebar {
    position: fixed;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    bottom: calc(var(--mobnav-h) + env(safe-area-inset-bottom));
    left: 0;
    width: min(290px, 84vw);
    z-index: 40;
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: 12px 0 32px rgba(0, 0, 0, 0.6);
  }

  .story-sidebar.open {
    transform: translateX(0);
  }

  .story-inspector {
    position: fixed;
    top: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
    bottom: calc(var(--mobnav-h) + env(safe-area-inset-bottom));
    right: 0;
    width: min(340px, 92vw);
    z-index: 42;
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.65);
  }
}

@media (max-width: 640px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    padding: 0 10px;
    gap: 6px;
  }

  #storyQuickModel {
    max-width: 145px;
  }

  .studio-gallery {
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 10px;
  }

  .character-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
