@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Manrope:wght@500;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Source+Serif+4:opsz,wght@8..60,400;500;600&display=swap');

.hidden { display: none !important; }

:root {
  color-scheme: light;
  --window-top-bar-height: 0px;
  --window-titlebar-clearance: 0px;
  --traffic-light-gutter: 0px;
  --bg: #f6f1e6;
  --bg-deep: #ece2d1;
  --panel: rgba(255, 251, 244, 0.82);
  --panel-2: rgba(255, 248, 238, 0.92);
  --panel-solid: #fbf7ef;
  --text: #2d241b;
  --muted: #7f6f60;
  --line: rgba(67, 50, 31, 0.16);
  --line-strong: rgba(67, 50, 31, 0.3);
  --accent: #6f4937;
  --accent-soft: #b88962;
  --accent-ink: #241d16;
  --shadow: 0 20px 48px rgba(73, 55, 36, 0.08);
  --shadow-soft: 0 10px 28px rgba(73, 55, 36, 0.06);
  --radius: 18px;
  --radius-lg: 28px;
  --sans: "Plus Jakarta Sans", "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Source Serif 4", Georgia, serif;
  --display: "Manrope", "Avenir Next", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  --reader-font-size: 20px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(184, 137, 98, 0.18), transparent 26%),
    radial-gradient(circle at 82% 12%, rgba(255, 252, 246, 0.72), transparent 24%),
    linear-gradient(180deg, #fbf7ef 0%, var(--bg) 48%, var(--bg-deep) 100%);
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
  font-size: 17px;
  line-height: 1.68;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -2;
  opacity: 0.34;
  background:
    linear-gradient(rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.34)),
    repeating-linear-gradient(
      180deg,
      transparent 0,
      transparent 31px,
      rgba(87, 68, 47, 0.03) 32px
    );
}

a {
  color: inherit;
  text-decoration: none;
}

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

.app {
  min-height: 100%;
}

html.desktop-shell {
  --traffic-light-clearance: 36px;
}

/* No body::before overlay — sidebar and topbar backgrounds fill from y=0,
   their padding-top pushes content below the traffic lights. */

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  padding: 40px 20px;
}

html.desktop-shell .auth {
  min-height: calc(100vh - var(--traffic-light-clearance));
  margin-top: var(--traffic-light-clearance);
  padding-top: 0;
}

html.desktop-shell .shell {
  height: 100vh;
  min-height: 0;
  margin-top: 0;
  padding-top: 0;
  overflow: hidden;
}

.auth-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel-solid), rgba(255, 249, 241, 0.96));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow);
  position: relative;
  z-index: 2;
}

.auth-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.auth-brand img {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: #0f172a;
}

.auth-title {
  font-family: var(--display);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

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

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-form label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.auth-form input {
  padding: 13px 15px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.62);
  color: var(--text);
}

.auth-note {
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
}

.auth-glow {
  position: absolute;
  inset: -40% 0 auto 0;
  height: 60%;
  background: radial-gradient(circle at center, rgba(184, 137, 98, 0.2), transparent 65%);
  filter: blur(90px);
}

.btn {
  padding: 10px 15px;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 251, 245, 0.84);
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(73, 55, 36, 0.05);
  transition:
    transform 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background-color 0.18s ease,
    color 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: rgba(111, 73, 55, 0.48);
  box-shadow: 0 14px 22px rgba(73, 55, 36, 0.08);
}

.btn.primary {
  background: linear-gradient(180deg, #43362a, #241d16);
  color: #fffaf2;
  border-color: rgba(36, 29, 22, 0.96);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.shell {
  display: none;
  min-height: 100vh;
  grid-template-columns: 260px 1fr;
}

.shell.active {
  display: grid;
}

.shell.sidebar-collapsed {
  grid-template-columns: 0 1fr;
}

.sidebar.collapsed {
  width: 0;
  padding: 0;
  border: none;
  overflow: hidden;
}

.sidebar.collapsed + .main {
  width: 100%;
}

.sidebar {
  background: rgba(250, 245, 236, 0.68);
  border-right: 1px solid var(--line);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  backdrop-filter: blur(12px);
}

.hamburger {
  width: 16px;
  height: 12px;
  display: inline-flex;
  align-items: center;
  position: relative;
}

.hamburger::before,
.hamburger::after,
.hamburger span {
  content: "";
  position: absolute;
  left: 0;
  width: 16px;
  height: 2px;
  background: currentColor;
  border-radius: 999px;
}

.hamburger::before {
  top: 0;
}

.hamburger::after {
  bottom: 0;
}

.hamburger span {
  top: 5px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

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

.brand img {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(180deg, #3f352b, #211a14);
}

.brand-title {
  font-family: var(--display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.sidebar-new-story {
  width: 100%;
  text-align: center;
  padding: 10px;
  font-weight: 600;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
  text-align: left;
}

.sidebar-nav-btn:hover {
  background: rgba(125, 211, 252, 0.08);
  color: var(--text);
}

.sidebar-nav-btn.active {
  background: rgba(125, 211, 252, 0.12);
  color: var(--text);
}

.sidebar-nav-icon {
  font-size: 18px;
}

.sidebar-library {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-library-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 0 4px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
}

.sidebar-footer-btn {
  flex: 1;
  font-size: 12px;
  text-align: center;
}

.story-list {
  display: grid;
  gap: 8px;
}

.story-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s ease;
}

.story-chip:hover {
  background: rgba(255, 255, 255, 0.04);
}

.story-chip-cover {
  width: 32px;
  height: 44px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.5);
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(148, 163, 184, 0.15);
  flex-shrink: 0;
}

.story-chip-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-chip.active {
  background: rgba(125, 211, 252, 0.1);
  border-color: rgba(125, 211, 252, 0.25);
}

.main {
  padding: 12px 20px 32px;
}

html.desktop-shell .main {
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-top: 0;
}

/* Topbar: fixed height, doesn't grow */
html.desktop-shell .main > header {
  flex: 0 0 auto;
}

/* List views (dashboard / explore / bookshelf): scroll their own content */
html.desktop-shell .main > .dashboard,
html.desktop-shell .main > .story-home {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* Story view: fills remaining space, panels scroll internally */
html.desktop-shell .main > .story {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

html.desktop-shell .story-main {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#storyView .story-header {
  display: none;
}

html.desktop-shell .story-header {
  flex: 0 0 auto;
}

/* Override the 100dvh from the wide-screen rule — let flex sizing drive height */
html.desktop-shell .story-body.v2-layout {
  flex: 1;
  min-height: 0;
  height: auto;
}

html.desktop-shell .sidebar {
  height: 100%;
  overflow: hidden;
  padding-top: var(--traffic-light-clearance);
}

html.desktop-shell .sidebar.collapsed {
  padding-top: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0 8px;
}

html.desktop-shell .topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  /* Topbar is in the main column (x=260px+), traffic lights are in the sidebar
     (x=8-80px) — no top clearance needed here. Negative margins make the
     background extend to the edges of .main's padding. */
  margin: 0 -20px;
  padding-top: 10px;
  padding-left: 20px;
  padding-right: 20px;
}

.topbar-story-only {
  display: none !important;
}

.shell.story-active .topbar-story-only {
  display: inline-flex !important;
  align-items: center;
}

.topbar-back {
  padding: 4px 6px;
  color: var(--text);
  opacity: 0.65;
  flex-shrink: 0;
}

.topbar-back:hover {
  opacity: 1;
}

.topbar-mini-cover {
  display: none;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background-color: rgba(12, 18, 32, 0.2);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

.shell.story-active .topbar-mini-cover {
  display: inline-block !important;
}

.topbar-genre {
  font-size: 0.78rem;
  color: var(--text-muted, rgba(0,0,0,0.45));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
  flex-shrink: 1;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 2px 10px;
}

.story-edit-btn {
  padding: 4px 6px;
  opacity: 0.55;
  color: var(--text);
}

.story-edit-btn:hover {
  opacity: 1;
}

.story-edit-btn svg {
  width: 14px;
  height: 14px;
  display: block;
}

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

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}

.topbar-title {
  font-family: var(--display);
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#sidebarToggle {
  display: inline-flex;
}

.dashboard {
  display: none;
}

.dashboard.active {
  display: block;
}

.dashboard-main {
  display: grid;
  gap: 10px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.chat-new-thread-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 18px;
  font-weight: 500;
  flex-shrink: 0;
}

.chat-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.panel-header.panel-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(9, 14, 26, 0.5);
  border-radius: 12px;
  border: 1px solid var(--line);
  justify-content: flex-start;
}

.panel-tab {
  flex: 1;
  text-align: center;
  padding: 6px 8px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.panel-tab.active {
  background: rgba(125, 211, 252, 0.15);
  color: var(--text);
  font-weight: 500;
}

.panel-tab:hover:not(.active) {
  color: var(--text);
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.story-card {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.story-card:hover {
  transform: translateY(-2px);
  border-color: rgba(125, 211, 252, 0.3);
}

.story-card-cover {
  width: 100%;
  aspect-ratio: 3 / 4;
  background-size: cover;
  background-position: center;
  background-color: rgba(15, 23, 42, 0.35);
  position: relative;
}

.story-card-cover::after {
  content: "";
  position: absolute;
  inset: 50% 0 0 0;
  background: linear-gradient(to bottom, transparent, rgba(0,0,0,0.3));
  pointer-events: none;
}

.story-card-body {
  padding: 12px 14px 14px;
  display: grid;
  gap: 6px;
}

.story-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.story-card-badges {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  overflow: hidden;
}

.badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(125, 211, 252, 0.1);
  color: var(--accent);
  border: 1px solid rgba(125, 211, 252, 0.2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  flex-shrink: 1;
  min-width: 0;
}

.badge-drama {
  background: rgba(168, 85, 247, 0.12);
  color: #c084fc;
  border-color: rgba(168, 85, 247, 0.25);
  margin-left: 8px;
  flex-shrink: 0;
}

.story-card-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.story-card-premise {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0;
}

.story-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 2px;
}

.story-card-stat, .story-card-date {
  font-size: 11px;
  color: var(--muted);
}

.story-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.story-card p.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}

.story-card p.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
  cursor: pointer;
}

/* View differentiation */
#exploreView2 .story-grid {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

#bookshelfView .story-grid {
  grid-template-columns: 1fr;
  gap: 10px;
  max-width: 640px;
}

/* Horizontal bookshelf card variant */
.story-card-horizontal {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 0;
}

.story-card-horizontal .story-card-cover-sm {
  width: 100px;
  height: 100%;
  min-height: 120px;
  background-size: cover;
  background-position: center;
  background-color: rgba(15, 23, 42, 0.35);
  border-radius: 14px 0 0 14px;
}

.story-card-horizontal .story-card-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.story-card-horizontal h3 {
  font-size: 15px;
}

.story-card-horizontal .story-card-badges {
  gap: 4px;
}

.story-card-horizontal .badge {
  font-size: 10px;
  padding: 1px 6px;
}

.story-card-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--muted);
}

.story-card-progress .progress-bar {
  flex: 1;
}

.progress-bar {
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

.story {
  display: none;
}

.story.active {
  display: block;
}

.story-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.story-header h2 {
  font-size: 18px;
  line-height: 1.3;
}

.story-back-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 18px;
  flex-shrink: 0;
}

.story-title-wrap {
  flex: 1;
  min-width: 0;
}

.story-actions {
  flex-shrink: 0;
}

.story-title-wrap {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.story-title-row,
.story-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.story-title-row h2 {
  margin: 0;
}

.story-cover {
  width: 48px;
  height: 72px;
  border-radius: 18px;
  background: rgba(12, 18, 32, 0.8);
  border: 1px solid var(--line);
  background-size: cover;
  background-position: center;
}

.story-cover.large {
  width: 64px;
  height: 96px;
  border-radius: 10px;
  flex-shrink: 0;
}

.story-meta {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
}

.story-edit-btn {
  border: 1px solid var(--line);
  background: rgba(10, 16, 28, 0.6);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: 0 0 auto;
}

.story-edit-btn svg {
  width: 14px;
  height: 14px;
}

.story-edit-btn:hover {
  color: var(--text);
  border-color: rgba(125, 211, 252, 0.45);
}

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

.story-body.v2-layout {
  display: grid;
  --splitter: 8px;
  grid-template-columns: var(--chat-width, minmax(280px, 70%)) var(--splitter, 12px) var(--chapter-width, 1fr);
  gap: 0;
  margin-top: 12px;
  align-items: start;
  position: relative;
}

.v2-chat-panel,
.v2-chapter-panel {
  background: rgba(12, 18, 32, 0.45);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  gap: 10px;
  min-height: 42vh;
  min-width: 0;
  align-content: start;
  overflow-x: hidden;
  width: 100%;
}

.v2-chat-panel {
  position: relative;
}

.chat-model-menu {
  position: absolute;
  top: 72px;
  right: 16px;
  z-index: 30;
  width: min(320px, 90%);
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(8, 12, 24, 0.96);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  display: none;
  gap: 10px;
}

.chat-model-menu.active {
  display: grid;
}

.chat-model-menu-header {
  font-size: 13px;
  font-weight: 600;
}

.chat-model-current {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.chat-model-menu .field {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.chat-model-menu input,
.chat-model-menu select {
  background: rgba(12, 18, 32, 0.8);
  border: 1px solid rgba(125, 211, 252, 0.2);
  border-radius: 10px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  width: 100%;
}

.chat-model-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.chat-pipeline-section {
  border-top: 1px solid var(--border, #333);
  padding-top: 8px;
  margin-top: 4px;
}

.chat-pipeline-desc {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  margin-bottom: 4px;
}

.chat-agent-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.chat-agent-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

.chat-agent-desc {
  font-size: 11px;
  color: var(--muted);
  margin-left: auto;
}

.v2-chapter-panel img {
  max-width: 100%;
  height: auto;
}

.v2-chat-panel .panel-header,
.v2-chapter-panel .panel-header {
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  gap: 8px;
}

.v2-splitter {
  width: var(--splitter, 8px);
  cursor: col-resize;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: transparent;
  border: none;
  transition: background 0.15s ease;
}

.v2-splitter::after {
  content: "";
  width: 3px;
  height: 40px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  transition: background 0.15s ease, height 0.15s ease;
}

.v2-splitter:hover::after {
  background: rgba(125, 211, 252, 0.5);
  height: 56px;
}

.splitter-toggle {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(10, 16, 30, 0.95);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: absolute;
  z-index: 5;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.splitter-toggle:hover {
  border-color: rgba(125, 211, 252, 0.5);
  color: var(--text);
}

.story-body.v2-layout.reader-active {
  grid-template-columns: var(--chat-width, minmax(240px, 1fr)) var(--splitter, 12px) minmax(0, 1.6fr);
}

.story-body.v2-layout.reader-active .v2-chapter-panel .panel-header {
  display: none;
}

.story-body.v2-layout.reader-active .v2-chapter-reader {
  align-self: start;
}

.story-body.v2-layout.chat-collapsed {
  grid-template-columns: 0 var(--splitter, 12px) minmax(0, 1fr);
}

.story-body.v2-layout.chat-collapsed .v2-chat-panel {
  display: none;
}

.story-body.v2-layout.chapter-collapsed {
  grid-template-columns: minmax(280px, 1.4fr) var(--splitter, 12px) 0;
}

.story-body.v2-layout.reader-active.chapter-collapsed {
  grid-template-columns: minmax(240px, 1fr) var(--splitter, 12px) 0;
}

.story-body.v2-layout.chapter-collapsed .v2-chapter-panel {
  display: none;
}

body.resizing {
  cursor: col-resize;
  user-select: none;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 46vh;
  max-height: 62vh;
  overflow-y: auto;
  padding-right: 4px;
}

.chat-message {
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(9, 14, 26, 0.7);
  border: 1px solid var(--line);
  max-width: 82%;
  font-size: 13.5px;
  line-height: 1.55;
  box-shadow: none;
}

.chat-message.user {
  border-color: rgba(125, 211, 252, 0.4);
  background: rgba(125, 211, 252, 0.12);
  align-self: flex-end;
}

.chat-message.streaming {
  opacity: 0.85;
}

.chat-message.typing-indicator {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  align-self: flex-start;
  width: fit-content;
  max-width: none;
  padding: 10px 12px;
  background: rgba(255, 248, 238, 0.9);
  border: 1px solid rgba(67, 50, 31, 0.14);
  box-shadow: var(--shadow-soft);
}

.chat-message.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(184, 137, 98, 0.8);
  animation: typingPulse 1.2s infinite ease-in-out;
}

.chat-message.typing-indicator span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-message.typing-indicator span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.chat-highlight {
  border-color: rgba(111, 73, 55, 0.28);
  background: rgba(111, 73, 55, 0.08);
  font-weight: 600;
}

.chat-attachment {
  border: 1px solid rgba(67, 50, 31, 0.14);
  border-radius: 16px;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(255, 251, 244, 0.86), rgba(255, 248, 238, 0.94));
  color: var(--muted);
  font-size: 0.92rem;
  box-shadow: var(--shadow-soft);
}

.chat-attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  align-items: stretch;
}

.chat-attachment-tile {
  border: 1px solid rgba(67, 50, 31, 0.14);
  border-radius: 16px;
  padding: 12px 14px;
  background: linear-gradient(180deg, rgba(255, 251, 244, 0.86), rgba(255, 248, 238, 0.94));
  color: var(--text);
  text-align: left;
  font-size: 0.92rem;
  display: grid;
  gap: 8px;
  cursor: pointer;
  overflow: hidden;
  min-width: 0;
  box-shadow: var(--shadow-soft);
}

.chat-attachment-tile.heavy {
  border-color: rgba(184, 137, 98, 0.42);
  box-shadow: inset 0 0 0 1px rgba(184, 137, 98, 0.12);
}

.chat-attachment-tile.failed {
  border-color: rgba(214, 31, 31, 0.32);
  background: linear-gradient(180deg, rgba(255, 247, 246, 0.92), rgba(255, 244, 242, 0.98));
}

.chat-attachment-tile.research {
  border-color: rgba(111, 73, 55, 0.24);
}

.chat-attachment-tile-title {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.02;
  color: var(--text);
}

.chat-attachment-tile-summary {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.chat-attachment-tile-badge {
  justify-self: start;
  align-self: start;
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(184, 137, 98, 0.14);
  color: var(--accent);
  border: 1px solid rgba(184, 137, 98, 0.18);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  line-height: 1.2;
  height: fit-content;
}

.chat-attachment-tile-detail {
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.55;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}

.chat-summary {
  border: 1px solid rgba(67, 50, 31, 0.14);
  border-radius: 18px;
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(255, 251, 244, 0.86), rgba(255, 248, 238, 0.94));
  color: var(--text);
  font-size: 0.94rem;
  display: grid;
  gap: 10px;
  box-shadow: var(--shadow-soft);
}

.chat-summary-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
  color: var(--muted);
}

.chat-summary-body {
  white-space: pre-wrap;
  color: var(--text);
}

.chat-summary-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(111, 73, 55, 0.2), transparent);
}

.chat-load-more {
  align-self: center;
  margin: 4px 0 12px;
}

.chat-attachment-header {
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-attachment-fail {
  font-size: 0.82rem;
  color: #d61f1f;
  font-weight: 500;
}

.chat-attachment-status {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  margin-top: 4px;
}

.chat-attachment-status.failed {
  color: #d61f1f;
}

.chat-attachment-diff {
  display: grid;
  gap: 8px;
  font-size: 0.94rem;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}

.chat-attachment-diff .diff-minus {
  color: #9d3b3b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  mask-image: linear-gradient(90deg, #000 70%, transparent);
}

.chat-attachment-diff .diff-plus {
  color: #256b42;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  mask-image: linear-gradient(90deg, #000 70%, transparent);
}

.chat-attachment-diff.expanded .diff-minus,
.chat-attachment-diff.expanded .diff-plus {
  white-space: normal;
  mask-image: none;
}

.chat-attachment-diff .diff-full {
  background: rgba(255, 251, 245, 0.82);
  border: 1px solid rgba(67, 50, 31, 0.14);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.86rem;
  color: var(--text);
  display: grid;
  gap: 6px;
}

.chat-attachment-diff .diff-full .diff-plus {
  color: #256b42;
}

.chat-attachment-diff .diff-full .diff-minus {
  color: #9d3b3b;
}

.chat-attachment-diff .diff-full .diff-context {
  color: var(--muted);
}

.chat-attachment-diff .diff-full .diff-hunk {
  color: var(--accent);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.chat-attachment-detail {
  margin-top: 6px;
  color: var(--muted);
}

.chat-attachment-result {
  margin: 8px 0 0;
  white-space: pre-wrap;
  font-size: 12px;
  color: var(--text);
}

.chat-attachment-debug {
  margin: 6px 0 0;
  white-space: pre-wrap;
  font-size: 0.84rem;
  color: var(--text);
  background: rgba(255, 251, 245, 0.82);
  border: 1px dashed rgba(67, 50, 31, 0.2);
  border-radius: 12px;
  padding: 10px 12px;
  user-select: text;
  cursor: text;
}

.chat-attachment-debug-wrap {
  margin-top: 8px;
}

.chat-attachment-debug-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(67, 50, 31, 0.18);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 0.78rem;
  color: var(--text);
  background: rgba(255, 251, 245, 0.82);
  cursor: pointer;
}

.chat-attachment-debug-copy:active {
  transform: translateY(1px);
}

.chat-request-debug {
  border: 1px dashed rgba(67, 50, 31, 0.2);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 8px 0 0;
  background: rgba(255, 251, 245, 0.74);
  font-size: 0.84rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.chat-request-debug .debug-label {
  color: var(--text);
  font-weight: 600;
}

.chat-request-debug .debug-error {
  color: #d61f1f;
  width: 100%;
}

.chat-attachment-tile.full-width {
  grid-column: 1 / -1;
  width: 100%;
}

.chat-attachment-cover {
  width: 100%;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.35);
  cursor: pointer;
}

.chat-attachment-cover-thumb {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  margin-top: 8px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.3);
  cursor: pointer;
}

.cover-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 16, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 24px;
}

.cover-lightbox-image {
  max-width: min(720px, 90vw);
  max-height: 90vh;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.chat-error {
  color: #f87171;
  font-size: 12px;
}


.markdown-content p {
  margin: 0 0 8px;
}

.markdown-content p:last-child {
  margin-bottom: 0;
}

.chat-input {
  display: grid;
  gap: 8px;
}

#storyChatInput.drag-over {
  border-color: var(--accent-soft);
  background: rgba(111, 73, 55, 0.08);
}

.chat-image-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-deep);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.chat-image-preview.upload-error {
  border-color: var(--error, #c0392b);
  opacity: 0.7;
}

.chat-image-preview img {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.chat-image-preview #chatImageClear {
  margin-left: auto;
  font-size: 13px;
  padding: 2px 6px;
  min-width: 0;
}

.chat-message-media-thumb {
  display: block;
  max-width: 200px;
  max-height: 160px;
  object-fit: contain;
  border-radius: 8px;
  margin-bottom: 6px;
}

.chat-input textarea {
  min-height: 72px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(11, 17, 32, 0.8);
  color: var(--text);
  font-size: 13.5px;
}

#storyChatStop {
  display: none;
}

.token-indicator {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.token-indicator.low {
  color: #fca5a5;
}

.compact-prompt {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: rgba(127, 29, 29, 0.15);
  color: #fecaca;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
}

.compact-prompt.active {
  display: flex;
}

.compact-warning {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.12);
  color: #fef3c7;
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 12px;
}

.compact-warning.active {
  display: flex;
}

.v2-chapter-list {
  display: grid;
  gap: 0;
  min-width: 0;
  width: 100%;
}

.v2-chapter-index {
  display: none;
  gap: 0;
  width: 100%;
}

.v2-chapter-index.active {
  display: grid;
}

.v2-chapter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border: none;
  border-radius: 10px;
  background: none;
  cursor: pointer;
  font-size: 13px;
  min-width: 0;
  overflow-wrap: anywhere;
  width: 100%;
  margin-bottom: 2px;
  transition: background 0.15s ease;
}

.v2-chapter-item:hover {
  background: rgba(125, 211, 252, 0.06);
}

.v2-chapter-item.active {
  background: rgba(125, 211, 252, 0.1);
}

.v2-chapter-item .v2-chapter-status {
  margin-left: auto;
  flex-shrink: 0;
}

.v2-chapter-meta {
  display: grid;
  gap: 2px;
}

.v2-chapter-index {
  font-size: 12px;
  color: var(--muted);
}

.v2-chapter-title {
  font-size: 15px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.v2-chapter-status {
  color: rgba(125, 211, 252, 0.4);
  font-size: 13px;
}

.v2-chapter-empty {
  color: var(--muted);
  font-size: 13px;
}

.v2-chapter-reader {
  display: none;
  gap: 16px;
}

.v2-chapter-reader.active {
  display: grid;
}

.v2-reader-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.v2-reader-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.reader-back-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 16px;
  flex-shrink: 0;
  padding: 0;
}

.v2-reader-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.v2-reader-controls {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.v2-reader-body {
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 6px;
  font-family: var(--serif);
  font-size: var(--reader-font-size);
  line-height: 1.75;
}

.v2-reader-body p {
  margin: 0 0 18px;
}

.v2-reader-body p:last-child {
  margin-bottom: 0;
}

.v2-reader-footer {
  display: flex;
  justify-content: center;
  padding-top: 8px;
}

.v2-reader-footer:empty {
  display: none;
}

.reader-ctrl {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 13px;
  color: var(--muted);
  transition: color 0.15s, background 0.15s;
}

.reader-ctrl:hover {
  color: var(--text);
  background: rgba(125, 211, 252, 0.1);
}

.reader-ctrl svg {
  flex-shrink: 0;
}

.reader-font-wrap {
  position: relative;
}

.reader-font-popover {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 50%;
  transform: translateX(50%);
  background: rgba(251, 247, 239, 0.92);
  backdrop-filter: blur(16px) saturate(1.04);
  -webkit-backdrop-filter: blur(16px) saturate(1.04);
  border: 1px solid rgba(67, 50, 31, 0.18);
  border-radius: 14px;
  padding: 8px 10px;
  gap: 6px;
  align-items: center;
  z-index: 20;
  white-space: nowrap;
  box-shadow: 0 14px 28px rgba(73, 55, 36, 0.14);
}

.reader-font-popover.active {
  display: inline-flex;
}

.reader-font-label {
  font-size: 0.84rem;
  color: var(--accent);
  font-weight: 500;
  min-width: 36px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.v2-reader-editor {
  width: 100%;
  min-height: 320px;
  max-height: 65vh;
  resize: vertical;
  padding: 18px 20px;
  border-radius: 22px;
  border: 1px solid rgba(67, 50, 31, 0.16);
  background: linear-gradient(180deg, rgba(255, 251, 244, 0.9), rgba(255, 248, 238, 0.96));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  color: var(--text);
  font-family: var(--serif);
  font-size: var(--reader-font-size);
  line-height: 1.82;
}

.v2-reader-edit-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

.v2-reader-edit-status {
  font-size: 12px;
  color: var(--muted);
}

.fullscreen-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  position: relative;
}

.fullscreen-icon::before,
.fullscreen-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid currentColor;
  border-left: none;
  border-bottom: none;
  opacity: 0.9;
}

.fullscreen-icon::after {
  border: 2px solid currentColor;
  border-right: none;
  border-top: none;
}

.fullscreen-icon::before {
  transform: translate(-2px, -2px);
}

.fullscreen-icon::after {
  transform: translate(2px, 2px);
}

.reader-modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.82);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 32px 18px;
}

.reader-modal.active {
  display: flex;
}

.reader-modal-card {
  width: min(900px, 92vw);
  height: min(92vh, 920px);
  background: rgba(9, 14, 26, 0.96);
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 20px 24px;
  gap: 16px;
}

.reader-modal-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.reader-modal-title {
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.reader-modal-controls {
  display: flex;
  gap: 8px;
  justify-self: end;
}

.reader-modal-body {
  overflow-y: auto;
  padding-right: 8px;
  margin: 0 auto;
  width: min(720px, 90vw);
  font-family: var(--serif);
  font-size: var(--reader-font-size);
  line-height: 1.75;
}

.reader-modal-body p {
  margin: 0 0 18px;
}

.reader-modal-body p:last-child {
  margin-bottom: 0;
}

.reader-modal-footer {
  display: flex;
  justify-content: center;
}

.audio-manager-modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.82);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 55;
  padding: 32px 18px;
}

.audio-manager-modal.active {
  display: flex;
}

.audio-manager-card {
  width: min(560px, 92vw);
  max-height: min(92vh, 920px);
  background: rgba(9, 14, 26, 0.96);
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 20px 24px;
  gap: 16px;
}

.audio-manager-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.audio-manager-header .btn {
  font-size: 16px;
  line-height: 1;
  padding: 4px 10px;
}

.audio-manager-title {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  text-align: center;
}

.audio-manager-body {
  overflow-y: auto;
  display: grid;
  gap: 20px;
  padding-right: 4px;
}

.audio-manager-section {
  display: grid;
  gap: 8px;
}

.audio-manager-section-title {
  font-weight: 600;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.audio-manager-narrator-slot {
  display: grid;
  gap: 4px;
}

.btn-icon.audio-preview-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(12, 18, 32, 0.7);
  color: var(--muted);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  padding: 0;
}

.btn-icon.audio-preview-btn:hover {
  border-color: rgba(125, 211, 252, 0.5);
  color: var(--text);
  background: rgba(125, 211, 252, 0.12);
}

.audio-manager-char-row .btn-icon.audio-preview-btn {
  width: 28px;
  height: 28px;
  font-size: 10px;
}

.audio-manager-char-card {
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.25);
  border-radius: 12px;
  padding: 4px 10px;
  max-height: 240px;
  overflow-y: auto;
}

.audio-manager-char-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}
.audio-manager-char-row:last-of-type {
  border-bottom: none;
}
.audio-manager-char-name {
  font-weight: 500;
  font-size: 12px;
  min-width: 70px;
  flex-shrink: 0;
  color: var(--muted);
}
.audio-manager-char-help {
  font-size: 12px;
  color: var(--muted);
}

.audio-drama-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.audio-drama-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent, #7dd3fc);
}

.audio-manager-save-row {
  display: flex;
  justify-content: flex-end;
}

.audio-manager-save-row .btn {
  padding: 8px 24px;
  font-size: 13px;
  font-weight: 600;
}

.audio-manager-save-row .btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.audio-manager-admin-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.35);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--sans);
  transition: border-color 0.15s, color 0.15s;
}

.audio-manager-admin-toggle:hover {
  border-color: rgba(125, 211, 252, 0.35);
  color: var(--text);
}

.audio-manager-admin-chevron {
  font-size: 10px;
  transition: transform 0.2s ease;
  display: inline-block;
}

.audio-manager-admin-chevron.expanded {
  transform: rotate(90deg);
}

.audio-manager-admin-body {
  display: grid;
  gap: 10px;
  padding-top: 10px;
}

.audio-manager-admin-actions {
  display: flex;
  justify-content: flex-end;
}

.audio-manager-list {
  overflow-y: auto;
  display: grid;
  gap: 8px;
}

.audio-manager-row {
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}

.audio-manager-row-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 10px;
}

.audio-manager-row-title {
  font-weight: 600;
  font-size: 13px;
}

.audio-manager-row-meta {
  color: var(--muted);
  font-size: 11px;
}

.audio-manager-row-actions {
  display: flex;
  gap: 8px;
}

/* Voice Slot (clickable row for narrator / character) */
.voice-slot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.35);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.voice-slot:hover {
  border-color: rgba(125, 211, 252, 0.45);
  background: rgba(125, 211, 252, 0.06);
}

/* Compact voice slots inside character rows */
.audio-manager-char-row.voice-slot {
  padding: 6px 0;
  border: none;
  border-radius: 0;
  background: transparent;
}

.audio-manager-char-row.voice-slot:hover {
  background: rgba(125, 211, 252, 0.04);
}

.voice-slot-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.voice-slot-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.audio-manager-char-row .voice-slot-name {
  font-size: 13px;
}

.voice-slot-meta {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Voice Browser Panel (inside audio manager) */
.voice-browser-panel {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: grid;
  gap: 10px;
}

.voice-browser-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.voice-browser-label {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.voice-browser-close {
  font-size: 14px;
  padding: 2px 8px;
}

.voice-browser-footer {
  display: flex;
  justify-content: center;
}

.voice-browser-use-narrator {
  font-size: 13px;
  color: var(--muted);
}

.voice-browser-empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 20px 0;
}

/* Override filter chip vars for audio-manager context (which uses --line not --border) */
.voice-browser-panel .voice-filter-chip {
  border-color: var(--line);
  color: var(--muted);
}

.voice-browser-panel .voice-filter-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.voice-browser-panel .voice-filter-chip.active {
  background: rgba(125, 211, 252, 0.2);
  color: var(--text);
  border-color: var(--accent);
}

/* Override browser card styles for audio-manager context */
.voice-browser-panel .voice-browser-card {
  background: rgba(15, 23, 42, 0.35);
}

.voice-browser-panel .voice-browser-card:hover {
  background: rgba(15, 23, 42, 0.6);
}

.voice-browser-panel .voice-browser-avatar {
  background: rgba(15, 23, 42, 0.6);
}

.pronunciation-modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.82);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 56;
  padding: 32px 18px;
}

.pronunciation-modal.active {
  display: flex;
}

.pronunciation-card {
  width: min(520px, 92vw);
  max-height: min(80vh, 600px);
  background: rgba(9, 14, 26, 0.96);
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  display: grid;
  grid-template-rows: auto auto 1fr;
  padding: 16px 20px;
  gap: 12px;
}

.pronunciation-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.pronunciation-title {
  font-weight: 600;
  font-size: 15px;
  text-align: center;
}

.pronunciation-help {
  color: var(--muted);
  font-size: 12px;
}

.pronunciation-list {
  overflow-y: auto;
  padding-right: 4px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.pronunciation-row {
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.35);
  border-radius: 10px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 8px;
  align-items: center;
}

.pronunciation-row-fields {
  display: contents;
}

.pronunciation-row-fields input {
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

.pronunciation-row-actions {
  display: contents;
}

.pronunciation-row-actions .btn {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.pronunciation-row-status {
  color: var(--muted);
  font-size: 11px;
  grid-column: 1 / -1;
  min-height: 0;
}


.story-edit-modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.82);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 58;
  padding: 24px 16px;
}

.story-edit-modal.active {
  display: flex;
}

.story-edit-card {
  width: min(640px, 92vw);
  background: rgba(9, 14, 26, 0.96);
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  display: grid;
  gap: 16px;
  padding: 20px 22px;
}

.story-edit-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.story-edit-title {
  font-weight: 600;
  font-size: 15px;
}

.story-edit-body {
  display: grid;
  gap: 14px;
}

.story-edit-meta-fields {
  display: grid;
  gap: 12px;
}

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s, background 0.2s;
  pointer-events: none;
}

.toggle.on {
  background: rgba(168, 85, 247, 0.25);
  border-color: rgba(168, 85, 247, 0.5);
}

.toggle.on .toggle-thumb {
  transform: translateX(18px);
  background: #c084fc;
}

.toggle-label {
  font-size: 12px;
  color: var(--muted);
}

.field-toggle > span {
  margin-bottom: 4px;
}

.story-edit-footer {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

.story-edit-status {
  font-size: 12px;
  color: var(--muted);
}

.story-edit-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}


.mini-player {
  position: fixed;
  left: 18px;
  right: 18px;
  bottom: 18px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(20, 22, 26, 0.92);
  color: var(--text);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px 16px;
  align-items: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.32);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
}

.mini-player.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.mini-player-info {
  display: grid;
  gap: 2px;
}

.mini-player-title {
  font-weight: 600;
}

.mini-player-subtitle {
  font-size: 13px;
  color: var(--muted);
}

.mini-player-status {
  font-size: 12px;
  color: var(--muted);
}

.mini-player-controls .btn {
  padding: 8px 14px;
}

.mini-player-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.mini-player-close {
  font-size: 14px;
  padding: 6px 10px;
  align-self: start;
}

.mini-player-select {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 12px;
  padding: 6px 28px 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.mini-player-select:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 2px;
}

.mini-player-speed {
  position: relative;
}

.mini-player-speed::after {
  content: "▾";
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--muted);
  pointer-events: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.mini-player-scrubber {
  position: relative;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 6px;
}

.mini-player-range {
  width: 100%;
}

.mini-player-time {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 96px;
  text-align: right;
}

.mini-player-overlay {
  display: none;
}

.mini-player.buffering .mini-player-range {
  animation: scrubber-pulse 1.5s ease-in-out infinite;
}

@keyframes scrubber-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@media (max-width: 900px) {
  .mini-player {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
}

.v2-timeline-view {
  display: none;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.v2-timeline-view.active {
  display: grid;
}

.v2-search-view {
  display: none;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.v2-search-view.active {
  display: grid;
}

.v2-search-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
}

.v2-search-actions {
  display: grid;
  grid-auto-flow: column;
  gap: 8px;
}

.v2-search-bar input,
.v2-search-bar select,
.v2-search-options input {
  background: rgba(11, 15, 26, 0.8);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}

.v2-search-options {
  display: grid;
  gap: 8px;
}

.v2-search-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.v2-search-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.v2-search-toggle input {
  accent-color: #60a5fa;
}

.v2-search-status {
  font-size: 12px;
  color: var(--muted);
}

.v2-search-results {
  display: grid;
  gap: 10px;
  min-width: 0;
  width: 100%;
}

.v2-search-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: rgba(9, 14, 26, 0.85);
  display: grid;
  gap: 6px;
  cursor: pointer;
  min-width: 0;
  overflow-wrap: anywhere;
  width: 100%;
}

.v2-search-title {
  font-weight: 600;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.v2-search-meta {
  font-size: 11px;
  color: var(--muted);
}

.v2-search-meta .v2-search-replaced {
  color: #86efac;
  font-weight: 600;
}

.v2-search-snippet {
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.v2-search-snippet mark {
  background: rgba(253, 230, 138, 0.35);
  color: inherit;
  padding: 0 2px;
  border-radius: 4px;
}

.v2-timeline-list {
  display: grid;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.v2-timeline-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: rgba(9, 14, 26, 0.85);
  display: grid;
  gap: 10px;
  cursor: pointer;
}

.v2-timeline-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 12px;
  align-items: center;
}

.v2-timeline-title {
  font-weight: 600;
  font-size: 13px;
}

.v2-timeline-meta {
  font-size: 11px;
  color: var(--muted);
}

.v2-timeline-toggle {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
  justify-self: end;
}

.v2-timeline-summary {
  font-size: 13px;
  color: var(--muted);
}

.v2-timeline-detail {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.v2-timeline-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.v2-timeline-editor {
  min-height: 100px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(6, 10, 22, 0.8);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.9;
  overflow: hidden;
  font-family: var(--serif);
}

.v2-timeline-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.v2-timeline-status {
  font-size: 12px;
  color: var(--muted);
}

.v2-timeline-error,
.v2-timeline-empty {
  font-size: 13px;
  color: var(--muted);
}

.v2-store-view {
  display: none;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.v2-store-view.active {
  display: grid;
}

.v2-media-view {
  display: none;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  width: 100%;
  overflow-y: auto;
  padding-bottom: 12px;
}

.v2-media-view.active {
  display: flex;
}

.v2-media-panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}

.media-panel-item {
  display: flex;
  flex-direction: column;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel-solid);
}

.media-panel-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.media-panel-item-placeholder {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  padding: 8px;
  word-break: break-all;
}

.media-panel-item-footer {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.media-panel-item-name {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-panel-item-actions {
  display: flex;
  gap: 4px;
}

.media-panel-item-copy,
.media-panel-item-delete {
  font-size: 11px;
  padding: 2px 6px;
}

.v2-media-panel-empty {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 0;
}

.v2-media-panel-upload {
  padding-top: 4px;
}

.v2-media-panel-upload-btn {
  cursor: pointer;
  font-size: 13px;
}

.v2-store-list {
  display: grid;
  gap: 12px;
  min-width: 0;
  width: 100%;
}

.v2-store-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: rgba(9, 14, 26, 0.85);
  display: grid;
  gap: 10px;
  min-width: 0;
  overflow-wrap: anywhere;
  width: 100%;
}

.v2-store-header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 6px 12px;
  align-items: start;
}

.v2-store-title {
  font-weight: 600;
  font-size: 13px;
  overflow-wrap: anywhere;
  grid-column: 1 / 2;
  cursor: pointer;
}

.v2-store-meta {
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
  grid-column: 1 / 2;
  grid-row: 2 / 3;
  min-width: 0;
}

.v2-store-delete {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
  justify-self: end;
  align-self: start;
  grid-column: 2 / 3;
  grid-row: 1 / 2;
  white-space: nowrap;
}

.v2-store-summary {
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
  cursor: pointer;
}

.v2-store-detail {
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  min-width: 0;
}

.v2-store-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.v2-store-editor {
  min-height: 100px;
  resize: vertical;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(6, 10, 22, 0.8);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.9;
  overflow: hidden;
  font-family: var(--serif);
  overflow-wrap: anywhere;
}

.v2-store-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.v2-store-status {
  font-size: 12px;
  color: var(--muted);
}

.v2-store-error,
.v2-store-empty {
  font-size: 13px;
  color: var(--muted);
}

.v2-chapter-reader.reader-fade-in {
  animation: readerFade 0.4s ease-out;
}

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

@media (max-width: 900px) {
  .story-body.v2-layout {
    grid-template-columns: 1fr;
  }
  .story-body.v2-layout.chat-collapsed {
    grid-template-columns: 1fr;
  }
  .story-body.v2-layout.chapter-collapsed {
    grid-template-columns: 1fr;
  }
  .v2-splitter {
    display: none;
  }
  .chat {
    max-height: 46vh;
  }
}

/* View header */
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.view-header h2 {
  margin: 0;
  font-size: 20px;
}

.view-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin: 2px 0 0;
}

/* Empty states */
.library-empty,
.explore-empty,
.bookshelf-empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
}

.library-empty p,
.explore-empty p,
.bookshelf-empty p {
  margin: 12px 0 16px;
  font-size: 14px;
}

/* Explore story view */
.explore-story { display: none; }
.explore-story.active { display: block; }
.explore-layout {
  display: block;
}
.explore-chapter-panel {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  background: none;
  border: none;
  padding: 0;
}

/* Hide story header when reading in explore */
.explore-story.reader-active .story-header {
  display: none;
}

/* Hide checkmarks in explore (all published chapters are complete) */
.explore-chapter-panel .v2-chapter-status {
  display: none;
}

/* Explore reader — immersive, no modal look */
.explore-chapter-panel .v2-chapter-reader {
  gap: 0;
}
.explore-chapter-panel .v2-reader-header {
  border-bottom: none;
  padding: 0 0 20px;
  flex-wrap: wrap;
  gap: 8px;
}
.explore-chapter-panel .v2-reader-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  flex: 1 1 100%;
  order: 2;
}
.explore-chapter-panel .v2-reader-header .btn {
  order: 1;
}
.explore-chapter-panel .v2-reader-controls {
  order: 1;
  margin-left: auto;
}
.explore-chapter-panel .v2-reader-body {
  max-height: none;
  overflow-y: visible;
  padding: 0;
  font-size: var(--reader-font-size, 18px);
  line-height: 1.85;
  color: rgba(226, 232, 240, 0.92);
}
.explore-chapter-panel .v2-reader-body p {
  margin: 0 0 24px;
}
.explore-chapter-panel .v2-reader-footer {
  padding-top: 32px;
  padding-bottom: 40px;
}
.explore-chapter-panel .v2-reader-footer .btn {
  font-size: 15px;
  padding: 10px 24px;
  border-radius: 12px;
  border: 1px solid rgba(125, 211, 252, 0.3);
  background: rgba(125, 211, 252, 0.08);
}

/* Story Home Page */
.story-home {
  display: none;
}
.story-home.active {
  display: block;
}
.story-home-main {
  max-width: 900px;
  margin: 0 auto;
  display: grid;
  gap: 32px;
}
.story-home-nav {
  margin-bottom: 8px;
}
.story-home-hero {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 32px;
  align-items: start;
}
.story-home-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.35);
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}
.story-home-info {
  display: grid;
  gap: 12px;
  align-content: start;
}
.story-home-title {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
}
.story-home-meta-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 13px;
  color: var(--muted);
}
.story-home-meta-label {
  opacity: 0.55;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  font-weight: 600;
}
.story-home-meta-sep {
  width: 1px;
  height: 14px;
  background: var(--line);
  flex-shrink: 0;
}
.story-home-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.story-home-badge {
  display: inline-flex;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(9, 14, 26, 0.7);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.03em;
}
.story-home-rating-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}
.story-home-stars {
  display: inline-flex;
  gap: 2px;
}
.story-home-star {
  color: #fbbf24;
  font-size: 18px;
  line-height: 1;
}
.story-home-star.empty {
  opacity: 0.25;
}
.story-home-synopsis {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}
.story-home-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.story-home-actions-secondary {
  display: flex;
  gap: 10px;
}
.story-home-cta {
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 600;
}
.story-home-listen {
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid rgba(125, 211, 252, 0.3);
  background: rgba(125, 211, 252, 0.08);
}
.story-home-listen:hover {
  border-color: rgba(125, 211, 252, 0.5);
  background: rgba(125, 211, 252, 0.15);
}
.story-home-divider {
  height: 1px;
  background: var(--line);
}
.story-home-reviews h3 {
  margin: 0 0 16px;
  font-size: 18px;
}

/* Review form */
.story-home-review-form {
  margin-bottom: 20px;
}
.review-form-inner {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(12, 18, 32, 0.6);
}
.review-form-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}
.review-star-selector {
  display: inline-flex;
  gap: 4px;
}
.review-star-selector .star-btn {
  background: none;
  border: none;
  color: #fbbf24;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  opacity: 0.25;
  transition: opacity 0.15s ease;
}
.review-star-selector .star-btn.active {
  opacity: 1;
}
.review-star-selector .star-btn:hover {
  opacity: 0.8;
}
.review-textarea {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(8, 12, 24, 0.7);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}
.review-form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.review-form-status {
  font-size: 12px;
  color: var(--muted);
}

/* Review cards */
.story-home-review-list {
  display: grid;
  gap: 12px;
}
.review-card {
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(12, 18, 32, 0.6);
  display: grid;
  gap: 8px;
}
.review-card.own {
  border-color: rgba(125, 211, 252, 0.4);
}
.review-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.review-card-stars {
  display: inline-flex;
  gap: 2px;
}
.review-card-star {
  color: #fbbf24;
  font-size: 14px;
  line-height: 1;
}
.review-card-star.empty {
  opacity: 0.25;
}
.review-card-date {
  font-size: 12px;
  color: var(--muted);
}
.review-card-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.6;
}
.review-card-actions {
  display: flex;
  gap: 8px;
}
.story-home-review-empty {
  color: var(--muted);
  font-size: 14px;
}

/* Explore grid card rating */
.story-card-rating {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.story-card-rating .story-home-stars {
  gap: 1px;
}
.story-card-rating .story-home-star {
  font-size: 13px;
}

/* Bookshelf save button */
.story-home-save {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: rgba(12, 18, 32, 0.7);
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 999px;
}
.story-home-save:hover {
  border-color: rgba(74, 222, 128, 0.5);
  background: rgba(74, 222, 128, 0.08);
}
.story-home-save.saved {
  border-color: rgba(74, 222, 128, 0.6);
  background: rgba(74, 222, 128, 0.15);
  color: #4ade80;
}
.story-home-fork {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: rgba(12, 18, 32, 0.7);
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 999px;
}
.story-home-fork:hover {
  border-color: rgba(167, 139, 250, 0.5);
  background: rgba(167, 139, 250, 0.08);
}

/* Bookshelf empty state */
.bookshelf-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
}
.bookshelf-empty p {
  margin: 8px 0 0;
  font-size: 14px;
}

@media (max-width: 900px) {
  .story-home-hero {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .story-home-cover {
    max-width: 220px;
  }
  .story-home-badges {
    justify-content: center;
  }
  .story-home-meta-line {
    justify-content: center;
  }
  .story-home-actions {
    grid-template-columns: 1fr;
  }
  .story-home-actions-secondary {
    justify-content: center;
  }
  .story-home-rating-summary {
    justify-content: center;
  }
}

/* Thread selector */
.chat-thread-selector {
  position: relative;
}
.chat-thread-current {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 8px;
  transition: background 0.15s, border-color 0.15s;
  max-width: 280px;
}
.chat-thread-current:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(125, 211, 252, 0.3);
}
.chat-thread-current span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-thread-arrow {
  font-size: 11px;
  opacity: 0.7;
  flex-shrink: 0;
}
.chat-thread-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  min-width: 260px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 4px 0;
}
.chat-thread-dropdown.active {
  display: block;
}
.chat-thread-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.1s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--text);
}
.chat-thread-item:hover {
  background: rgba(255, 255, 255, 0.06);
}
.chat-thread-item.active {
  background: rgba(125, 211, 252, 0.1);
  font-weight: 600;
}
.chat-thread-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-thread-item-date {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}
.chat-thread-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}
.chat-thread-new {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  text-align: left;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.1s;
}
.chat-thread-new:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* --- Profile --- */

.profile-edit-modal {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.82);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px 16px;
}

.profile-edit-modal.active {
  display: flex;
}

.profile-edit-card {
  width: min(620px, 94vw);
  background: rgba(9, 14, 26, 0.96);
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  display: grid;
  gap: 16px;
  padding: 20px 22px;
  max-height: 92vh;
}

.profile-edit-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.profile-edit-title {
  font-weight: 600;
  font-size: 15px;
}

.profile-edit-header .btn {
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
}

.profile-edit-body {
  display: grid;
  gap: 16px;
  overflow-y: auto;
  padding-right: 2px;
}

.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.profile-avatar-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(148, 163, 184, 0.12);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

.profile-avatar-upload {
  cursor: pointer;
  font-size: 13px;
}

.profile-field {
  display: grid;
  gap: 6px;
}

.profile-field-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.profile-field input,
.profile-field textarea {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.profile-field input:focus,
.profile-field textarea:focus {
  border-color: var(--accent);
}

.profile-field textarea {
  resize: vertical;
  min-height: 72px;
}

#profileEditDirectorNotes {
  min-height: 180px;
  line-height: 1.45;
  font-family: "IBM Plex Sans", var(--sans);
}

.profile-director-hint {
  margin: -4px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.profile-edit-footer {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
}

.profile-edit-status {
  font-size: 12px;
  color: var(--muted);
}

.profile-edit-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.author-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  background-color: rgba(148, 163, 184, 0.15);
  flex-shrink: 0;
}

.author-avatar-sm {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  background-color: rgba(148, 163, 184, 0.15);
  flex-shrink: 0;
}

.story-card-author {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.story-home-author {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
}

.review-card-author {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  margin-left: 6px;
}

/* Voice Browser (used by audio manager) */

.voice-browser-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding: 4px;
}

.voice-browser-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 6px;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}

.voice-browser-card:hover {
  background: var(--surface-raised, #2a2a3e);
}

.voice-browser-card.selected {
  border-color: var(--accent);
}

.voice-browser-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-raised, #2a2a3e);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.voice-browser-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.voice-browser-meta {
  font-size: 9px;
  color: var(--text-muted);
  margin-top: 2px;
}

.voice-browser-filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

/* Editorial redesign */

.main {
  padding: 12px 18px 22px;
}



.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 0 10px;
  border-bottom: 1px solid rgba(67, 50, 31, 0.1);
  margin-bottom: 8px;
  min-height: auto;
}

#sidebarToggle,
.story-back-btn,
.reader-back-btn,
.story-edit-btn,
.reader-ctrl,
.chat-new-thread-btn,
.chat-thread-current,
.chat-model-menu .btn,
.chat-thread-item,
.chat-thread-new,
.btn-icon.audio-preview-btn,
.audio-manager-header .btn,
.profile-edit-header .btn,
.voice-browser-close {
  border-radius: 14px;
}

#sidebarToggle {
  border-color: var(--line);
  background: rgba(255, 251, 245, 0.76);
  color: var(--accent);
}

.sidebar-header,
.sidebar-footer,
.story-header,
.v2-chat-panel .panel-header,
.v2-chapter-panel .panel-header,
.v2-reader-header,
.audio-manager-header,
.story-edit-header,
.profile-edit-header,
.pronunciation-header,
.reader-modal-header {
  border-color: rgba(67, 50, 31, 0.12);
}

.sidebar-new-story,
.btn.primary,
.story-home-cta,
.story-home-listen,
.mini-player-controls .btn {
  border-radius: 999px;
}

.sidebar-nav-btn,
.sidebar-footer-btn {
  justify-content: flex-start;
  padding: 11px 12px;
  box-shadow: none;
}

.sidebar-nav-btn.active,
.sidebar-nav-btn:hover,
.sidebar-footer-btn:hover {
  background: rgba(255, 251, 245, 0.7);
  color: var(--text);
}

.sidebar-library-label,
.auth-form label,
.audio-manager-section-title,
.v2-timeline-label,
.chat-summary-label,
.voice-browser-label,
.review-form-label {
  color: var(--accent);
  font-size: 0.74rem;
  letter-spacing: 0.08em;
}

.story-list {
  display: grid;
  gap: 8px;
}

.story-list .btn,
.story-list button {
  justify-content: flex-start;
}

.dashboard-main,
.story-main,
.story-home-main {
  gap: 20px;
}

.story-main {
  display: grid;
}

.view-header h2,
.story-header h2,
.story-home-title,
.story-edit-title,
.profile-edit-title,
.audio-manager-title,
.reader-modal-title,
.pronunciation-title {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.015em;
}

.view-header h2 {
  margin: 0;
  font-size: 1px;
  line-height: 0.98;
  opacity: 0;
  pointer-events: none;
  height: 0;
  overflow: hidden;
}

.view-subtitle,
.story-meta,
.story-card-meta,
.story-card-stat,
.story-card-date,
.audio-manager-row-meta,
.review-card-date,
.story-home-meta-line,
.story-home-synopsis,
.profile-field-help,
.toggle-label,
.chat-model-current,
.chat-pipeline-desc,
.story-edit-status,
.profile-edit-status,
.v2-search-meta,
.v2-timeline-meta,
.v2-timeline-summary,
.v2-search-status,
.v2-timeline-status,
.audio-manager-char-help,
.voice-browser-meta {
  color: var(--muted);
}

.story-grid {
  gap: 18px;
}

.story-card,
.story-card-horizontal,
.v2-chat-panel,
.v2-chapter-panel,
.v2-search-card,
.v2-timeline-card,
.v2-store-card,
.review-card,
.review-form-inner,
.story-home-save,
.story-home-fork,
.chat-thread-dropdown,
.chat-model-menu,
.reader-modal-card,
.audio-manager-card,
.story-edit-card,
.profile-edit-card,
.pronunciation-card,
.voice-browser-panel,
.chat-summary {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
}

.story-card,
.story-card-horizontal,
.v2-chat-panel,
.v2-chapter-panel,
.reader-modal-card,
.audio-manager-card,
.story-edit-card,
.profile-edit-card,
.pronunciation-card,
.voice-browser-panel {
  border-radius: 22px;
}

.story-card:hover,
.story-card-horizontal:hover,
.v2-search-card:hover,
.v2-timeline-card:hover,
.voice-browser-card:hover,
.audio-manager-char-row.voice-slot:hover {
  border-color: rgba(111, 73, 55, 0.36);
  transform: translateY(-2px);
}

.story-card-cover,
.story-card-horizontal .story-card-cover-sm,
.story-home-cover,
.story-cover,
.story-cover.large {
  border: 0;
  box-shadow: none;
}

.story-card-body,
.story-card-horizontal .story-card-body {
  padding: 14px 14px 16px;
  gap: 7px;
}

.story-card h3,
.story-card-horizontal h3,
.mini-title,
.story-home-reviews h3 {
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.015em;
}

.story-card h3,
.story-card-horizontal h3 {
  font-size: 1.28rem;
}

.badge,
.story-home-badge {
  background: rgba(111, 73, 55, 0.08);
  color: var(--accent);
  border: 1px solid rgba(111, 73, 55, 0.18);
}

.badge-drama {
  background: rgba(160, 123, 91, 0.12);
  color: var(--accent);
  border-color: rgba(111, 73, 55, 0.2);
}

.story-card-premise,
.story-card p,
.chat-message,
.chat-summary,
.review-card-text,
.v2-search-snippet,
.v2-reader-body,
.reader-modal-body,
.v2-reader-editor,
.v2-timeline-editor,
.review-textarea,
.story-edit-body textarea,
.profile-field textarea {
  font-family: var(--serif);
}

.story-header {
  align-items: start;
  gap: 14px;
  margin-bottom: 14px;
  padding: 0 0 14px;
}

.story-title-row h2,
.story-home-title {
  font-size: clamp(2.8rem, 4.5vw, 4.3rem);
  line-height: 0.96;
}

.story-actions .btn,
.story-actions button,
.story-home-actions .btn,
.story-home-actions-secondary .btn {
  min-height: 42px;
}

.story-body.v2-layout {
  grid-template-columns: minmax(0, 1.02fr) 4px minmax(0, 1fr);
  column-gap: 4px;
  margin-top: 12px;
  height: 100dvh;
  min-height: 100dvh;
  align-items: stretch;
  overflow: hidden;
}

.v2-chat-panel,
.v2-chapter-panel {
  padding: 12px;
  min-height: 0;
  height: 100%;
  gap: 0;
  overflow: hidden;
}

.v2-chat-panel {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.v2-chapter-panel {
  grid-template-rows: auto minmax(0, 1fr);
}

.panel-header.panel-tabs {
  padding: 2px 0 10px;
  background: transparent;
  border: 0;
  border-radius: 0;
  gap: 8px;
  overflow-x: auto;
}

.panel-tab {
  flex: 0 0 auto;
  padding: 6px 2px;
  border-radius: 0;
  border-bottom: 1px solid transparent;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.panel-tab.active {
  background: transparent;
  color: var(--text);
  border-bottom-color: var(--accent);
}

.chat {
  gap: 10px;
  min-height: 0;
  max-height: none;
  height: 100%;
  overflow-y: auto;
  padding-bottom: 6px;
}

.chat-message {
  padding: 11px 14px;
  border-radius: 16px;
  background: rgba(255, 250, 243, 0.7);
  border: 1px solid rgba(67, 50, 31, 0.14);
  max-width: 88%;
  font-size: 1rem;
  line-height: 1.62;
}

.chat-message.assistant {
  width: 100%;
  max-width: none;
  padding: 2px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  align-self: stretch;
  font-family: var(--sans);
}

.chat-message.assistant h1,
.chat-message.assistant h2,
.chat-message.assistant h3,
.chat-message.assistant h4 {
  font-family: var(--display);
  font-weight: 700;
  line-height: 1.25;
  margin: 0.75em 0 0.25em;
}

.chat-message.assistant h1 { font-size: 1.15rem; }
.chat-message.assistant h2 { font-size: 1.05rem; }
.chat-message.assistant h3 { font-size: 0.95rem; }
.chat-message.assistant h4 { font-size: 0.9rem; }

.chat-message.user {
  background: rgba(111, 73, 55, 0.08);
  border-color: rgba(111, 73, 55, 0.22);
  align-self: flex-end;
}

.chat-message.assistant.chat-highlight {
  padding: 11px 14px;
  width: auto;
  max-width: 88%;
  border: 1px solid rgba(111, 73, 55, 0.28);
  border-radius: 16px;
  background: rgba(111, 73, 55, 0.08);
  align-self: flex-start;
}

.chat-message.assistant.typing-indicator {
  width: fit-content;
  max-width: none;
  padding: 10px 12px;
  border: 1px solid rgba(67, 50, 31, 0.14);
  border-radius: 16px;
  background: rgba(255, 248, 238, 0.9);
  align-self: flex-start;
}

.story-title-wrap {
  min-width: 0;
  align-content: center;
}

.story-meta {
  line-height: 1.45;
}

.story-actions {
  position: relative;
  justify-self: end;
}

.story-menu {
  position: relative;
}

.story-menu-toggle {
  min-width: 44px;
  padding: 0 14px;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
}

.story-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  padding: 8px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow: var(--shadow-soft);
  display: none;
  z-index: 25;
}

.story-menu-dropdown.active {
  display: grid;
}

.story-menu-item {
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-family: var(--serif);
  font-size: 0.98rem;
  cursor: pointer;
}

.story-menu-item:hover {
  background: rgba(111, 73, 55, 0.08);
}

.story-menu-item-danger {
  color: #d61f1f;
  font-weight: 600;
}

.story-menu-item-danger:hover {
  background: rgba(214, 31, 31, 0.12);
}

.chat-input textarea,
.review-textarea,
.story-edit-body textarea,
.story-edit-body input,
.story-edit-body select,
.profile-field input,
.profile-field textarea,
.chat-model-menu input,
.chat-model-menu select,
.v2-search-bar input,
.v2-search-bar select,
.v2-search-options input,
.v2-timeline-editor,
.mini-player-select {
  background: rgba(255, 255, 255, 0.64);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  color: var(--text);
  padding: 11px 13px;
}

.chat-input textarea {
  min-height: 110px;
}

.token-indicator,
.compact-warning,
.compact-prompt {
  font-size: 0.82rem;
}

.compact-warning,
.compact-prompt {
  background: rgba(111, 73, 55, 0.08);
  color: var(--accent);
  border-color: rgba(111, 73, 55, 0.2);
}

.v2-reader-header {
  padding-bottom: 14px;
}

.v2-reader-title,
.reader-modal-title {
  font-family: var(--display);
  font-size: 1.8rem;
  color: var(--text);
}

.v2-reader-body,
.reader-modal-body {
  color: var(--text);
  font-size: var(--reader-font-size);
  line-height: 1.86;
}

.v2-chapter-index,
.v2-timeline-view,
.v2-search-view,
.v2-store-view,
.v2-chapter-reader {
  min-height: 0;
  height: 100%;
}

.v2-chapter-index.active,
.v2-timeline-view.active,
.v2-search-view.active,
.v2-store-view.active,
.v2-chapter-reader.active {
  display: grid;
}

.v2-chapter-index.active,
.v2-timeline-view.active,
.v2-store-view.active {
  align-content: start;
  overflow-y: auto;
  padding-right: 4px;
}

.v2-search-view.active {
  grid-template-rows: auto auto auto minmax(0, 1fr);
  overflow: hidden;
}

.v2-director-view.active {
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  padding-right: 0;
}

.v2-chapter-reader.active {
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
  overflow: hidden;
}

.v2-search-results,
.v2-reader-body {
  min-height: 0;
}

.v2-search-results {
  overflow-y: auto;
  padding-right: 4px;
}

.v2-reader-body {
  max-height: none;
  height: 100%;
  overflow-y: auto;
}

.v2-chat {
  padding-top: 0;
}

.v2-reader-body,
.v2-chapter-index.active,
.v2-timeline-view.active,
.v2-store-view.active,
.v2-search-results {
  padding-top: 0;
}

.v2-director-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  min-height: 0;
  height: 100%;
  padding: 22px 24px;
  border: 1px solid rgba(67, 50, 31, 0.14);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 251, 244, 0.82), rgba(255, 248, 238, 0.94));
  box-shadow: 0 18px 40px rgba(73, 55, 36, 0.08);
}

.v2-director-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.v2-director-title {
  font-family: var(--display);
  font-size: 1.8rem;
  line-height: 0.96;
  color: var(--text);
}

.v2-director-subtitle {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.55;
  max-width: 46ch;
}

.v2-director-editor {
  width: 100%;
  min-height: 280px;
  height: 100%;
  resize: vertical;
  padding: 18px 20px;
  border-radius: 22px;
  border: 1px solid rgba(67, 50, 31, 0.16);
  background: linear-gradient(180deg, rgba(255, 251, 244, 0.9), rgba(255, 248, 238, 0.96));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.02rem;
  line-height: 1.82;
}

.v2-director-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.v2-director-status {
  font-size: 0.84rem;
  color: var(--muted);
}

.chat-input,
.v2-reader-footer {
  margin-top: 10px;
}

.v2-reader-next-inline {
  display: flex;
  justify-content: center;
  padding: 28px 0 8px;
}

.reader-ctrl,
.splitter-toggle,
.story-edit-btn,
.reader-back-btn,
.story-back-btn {
  background: rgba(255, 251, 245, 0.7);
  border: 1px solid var(--line);
  color: var(--accent);
}

.chat-thread-current,
.v2-search-toggle,
.audio-manager-admin-toggle,
.v2-timeline-toggle {
  background: rgba(255, 251, 245, 0.7);
  border-color: var(--line);
  color: var(--muted);
}

.chat-thread-dropdown,
.chat-model-menu {
  padding: 14px;
}

.reader-modal,
.audio-manager-modal,
.story-edit-modal,
.profile-edit-modal,
.pronunciation-modal {
  background: rgba(236, 226, 209, 0.42);
  backdrop-filter: blur(12px);
}

.audio-manager-body,
.profile-edit-body,
.pronunciation-body {
  gap: 18px;
}

.audio-manager-narrator-slot,
.audio-manager-char-card,
.audio-manager-row,
.voice-browser-card,
.story-edit-section,
.profile-section,
.v2-search-card,
.v2-timeline-card,
.v2-store-card {
  border-radius: 16px;
}

.voice-browser-card.selected,
.audio-manager-char-row.voice-slot.selected,
.audio-manager-char-card.selected {
  border-color: rgba(111, 73, 55, 0.4);
  box-shadow: inset 0 0 0 1px rgba(111, 73, 55, 0.12);
}

.story-home-main {
  gap: 26px;
}

.story-home-hero {
  align-items: start;
  gap: 24px;
}

.story-home-synopsis {
  font-size: 1.06rem;
  line-height: 1.72;
}

.review-card,
.review-form-inner {
  padding: 18px;
}

.explore-layout .story-header,
.story-home-nav {
  margin-bottom: 8px;
}

.mini-player {
  border: 1px solid var(--line);
  background: rgba(255, 250, 243, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
}

.mini-player-title {
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 600;
}

.mini-player-subtitle,
.mini-player-status,
.mini-player-time {
  color: var(--muted);
}

.progress-bar,
.story-card-progress .progress-bar,
.mini-player-range,
.range {
  background: rgba(111, 73, 55, 0.12);
}

.progress-fill {
  background: linear-gradient(90deg, #6f4937, #b88962);
}

.auth-card,
.story-card,
.story-card-horizontal,
.v2-chat-panel,
.v2-chapter-panel,
.reader-modal-card,
.audio-manager-card,
.story-edit-card,
.profile-edit-card,
.pronunciation-card,
.voice-browser-panel,
.story-home-cover,
.story-cover,
.story-cover.large,
.review-card,
.review-form-inner {
  position: relative;
}

.auth-card::before,
.story-card::before,
.story-card-horizontal::before,
.reader-modal-card::before,
.audio-manager-card::before,
.story-edit-card::before,
.profile-edit-card::before,
.pronunciation-card::before,
.voice-browser-panel::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(67, 50, 31, 0.08);
  border-radius: calc(var(--radius) - 4px);
  pointer-events: none;
}

.story-card::before,
.story-card-horizontal::before {
  content: none;
}

.v2-chat-panel::before,
.v2-chapter-panel::before {
  content: none;
}

@media (max-width: 1100px) {
  .shell {
    grid-template-columns: 220px 1fr;
  }

  .story-body.v2-layout,
  .story-body.v2-layout.reader-active {
    grid-template-columns: 1fr;
    row-gap: 14px;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .v2-splitter {
    display: none;
  }

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

  .v2-chat-panel,
  .v2-chapter-panel,
  .chat,
  .v2-chapter-index.active,
  .v2-timeline-view.active,
  .v2-search-view.active,
  .v2-store-view.active,
  .v2-chapter-reader.active,
  .v2-reader-body,
  .v2-search-results {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 760px) {
  .main {
    padding: 10px 14px 18px;
  }

  .sidebar {
    padding: 14px 12px;
  }

  .view-header h2,
  .story-title-row h2,
  .story-home-title {
    font-size: clamp(2.2rem, 8vw, 3.4rem);
  }

  .story-header {
    flex-wrap: wrap;
    align-items: start;
  }

  .story-actions {
    margin-left: auto;
  }

  .story-grid {
    grid-template-columns: 1fr;
  }

  .story-card-horizontal {
    grid-template-columns: 84px 1fr;
  }

  .story-card-horizontal .story-card-cover-sm {
    width: 84px;
  }

  .story-home-hero {
    grid-template-columns: 1fr;
  }
}

/* Editorial refinement pass */

.chat-model-menu {
  top: 54px;
  right: 8px;
  width: min(420px, calc(100vw - 40px));
  max-height: min(76vh, 720px);
  overflow: auto;
  padding: 14px 14px 12px;
  gap: 10px;
  background: rgba(251, 247, 239, 0.88);
  backdrop-filter: blur(18px) saturate(1.05);
  -webkit-backdrop-filter: blur(18px) saturate(1.05);
  border: 1px solid rgba(67, 50, 31, 0.18);
  box-shadow:
    0 18px 42px rgba(73, 55, 36, 0.14),
    inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.chat-model-menu-header {
  font-family: var(--display);
  font-size: 1.35rem;
  line-height: 0.98;
  color: var(--text);
}

.chat-model-current {
  font-size: 0.84rem;
  line-height: 1.4;
  max-width: 38ch;
}

.chat-model-menu .field,
.story-edit-body .field,
.profile-field {
  display: grid;
  gap: 8px;
}

.chat-model-menu .field > span,
.story-edit-body .field > span {
  color: var(--accent);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-model-menu input,
.chat-model-menu select {
  min-height: 46px;
  font-size: 0.98rem;
}

.chat-pipeline-section {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top-color: rgba(67, 50, 31, 0.12);
}

.v2-search-toggle input,
.audio-drama-toggle input[type="checkbox"] {
  accent-color: #6f4937;
}

.chat-model-menu input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.chat-agent-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 8px;
}

.chat-agent-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(67, 50, 31, 0.12);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.52);
  line-height: 1.25;
}

.chat-agent-item:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.chat-agent-item input {
  margin-top: 0;
  flex-shrink: 0;
}

.chat-agent-desc {
  display: none;
}

#exploreView2 .story-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 320px));
  justify-content: start;
}

#exploreView2 .story-card {
  max-width: 320px;
}

#bookshelfView .story-grid {
  max-width: 760px;
  gap: 14px;
}

.story-card-body,
.story-card-horizontal .story-card-body {
  gap: 10px;
}

.story-card h3 {
  font-size: 1.14rem;
  line-height: 1.08;
}

#exploreView2 .story-card h3 {
  font-size: 1.28rem;
}

.story-card-premise {
  font-size: 0.98rem;
  line-height: 1.6;
  -webkit-line-clamp: 3;
}

.story-card-horizontal {
  grid-template-columns: 128px minmax(0, 1fr);
}

.story-card-horizontal .story-card-cover-sm {
  width: 128px;
  min-height: 146px;
  border-radius: 22px 0 0 22px;
}

.story-card-horizontal h3 {
  font-size: 1.26rem;
  line-height: 1.06;
}

.story-card-progress {
  margin-top: 4px;
}

.story-edit-card,
.profile-edit-card,
.pronunciation-card,
.audio-manager-card {
  max-height: 90vh;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: 22px 24px 20px;
  gap: 18px;
}

.story-edit-card {
  width: min(780px, 94vw);
}

.profile-edit-card {
  width: min(760px, 94vw);
}

.pronunciation-card {
  width: min(860px, 94vw);
}

.audio-manager-card {
  width: min(860px, 94vw);
  grid-template-rows: auto minmax(0, 1fr);
}

.story-edit-title,
.profile-edit-title,
.pronunciation-title,
.audio-manager-title {
  font-size: 2rem;
  line-height: 0.98;
}

.story-edit-header,
.profile-edit-header,
.pronunciation-header,
.audio-manager-header {
  padding-bottom: 14px;
}

.story-edit-body,
.profile-edit-body,
.pronunciation-list,
.audio-manager-body {
  overflow: auto;
  padding-right: 6px;
}

.story-edit-meta-fields {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}

.story-edit-meta-fields .field:first-child,
.story-edit-meta-fields .field-toggle {
  grid-column: 1 / -1;
}

.story-edit-body input,
.story-edit-body select,
.profile-field input,
.pronunciation-row-fields input {
  min-height: 46px;
  font-size: 0.98rem;
}

.story-edit-body textarea,
.profile-field textarea,
.review-textarea,
.v2-timeline-editor,
.v2-store-editor,
.v2-director-editor {
  line-height: 1.65;
}

.story-edit-body textarea {
  min-height: 150px;
}

.v2-timeline-editor,
.v2-store-editor {
  background: linear-gradient(180deg, rgba(255, 251, 244, 0.9), rgba(255, 248, 238, 0.96));
  border: 1px solid rgba(67, 50, 31, 0.16);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.field-toggle,
.audio-drama-toggle {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.44);
}

.toggle {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: rgba(111, 73, 55, 0.1);
  border-color: rgba(111, 73, 55, 0.18);
}

.toggle-thumb {
  width: 20px;
  height: 20px;
  background: rgba(111, 73, 55, 0.58);
}

.toggle.on {
  background: rgba(111, 73, 55, 0.18);
  border-color: rgba(111, 73, 55, 0.32);
}

.toggle.on .toggle-thumb {
  transform: translateX(20px);
  background: #6f4937;
}

.toggle-label,
.profile-director-hint,
.pronunciation-help {
  font-size: 0.9rem;
  line-height: 1.55;
}

.story-edit-footer,
.profile-edit-footer,
.audio-manager-save-row {
  padding-top: 4px;
  border-top: 1px solid rgba(67, 50, 31, 0.12);
}

.profile-avatar-row {
  align-items: center;
  gap: 18px;
}

.profile-avatar-circle {
  width: 84px;
  height: 84px;
  border-radius: 20px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.profile-field-label {
  color: var(--accent);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
}

#profileEditDirectorNotes {
  min-height: 220px;
  font-family: var(--serif);
  line-height: 1.7;
}

.pronunciation-help {
  max-width: 58ch;
}

.pronunciation-list {
  gap: 12px;
  align-content: start;
}

.pronunciation-row {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto auto;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.52);
}

.pronunciation-row-fields input {
  background: rgba(255, 255, 255, 0.74);
}

.pronunciation-row-actions .btn {
  padding: 8px 12px;
  border-radius: 12px;
}

.audio-manager-body {
  gap: 20px;
}

.voice-slot,
.audio-manager-row,
.audio-manager-char-card,
.pronunciation-row,
.voice-browser-card {
  background: rgba(255, 255, 255, 0.54);
}

.voice-slot {
  padding: 14px 16px;
  border-radius: 16px;
}

.voice-slot-info {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.voice-slot-name {
  font-family: var(--display);
  font-size: 1.3rem;
  line-height: 1.04;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}

.audio-manager-char-row .voice-slot-name {
  font-size: 1.06rem;
}

.voice-slot-meta {
  font-size: 0.84rem;
  white-space: normal;
}

.btn-icon.audio-preview-btn {
  width: auto;
  min-width: 42px;
  height: 38px;
  padding: 0 12px;
  border-radius: 12px;
  background: rgba(255, 251, 245, 0.78);
  color: var(--accent);
}

.audio-manager-char-card {
  padding: 10px 14px;
}

.audio-manager-char-row {
  display: grid;
  grid-template-columns: minmax(104px, 140px) minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 0;
  align-items: center;
}

.audio-manager-char-name {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.audio-manager-admin-toggle {
  padding: 12px 14px;
  font-size: 0.95rem;
}

.audio-manager-list {
  gap: 10px;
}

.audio-manager-row {
  padding: 14px 16px;
  gap: 8px;
}

.audio-manager-row-title {
  font-family: var(--display);
  font-size: 1.25rem;
  line-height: 1.05;
}

.audio-manager-row-meta {
  font-size: 0.82rem;
}

.audio-manager-row-actions .btn,
.audio-manager-save-row .btn {
  min-height: 42px;
  padding-inline: 16px;
}

.voice-browser-panel {
  padding-top: 18px;
  gap: 14px;
}

.voice-browser-label {
  font-family: var(--display);
  font-size: 1.45rem;
  line-height: 1;
  letter-spacing: -0.01em;
  text-transform: none;
  color: var(--text);
}

.voice-browser-filters,
.voice-filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.voice-filter-chip {
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
  color: var(--muted);
  font-family: var(--serif);
  font-size: 0.92rem;
  line-height: 1;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.voice-filter-chip:hover {
  border-color: rgba(111, 73, 55, 0.28);
  color: var(--text);
}

.voice-filter-chip.active {
  border-color: rgba(111, 73, 55, 0.28);
  background: rgba(111, 73, 55, 0.08);
  color: var(--accent);
}

.voice-browser-grid {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  max-height: 360px;
  padding: 2px;
}

.voice-browser-card {
  align-items: flex-start;
  text-align: left;
  gap: 8px;
  padding: 14px;
  border-width: 1px;
  border-color: var(--line);
  border-radius: 16px;
  background: rgba(255, 251, 245, 0.78);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.voice-browser-avatar {
  width: 48px;
  height: 48px;
  margin-bottom: 0;
  border-radius: 14px;
  background: rgba(111, 73, 55, 0.12);
  color: var(--accent);
}

.voice-browser-name {
  font-family: var(--display);
  font-size: 1.1rem;
  line-height: 1.05;
  white-space: normal;
}

.voice-browser-meta {
  font-size: 0.84rem;
  line-height: 1.45;
}

.voice-browser-card.selected {
  background: rgba(111, 73, 55, 0.08);
  border-color: rgba(111, 73, 55, 0.32);
}

.voice-browser-panel .voice-browser-card {
  background: rgba(255, 251, 245, 0.78);
}

.voice-browser-panel .voice-browser-card.selected {
  background: rgba(111, 73, 55, 0.08);
}

.voice-browser-panel .voice-browser-avatar {
  background: rgba(111, 73, 55, 0.12);
  color: var(--accent);
}

.story-home-hero {
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 30px;
}

.story-home-info {
  gap: 14px;
}

.story-home-rating-summary {
  flex-wrap: wrap;
}

.story-home-actions {
  max-width: 620px;
}

.story-home-listen,
.story-home-save,
.story-home-fork,
.review-card-actions .btn,
.review-form-actions .btn {
  background: rgba(255, 255, 255, 0.62);
  border-color: var(--line);
  color: var(--text);
}

.story-home-listen:hover,
.story-home-save:hover,
.story-home-fork:hover {
  background: rgba(255, 255, 255, 0.82);
}

.review-card-header {
  align-items: start;
}

.review-card-author {
  margin-left: 0;
  font-size: 0.9rem;
}

.review-card-actions {
  flex-wrap: wrap;
}

.explore-layout {
  padding-top: 4px;
}

.explore-chapter-panel {
  position: relative;
  max-width: 900px;
  padding: 24px 28px 30px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow: var(--shadow-soft);
}

.explore-chapter-panel::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(67, 50, 31, 0.08);
  border-radius: 18px;
  pointer-events: none;
}

.explore-chapter-panel .v2-reader-header {
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(67, 50, 31, 0.12);
}

.explore-chapter-panel .v2-reader-title {
  font-family: var(--display);
  font-size: clamp(2rem, 3vw, 3rem);
  line-height: 0.98;
}

.explore-chapter-panel .v2-reader-body {
  max-width: 68ch;
  margin: 0 auto;
  padding-top: 18px;
  color: var(--text);
  font-size: clamp(1.08rem, 1.25vw, 1.22rem);
  line-height: 1.9;
}

.explore-chapter-panel .v2-reader-footer {
  padding-top: 28px;
  padding-bottom: 0;
  display: flex;
  justify-content: center;
}

.explore-chapter-panel .v2-reader-footer .btn {
  background: rgba(255, 255, 255, 0.72);
  border-color: var(--line);
  color: var(--text);
}

@media (max-width: 900px) {
  .story-edit-meta-fields,
  .pronunciation-row {
    grid-template-columns: 1fr;
  }

  .audio-manager-char-row {
    grid-template-columns: 1fr auto;
  }

  .audio-manager-char-name {
    grid-column: 1 / -1;
  }

  .story-home-hero {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  .explore-chapter-panel {
    padding: 20px 18px 24px;
  }
}

@media (max-width: 760px) {
  .chat-model-menu {
    right: 0;
    width: min(100%, calc(100vw - 32px));
  }

  .story-card,
  .story-card-horizontal {
    max-width: none;
  }

  .story-card-horizontal {
    grid-template-columns: 96px minmax(0, 1fr);
  }

  .story-card-horizontal .story-card-cover-sm {
    width: 96px;
    min-height: 132px;
  }

  .story-edit-card,
  .profile-edit-card,
  .pronunciation-card,
  .audio-manager-card {
    padding: 18px 18px 16px;
  }

  .voice-browser-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

/* ------------------------------------------------------------------ */
/*  Gallery modal                                                      */
/* ------------------------------------------------------------------ */

.gallery-modal {
  position: fixed;
  inset: 0;
  background: rgba(236, 226, 209, 0.42);
  backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 55;
  padding: 32px 18px;
}

.gallery-modal.active {
  display: flex;
}

.gallery-card {
  width: min(680px, 96vw);
  max-height: min(92vh, 860px);
  background: var(--panel-solid);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.gallery-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.gallery-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.gallery-empty {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  padding: 24px 0;
  margin: 0;
}

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

.gallery-item {
  position: relative;
  border-radius: 10px;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--bg-deep);
  border: 1px solid var(--line);
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-item-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  padding: 8px;
  text-align: center;
  word-break: break-all;
}

.gallery-item-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
  padding: 18px 8px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.gallery-item:hover .gallery-item-actions {
  opacity: 1;
}

.gallery-item-filename {
  flex: 1;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.85);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-item-insert,
.gallery-item-delete {
  font-size: 11px;
  padding: 3px 7px;
  border-radius: 6px;
  color: #fff;
  flex-shrink: 0;
}

.gallery-item-delete {
  color: rgba(255, 120, 120, 0.9);
}

.gallery-section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: block;
  margin-bottom: 8px;
}

.gallery-upload-section,
.gallery-generate-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.gallery-upload-btn {
  align-self: flex-start;
}

.gallery-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: var(--sans);
  outline: none;
}

.gallery-input:focus {
  border-color: var(--accent-soft);
}

.gallery-gen-submit {
  align-self: flex-start;
}

.gallery-status {
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
}

@media (max-width: 600px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
