@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500&family=DM+Sans:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #4A148C;
  --primary-light: #6A1B9A;
  --secondary: #8E24AA;
  --accent: #CE93D8;
  --accent-light: #F3E5F5;
  --accent-glow: #F0DCC4;
  --bg: #FAF6F1;
  --bg-warm: #F5EDE4;
  --bg-card: #FFFFFF;
  --text: #2C2420;
  --text-light: #7A6E65;
  --text-muted: #A89B91;
  --border: #E8DDD3;
  --border-light: #F0E8DF;
  --success: #4A7C59;
  --shadow-sm: 0 1px 3px rgba(92, 61, 46, 0.06);
  --shadow-md: 0 4px 12px rgba(92, 61, 46, 0.08);
  --shadow-lg: 0 8px 24px rgba(92, 61, 46, 0.1);
  --radius: 10px;
  --radius-lg: 16px;
}

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

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Loading Screen */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: 1rem;
}

.loading-quill {
  font-size: 3rem;
  animation: quillBob 1.5s ease-in-out infinite;
}

@keyframes quillBob {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-10px) rotate(5deg); }
}

.loading-text {
  font-family: 'Lora', serif;
  color: var(--text-light);
  font-style: italic;
  font-size: 1.1rem;
}

/* App Shell */
.app-shell {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
  min-height: 100vh;
}

/* Story Header */
.story-header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  position: relative;
}

.header-decoration {
  margin-bottom: 0.75rem;
}

.header-icon {
  font-size: 2.5rem;
  display: inline-block;
  animation: unfurl 0.8s ease-out;
}

@keyframes unfurl {
  from { opacity: 0; transform: scale(0.5) rotate(-20deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

.title-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.story-title {
  font-family: 'Lora', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  transition: color 0.2s;
  letter-spacing: -0.02em;
}

.story-title:hover {
  color: var(--primary-light);
}

.edit-title-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.4;
  transition: opacity 0.2s;
  padding: 0.25rem;
}

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

.title-edit {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.title-input {
  font-family: 'Lora', serif;
  font-size: 1.4rem;
  font-weight: 600;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  text-align: center;
  outline: none;
  background: var(--bg-card);
  color: var(--primary);
  width: 100%;
  max-width: 400px;
}

.title-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.save-title-btn, .cancel-title-btn {
  padding: 0.4rem 1rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-weight: 500;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.save-title-btn {
  background: var(--primary);
  color: white;
}

.save-title-btn:hover {
  background: var(--primary-light);
}

.cancel-title-btn {
  background: var(--border-light);
  color: var(--text-light);
}

.cancel-title-btn:hover {
  background: var(--border);
}

.story-subtitle {
  margin-top: 0.5rem;
  font-style: italic;
  color: var(--text-muted);
  font-family: 'Lora', serif;
  font-size: 0.95rem;
}

/* Tab Bar */
.tab-bar {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-warm);
  border-radius: var(--radius-lg);
  padding: 0.3rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border-light);
}

.tab-btn {
  flex: 1;
  padding: 0.65rem 0.75rem;
  border: none;
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-light);
  transition: all 0.25s;
  font-family: 'DM Sans', sans-serif;
}

.tab-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.tab-btn:not(.active):hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.5);
}

/* Story View */
.story-scroll {
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.story-body {
  position: relative;
  padding-left: 1.5rem;
  border-left: 2px solid var(--border);
}

.paragraph-block {
  position: relative;
  margin-bottom: 2rem;
  padding: 1.25rem 1.5rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  animation: slideIn 0.5s ease-out both;
}

.paragraph-block::before {
  content: '';
  position: absolute;
  left: -1.85rem;
  top: 1.5rem;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--bg);
}

.paragraph-block:nth-child(1) { animation-delay: 0s; }
.paragraph-block:nth-child(2) { animation-delay: 0.05s; }
.paragraph-block:nth-child(3) { animation-delay: 0.1s; }
.paragraph-block:nth-child(4) { animation-delay: 0.15s; }
.paragraph-block:nth-child(5) { animation-delay: 0.2s; }
.paragraph-block:nth-child(6) { animation-delay: 0.25s; }
.paragraph-block:nth-child(7) { animation-delay: 0.3s; }
.paragraph-block:nth-child(8) { animation-delay: 0.35s; }
.paragraph-block:nth-child(9) { animation-delay: 0.4s; }
.paragraph-block:nth-child(10) { animation-delay: 0.45s; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

.first-paragraph {
  border-top: 3px solid var(--accent);
}

.drop-cap {
  float: left;
  font-family: 'Lora', serif;
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 0.85;
  color: var(--primary);
  margin-right: 0.15rem;
  margin-top: 0.1rem;
  padding-right: 0.1rem;
}

.paragraph-text {
  font-family: 'Lora', serif;
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text);
}

.paragraph-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.author-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
}

.author-name {
  font-weight: 600;
  color: var(--primary-light);
}

.meta-separator {
  opacity: 0.4;
}

.paragraph-number {
  font-family: 'Lora', serif;
  font-style: italic;
}

.story-end-marker {
  text-align: center;
  padding: 2rem 0;
  color: var(--text-muted);
}

.end-flourish {
  font-family: 'Lora', serif;
  font-size: 1.2rem;
  letter-spacing: 0.5rem;
  color: var(--accent);
}

.end-text {
  margin-top: 0.5rem;
  font-style: italic;
  font-family: 'Lora', serif;
  font-size: 0.9rem;
}

/* Empty States */
.empty-story, .empty-stats {
  text-align: center;
  padding: 3rem 1.5rem;
  animation: fadeIn 0.5s ease;
}

.empty-illustration {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: quillBob 2s ease-in-out infinite;
}

.empty-title {
  font-family: 'Lora', serif;
  font-size: 1.4rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.empty-desc {
  color: var(--text-light);
  max-width: 360px;
  margin: 0 auto;
  line-height: 1.7;
}

/* Write Section */
.write-section {
  animation: fadeIn 0.4s ease;
}

.write-header {
  margin-bottom: 1.25rem;
}

.write-title {
  font-family: 'Lora', serif;
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 0.25rem;
}

.write-hint {
  color: var(--text-light);
  font-size: 0.9rem;
}

.last-paragraph-preview {
  background: var(--bg-warm);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  border-left: 3px solid var(--accent);
}

.preview-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.preview-text {
  font-family: 'Lora', serif;
  font-style: italic;
  color: var(--text-light);
  line-height: 1.7;
  font-size: 0.95rem;
  border: none;
  margin: 0;
  padding: 0;
}

.write-area {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.write-area:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.paragraph-textarea {
  width: 100%;
  border: none;
  padding: 1.25rem;
  font-family: 'Lora', serif;
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text);
  background: transparent;
  resize: vertical;
  min-height: 160px;
  outline: none;
}

.paragraph-textarea::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.write-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border-light);
  background: var(--bg);
}

.word-indicator {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.submit-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.25s;
  font-family: 'DM Sans', sans-serif;
}

.submit-btn:hover:not(:disabled) {
  background: var(--primary-light);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

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

.writing-tips {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: var(--bg-warm);
  border-radius: var(--radius);
  border: 1px dashed var(--border);
}

.tips-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.tips-list {
  list-style: none;
  padding: 0;
}

.tips-list li {
  padding: 0.3rem 0;
  padding-left: 1.2rem;
  position: relative;
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.6;
}

.tips-list li::before {
  content: '→';
  position: absolute;
  left: 0;
  color: var(--accent);
  font-weight: 600;
}

/* Stats Section */
.stats-section {
  animation: fadeIn 0.4s ease;
}

.stats-heading {
  font-family: 'Lora', serif;
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 1.25rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, box-shadow 0.2s;
  animation: popIn 0.4s ease-out both;
}

.stat-card:nth-child(1) { animation-delay: 0s; }
.stat-card:nth-child(2) { animation-delay: 0.05s; }
.stat-card:nth-child(3) { animation-delay: 0.1s; }
.stat-card:nth-child(4) { animation-delay: 0.15s; }
.stat-card:nth-child(5) { animation-delay: 0.2s; }
.stat-card:nth-child(6) { animation-delay: 0.25s; }

@keyframes popIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  font-size: 1.5rem;
}

.stat-value {
  font-family: 'Lora', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.contributors-section {
  margin-bottom: 1.5rem;
}

.contributors-title {
  font-family: 'Lora', serif;
  font-size: 1.15rem;
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.contributors-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.contributor-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  animation: slideIn 0.4s ease-out both;
}

.contributor-card:nth-child(1) { animation-delay: 0s; }
.contributor-card:nth-child(2) { animation-delay: 0.05s; }
.contributor-card:nth-child(3) { animation-delay: 0.1s; }
.contributor-card:nth-child(4) { animation-delay: 0.15s; }

.contributor-rank {
  font-family: 'Lora', serif;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.9rem;
  min-width: 1.5rem;
}

.contributor-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--accent-light);
}

.contributor-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.contributor-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contributor-details {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.contributor-bar-wrap {
  width: 60px;
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}

.contributor-bar {
  height: 100%;
  width: var(--bar-width);
  background: linear-gradient(90deg, var(--accent), var(--primary-light));
  border-radius: 3px;
  transition: width 0.5s ease;
}

.contributor-pct {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary-light);
  min-width: 2.5rem;
  text-align: right;
}

.reading-estimate {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, var(--bg-warm), var(--accent-glow));
  border-radius: var(--radius);
  border: 1px solid var(--accent-light);
}

.estimate-icon {
  font-size: 1.5rem;
}

.estimate-text {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

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

/* Mobile Responsive */
@media (max-width: 640px) {
  .app-shell {
    padding: 0 0.75rem 2rem;
  }

  .story-title {
    font-size: 1.5rem;
  }

  .story-header {
    padding: 1.5rem 0.5rem 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .paragraph-block {
    padding: 1rem;
  }

  .story-body {
    padding-left: 1rem;
  }

  .paragraph-block::before {
    left: -1.35rem;
    width: 8px;
    height: 8px;
  }

  .drop-cap {
    font-size: 2.8rem;
  }

  .contributor-bar-wrap {
    display: none;
  }

  .title-edit {
    flex-direction: column;
  }

  .title-input {
    max-width: 100%;
    font-size: 1.2rem;
  }

  .tab-btn {
    font-size: 0.82rem;
    padding: 0.55rem 0.5rem;
  }
}

/* Focus styles */
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
```

<!-- WALKTHROUGH_SCRIPT:
[
  {"step": 1, "narration": "Welcome to the Collaborative Story Builder! This is a shared space where everyone can contribute to a story, one paragraph at a time.", "view": "all", "highlight_selector": ".story-header", "wait_for": "tap_to_continue"},
  {"step": 2, "narration": "Click the story title to give your story a name. This sets the stage for all contributors.", "view": "all", "highlight_selector": ".title-display", "wait_for": "tap_to_continue"},
  {"step": 3, "narration": "The Story tab shows the full story with a timeline view. Each paragraph shows who wrote it and when.", "view": "all", "highlight_selector": ".tab-btn:first-child", "wait_for": "tap_to_continue"},
  {"step": 4, "narration": "Switch to the Write tab to add your paragraph. You'll see the last paragraph for context, plus writing tips.", "view": "all", "highlight_selector": ".tab-btn:nth-child(2)", "wait_for": "user_interaction"},
  {"step": 5, "narration": "Type your paragraph and hit 'Add Paragraph'. The word counter shows you how long your contribution is.", "view": "all", "highlight_selector": ".write-area", "wait_for": "tap_to_continue"},
  {"step": 6, "narration": "Check the Stats tab for word count, reading time, and a leaderboard of contributors. Share the link to invite friends!", "view": "all", "highlight_selector": ".tab-btn:nth-child(3)", "wait_for": "tap_to_continue"}
]
-->

.story-auth-bar {
  margin-bottom: 1rem;
}

.story-auth-status,
.story-auth-cta,
.story-auth-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.story-auth-status {
  justify-content: center;
  color: var(--text-light);
  font-size: 0.9rem;
}

.story-auth-cta {
  flex-wrap: wrap;
}

.story-auth-title {
  font-weight: 600;
  color: var(--primary);
}

.story-auth-subtitle {
  font-size: 0.85rem;
  color: var(--text-light);
}

.story-auth-user {
  flex-wrap: wrap;
}

.story-auth-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--accent-light);
  object-fit: cover;
}

.story-auth-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.story-auth-name {
  font-weight: 600;
  color: var(--primary);
}

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

.story-auth-login,
.story-auth-logout {
  border: none;
  cursor: pointer;
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  font-weight: 600;
  transition: all 0.2s;
  font-family: 'DM Sans', sans-serif;
}

.story-auth-login {
  background: var(--primary);
  color: #fff;
}

.story-auth-login:hover {
  background: var(--primary-light);
}

.story-auth-logout {
  background: var(--border-light);
  color: var(--text-light);
}

.story-auth-logout:hover {
  background: var(--border);
  color: var(--text);
}

.contributor-gated,
.write-gated {
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, var(--bg-warm), var(--accent-glow));
  border: 1px solid var(--accent-light);
  border-radius: var(--radius);
  color: var(--text);
}

.paragraph-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
}

.reaction-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border-light);
  background: var(--bg);
  color: var(--text-light);
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'DM Sans', sans-serif;
}

.reaction-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  border-color: var(--accent-light);
  background: var(--bg-card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.reaction-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.reaction-btn[aria-pressed='true'] {
  border-color: var(--accent);
  background: linear-gradient(135deg, var(--bg-warm), var(--accent-glow));
  color: var(--primary);
}

.reaction-emoji {
  font-size: 0.95rem;
  line-height: 1;
}

.reaction-count {
  min-width: 0.9rem;
  text-align: left;
}

@media (max-width: 640px) {
  .paragraph-reactions {
    gap: 0.35rem;
  }

  .reaction-btn {
    padding: 0.3rem 0.55rem;
    font-size: 0.78rem;
  }
}

.rich-rendered h1,
.rich-rendered h2,
.rich-rendered h3,
.rich-rendered h4,
.rich-rendered h5,
.rich-rendered h6 {
  font-family: 'Lora', serif;
  color: var(--primary);
  line-height: 1.3;
  margin: 0.25rem 0 0.75rem;
}

.rich-rendered h1 { font-size: 1.7rem; }
.rich-rendered h2 { font-size: 1.45rem; }
.rich-rendered h3 { font-size: 1.2rem; }

.rich-rendered p {
  margin: 0 0 0.85rem;
}

.rich-rendered p:last-child {
  margin-bottom: 0;
}

.rich-rendered strong {
  font-weight: 700;
  color: var(--text);
}

.rich-rendered em {
  font-style: italic;
}

.rich-rendered u {
  text-decoration-color: var(--accent);
}

.rich-rendered s {
  color: var(--text-muted);
}

.rich-rendered ul,
.rich-rendered ol {
  padding-left: 1.25rem;
  margin: 0 0 0.9rem;
}

.rich-rendered li {
  margin: 0.2rem 0;
}

.rich-rendered blockquote {
  margin: 0.5rem 0 1rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--accent);
  background: var(--bg-warm);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--text-light);
}

.rich-rendered a {
  color: var(--secondary);
  text-decoration: underline;
  text-decoration-color: var(--accent);
}

.rich-rendered code {
  background: var(--bg-warm);
  color: var(--primary);
  padding: 0.15rem 0.35rem;
  border-radius: 6px;
  font-size: 0.92em;
}

.rich-rendered pre {
  overflow: auto;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  background: #f7f1ea;
  border: 1px solid var(--border-light);
  margin: 0 0 0.9rem;
}

.rich-rendered img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  margin: 0.35rem 0 0.9rem;
}

.write-editor-shell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.write-editor-shell:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.rich-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg);
}

.rich-toolbar-btn {
  border: 1px solid var(--border-light);
  background: var(--bg-card);
  color: var(--text-light);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'DM Sans', sans-serif;
}

.rich-toolbar-btn:hover {
  border-color: var(--accent-light);
  color: var(--text);
  background: var(--bg-warm);
}

.rich-toolbar-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.rich-editor {
  min-height: 180px;
  padding: 1.25rem;
  font-family: 'Lora', serif;
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text);
  background: transparent;
  outline: none;
}

.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  font-style: italic;
}

.rich-editor p {
  margin: 0 0 0.85rem;
}

.rich-editor:focus {
  outline: none;
}

.write-footer.rich-footer {
  gap: 0.75rem;
  flex-wrap: wrap;
}

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

.story-preview-label {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.story-preview-card {
  margin-top: 0.5rem;
  padding: 1rem 1.15rem;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 640px) {
  .rich-toolbar {
    padding: 0.6rem;
  }

  .rich-toolbar-btn {
    padding: 0.4rem 0.55rem;
    font-size: 0.8rem;
  }

  .rich-editor {
    min-height: 160px;
    padding: 1rem;
  }
}

.presence-panel {
  margin-bottom: 1rem;
  padding: 0.9rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.presence-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.presence-title {
  font-weight: 600;
  color: var(--primary);
}

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

.presence-message {
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
  color: var(--success);
}

.presence-users {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

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

.presence-user {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border-light);
  border-radius: 999px;
  background: var(--bg);
}

.presence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5cc66b;
  box-shadow: 0 0 0 4px rgba(92, 198, 107, 0.16);
  flex: 0 0 auto;
}

.presence-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

.presence-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.presence-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

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

@media (max-width: 640px) {
  .presence-panel {
    padding: 0.8rem 0.9rem;
  }

  .presence-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

.story-sync-message {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, var(--bg-warm), var(--accent-glow));
  border: 1px solid var(--accent-light);
  border-radius: var(--radius);
  color: var(--primary);
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
}

.cliffhanger-panel {
  margin-bottom: 1rem;
  padding: 1rem 1.1rem;
  background: linear-gradient(135deg, var(--bg-warm), var(--accent-glow));
  border: 1px solid var(--accent-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.cliffhanger-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.cliffhanger-title {
  font-weight: 700;
  color: var(--primary);
}

.cliffhanger-badge {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--secondary);
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--accent-light);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
}

.cliffhanger-reason {
  margin-bottom: 0.85rem;
  color: var(--text);
  font-size: 0.92rem;
}

.cliffhanger-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.cliffhanger-option {
  text-align: left;
  border: 1px solid var(--border-light);
  background: rgba(255, 255, 255, 0.8);
  border-radius: var(--radius);
  padding: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.cliffhanger-option:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
}

.cliffhanger-option-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--primary-light);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cliffhanger-option-text {
  display: block;
  font-size: 0.88rem;
  line-height: 1.55;
}

.cliffhanger-applied {
  margin-top: 0.85rem;
  font-size: 0.88rem;
  color: var(--primary);
  font-weight: 600;
}

@media (max-width: 640px) {
  .cliffhanger-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .cliffhanger-options {
    grid-template-columns: 1fr;
  }
}

.booklet-export-bar {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 1rem;
}

.story-booklet-export {
  background: var(--secondary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'DM Sans', sans-serif;
}

.story-booklet-export:hover:not(:disabled) {
  background: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.story-booklet-export:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.booklet-export-canvas {
  position: fixed;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  z-index: -1;
  background: #fff;
  color: #111;
  padding: 24px;
}

.booklet-page {
  width: 100%;
  min-height: 100vh;
  page-break-after: always;
  break-after: page;
  padding: 48px 56px;
  background: #fff;
  color: #1f1b18;
  font-family: 'Lora', serif;
}

.booklet-cover {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(135deg, #faf6f1, #f5ede4);
}

.booklet-cover-inner {
  max-width: 620px;
  margin: 0 auto;
}

.booklet-mark {
  display: inline-block;
  margin-bottom: 1rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid #d9c7b5;
  border-radius: 999px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary);
}

.booklet-cover h1 {
  margin: 0;
  font-size: 2.6rem;
  line-height: 1.1;
  color: var(--primary);
}

.booklet-subtitle {
  margin-top: 0.9rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 1rem;
  color: var(--text-light);
}

.booklet-divider {
  width: 120px;
  height: 2px;
  margin: 1.5rem auto;
  background: var(--accent);
}

.booklet-intro {
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text);
}

.booklet-story-page {
  display: flex;
  flex-direction: column;
}

.booklet-page-header,
.booklet-page-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.booklet-content {
  margin: 1.5rem 0;
  font-size: 1.08rem;
  line-height: 1.9;
  color: #1f1b18;
}

.booklet-content img {
  max-width: 100%;
}

@media print {
  .booklet-export-canvas {
    position: static;
    opacity: 1;
    z-index: auto;
  }

  .story-auth-bar,
  .story-sync-message,
  .presence-panel,
  .booklet-export-bar,
  .cliffhanger-panel,
  .paragraph-reactions,
  .story-end-marker {
    display: none !important;
  }
}

.story-share-bar {
  justify-content: space-between;
  align-items: center;
}

.story-share-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.story-share-btn,
.story-share-copy,
.story-share-target,
.story-share-close {
  border: none;
  cursor: pointer;
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  font-weight: 600;
  transition: all 0.2s;
  font-family: 'DM Sans', sans-serif;
}

.story-share-btn {
  background: var(--primary);
  color: #fff;
}

.story-share-btn:hover:not(:disabled) {
  background: var(--primary-light);
}

.story-share-copy {
  background: var(--bg-card);
  color: var(--primary);
  border: 1px solid var(--border-light);
}

.story-share-copy:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-warm);
}

.story-share-btn:disabled,
.story-share-copy:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.story-share-panel {
  margin: 0 0 1rem;
  padding: 1rem 1.1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.story-share-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.story-share-panel-title {
  font-weight: 700;
  color: var(--primary);
}

.story-share-close {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-warm);
  color: var(--text-light);
}

.story-share-close:hover {
  background: var(--border-light);
  color: var(--text);
}

.story-share-link-row {
  margin-bottom: 0.85rem;
}

.story-share-link {
  width: 100%;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 0.7rem 0.85rem;
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
}

.story-share-targets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.story-share-target {
  background: var(--bg-warm);
  color: var(--primary);
  border: 1px solid var(--border-light);
  padding: 0.55rem 0.85rem;
}

.story-share-target:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}

@media (max-width: 640px) {
  .story-share-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .story-share-actions {
    width: 100%;
  }

  .story-share-btn,
  .story-share-copy,
  .story-share-target {
    width: 100%;
    justify-content: center;
  }

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