/* ==========================================================================
   WRITE — Writing Studio & Journal
   ========================================================================== */

:root {
  --desk: #e6e4de;
  --paper: #f4f3ef;
  --paper-card: #ecebe6;
  --ink: #121211;
  --mid: #4a4945;
  --muted: #75746f;
  --soft: #a3a29d;
  --rule: #d2d1cb;
  --rule-light: #e1e0da;
  --stamp: #a8321f;
  --field: rgba(18, 18, 17, 0.055);
  --field-active: rgba(18, 18, 17, 0.09);

  /* Fonts */
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-serif: 'Merriweather', Georgia, 'Times New Roman', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-typewriter: 'Courier Prime', 'Courier New', monospace;
  --font: var(--font-mono);

  /* Accent Inks */
  --ink-blue: #325b99;
  --ink-green: #376b42;
  --ink-gold: #9e7314;
  --ink-purple: #6d478f;
  --ink-red: #a8321f;

  /* Accent Backgrounds */
  --bg-blue: rgba(50, 91, 153, 0.09);
  --bg-green: rgba(55, 107, 66, 0.09);
  --bg-gold: rgba(158, 115, 20, 0.09);
  --bg-purple: rgba(109, 71, 143, 0.09);
  --bg-red: rgba(168, 50, 31, 0.09);

  --text-main: var(--ink);
  --text-muted: var(--muted);
  --text-dim: var(--soft);
  --border-subtle: var(--rule);
  --primary: var(--ink);
  --danger: var(--stamp);
  --radius-sm: 2px;
  --radius-md: 4px;

  --ease-out-gentle: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.12);

  /* Editor Canvas Settings Defaults */
  --editor-font-size: 15px;
  --editor-line-height: 1.8;
  --editor-max-width: 68ch;

  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;
  --desk: #0c0c0b;
  --paper: #181816;
  --paper-card: #20201d;
  --ink: #efeee9;
  --mid: #c5c4be;
  --muted: #8d8c86;
  --soft: #62615c;
  --rule: #34342f;
  --rule-light: #292925;
  --stamp: #ff8f70;
  --field: rgba(255, 255, 255, 0.06);
  --field-active: rgba(255, 255, 255, 0.1);

  --ink-blue: #86b2ff;
  --ink-green: #81cf93;
  --ink-gold: #f2c14e;
  --ink-purple: #c79ff5;
  --ink-red: #ff8f70;

  --bg-blue: rgba(134, 178, 255, 0.14);
  --bg-green: rgba(129, 207, 147, 0.14);
  --bg-gold: rgba(242, 193, 78, 0.14);
  --bg-purple: rgba(199, 159, 245, 0.14);
  --bg-red: rgba(255, 143, 112, 0.14);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.6);
}

/* ==========================================================================
   Base & Resets
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 99px;
  border: 1px solid transparent;
  background-clip: padding-box;
  transition: background 0.15s ease;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--soft);
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--desk);
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  background: var(--desk);
  color: var(--ink);
  height: 100%;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: slashed-zero;
}

/* ==========================================================================
   Main Studio Shell
   ========================================================================== */
.studio-shell {
  width: 100vw;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
}

/* ==========================================================================
   Header & Navigation
   ========================================================================== */
.studio-header {
  height: 48px;
  min-height: 48px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 12px;
  z-index: 40;
}

.header-left, .header-center, .header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-left {
  flex-shrink: 0;
}

.header-center {
  flex: 1;
  justify-content: center;
}

.header-right {
  flex-shrink: 0;
}

.nav-back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all 0.15s ease;
}
.nav-back-link:hover {
  color: var(--ink);
  border-color: var(--rule);
  background: var(--field);
}

.brand-badge {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.02em;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
}
.brand-badge .version-tag {
  font-size: 9px;
  font-weight: 500;
  padding: 1px 4px;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--r-sm);
  letter-spacing: 0;
}

.project-select-btn {
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 200px;
  transition: all 0.15s ease;
}
.project-select-btn:hover {
  background: var(--field-active);
  border-color: var(--soft);
}

/* Mode Switch Tabs */
.view-mode-tabs {
  display: flex;
  align-items: center;
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.mode-tab-btn {
  background: transparent;
  border: none;
  padding: 4px 10px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  white-space: nowrap;
}
.mode-tab-btn:hover {
  color: var(--ink);
}
.mode-tab-btn.active {
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

/* Header utility buttons */
.tool-icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--mid);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}
.tool-icon-btn:hover {
  background: var(--field);
  border-color: var(--rule);
  color: var(--ink);
}
.tool-icon-btn.active {
  background: var(--bg-blue);
  border-color: var(--ink-blue);
  color: var(--ink-blue);
}

.btn-theme-toggle {
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--mid);
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-theme-toggle:hover {
  color: var(--ink);
  border-color: var(--soft);
}

/* ==========================================================================
   Layout Body & Panes
   ========================================================================== */
.studio-body {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* Left Sidebar (Outline / Chapters / Journal Logs) */
.studio-sidebar-left {
  width: 290px;
  min-width: 290px;
  background: var(--paper-card);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  transition: transform 0.25s var(--ease-out-gentle), width 0.25s var(--ease-out-gentle);
  z-index: 20;
}
.studio-sidebar-left.collapsed {
  width: 0;
  min-width: 0;
  transform: translateX(-100%);
  border-right: none;
}

.sidebar-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--paper-card);
}
.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.sidebar-search-box {
  padding: 8px 12px;
  border-bottom: 1px solid var(--rule);
}
.sidebar-search-input {
  width: 100%;
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink);
  outline: none;
}
.sidebar-search-input:focus {
  border-color: var(--ink-blue);
  background: var(--paper);
}

.sidebar-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--rule);
  background: var(--paper-card);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Right Sidebar (Inspector, Notes, Quick Codex) */
.studio-sidebar-right {
  width: 310px;
  min-width: 310px;
  background: var(--paper-card);
  border-left: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  transition: transform 0.25s var(--ease-out-gentle), width 0.25s var(--ease-out-gentle);
  z-index: 20;
}
.studio-sidebar-right.collapsed {
  width: 0;
  min-width: 0;
  transform: translateX(100%);
  border-left: none;
}

/* Center Content Area */
.studio-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background: var(--paper);
}

/* ==========================================================================
   Novel Studio / Tree Outline Elements
   ========================================================================== */
.act-group {
  margin-bottom: 10px;
}
.act-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--soft);
}

.chapter-item {
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  overflow: hidden;
}
.chapter-header {
  padding: 7px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  background: var(--field);
  border-bottom: 1px solid transparent;
  user-select: none;
  transition: background 0.15s ease;
}
.chapter-header:hover {
  background: var(--field-active);
}
.chapter-header.expanded {
  border-bottom-color: var(--rule);
}
.chapter-title-text {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
}
.chapter-words-badge {
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
}

.scenes-container {
  display: flex;
  flex-direction: column;
}

.scene-item {
  padding: 6px 10px 6px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  border-bottom: 1px solid var(--rule-light);
  transition: background 0.15s ease, border-color 0.15s ease;
  position: relative;
}
.scene-item:last-child {
  border-bottom: none;
}
.scene-item:hover {
  background: var(--field);
}
.scene-item.active {
  background: var(--bg-blue);
  color: var(--ink-blue);
  border-left: 3px solid var(--ink-blue);
  font-weight: 600;
}
.scene-item.active .scene-item-title {
  color: var(--ink-blue);
  font-weight: 700;
}

.scene-item-left {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scene-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-draft { background: var(--ink-gold); }
.status-outline { background: var(--soft); }
.status-revision { background: var(--ink-purple); }
.status-polished { background: var(--ink-blue); }
.status-done { background: var(--ink-green); }

.scene-item-title {
  font-size: 11px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scene-item-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* ==========================================================================
   Journal Studio / Timeline Entries Elements
   ========================================================================== */
.journal-group-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--soft);
  letter-spacing: 0.05em;
  padding: 6px 4px 2px 4px;
  margin-top: 6px;
}

.journal-entry-item {
  padding: 8px 10px;
  border: 1px solid var(--rule);
  background: var(--paper);
  border-radius: var(--radius-sm);
  margin-bottom: 5px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.journal-entry-item:hover {
  background: var(--field);
  border-color: var(--soft);
}
.journal-entry-item.active {
  border-color: var(--ink-purple);
  background: var(--bg-purple);
}
.journal-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 3px;
}
.journal-entry-date {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
}
.journal-entry-mood {
  font-size: 12px;
}
.journal-entry-snippet {
  font-size: 11px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.journal-entry-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 9px;
  color: var(--soft);
}

/* ==========================================================================
   Editor Canvas & Toolbars
   ========================================================================== */
.editor-top-meta {
  padding: 12px 24px 8px 24px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editor-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-title-input {
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
  letter-spacing: -0.02em;
}
.editor-title-input::placeholder {
  color: var(--soft);
}

.editor-meta-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  color: var(--mid);
  transition: all 0.15s ease;
}

.meta-badge:hover,
.meta-badge:focus-within {
  border-color: var(--soft);
  background: var(--field-active);
}

.meta-select {
  background: transparent;
  border: none;
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--ink);
  outline: none;
  cursor: pointer;
}

/* Base Select & Option elements styling for full contrast across light and dark themes */
select, .meta-select, .form-select {
  color: var(--ink);
}

select option,
.meta-select option,
.form-select option,
optgroup {
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
}

[data-theme="dark"] select,
[data-theme="dark"] .meta-select,
[data-theme="dark"] .form-select {
  color: #efeee9;
}

[data-theme="dark"] select option,
[data-theme="dark"] .meta-select option,
[data-theme="dark"] .form-select option,
[data-theme="dark"] optgroup {
  background-color: #20201d;
  color: #efeee9;
}

[data-theme="dark"] .meta-badge {
  background: rgba(255, 255, 255, 0.08);
  border-color: #3e3e38;
}

[data-theme="dark"] .meta-badge:hover,
[data-theme="dark"] .meta-badge:focus-within {
  background: rgba(255, 255, 255, 0.13);
  border-color: var(--soft);
}

/* Journal Entry Specific Meta Bar */
.journal-meta-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 6px 0;
  border-top: 1px solid var(--rule-light);
}
.mood-picker-group {
  display: flex;
  align-items: center;
  gap: 3px;
}
.mood-btn {
  background: var(--paper-card);
  border: 1px solid var(--rule-light);
  border-radius: var(--radius-sm);
  padding: 3px 5px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}
.mood-btn:hover {
  background: var(--field);
  border-color: var(--rule);
  color: var(--ink);
  transform: translateY(-1px);
}
.mood-btn.active {
  background: var(--bg-gold);
  border-color: var(--ink-gold);
  color: var(--ink-gold);
  box-shadow: 0 0 0 1px var(--ink-gold);
}
.mood-btn svg, .mood-btn [data-lucide] {
  width: 13px;
  height: 13px;
  stroke-width: 2px;
}

/* Habit tracker pills in toolbar and inspector */
.habits-picker-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.habit-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  font-size: 10px;
  font-family: var(--font-ui);
  background: var(--paper-card);
  border: 1px solid var(--rule-light);
  border-radius: 99px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}
.habit-pill:hover {
  border-color: var(--rule);
  color: var(--ink);
}
.habit-pill.checked {
  background: var(--bg-green);
  border-color: var(--ink-green);
  color: var(--ink-green);
  font-weight: 600;
}

/* Editor Action Bar (Formatting & Focus Controls) */
.editor-action-bar {
  padding: 6px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.action-bar-group {
  display: flex;
  align-items: center;
  gap: 3px;
}

.action-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 3px 7px;
  font-family: var(--font-ui);
  font-size: 11px;
  color: var(--mid);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s ease;
  height: 26px;
}
.action-btn:hover {
  background: var(--field);
  border-color: var(--rule);
  color: var(--ink);
}
.action-btn.active {
  background: var(--field-active);
  border-color: var(--border-strong);
  color: var(--ink);
  font-weight: 700;
}

.divider-vertical {
  width: 1px;
  height: 16px;
  background: var(--rule);
  margin: 0 4px;
}

/* The Core Writing Canvas Area */
.editor-canvas-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 80px 20px;
  display: flex;
  justify-content: center;
  position: relative;
  background: var(--paper);
}

.editor-canvas-wrapper {
  width: 100%;
  max-width: var(--editor-max-width);
  min-height: 60vh;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* Font Family Classes */
.font-mode-mono { font-family: var(--font-mono); }
.font-mode-serif { font-family: var(--font-serif); }
.font-mode-sans { font-family: var(--font-sans); }
.font-mode-typewriter { font-family: var(--font-typewriter); }

/* Fiction Indent Mode */
.indent-mode-fiction p {
  text-indent: 1.8em;
  margin-bottom: 0 !important;
}
.indent-mode-fiction p:first-of-type,
.indent-mode-fiction h1 + p,
.indent-mode-fiction h2 + p,
.indent-mode-fiction h3 + p,
.indent-mode-fiction hr + p {
  text-indent: 0;
}

/* The actual text content area */
.writing-textarea {
  width: 100%;
  min-height: 400px;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  font-size: var(--editor-font-size);
  line-height: var(--editor-line-height);
  color: var(--ink);
  caret-color: var(--stamp);
  white-space: pre-wrap;
  word-wrap: break-word;
  tab-size: 4;
}

/* Focus / Zen Mode */
.studio-shell.zen-mode .studio-header,
.studio-shell.zen-mode .studio-sidebar-left,
.studio-shell.zen-mode .studio-sidebar-right,
.studio-shell.zen-mode .editor-top-meta,
.studio-shell.zen-mode .editor-action-bar,
.studio-shell.zen-mode .editor-status-bar {
  display: none !important;
}
.studio-shell.zen-mode .studio-center {
  background: var(--paper);
}
.studio-shell.zen-mode .editor-canvas-scroll {
  padding-top: 60px;
}
.zen-exit-floating-btn {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 100;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: var(--font-ui);
  font-size: 11px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  opacity: 0.3;
  transition: opacity 0.2s ease;
}
.zen-exit-floating-btn:hover {
  opacity: 1;
  color: var(--ink);
}

/* Typewriter Scrolling: Keeps active line centered */
.typewriter-mode .editor-canvas-scroll {
  padding-bottom: 50vh !important;
}

/* Prose Highlighter Overlay */
.prose-analysis-panel {
  margin-top: 14px;
  padding: 10px 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--field);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.prose-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: var(--r-sm);
  font-size: 10px;
  font-weight: 600;
}

/* Status Bar at the bottom */
.editor-status-bar {
  height: 32px;
  min-height: 32px;
  background: var(--paper-card);
  border-top: 1px solid var(--rule);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  z-index: 30;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.save-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--ink-green);
}
.save-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-green);
}
.save-dot.unsaved {
  background: var(--ink-gold);
}

/* ==========================================================================
   Corkboard / Beat Board View
   ========================================================================== */
.view-corkboard-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--desk);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.corkboard-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
}

.corkboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.cork-card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative;
}
.cork-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.cork-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.cork-card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cork-card-synopsis {
  font-size: 11px;
  color: var(--mid);
  line-height: 1.4;
  min-height: 48px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.cork-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 6px;
  border-top: 1px solid var(--rule-light);
  font-size: 10px;
  color: var(--soft);
}

/* ==========================================================================
   Codex & Worldbuilding Bible View
   ========================================================================== */
.view-codex-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.codex-nav-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 10px;
  flex-wrap: wrap;
}

.codex-tab-btn {
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--mid);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  transition: all 0.15s ease;
  user-select: none;
}
.codex-tab-btn svg {
  width: 15px;
  height: 15px;
  color: var(--muted);
  flex-shrink: 0;
}
.codex-tab-btn:hover {
  color: var(--ink);
  background: var(--field-active);
  border-color: var(--soft);
}
.codex-tab-btn.active {
  background: var(--paper-card);
  border-color: var(--border-strong);
  color: var(--ink);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.codex-tab-btn.active svg {
  color: var(--ink);
}

.codex-tab-label {
  white-space: nowrap;
}

.codex-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  background: var(--field-active);
  color: var(--muted);
  border: 1px solid var(--rule);
}
.codex-tab-btn.active .codex-count-badge {
  background: var(--solid);
  color: var(--on-solid);
  border-color: var(--border-strong);
}

.codex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.codex-card {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease;
}
.codex-card:hover {
  border-color: var(--soft);
}
.codex-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.codex-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}
.codex-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.codex-role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.codex-card-body {
  font-size: 11px;
  color: var(--mid);
  line-height: 1.5;
}
.codex-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.trait-tag {
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 1px 6px;
  font-size: 10px;
  color: var(--mid);
}

/* ==========================================================================
   Analytics, Heatmap & Metrics View
   ========================================================================== */
.view-analytics-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

.stats-card-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.stat-metric-card {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-metric-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.stat-metric-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.stat-metric-sub {
  font-size: 10px;
  color: var(--soft);
}

/* GitHub style contribution heatmap */
.heatmap-container {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.heatmap-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, 13px);
  grid-auto-flow: column;
  gap: 3px;
  overflow-x: auto;
  padding-bottom: 6px;
}
.heatmap-cell {
  width: 13px;
  height: 13px;
  border-radius: var(--r-sm);
  background: var(--field);
  border: 1px solid var(--rule-light);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.heatmap-cell:hover {
  transform: scale(1.3);
  z-index: 5;
}
.cell-lvl-1 { background: rgba(55, 107, 66, 0.25); border-color: rgba(55, 107, 66, 0.4); }
.cell-lvl-2 { background: rgba(55, 107, 66, 0.50); border-color: rgba(55, 107, 66, 0.7); }
.cell-lvl-3 { background: rgba(55, 107, 66, 0.75); border-color: var(--ink-green); }
.cell-lvl-4 { background: var(--ink-green); border-color: var(--ink-green); }

/* ==========================================================================
   Modals, Floating Panels & Drawers
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.modal-overlay.hidden {
  display: none !important;
}

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

.modal-dialog {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  animation: modalSlideUp 0.2s var(--ease-out-gentle);
}

@keyframes modalSlideUp {
  from { transform: translateY(12px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}
.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.modal-close-btn:hover {
  color: var(--ink);
}

.modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  background: var(--paper-card);
}

/* Form inputs inside modals */
.input-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 3px;
  display: block;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
[data-theme="dark"] .form-select {
  background-color: #1e1e1b;
  border-color: #3e3e38;
  color: #efeee9;
}
[data-theme="dark"] .form-select:focus {
  border-color: var(--stamp);
  background-color: #242420;
}
/* Project Studio Modes Grid */
.project-modes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 6px;
}
@media (max-width: 600px) {
  .project-modes-grid {
    grid-template-columns: 1fr;
  }
}
.mode-card {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.15s ease;
  position: relative;
  user-select: none;
}
.mode-card:hover {
  border-color: var(--soft);
  background: var(--field-active);
  transform: translateY(-1px);
}
.mode-card.selected {
  border-color: var(--stamp);
  background: var(--bg-gold);
  box-shadow: 0 0 0 1px var(--stamp);
}
.mode-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mode-card-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.mode-card-title {
  font-weight: 700;
  font-size: 11px;
  color: var(--ink);
}
.mode-card-desc {
  font-size: 10px;
  color: var(--mid);
  line-height: 1.35;
  flex: 1;
}
.mode-card-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-top: 4px;
}
.mode-card.selected .mode-card-badge {
  color: var(--stamp);
}

/* Starter Option Cards (Clean Slate vs Mode Defaults) */
.starter-option-card {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}
.starter-option-card:hover {
  border-color: var(--soft);
  background: var(--field-active);
}
.starter-option-card.selected {
  border-color: var(--ink-blue);
  background: var(--bg-blue);
  box-shadow: 0 0 0 1px var(--ink-blue);
}

/* Writing Canvas Empty State */
.canvas-empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  padding: 48px 20px;
  text-align: center;
}
.canvas-empty-card {
  max-width: 440px;
  background: var(--paper-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 36px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.canvas-empty-icon {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--field);
  border: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

/* Codex Relationship Cards */
.relation-card {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.15s ease;
}
.relation-card:hover {
  border-color: var(--soft);
  box-shadow: var(--shadow-sm);
}
.relation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.relation-chars {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 12px;
  color: var(--ink);
}
.relation-badge {
  display: inline-block;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
  border-radius: var(--r-sm);
  background: var(--bg-purple);
  color: var(--ink-purple);
  border: 1px solid rgba(109, 71, 143, 0.2);
}
.relation-notes {
  font-size: 11px;
  color: var(--mid);
  line-height: 1.45;
}

/* ==========================================================================
   Buttons & Tags
   ========================================================================== */
.btn {
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}
.btn:hover {
  background: var(--field-active);
  border-color: var(--soft);
}

.btn-primary {
  background: var(--solid);
  border-color: var(--border-strong);
  color: var(--on-solid);
}
.btn-primary:hover {
  opacity: 0.9;
}

.btn-danger {
  color: var(--stamp);
  border-color: var(--stamp);
}
.btn-danger:hover {
  background: var(--bg-red);
}

.btn-sm {
  padding: 3px 8px;
  font-size: 10px;
}

.btn-spark-filter {
  background: var(--paper-card);
  border-color: var(--rule);
  color: var(--mid);
  transition: all 0.15s ease;
}
.btn-spark-filter:hover {
  border-color: var(--ink-blue);
  color: var(--ink);
}
.btn-spark-filter.active {
  background: var(--ink-blue);
  color: #ffffff;
  border-color: var(--ink-blue);
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule);
}

/* ==========================================================================
   Writing Sprint HUD (Floating Overlay)
   ========================================================================== */
.sprint-hud {
  position: fixed;
  bottom: 46px;
  right: 20px;
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: var(--shadow-md);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 14px;
  animation: modalSlideUp 0.2s ease;
}
.sprint-hud.hidden {
  display: none !important;
}
.sprint-timer-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--stamp);
  letter-spacing: -0.02em;
}
.sprint-word-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

/* ==========================================================================
   Sound Ambience HUD
   ========================================================================== */
.ambience-popover {
  position: absolute;
  top: 48px;
  right: 14px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ambience-popover.hidden {
  display: none !important;
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-banner {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--solid);
  color: var(--on-solid);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 200;
  pointer-events: none;
  animation: fadeIn 0.15s ease;
}
.toast-banner.hidden {
  display: none !important;
}

/* ==========================================================================
   Mobile-only Elements (hidden on desktop)
   ========================================================================== */
.mobile-only {
  display: none !important;
}

.drawer-backdrop {
  display: none;
}

.mobile-bottom-nav {
  display: none;
}

.sheet-menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px 16px 18px 16px;
}
.sheet-menu-item {
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 14px 6px 12px 6px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  text-align: center;
  text-decoration: none;
  line-height: 1.2;
  min-height: 78px;
  transition: background 0.15s ease, transform 0.1s ease;
}
.sheet-menu-item:active {
  transform: scale(0.96);
  background: var(--field-active);
}
.sheet-menu-item svg {
  width: 20px;
  height: 20px;
  color: var(--mid);
}
.sheet-menu-item.accent svg {
  color: var(--stamp);
}

/* ==========================================================================
   Tablet & Mobile Layout (≤ 900px)
   ========================================================================== */
@media (max-width: 900px) {
  .mobile-only {
    display: inline-flex !important;
  }
  .desktop-only {
    display: none !important;
  }

  /* Track the real visible viewport (keyboard-aware on iOS) */
  html, body, .studio-shell {
    height: var(--app-height, 100dvh);
  }

  /* ---------- Header ---------- */
  .studio-header {
    height: auto;
    min-height: 52px;
    padding: env(safe-area-inset-top) 10px 0 10px;
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
    gap: 6px;
  }
  .header-left {
    flex: 1;
    min-width: 0;
    gap: 6px;
    height: 52px;
  }
  .header-right {
    gap: 4px;
    height: 52px;
  }
  .header-center {
    display: none;
  }
  .nav-back-link {
    padding: 0;
    width: 38px;
    height: 38px;
    justify-content: center;
    flex-shrink: 0;
  }
  .nav-back-link .btn-label {
    display: none;
  }
  .brand-badge .version-tag {
    display: none;
  }
  .project-select-btn {
    flex: 1;
    min-width: 0;
    max-width: none;
    height: 38px;
    padding: 0 12px;
    font-size: 12px;
    justify-content: flex-start;
  }
  .project-select-btn #current-project-name {
    flex: 1;
    text-align: left;
  }
  .tool-icon-btn,
  .btn-theme-toggle {
    width: 40px;
    height: 40px;
  }

  /* ---------- Drawers ---------- */
  .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    z-index: 70;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }
  .drawer-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .studio-sidebar-left,
  .studio-sidebar-left.collapsed {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 340px);
    min-width: 0;
    border-right: 1px solid var(--rule);
    transform: translateX(-104%);
    box-shadow: var(--shadow-lg);
    z-index: 80;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    transition: transform 0.26s var(--ease-out-gentle);
  }
  .studio-sidebar-left.mobile-open {
    transform: translateX(0);
  }

  .studio-sidebar-right,
  .studio-sidebar-right.collapsed {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    min-width: 0;
    height: min(78dvh, 640px);
    border-left: none;
    border-top: 1px solid var(--rule);
    border-radius: 16px 16px 0 0;
    transform: translateY(104%);
    box-shadow: var(--shadow-lg);
    z-index: 80;
    padding-bottom: env(safe-area-inset-bottom);
    transition: transform 0.28s var(--ease-out-gentle);
  }
  .studio-sidebar-right.mobile-open {
    transform: translateY(0);
  }
  .studio-sidebar-right .sidebar-header {
    border-radius: 16px 16px 0 0;
    padding-top: 18px;
    position: relative;
    touch-action: none;
  }
  .studio-sidebar-right .sidebar-header::before {
    content: '';
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    border-radius: 99px;
    background: var(--rule);
  }
  .studio-sidebar-right .sidebar-scroll-area {
    padding: 12px 16px 20px 16px;
  }

  .sidebar-header {
    padding: 12px 14px;
  }
  .sidebar-search-box {
    padding: 10px 12px;
  }
  .sidebar-search-input {
    font-size: 16px;
    padding: 9px 12px;
    border-radius: 8px;
  }
  .sidebar-footer {
    padding: 10px 12px;
  }
  .sidebar-footer .btn {
    min-height: 42px;
    font-size: 12px;
  }

  /* Bigger tree rows for fingers */
  .chapter-header {
    padding: 11px 12px;
  }
  .chapter-title-text {
    font-size: 12px;
  }
  .scene-item {
    padding: 10px 8px 10px 22px;
    min-height: 46px;
  }
  .scene-item-title {
    font-size: 12.5px;
  }
  .scene-item-right .action-btn,
  .journal-entry-meta .action-btn {
    width: 32px;
    height: 32px !important;
    padding: 0 !important;
    color: var(--soft);
  }
  .journal-entry-item {
    padding: 12px;
    margin-bottom: 7px;
  }
  .journal-entry-snippet {
    font-size: 12px;
  }

  /* ---------- Bottom Tab Bar ---------- */
  .mobile-bottom-nav {
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    background: var(--paper-card);
    border-top: 1px solid var(--rule);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    z-index: 60;
    flex-shrink: 0;
  }
  .bnav-btn {
    flex: 1;
    background: transparent;
    border: none;
    font-family: var(--font-ui);
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 56px;
    cursor: pointer;
    position: relative;
    transition: color 0.15s ease;
  }
  .bnav-btn svg {
    width: 20px;
    height: 20px;
    stroke-width: 1.9px;
  }
  .bnav-btn.active {
    color: var(--ink);
    font-weight: 700;
  }
  .bnav-btn.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 28%;
    right: 28%;
    height: 2px;
    border-radius: 0 0 2px 2px;
    background: var(--stamp);
  }
  .bnav-btn:active {
    background: var(--field);
  }

  /* Hide tab bar while typing or in Zen to maximise writing room */
  body.kb-open .mobile-bottom-nav,
  .studio-shell.zen-mode .mobile-bottom-nav {
    display: none;
  }

  /* ---------- Editor ---------- */
  :root {
    --editor-font-size: 16px;
  }
  .editor-top-meta {
    padding: 10px 14px 8px 14px;
    gap: 8px;
  }
  .editor-title-input {
    font-size: 18px;
  }
  .editor-title-row .action-btn {
    width: 38px;
    height: 38px;
    padding: 0;
  }
  .editor-title-row .action-btn .btn-label {
    display: none;
  }

  /* Metadata chips: one swipeable row */
  .editor-meta-badges,
  .journal-meta-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -14px;
    padding-left: 14px;
    padding-right: 14px;
    -webkit-overflow-scrolling: touch;
  }
  .editor-meta-badges::-webkit-scrollbar,
  .journal-meta-bar::-webkit-scrollbar {
    display: none;
  }
  .meta-badge {
    flex-shrink: 0;
    padding: 6px 10px;
    border-radius: 99px;
  }
  .meta-select {
    font-size: 12px;
  }
  .journal-meta-bar > * {
    flex-shrink: 0;
  }
  .mood-btn {
    padding: 6px 8px;
  }
  .mood-btn svg, .mood-btn [data-lucide] {
    width: 14px;
    height: 14px;
  }

  /* Collapse metadata while actively writing on small screens */
  body.editing-text .editor-meta-badges,
  body.editing-text .journal-meta-bar {
    display: none !important;
  }

  /* Formatting bar: single swipeable row with large keys */
  .editor-action-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding: 6px 10px;
    gap: 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(to right, #000 88%, transparent);
    -webkit-mask-image: linear-gradient(to right, #000 88%, transparent);
  }
  .editor-action-bar::-webkit-scrollbar {
    display: none;
  }
  .action-bar-group {
    flex-shrink: 0;
    gap: 4px;
  }
  .action-btn {
    height: 36px;
    min-width: 36px;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .editor-canvas-scroll {
    padding: 18px 18px 40px 18px;
    padding-left: max(18px, env(safe-area-inset-left));
    padding-right: max(18px, env(safe-area-inset-right));
  }
  .editor-canvas-wrapper {
    min-height: 0;
  }
  .writing-textarea {
    min-height: 50dvh;
  }

  /* Status bar: keep only what matters */
  .editor-status-bar {
    height: 30px;
    min-height: 30px;
    padding: 0 14px;
  }
  .stat-secondary {
    display: none;
  }

  /* ---------- Board / Codex / Stats ---------- */
  .view-corkboard-container,
  .view-codex-container,
  .view-analytics-container {
    padding: 14px;
    gap: 12px;
  }
  .corkboard-toolbar {
    padding: 10px 12px;
  }
  .corkboard-toolbar .toolbar-desc {
    display: none;
  }
  .corkboard-grid,
  .codex-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .codex-header-row {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px;
  }
  .codex-header-row .btn {
    min-height: 40px;
  }
  .codex-nav-tabs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    width: 100%;
    margin: 0;
    padding: 0 0 10px 0;
    overflow: visible;
  }
  .codex-tab-btn {
    width: 100%;
    min-height: 44px;
    padding: 9px 12px;
    font-size: 12px;
    border-radius: 8px;
    justify-content: flex-start;
    gap: 8px;
  }
  .codex-tab-btn .codex-count-badge {
    margin-left: auto;
  }
  .stats-card-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .stat-metric-card {
    padding: 12px;
  }
  .stat-metric-value {
    font-size: 20px;
  }
  .heatmap-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  /* Touch devices: no sticky hover lifts */
  .cork-card:hover {
    transform: none;
  }
  .cork-card:active {
    transform: scale(0.985);
  }

  /* ---------- Modals become bottom sheets ---------- */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal-dialog,
  .modal-dialog[style] {
    max-width: 100% !important;
    width: 100%;
    max-height: 90dvh;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheetSlideUp 0.26s var(--ease-out-gentle);
    position: relative;
  }
  .modal-dialog::before {
    content: '';
    display: block;
    width: 38px;
    height: 4px;
    border-radius: 99px;
    background: var(--rule);
    margin: 8px auto 0 auto;
    flex-shrink: 0;
  }
  .modal-header {
    padding: 10px 16px 12px 16px;
  }
  .modal-title {
    font-size: 14px;
  }
  .modal-close-btn {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }
  .modal-footer {
    flex-wrap: wrap;
    padding: 12px 16px;
  }
  .modal-footer .btn {
    flex: 1;
    min-height: 44px;
    font-size: 12px;
  }
  .modal-body .btn-sm {
    min-height: 40px;
    font-size: 11px;
  }
  .form-input,
  .form-textarea,
  .form-select {
    font-size: 16px;
    padding: 10px 12px;
    border-radius: 8px;
  }
  .snapshot-input-row {
    flex-direction: column;
  }

  /* Ambience panel docks to the bottom as a sheet */
  .ambience-popover {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom)) 16px;
    z-index: 90;
    animation: sheetSlideUp 0.26s var(--ease-out-gentle);
  }
  .ambience-popover .btn-sm {
    min-height: 44px;
    font-size: 12px;
    justify-content: flex-start;
  }
  .ambience-popover .btn-sm.active {
    background: var(--bg-blue);
    border-color: var(--ink-blue);
    color: var(--ink-blue);
  }

  /* Sprint HUD floats under the header */
  .sprint-hud {
    top: calc(60px + env(safe-area-inset-top));
    bottom: auto;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    padding: 8px 12px;
    gap: 10px;
    border-radius: 99px;
    max-width: calc(100vw - 20px);
  }
  .sprint-timer-val {
    font-size: 15px;
  }

  .toast-banner {
    top: calc(12px + env(safe-area-inset-top));
    max-width: calc(100vw - 32px);
    text-align: center;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 12px;
  }

  .zen-exit-floating-btn {
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
    padding: 10px 14px;
    opacity: 0.55;
  }
  .studio-shell.zen-mode .editor-canvas-scroll {
    padding-top: calc(64px + env(safe-area-inset-top));
  }
}

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ==========================================================================
   Phones (≤ 600px)
   ========================================================================== */
@media (max-width: 600px) {
  .brand-badge {
    display: none;
  }
  .editor-canvas-scroll {
    padding: 14px 16px 32px 16px;
  }
  .editor-title-input {
    font-size: 17px;
  }
  .sheet-menu-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 360px) {
  .bnav-btn span {
    font-size: 9px;
  }
  .sheet-menu-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Utility Hidden */
.hidden {
  display: none !important;
}

/* ==========================================================================
   Supabase Cloud Sync Status Pill & Modal Elements
   ========================================================================== */
.sync-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  height: 26px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--rule);
  background: var(--field);
  color: var(--mid);
  user-select: none;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
  vertical-align: middle;
}

.sync-status-pill:hover {
  background: var(--field-active);
  border-color: var(--soft);
  color: var(--ink);
}

.sync-status-pill .sync-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-green);
  display: inline-block;
  flex-shrink: 0;
  transition: background 0.2s ease;
}

.sync-status-pill.syncing {
  color: var(--ink-gold);
  border-color: rgba(158, 115, 20, 0.4);
  background: var(--bg-gold);
}

.sync-status-pill.syncing .sync-dot {
  background: var(--ink-gold);
  animation: pulseDot 0.8s infinite ease-in-out;
}

.sync-status-pill.offline {
  color: var(--soft);
  border-color: var(--rule);
  background: transparent;
}

.sync-status-pill.offline .sync-dot {
  background: var(--soft);
}

.sync-status-pill.error {
  color: var(--stamp);
  border-color: rgba(168, 50, 31, 0.4);
  background: var(--bg-red);
}

.sync-status-pill.error .sync-dot {
  background: var(--stamp);
  animation: pulseDot 0.6s infinite ease-in-out;
}

/* Footer Status Bar Sync Indicator */
.footer-sync-indicator {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  line-height: 1;
}

.footer-sync-indicator:hover {
  color: var(--ink);
  background: var(--field);
}

.footer-sync-indicator .sync-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-green);
  display: inline-block;
  flex-shrink: 0;
  transition: background 0.2s ease;
}

.footer-sync-indicator.syncing {
  color: var(--ink-gold);
}

.footer-sync-indicator.syncing .sync-dot {
  background: var(--ink-gold);
  animation: pulseDot 0.8s infinite ease-in-out;
}

.footer-sync-indicator.offline {
  color: var(--soft);
}

.footer-sync-indicator.offline .sync-dot {
  background: var(--soft);
}

.footer-sync-indicator.error {
  color: var(--stamp);
}

.footer-sync-indicator.error .sync-dot {
  background: var(--stamp);
  animation: pulseDot 0.6s infinite ease-in-out;
}

@keyframes pulseDot {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.4);
    opacity: 0.5;
  }
}

.sync-banner-card {
  padding: 12px;
  background: var(--field);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
}



/* ==========================================================================
   zUI polish layer — glass chrome around a calm, solid writing surface
   ========================================================================== */
.studio-shell { background: transparent; }

.studio-header {
  height: 54px;
  min-height: 54px;
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: var(--glass-hi);
  padding: 0 16px;
}

.studio-sidebar-left, .studio-sidebar-right,
.sidebar-header, .sidebar-footer {
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
}
.sidebar-header, .sidebar-footer { background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; }
.studio-sidebar-left { border-right: 1px solid var(--glass-border); }
.studio-sidebar-right { border-left: 1px solid var(--glass-border); }
.sidebar-header, .sidebar-search-box { border-bottom-color: var(--border); }
.sidebar-footer { border-top-color: var(--border); }
.sidebar-title { font-weight: 600; letter-spacing: .08em; color: var(--text-3); }
.sidebar-search-input { border-radius: var(--r-md); }

/* The writing surface stays solid and quiet */
.studio-center, .editor-canvas-scroll { background: var(--surface); }
:root:not([data-theme="dark"]) .studio-center,
:root:not([data-theme="dark"]) .editor-canvas-scroll { background: #fcfcfe; }
.editor-title-input { font-weight: 680; letter-spacing: -0.03em; }
.editor-action-bar, .editor-top-meta { border-bottom-color: var(--border); }
.editor-status-bar { border-top-color: var(--border); background: var(--surface); }
.editor-status-bar, .footer-sync-indicator { font-family: var(--font-num); font-size: 11px; }

/* View tabs: segmented control with sliding pill */
.view-mode-tabs {
  padding: 3px;
  gap: 2px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--fill);
}
.mode-tab-btn {
  font-size: 12.5px;
  font-weight: 540;
  padding: 6px 12px;
  border-radius: var(--r-md);
  color: var(--text-3);
}
.mode-tab-btn.active { background: transparent; box-shadow: none; color: var(--text); font-weight: 600; }
.view-mode-tabs.zui-tabs .zui-tab-pill { background: var(--surface-3); }
:root:not([data-theme="dark"]) .view-mode-tabs.zui-tabs .zui-tab-pill { background: var(--surface); }

.tool-icon-btn {
  border-radius: var(--r-md);
  color: var(--text-3);
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-slow) var(--ease-spring);
}
.tool-icon-btn:hover { background: var(--fill-2); color: var(--text); }
.tool-icon-btn:active { transform: scale(.92); }
.tool-icon-btn.active { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }

/* Manuscript tree */
.chapter-header { border-radius: var(--r-md); transition: background var(--t-fast); }
.chapter-header:hover { background: var(--fill-2); }
.chapter-words-badge { font-family: var(--font-num); border-radius: var(--r-pill); }
.scene-item { border-radius: var(--r-md); transition: background var(--t-fast), transform var(--t-slow) var(--ease-spring); }
.scene-item:hover { background: var(--fill-2); transform: translateX(2px); }
.scene-item.active { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.scene-item.active .scene-item-title { color: var(--accent-text); }
.scene-status-dot { box-shadow: 0 0 0 3px var(--fill); }

/* Corkboard + codex */
.cork-card {
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--fill);
  box-shadow: var(--glass-hi);
  animation: zuiPop .4s var(--ease-spring) both;
  transition: transform var(--t-slow) var(--ease-spring), box-shadow var(--t-med), border-color var(--t-med);
}
.cork-card:hover { transform: translateY(-3px) rotate(-.3deg); border-color: var(--border-strong); box-shadow: var(--glass-hi), var(--shadow-2); }
.codex-nav-tabs { border-bottom-color: var(--border); }
.codex-tab-btn { border-radius: var(--r-md); }
.codex-tab-btn.active { background: var(--accent-soft); color: var(--accent-text); }

/* Zen mode: chrome fades away, page eases in */
.studio-shell.zen-mode .editor-canvas-scroll { animation: zuiFade .6s var(--ease-out) both; }
.zen-exit-floating-btn {
  border-radius: var(--r-pill);
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-hi), var(--shadow-2);
  opacity: .5;
  transition: opacity var(--t-med);
}
.zen-exit-floating-btn:hover { opacity: 1; }

.sprint-hud {
  border-radius: var(--r-pill);
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-hi), var(--shadow-2);
  font-family: var(--font-num);
}

/* ==========================================================================
   Scroll layer hooks (see /shared/zui.css)
   ========================================================================== */
.studio-header { position: relative; }
.manuscript-progress { position: absolute; left: 0; right: 0; bottom: -1px; }
@supports (animation-timeline: view()) {
@media (prefers-reduced-motion: no-preference) {
  /* The textarea auto-grows, so the canvas is the real scroller */
  .studio-shell { timeline-scope: --manuscript; }
  .editor-canvas-scroll { scroll-timeline: --manuscript block; }
  .studio-header .manuscript-progress { animation-timeline: --manuscript; }
  .studio-shell.zen-mode .manuscript-progress { display: none; }
}
}
