/* ── Warm Ink Layout ── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  transition: background var(--duration-slow), color var(--duration-slow);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

#app.app-hidden { display: none !important; }

/* ── Canvas-first: single column, full viewport ── */
#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* ── Topbar: thin context bar ── */
#topbar {
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  height: var(--topbar-height);
  gap: 0.5rem;
  flex-shrink: 0;
  background: transparent;
  border-bottom: 1px solid var(--border);
  z-index: 10;
  position: relative;
}

/* Hamburger button — always visible, same class as topbar-icon */
#topbar-hamburger {
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
  flex-shrink: 0;
  padding: 0;
  font-size: inherit;
  line-height: 1;
}
#topbar-hamburger:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
#topbar-hamburger svg { width: 18px; height: 18px; stroke-width: 2; pointer-events: none; }

#topbar-title {
  font-family: var(--font-ui);
  font-size: var(--font-base);
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
  padding: 2px 4px;
  border-radius: var(--radius);
  flex: 1;
  min-width: 0;
  transition: background var(--duration-fast), color var(--duration-fast);
}
#topbar-title[data-renamable="true"] {
  cursor: text;
}
#topbar-title[data-renamable="true"]:hover {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: underline dotted;
}

.topbar-sep {
  color: var(--muted);
  opacity: 0.4;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.topbar-chapter {
  font-family: var(--font-ui);
  font-size: var(--font-sm);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  flex-shrink: 1;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.125rem;
  flex-shrink: 0;
}

/* Generic topbar button — used by all icon buttons in the bar */
.topbar-btn {
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
  flex-shrink: 0;
  padding: 0;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  line-height: 1;
}
.topbar-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.topbar-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.topbar-btn svg,
.topbar-btn i { /* lucide icons */
  width: 16px;
  height: 16px;
  stroke-width: 2;
  vertical-align: middle;
  pointer-events: none;
  display: inline-block;
}

/* Lucide icon sizing — catches <i data-lucide="..."> rendered SVGs */
.topbar-btn svg { width: 16px; height: 16px; }
#topbar-hamburger svg { width: 18px; height: 18px; }
.editor-toolbar-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  vertical-align: middle;
  pointer-events: none;
  display: inline-block;
}

/* Auth status chip */
#auth-status {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 2px 8px;
  border-radius: var(--radius);
  background: var(--surface);
  white-space: nowrap;
}

/* Sync indicator */
#sync-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: var(--font-xs, 0.7rem);
  font-weight: 500;
  font-family: var(--font-ui);
  white-space: nowrap;
  background: rgba(90,138,60,0.1);
  color: var(--success);
}
#sync-indicator:empty { display: none; }
#sync-indicator.synced { background: rgba(90,138,60,0.1); color: var(--success); }
#sync-indicator.syncing { background: rgba(200,150,50,0.1); color: var(--warning); animation: pulse 1s infinite; }
#sync-indicator.error { background: rgba(200,60,60,0.1); color: var(--error); }

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

/* Desktop-only / overflow buttons */
.topbar-desktop-only { /* visible on desktop by default */ }
.topbar-overflow-btn { display: none; }
.panel-pull-tab { display: none; }

/* Profile dropdown */
.profile-dropdown {
  position: absolute;
  top: var(--topbar-height);
  right: 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 50;
  min-width: 200px;
  padding: 0.25rem 0;
}
.profile-dropdown-email {
  padding: 0.6rem 1rem;
  font-size: 0.78rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 1rem;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-ui);
  cursor: pointer;
  text-align: left;
}
.profile-dropdown-item:hover { background: var(--surface-2); }
.profile-dropdown-item svg { width: 16px; height: 16px; }

/* Overflow menu */
.topbar-overflow-menu {
  position: absolute;
  top: var(--topbar-height);
  right: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 50;
  min-width: 160px;
}
.overflow-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 1rem;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-ui);
  cursor: pointer;
  text-align: left;
}
.overflow-item:hover { background: var(--surface); }
.overflow-item svg { width: 16px; height: 16px; }

/* ── Main content area: fills remaining height ── */
#main-area {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ── Tab bar: hidden in Warm Ink ── */
#tab-bar { display: none !important; }

/* ── Editor panel: full remaining height ── */
#editor-panel {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  scroll-behavior: smooth;
  min-width: 0;
  overflow-x: hidden;
}

/* Editor toolbar — hidden; replaced by floating format toolbar */
#editor-toolbar {
  display: none !important;
}
#toolbar-format-row {
  display: none !important;
}

/* Editor content container */
#editor-container {
  min-height: 100%;
  padding: 2rem 2.5rem;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.8;
  color: var(--text);
}
#editor-container .ProseMirror {
  outline: none;
  min-height: 300px;
}
#editor-container .ProseMirror p {
  margin-bottom: 1em;
}

/* Editor toolbar buttons */
.editor-toolbar-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: var(--font-ui);
  transition: background 0.1s;
}
.editor-toolbar-btn:hover { background: var(--surface); }
.editor-toolbar-btn.active {
  color: var(--accent);
  background: var(--accent-soft);
}
.editor-toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
  flex-shrink: 0;
}

/* ── Player bar ── */
#player-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.4rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  min-width: 0;
  overflow-x: hidden;
}
#player-bar:empty { display: none; }

/* ── Status bar ── */
#status-bar {
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  padding-bottom: env(safe-area-inset-bottom, 0);
  height: var(--statusbar-height);
  font-family: var(--font-ui);
  font-size: var(--font-xs, 0.7rem);
  color: var(--muted);
  gap: 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
}
#status-bar span { flex-shrink: 0; }
#status-wordcount { font-weight: 600; opacity: 0.85; }
#status-charcount { opacity: 0.65; }
#status-session-count { opacity: 0.60; }
#status-streak { opacity: 0.60; }
#status-save { color: var(--success); font-style: italic; }

/* ── Binder overlay (positioned drawer, always off-screen by default) ── */
#binder-panel {
  position: fixed;
  left: 0;
  top: var(--topbar-height);
  bottom: var(--statusbar-height);
  width: var(--binder-width, 240px);
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 4px 0 24px var(--shadow);
  z-index: 40;
  transform: translateX(-100%);
  transition: transform var(--duration-slow, 0.28s) var(--ease-out, ease-out);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.75rem;
  font-size: 0.85rem;
  min-width: 0;
}
#binder-panel.open {
  transform: translateX(0);
}

#binder-panel .binder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.5rem;
  margin-bottom: 0.5rem;
}
#binder-panel .binder-header h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}
#binder-tree {
  flex: 1;
  overflow-y: auto;
}

/* ── Inspector overlay (positioned drawer, always off-screen by default) ── */
#inspector-panel {
  position: fixed;
  right: 0;
  top: var(--topbar-height);
  bottom: var(--statusbar-height);
  width: var(--inspector-width, 280px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px var(--shadow);
  z-index: 40;
  transform: translateX(100%);
  transition: transform var(--duration-slow, 0.28s) var(--ease-out, ease-out);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  font-size: 0.85rem;
  min-width: 0;
  /* isolation so sticky inspector header doesn't escape */
  isolation: isolate;
}
#inspector-panel.open {
  transform: translateX(0);
}

/* ── Inspector header — Warm Ink underline tabs ── */
#inspector-panel .inspector-header {
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  margin-bottom: 0;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
#inspector-panel .inspector-header::-webkit-scrollbar { display: none; }

/* Close button inside header */
.inspector-close-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin: auto 0.25rem auto auto;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: background var(--duration-fast, 0.12s), color var(--duration-fast, 0.12s);
}
.inspector-close-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Tabs — underline style */
.inspector-tab {
  flex: 0 0 auto;
  padding: 0.55rem 0.5rem;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  transition: color var(--duration-fast, 0.12s), border-color var(--duration-fast, 0.12s);
}
.inspector-tab:hover { color: var(--text); }
.inspector-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

#inspector-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
  padding: 0.75rem;
}
#inspector-content .snapshot-item,
#inspector-content .comment-item {
  word-break: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  box-sizing: border-box;
}

/* ── Inspector content — comment and snapshot items ── */
.comment-item {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.comment-item:last-child { border-bottom: none; }
.comment-author {
  font-family: var(--font-ui);
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.2rem;
}
.comment-text {
  font-size: var(--font-sm);
  color: var(--text-secondary, var(--muted));
  line-height: 1.5;
}
.comment-time {
  font-family: var(--font-ui);
  font-size: var(--font-xs);
  color: var(--muted);
  margin-top: 0.2rem;
}
.snapshot-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 0;
  transition: background var(--duration-fast, 0.12s);
}
.snapshot-item:last-child { border-bottom: none; }
.snapshot-item:hover {
  background: var(--surface-2);
  border-radius: var(--radius);
  margin: 0 -0.5rem;
  padding: 0.55rem 0.5rem;
}
.snapshot-date {
  font-family: var(--font-ui);
  font-size: var(--font-xs);
  color: var(--muted);
  flex-shrink: 0;
}
.snapshot-label {
  font-family: var(--font-ui);
  font-size: var(--font-sm);
  color: var(--text);
  flex: 1;
}
.snapshot-wc {
  font-family: var(--font-ui);
  font-size: var(--font-xs);
  color: var(--muted);
  flex-shrink: 0;
}

/* ── Overlay backdrops ── */
#binder-overlay,
#inspector-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 39;
  /* Hidden: use display:none / .open { display:block } to match existing JS */
  display: none;
}
#binder-overlay.open,
#inspector-overlay.open {
  display: block;
}

/* ── Binder edge hint ── */
.binder-edge-hint {
  position: fixed;
  left: 0;
  top: var(--topbar-height);
  bottom: var(--statusbar-height);
  width: 3px;
  background: linear-gradient(to bottom, transparent 10%, var(--accent) 50%, transparent 90%);
  opacity: 0.15;
  border-radius: 0 2px 2px 0;
  cursor: pointer;
  transition: opacity var(--duration-fast, 0.12s), width var(--duration-fast, 0.12s);
  z-index: 11;
}
.binder-edge-hint:hover {
  opacity: 0.4;
  width: 5px;
}

/* ── Auth overlay ── */
#auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 450;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1.2rem;
  padding: 2rem;
  text-align: center;
}
#auth-overlay.hidden { display: none; }

/* ── Settings panel — see css/warm-ink-settings.css ── */

/* ── Inline rename input ── */
#rename-input {
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--accent);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0 2px;
  min-width: 80px;
  max-width: 40vw;
  width: auto;
  outline: none;
}

/* ── ::selection colour ── */
::selection {
  background: var(--accent-soft);
  color: var(--text);
}

/* ── Library screen (welcome-screen) ── */
#welcome-screen {
  display: none;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  height: 100%;
  overflow-y: auto;
  gap: 0;
}

/* Library top bar */
#library-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  gap: 1rem;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
}
.library-color-hint {
  font-size: 0.75rem;
  color: var(--muted);
  cursor: help;
  opacity: 0.5;
  user-select: none;
}
.library-logo {
  max-height: 80px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
#library-heading {
  font-family: var(--font-body);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
#library-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
#library-sort-select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  font-family: var(--font-ui);
  cursor: pointer;
  outline: none;
}
#library-controls .welcome-btn {
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

/* Library card grid */
#manuscript-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1.25rem;
  padding: 1.75rem 2rem;
  align-content: start;
  flex: 1;
}

/* Manuscript card */
.ms-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 0.12s, box-shadow 0.12s;
  position: relative;
}
@media (hover: hover) {
  .ms-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 28px rgba(0,0,0,0.3);
  }
}
.ms-card-spine {
  height: 5px;
  background: var(--card-color, var(--accent));
  flex-shrink: 0;
}
.ms-card-body {
  padding: 1rem 1rem 0.75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: relative;
}
.ms-card-title {
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
  margin-bottom: 0.6rem;
}
.ms-card-meta {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.ms-card-stat {
  font-size: 0.75rem;
  color: var(--muted);
}
/* Word count progress bar */
.ms-card-progress {
  height: 3px;
  background: var(--surface-2);
  border-radius: 2px;
  overflow: hidden;
  margin: 0.3rem 0 0.15rem;
}
.ms-card-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width var(--duration-normal);
}
.ms-card-date {
  font-size: 0.7rem;
  color: var(--muted);
  opacity: 0.65;
  margin-top: 0.3rem;
}
.ms-card-actions {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,0.08);
  flex-shrink: 0;
}
.ms-card-open {
  flex: 1;
  padding: 0.35rem 0.5rem;
  background: var(--card-color, var(--accent));
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-ui);
  transition: opacity 0.1s;
}
.ms-card-open:hover { opacity: 0.85; }
.ms-card-rename {
  padding: 0.35rem 0.5rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-ui);
  transition: background 0.1s, color 0.1s;
}
.ms-card-rename:hover {
  background: var(--surface);
  color: var(--text);
}
.ms-card-delete {
  padding: 0.35rem 0.5rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.78rem;
  font-family: var(--font-ui);
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}
.ms-card-delete:hover {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}

/* Multi-select checkbox on cards */
.ms-card-check {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
  cursor: pointer;
}
.ms-card-check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Floating selection action bar */
.selection-action-bar {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 8000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  font-size: 0.85rem;
  color: var(--text);
  font-family: var(--font-ui);
}

/* Action buttons used in library topbar and elsewhere */
.welcome-btn {
  display: inline-block;
  padding: 0.6rem 1.8rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  cursor: pointer;
  font-family: var(--font-ui);
  transition: opacity 0.15s;
  text-align: center;
  text-decoration: none;
  user-select: none;
}
.welcome-btn:hover { opacity: 0.9; }
.welcome-btn.secondary {
  background: var(--surface);
  color: var(--text);
}

/* View mode toggle buttons */
.view-mode-toggle {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.view-mode-btn {
  background: var(--surface);
  color: var(--muted);
  border: none;
  border-right: 1px solid var(--border);
  padding: 0.3rem 0.55rem;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--font-ui);
  line-height: 1;
}
.view-mode-btn:last-child { border-right: none; }
.view-mode-btn.active {
  background: var(--accent);
  color: #fff;
}

/* View mode: icons (compact grid) */
#manuscript-list.view-icons {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}
#manuscript-list.view-icons .ms-card-body { padding: 0.6rem 0.6rem 0.4rem; }
#manuscript-list.view-icons .ms-card-title {
  font-size: 0.82rem;
  margin-bottom: 0.3rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
#manuscript-list.view-icons .ms-card-meta { gap: 0; }
#manuscript-list.view-icons .ms-card-stat { font-size: 0.65rem; }
#manuscript-list.view-icons .ms-card-date { font-size: 0.6rem; }
#manuscript-list.view-icons .ms-card-actions { padding: 0.4rem 0.5rem; }
#manuscript-list.view-icons .ms-card-actions .ms-card-rename,
#manuscript-list.view-icons .ms-card-actions .ms-card-delete {
  font-size: 0.7rem;
  padding: 0.25rem 0.4rem;
}
#manuscript-list.view-icons .ms-card-open { font-size: 0.72rem; padding: 0.25rem 0.4rem; }

/* View mode: list (single-column detail rows) */
#manuscript-list.view-list {
  grid-template-columns: 1fr;
  gap: 0;
}
#manuscript-list.view-list .ms-card {
  flex-direction: row;
  align-items: center;
  border-radius: 0;
  border-bottom: 1px solid var(--border);
  border-left: none;
  border-right: none;
  border-top: none;
}
#manuscript-list.view-list .ms-card-spine { height: auto; width: 5px; align-self: stretch; }
#manuscript-list.view-list .ms-card-body {
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  flex: 1;
  min-width: 0;
}
#manuscript-list.view-list .ms-card-title {
  font-size: 0.9rem;
  margin-bottom: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 120px;
  flex: 1;
}
#manuscript-list.view-list .ms-card-meta {
  flex-direction: row;
  gap: 0.75rem;
  margin-top: 0;
  flex-shrink: 0;
}
#manuscript-list.view-list .ms-card-date { margin-top: 0; }
#manuscript-list.view-list .ms-card-actions {
  border-top: none;
  border-left: 1px solid var(--border);
  background: none;
  flex-shrink: 0;
}
#manuscript-list.view-list .ms-card-check { position: static; margin-right: 0; }

/* Empty library state */
.library-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5rem 2rem;
  text-align: center;
  gap: 0.75rem;
}
.library-empty-icon {
  font-size: 3.5rem;
  line-height: 1;
  opacity: 0.25;
  margin-bottom: 0.5rem;
}
.library-empty h3 {
  font-family: var(--font-body);
  font-size: 1.2rem;
  color: var(--text);
  font-weight: 600;
}
.library-empty p {
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 300px;
  line-height: 1.6;
}

/* Loading skeleton pulse */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}
.ms-card-stat.loading {
  animation: skeleton-pulse 1.4s var(--ease-in-out, ease-in-out) infinite;
}

/* ── Toast container ── */
#toast-container { pointer-events: none; }

/* ── Heading preview tooltip ── */
#heading-tooltip {
  position: fixed;
  z-index: 9999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  font-family: var(--font-body);
  color: var(--text);
  white-space: nowrap;
}
#heading-tooltip.visible { opacity: 1; }
#heading-tooltip.h1-preview { font-size: 1.8em; font-weight: 700; line-height: 1.2; }
#heading-tooltip.h2-preview { font-size: 1.4em; font-weight: 700; line-height: 1.2; }
#heading-tooltip.h3-preview { font-size: 1.2em; font-weight: 600; line-height: 1.2; }

/* ── Zen mode (distraction-free writing) ── */
body.zen-mode #topbar,
body.zen-mode #tab-bar,
body.zen-mode #binder-panel,
body.zen-mode #inspector-panel,
body.zen-mode #editor-toolbar,
body.zen-mode #status-bar,
body.zen-mode #player-bar { display: none !important; }
body.zen-mode #app {
  flex-direction: column;
}
body.zen-mode #editor-panel {
  flex: 1;
}
body.zen-mode #editor-container {
  max-width: 680px;
  padding: 3rem 2rem;
}
body.zen-mode .zen-exit-hint {
  position: fixed;
  top: 1rem;
  right: 1rem;
  background: var(--surface);
  color: var(--muted);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  font-size: 0.75rem;
  opacity: 0.6;
  z-index: 999;
  pointer-events: none;
  transition: opacity 3s var(--ease-out, ease-out) 2s;
}
body.zen-mode .zen-exit-hint.fade { opacity: 0; }

/* ── Mobile breakpoint ── */
@media (max-width: 768px) {
  #library-topbar { padding: 1rem; gap: 0.75rem; }
  #manuscript-list { grid-template-columns: 1fr; padding: 1rem; gap: 0.75rem; }

  /* Show overflow button, hide desktop-only buttons */
  .topbar-desktop-only { display: none !important; }
  .topbar-overflow-btn { display: flex; }

  #auth-status { font-size: 0.7rem; padding: 1px 6px; }

  #editor-container { padding: 1rem; }
  #editor-toolbar { padding: 0.3rem 0.5rem; }
  #player-bar { padding: 0.4rem 0.75rem; }
}

/* ── Compensate for active player bar on sidebars + editor ── */
body.player-active #inspector-panel,
body.player-active #binder-panel {
  padding-bottom: 80px;
}
body.player-active #editor-panel {
  /* Prevent player pill from covering text at bottom of writing area */
  scroll-padding-bottom: 80px;
  padding-bottom: 80px;
}
