/* ── Editor Surface — Warm Ink ── */

/* Writing area container */
#editor-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 1.5rem 5rem;
  background: var(--bg);
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* The canvas — centered, max-width */
#editor-container {
  width: 100%;
  max-width: 620px;
  position: relative;
}

/* TipTap editor element */
.ProseMirror {
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.85;
  color: var(--text);
  outline: none;
  min-height: 60vh;
  caret-color: var(--accent);
}

/* Paragraphs */
.ProseMirror p {
  margin-bottom: 0;
  margin-top: 0;
}

/* Scene separator — the * * * break */
.ProseMirror hr {
  border: none;
  text-align: center;
  margin: 2em 0;
  color: var(--muted);
  opacity: 0.5;
}
.ProseMirror hr::before {
  content: '* * *';
  font-family: var(--font-body);
  font-size: 1rem;
  letter-spacing: 0.5em;
  color: var(--muted);
}

/* Headings */
.ProseMirror h1 {
  font-family: var(--font-body);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}
.ProseMirror h2 {
  font-family: var(--font-body);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}
.ProseMirror h3 {
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

/* Strong / Em */
.ProseMirror strong { font-weight: 600; }
.ProseMirror em { font-style: italic; color: var(--text); }

/* Block quote */
.ProseMirror blockquote {
  border-left: 3px solid var(--accent);
  margin: 1.5rem 0;
  padding: 0.5rem 0 0.5rem 1.25rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* Code inline */
.ProseMirror code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  color: var(--accent);
}

/* Code block */
.ProseMirror pre {
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  overflow-x: auto;
  margin: 1.25rem 0;
}
.ProseMirror pre code {
  background: none;
  padding: 0;
  font-size: 0.88rem;
  color: var(--text);
}

/* Lists */
.ProseMirror ul, .ProseMirror ol {
  padding-left: 1.5rem;
  margin: 0.75rem 0;
}
.ProseMirror li { margin-bottom: 0.25rem; }

/* Text selection */
.ProseMirror ::selection {
  background: var(--accent-hover);
}

/* Placeholder */
.ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  pointer-events: none;
  color: var(--muted);
  font-style: italic;
  opacity: 0.6;
  font-family: var(--font-body);
}

/* Focus mode — cursor line highlight */
.ProseMirror.typewriter-active p:focus-within,
.ProseMirror.typewriter-active .focused-line {
  background: var(--accent-soft);
  border-radius: 2px;
  transition: background var(--duration-fast);
}

/* Chapter label */
.chapter-label {
  font-family: var(--font-ui);
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.chapter-label::before,
.chapter-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Drop cap for chapter openings — applied via TipTap DropCap extension */
/* The extension adds class="drop-cap" and data-drop-cap="true" to the first paragraph */
.ProseMirror p.drop-cap::first-letter {
  float: left;
  font-family: var(--font-body);
  font-size: 3.8rem;
  font-weight: 600;
  line-height: 0.8;
  margin-right: 0.08em;
  margin-top: 0.05em;
  color: var(--accent);
}

/* Revision marking colors */
.revision-add { background: rgba(90,138,60,0.15); }
.revision-delete {
  text-decoration: line-through;
  background: rgba(184,60,46,0.1);
  color: var(--muted);
}

/* Comments highlight — replaces old .comment-highlight */
.comment-mark {
  background: rgba(184,92,56,0.15);
  border-bottom: 2px solid var(--accent);
  cursor: pointer;
  border-radius: 2px;
}
.comment-mark:hover { background: rgba(184,92,56,0.25); }

/* Legacy comment-highlight alias (keep for backward compat) */
.comment-highlight {
  background: rgba(184,92,56,0.15);
  border-bottom: 2px solid var(--accent);
  cursor: pointer;
  position: relative;
}
.comment-highlight:hover { background: rgba(184,92,56,0.25); }
.comment-highlight.comment-resolved {
  background: rgba(34,197,94,0.1);
  border-bottom-color: rgba(34,197,94,0.3);
}

/* Link styling */
.ProseMirror a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: var(--accent-soft);
  text-underline-offset: 3px;
  transition: text-decoration-color var(--duration-fast);
}
.ProseMirror a:hover { text-decoration-color: var(--accent); }

/* Highlight mark — keep yellow tint for readability across themes */
.ProseMirror mark {
  background: #fef08a;
  padding: 0 2px;
  border-radius: 2px;
}

/* Word goal progress bar (if shown in editor) */
#word-goal-bar {
  position: fixed;
  bottom: var(--statusbar-height);
  left: 0;
  right: 0;
  height: 2px;
  background: var(--surface-3);
  z-index: 5;
}
#word-goal-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width var(--duration-normal);
}

/* Focus mode dimming */
body.focus-mode .ProseMirror *:not(.ProseMirror-focused):not(.ProseMirror-focused *) {
  opacity: 0.3;
  transition: opacity var(--duration-slow);
}

/* Existing focus-mode class-based dimming (keep for compat) */
.focus-mode-dimmed {
  opacity: 0.25;
  transition: opacity 0.2s var(--ease-out);
}
.ProseMirror.focus-mode-active > *:not(.focus-mode-dimmed) {
  opacity: 1;
}

/* Zen mode */
body.zen-mode #topbar,
body.zen-mode #status-bar { opacity: 0; transition: opacity var(--duration-slow); }
body.zen-mode #topbar:hover,
body.zen-mode #status-bar:hover { opacity: 1; }

/* ── TTS Highlight Sync ── */
.ProseMirror .hl-active {
  background: rgba(255, 200, 50, 0.22) !important;
  border-left: 4px solid var(--accent) !important;
  padding-left: 12px !important;
  border-radius: 0 4px 4px 0;
  transition: background 0.15s var(--ease-out);
}

/* ── Audio Annotations Panel ── */
.annotations-panel {
  padding: 12px;
  max-height: 300px;
  overflow-y: auto;
}
.annotation-empty {
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}
.annotation-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.annotation-time {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 60px;
}
.annotation-text {
  flex: 1;
  color: var(--text);
}
.annotation-delete {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 4px;
  line-height: 1;
}
.annotation-delete:hover { color: var(--accent); }

/* ── Editor Status Bar ── */
.editor-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
  border-radius: 0 0 6px 6px;
}
.editor-status-bar .word-count { font-variant-numeric: tabular-nums; }
.editor-status-bar .save-status {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.editor-status-bar .save-status.saving { color: var(--accent); }
.editor-status-bar .save-status.saved { color: var(--muted); }

/* ── Find & Replace Bar ── */
.find-replace-bar {
  display: none;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.find-replace-bar.visible { display: flex; }
.find-replace-bar input {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-ui);
  flex: 1;
  min-width: 120px;
}
.find-replace-bar button {
  padding: 0.3rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font-ui);
  white-space: nowrap;
}
.find-replace-bar button:hover { background: var(--surface-2); }
.find-replace-bar .match-count {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 60px;
  text-align: center;
}

/* Find bar (inline) */
.find-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  flex-shrink: 0;
}
.find-bar-main {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.find-input,
.replace-input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.82rem;
  outline: none;
  min-width: 150px;
}
.find-input:focus,
.replace-input:focus { border-color: var(--accent); }
.match-count {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  min-width: 60px;
}
.find-nav-btn,
.find-action-btn,
.find-close-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}
.find-nav-btn:hover,
.find-action-btn:hover { border-color: var(--accent); color: var(--accent); }
.find-close-btn { margin-left: auto; }
.find-close-btn:hover { color: var(--error, #ef4444); border-color: var(--error, #ef4444); }
.find-all-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.find-results {
  margin-top: 0.3rem;
  max-height: 200px;
  overflow-y: auto;
}
.find-results-panel { font-size: 0.82rem; }
.find-results-summary { color: var(--muted); padding: 2px 0 4px; font-size: 0.75rem; }
.find-result-group { margin-bottom: 4px; }
.find-result-group-header {
  display: flex;
  justify-content: space-between;
  padding: 3px 6px;
  background: var(--surface-2);
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.8rem;
}
.find-result-group-header:hover { background: var(--surface-3); }
.find-result-item {
  padding: 3px 12px;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--muted);
  border-radius: 3px;
}
.find-result-item:hover { background: var(--surface-2); color: var(--text); }
.find-result-highlight { background: rgba(253,224,71,0.3); color: var(--text); border-radius: 2px; }
.find-group-collapsed .find-result-items { display: none; }
.find-results-empty { color: var(--muted); font-size: 0.78rem; padding: 4px 0; }

/* ── Floating Format Toolbar ── */

#floating-toolbar {
  position: fixed;
  z-index: 60;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px var(--shadow), 0 1px 4px var(--shadow);
  transform: translateY(-4px);
  opacity: 0;
  transition: opacity var(--duration-fast), transform var(--duration-fast);
  pointer-events: none;
}
#floating-toolbar.visible {
  display: flex;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Arrow pointer below toolbar */
#floating-toolbar::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--border);
  pointer-events: none;
}

/* Toolbar buttons */
.ftb-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 500;
  transition: background var(--duration-fast), color var(--duration-fast);
}
.ftb-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.ftb-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.ftb-btn svg { width: 14px; height: 14px; }

/* Divider */
.ftb-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 2px;
  flex-shrink: 0;
}

/* Bold/Italic text labels for those buttons */
.ftb-label {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
}
