:root {
  --bg-parchment: #fcf8f2;
  --bg-card: #ffffff;
  --bg-warm-tint: #f5ede0;
  --bg-highlight: #fdf3e3;
  --text-primary: #231b15;
  --text-secondary: #5a4b3f;
  --text-muted: #7b6a5c;
  --border-warm: #e2d5c3;
  --accent-amber: #b85d19;
  --accent-amber-hover: #96480e;
  --accent-gold: #d9822b;
  --accent-green: #1f6b52;
  --accent-green-hover: #16513d;
  --danger-red: #b92b27;
  --shadow-soft: 0 4px 18px rgba(58, 40, 22, 0.08);
  --shadow-elevated: 0 10px 32px rgba(58, 40, 22, 0.14);
  --radius-md: 14px;
  --radius-lg: 20px;
  --font-ui: 'Assistant', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif: 'Frank Ruhl Libre', Georgia, 'Times New Roman', serif;
  --base-font-size: 20px;
}

body.font-normal {
  --base-font-size: 18px;
}

body.font-large {
  --base-font-size: 21px;
}

body.font-xlarge {
  --base-font-size: 25px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  font-size: var(--base-font-size);
  line-height: 1.6;
  background-color: var(--bg-parchment);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, #fffdf9 0%, #f6ece0 100%);
  border-bottom: 2px solid var(--border-warm);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  box-shadow: var(--shadow-soft);
  z-index: 10;
}

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

.brand-logo {
  font-size: 2.3rem;
  background: var(--bg-highlight);
  border: 2px solid var(--border-warm);
  width: 60px;
  height: 60px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(184, 93, 25, 0.12);
}

.brand-titles h1 {
  font-family: var(--font-serif);
  font-size: 1.55em;
  font-weight: 900;
  color: var(--accent-amber);
  line-height: 1.15;
}

.brand-titles p {
  font-size: 0.85em;
  color: var(--text-secondary);
  font-weight: 600;
}

.header-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-warm);
}

.control-group label,
.control-label {
  font-size: 0.82em;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
}

.header-input,
.header-select {
  font-family: var(--font-ui);
  font-size: 0.9em;
  font-weight: 700;
  color: var(--text-primary);
  border: 1px solid var(--border-warm);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fffcf7;
}

.header-input {
  width: 150px;
}

.size-btn {
  font-family: var(--font-ui);
  font-size: 0.85em;
  font-weight: 800;
  padding: 5px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-warm);
  background: var(--bg-parchment);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.size-btn.active,
.size-btn:hover {
  background: var(--accent-amber);
  color: #ffffff;
  border-color: var(--accent-amber);
}

.tts-toggle-btn {
  font-family: var(--font-ui);
  font-size: 0.85em;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: 12px;
  border: 2px solid var(--border-warm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.tts-toggle-btn.active {
  background: #e9f5f0;
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.icon-btn {
  font-size: 1.15em;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-warm);
  background: var(--bg-card);
  cursor: pointer;
}

/* Main Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-card {
  background: var(--bg-card);
  border: 2px solid var(--border-warm);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-soft);
}

.highlight-card {
  background: linear-gradient(180deg, #fffaf0 0%, #fdf1db 100%);
  border-color: #e4b97c;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sidebar-card h2 {
  font-family: var(--font-serif);
  font-size: 1.18em;
  color: var(--text-primary);
}

.sidebar-hint,
#uiBookCardDesc {
  font-size: 0.84em;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.progress-badge,
.count-pill {
  background: var(--accent-amber);
  color: #fff;
  font-size: 0.78em;
  font-weight: 800;
  padding: 3px 10px;
  border-radius: 99px;
}

.chapters-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 350px;
  overflow-y: auto;
  padding-inline-end: 4px;
}

.chapter-item-btn {
  font-family: var(--font-ui);
  font-size: 0.88em;
  font-weight: 700;
  text-align: start;
  padding: 11px 14px;
  border-radius: 12px;
  border: 2px solid var(--border-warm);
  background: var(--bg-parchment);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: all 0.15s ease;
}

.chapter-item-btn:hover {
  border-color: var(--accent-gold);
  background: var(--bg-highlight);
}

.chapter-item-btn.active {
  background: var(--accent-amber);
  color: #ffffff;
  border-color: var(--accent-amber);
}

.chapter-status-icon {
  font-size: 0.95em;
}

/* Book Generator Controls */
.book-style-row {
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.book-style-row label {
  font-size: 0.82em;
  font-weight: 700;
  color: var(--text-secondary);
}

.full-select,
.full-input {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 0.88em;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid var(--border-warm);
  background: #ffffff;
  color: var(--text-primary);
}

.generate-book-btn {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 1.05em;
  font-weight: 800;
  padding: 16px 18px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #c86419 0%, #9c4406 100%);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 6px 18px rgba(184, 93, 25, 0.32);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.generate-book-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(184, 93, 25, 0.42);
}

.secondary-book-btn {
  width: 100%;
  margin-top: 10px;
  font-family: var(--font-ui);
  font-size: 0.92em;
  font-weight: 700;
  padding: 11px;
  border-radius: 12px;
  border: 2px solid var(--accent-amber);
  background: #ffffff;
  color: var(--accent-amber);
  cursor: pointer;
}

/* Recordings List */
.recordings-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 240px;
  overflow-y: auto;
}

.recording-card {
  background: var(--bg-parchment);
  border: 1px solid var(--border-warm);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.82em;
}

.recording-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.recording-card audio {
  width: 100%;
  height: 36px;
  margin-top: 4px;
}

.recording-transcript-snippet {
  margin-top: 6px;
  color: var(--text-primary);
  font-style: italic;
}

.empty-note {
  font-size: 0.84em;
  color: var(--text-muted);
}

.backup-actions {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-warm);
}

.small-action-btn {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 0.84em;
  font-weight: 700;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-warm);
  background: var(--bg-parchment);
  color: var(--text-secondary);
  cursor: pointer;
}

.small-action-btn:hover {
  background: var(--bg-warm-tint);
  color: var(--text-primary);
}

/* Center Interview Studio */
.chat-studio {
  background: var(--bg-card);
  border: 2px solid var(--border-warm);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 74vh;
}

.current-chapter-banner {
  background: var(--bg-warm-tint);
  border-bottom: 2px solid var(--border-warm);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.chapter-banner-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chapter-tag {
  font-size: 0.85em;
  color: var(--text-secondary);
  font-weight: 600;
}

.chapter-banner-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.gentle-pill-btn {
  font-family: var(--font-ui);
  font-size: 0.85em;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 99px;
  border: 1px solid var(--border-warm);
  background: #ffffff;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.gentle-pill-btn:hover {
  border-color: var(--accent-amber);
  background: var(--bg-highlight);
}

/* Conversation Messages */
.chat-messages {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background-image: radial-gradient(#e9decb 1px, transparent 1px);
  background-size: 28px 28px;
}

.message-bubble {
  max-width: 85%;
  padding: 18px 22px;
  border-radius: 20px;
  position: relative;
  box-shadow: 0 3px 12px rgba(42, 33, 27, 0.06);
  line-height: 1.65;
}

.message-bubble.assistant {
  align-self: flex-start;
  background: #fff9ef;
  border: 2px solid #e6d2b5;
  color: var(--text-primary);
}

.message-bubble.user {
  align-self: flex-end;
  background: #eef7f3;
  border: 2px solid #b8dcd0;
  color: #163329;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  font-size: 0.78em;
  font-weight: 700;
  color: var(--text-secondary);
}

.speak-msg-btn {
  font-family: var(--font-ui);
  font-size: 0.92em;
  font-weight: 700;
  background: #ffffff;
  border: 1px solid var(--border-warm);
  border-radius: 99px;
  padding: 3px 11px;
  cursor: pointer;
  color: var(--accent-amber);
}

.speak-msg-btn:hover {
  background: var(--accent-amber);
  color: #ffffff;
}

.message-audio-attachment {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed #9fc9ba;
}

.message-audio-attachment audio {
  width: 100%;
  max-width: 340px;
  height: 38px;
}

/* Input Panel */
.story-input-panel {
  background: var(--bg-warm-tint);
  border-top: 2px solid var(--border-warm);
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.voice-controls-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.giant-mic-btn {
  width: 100%;
  padding: 16px 22px;
  border-radius: 16px;
  border: 3px solid var(--accent-green);
  background: linear-gradient(135deg, #23765b 0%, #175440 100%);
  color: #ffffff;
  font-family: var(--font-ui);
  font-size: 1.05em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  box-shadow: 0 6px 16px rgba(31, 107, 82, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.giant-mic-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(31, 107, 82, 0.35);
}

.mic-icon {
  font-size: 1.9em;
}

.mic-text-col {
  display: flex;
  flex-direction: column;
  text-align: start;
}

.mic-text-col strong {
  font-size: 1.08em;
}

.mic-text-col small {
  font-size: 0.82em;
  opacity: 0.92;
}

.recording-status-box {
  width: 100%;
  background: #fff2f2;
  border: 3px solid var(--danger-red);
  border-radius: 16px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.pulse-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger-red);
  animation: pulseAnim 1.2s infinite ease-in-out;
}

@keyframes pulseAnim {
  0% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(185, 43, 39, 0.7);
  }
  70% {
    transform: scale(1.1);
    box-shadow: 0 0 0 14px rgba(185, 43, 39, 0);
  }
  100% {
    transform: scale(0.9);
    box-shadow: 0 0 0 0 rgba(185, 43, 39, 0);
  }
}

.recording-status-info {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #7c1815;
}

#recordingTimer {
  font-weight: 800;
  font-size: 1.2em;
  font-variant-numeric: tabular-nums;
}

.stop-mic-btn {
  font-family: var(--font-ui);
  font-size: 0.95em;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: 12px;
  border: none;
  background: var(--danger-red);
  color: #ffffff;
  cursor: pointer;
}

.text-compose-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
}

.story-textarea {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 1.02em;
  line-height: 1.5;
  padding: 14px 18px;
  border-radius: 14px;
  border: 2px solid var(--border-warm);
  background: #ffffff;
  color: var(--text-primary);
  resize: vertical;
}

.story-textarea:focus {
  outline: none;
  border-color: var(--accent-amber);
  box-shadow: 0 0 0 3px rgba(184, 93, 25, 0.18);
}

.send-story-btn {
  font-family: var(--font-ui);
  font-size: 1.05em;
  font-weight: 800;
  padding: 0 26px;
  border-radius: 14px;
  border: none;
  background: var(--accent-amber);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease;
}

.send-story-btn:hover {
  background: var(--accent-amber-hover);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 20, 14, 0.68);
  backdrop-filter: blur(3px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.hidden {
  display: none !important;
}

.book-modal-container {
  background: var(--bg-parchment);
  border: 3px solid #d4bc9b;
  border-radius: 22px;
  max-width: 1020px;
  width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-elevated);
  overflow: hidden;
}

.book-modal-toolbar {
  background: var(--bg-warm-tint);
  border-bottom: 2px solid var(--border-warm);
  padding: 14px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.toolbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-serif);
  font-size: 1.2em;
}

.toolbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-btn {
  font-family: var(--font-ui);
  font-size: 0.88em;
  font-weight: 700;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-warm);
  background: #ffffff;
  color: var(--text-primary);
  cursor: pointer;
}

.toolbar-btn.primary {
  background: var(--accent-amber);
  color: #ffffff;
  border-color: var(--accent-amber);
}

.toolbar-btn.close {
  background: #f3e5d7;
}

.book-loading-state {
  padding: 64px 32px;
  text-align: center;
}

.book-spinner {
  font-size: 3.6rem;
  margin-bottom: 16px;
  animation: pulseAnim 1.5s infinite ease-in-out;
  display: inline-block;
}

/* Heirloom Book Manuscript Styling */
.book-manuscript {
  flex: 1;
  overflow-y: auto;
  padding: 52px 68px;
  background: #fffdf8;
  font-family: var(--font-serif);
  font-size: 1.15em;
  line-height: 1.85;
  color: #1f1712;
}

@media (max-width: 768px) {
  .book-manuscript {
    padding: 28px 22px;
  }
}

.book-manuscript h1 {
  font-size: 2.2em;
  color: var(--accent-amber);
  text-align: center;
  margin-bottom: 8px;
  border-bottom: 3px double #d8c0a0;
  padding-bottom: 18px;
}

.book-manuscript h2 {
  font-size: 1.55em;
  color: #6d3710;
  margin-top: 36px;
  margin-bottom: 14px;
  border-bottom: 1px solid #eadbc6;
  padding-bottom: 6px;
}

.book-manuscript h3 {
  font-size: 1.2em;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 28px;
}

.book-manuscript p {
  margin-bottom: 18px;
  text-align: justify;
}

.book-manuscript blockquote {
  margin: 24px 0;
  padding: 16px 24px;
  background: #faf2e4;
  border-inline-start: 5px solid var(--accent-amber);
  font-style: italic;
  font-size: 1.08em;
  color: #4a3321;
  border-radius: 8px;
}

/* Settings Modal */
.settings-modal-card {
  background: var(--bg-card);
  border: 2px solid var(--border-warm);
  border-radius: 20px;
  max-width: 560px;
  width: 100%;
  padding: 24px;
  box-shadow: var(--shadow-elevated);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.settings-note {
  font-size: 0.85em;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.form-field {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 0.85em;
  font-weight: 700;
}

.settings-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
}

.primary-save-btn {
  font-family: var(--font-ui);
  font-size: 0.95em;
  font-weight: 800;
  padding: 10px 22px;
  border-radius: 10px;
  border: none;
  background: var(--accent-amber);
  color: #ffffff;
  cursor: pointer;
}

.danger-outline-btn {
  font-family: var(--font-ui);
  font-size: 0.85em;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--danger-red);
  background: #fff5f5;
  color: var(--danger-red);
  cursor: pointer;
}

/* Print Layout for Exporting Beautiful Book PDF */
@media print {
  .no-print {
    display: none !important;
  }
  body {
    background: #ffffff;
  }
  .modal-backdrop {
    position: static;
    background: none;
    padding: 0;
    display: block !important;
  }
  .book-modal-container {
    border: none;
    box-shadow: none;
    max-height: none;
    max-width: none;
  }
  .book-manuscript {
    overflow: visible;
    padding: 0;
  }
}
