/* ========================================
   TYPEWRITER WEB v1.3.0 — STYLES
   Major revision: formatting toolbar, cleaner status bar,
   collapsed panels by default, white theme
   ======================================== */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #2c2825; --bg-2: #1f1c1a; --input-bg: #2a2624;
  --paper: #f4ecd8; --paper-2: #ede4c8; --ink: #2c1810;
  --text: #f4ecd8; --text-dim: #b8a988; --text-strong: #ffffff;
  --accent: #8b4513; --accent-2: #a0522d;
  --border: rgba(244, 236, 216, 0.12); --border-strong: rgba(244, 236, 216, 0.25);
  --input-border: rgba(244, 236, 216, 0.18);
  --shadow: rgba(0, 0, 0, 0.5); --shadow-strong: rgba(0, 0, 0, 0.7);
  --modal-bg: #2c2825; --panel-bg: #1f1c1a;
  --hover: rgba(244, 236, 216, 0.08);
  --selection: rgba(139, 69, 19, 0.4);
  --paper-shadow: rgba(0, 0, 0, 0.4); --paper-line: rgba(139, 69, 19, 0.15);
  --success: #5cb85c; --warning: #f0ad4e; --danger: #d9534f;
  --pattern-opacity: 0.04;
  --font-family: 'Courier Prime', monospace;
  --font-size: 18px; --line-height: 1.8;
  --paper-width: 800px; --paper-height: 1100px;
}

/* ============================================
   THEMES — 12 total, including new WHITE theme
   ============================================ */
[data-theme="white"] {
  --bg: #fafafa; --bg-2: #ffffff; --input-bg: #ffffff;
  --panel-bg: #ffffff; --modal-bg: #ffffff;
  --paper: #ffffff; --ink: #1a1a1a;
  --text: #1a1a1a; --text-dim: #666; --text-strong: #000;
  --accent: #2563eb; --accent-2: #3b82f6;
  --border: rgba(0, 0, 0, 0.10); --border-strong: rgba(0, 0, 0, 0.20);
  --input-border: rgba(0, 0, 0, 0.15);
  --hover: rgba(0, 0, 0, 0.04);
  --selection: rgba(37, 99, 235, 0.20);
  --paper-shadow: rgba(0, 0, 0, 0.10);
  --paper-line: rgba(0, 0, 0, 0.06);
  --pattern-opacity: 0.02;
}
[data-theme="classic"] {
  --bg: #2c2825; --bg-2: #1f1c1a; --input-bg: #2a2624;
  --panel-bg: #1f1c1a; --modal-bg: #2c2825;
  --paper: #f4ecd8; --ink: #2c1810;
  --text: #f4ecd8; --text-dim: #b8a988; --text-strong: #ffffff;
  --accent: #8b4513; --accent-2: #a0522d;
  --border: rgba(244, 236, 216, 0.12); --border-strong: rgba(244, 236, 216, 0.25);
  --input-border: rgba(244, 236, 216, 0.18);
  --paper-shadow: rgba(0, 0, 0, 0.5); --paper-line: rgba(139, 69, 19, 0.15);
}
[data-theme="paper"] {
  --bg: #d4c5a0; --bg-2: #ebe0c0; --input-bg: #f0e8d0;
  --panel-bg: #ebe0c0; --modal-bg: #ebe0c0;
  --paper: #ffffff; --ink: #1a1a1a;
  --text: #1a1410; --text-dim: #5a4a38; --text-strong: #000;
  --accent: #6b3410; --accent-2: #8b4513;
  --border: rgba(0, 0, 0, 0.15); --border-strong: rgba(0, 0, 0, 0.30);
  --input-border: rgba(0, 0, 0, 0.22);
  --hover: rgba(0, 0, 0, 0.08); --selection: rgba(107, 52, 16, 0.30);
  --paper-shadow: rgba(60, 40, 20, 0.25); --paper-line: rgba(0, 0, 0, 0.08);
}
[data-theme="dark"] {
  --bg: #0f0f0f; --bg-2: #060606; --input-bg: #1a1a1a;
  --panel-bg: #0a0a0a; --modal-bg: #0a0a0a;
  --paper: #1f1f1f; --ink: #e8e8e8;
  --text: #e0e0e0; --text-dim: #999; --text-strong: #fff;
  --accent: #4a9eff; --accent-2: #6ab0ff;
  --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.22);
  --input-border: rgba(255, 255, 255, 0.16);
  --paper-shadow: rgba(0, 0, 0, 0.8); --paper-line: rgba(255, 255, 255, 0.06);
}
[data-theme="sepia"] {
  --bg: #3a2e1f; --bg-2: #2a1f12; --input-bg: #3a2e1f;
  --panel-bg: #26190a; --modal-bg: #26190a;
  --paper: #f4e4bc; --ink: #5b4636;
  --text: #f4e4bc; --text-dim: #c0a880; --text-strong: #fff8e0;
  --accent: #8b4513; --accent-2: #c06820;
  --border: rgba(244, 228, 188, 0.14); --border-strong: rgba(244, 228, 188, 0.28);
  --input-border: rgba(244, 228, 188, 0.20);
  --paper-shadow: rgba(0, 0, 0, 0.35); --paper-line: rgba(91, 70, 54, 0.18);
}
[data-theme="midnight"] {
  --bg: #0a1929; --bg-2: #050f1f; --input-bg: #0d1f35;
  --panel-bg: #051222; --modal-bg: #051222;
  --paper: #122e4f; --ink: #c0d8ff;
  --text: #c0d8ff; --text-dim: #6088b0; --text-strong: #fff;
  --accent: #4a9eff; --accent-2: #6ab0ff;
  --border: rgba(160, 196, 255, 0.14); --border-strong: rgba(160, 196, 255, 0.28);
  --input-border: rgba(160, 196, 255, 0.20);
  --paper-shadow: rgba(0, 0, 0, 0.6); --paper-line: rgba(74, 158, 255, 0.12);
}
[data-theme="forest"] {
  --bg: #1a2e1a; --bg-2: #0d1f0d; --input-bg: #1a2e1a;
  --panel-bg: #0a180a; --modal-bg: #0a180a;
  --paper: #2d4a2d; --ink: #d0e6d0;
  --text: #c8e6c8; --text-dim: #80a080; --text-strong: #fff;
  --accent: #8fbc8f; --accent-2: #a8d4a8;
  --border: rgba(200, 230, 200, 0.14); --border-strong: rgba(200, 230, 200, 0.28);
  --input-border: rgba(200, 230, 200, 0.20);
  --paper-shadow: rgba(0, 0, 0, 0.5); --paper-line: rgba(143, 188, 143, 0.12);
}
[data-theme="retro"] {
  --bg: #000; --bg-2: #050505; --input-bg: #001a00;
  --panel-bg: #000; --modal-bg: #000;
  --paper: #0d2210; --ink: #5cff5c;
  --text: #33ff33; --text-dim: #2a8a2a; --text-strong: #aaffaa;
  --accent: #00ff00; --accent-2: #66ff66;
  --border: rgba(51, 255, 51, 0.22); --border-strong: rgba(51, 255, 51, 0.40);
  --input-border: rgba(51, 255, 51, 0.30);
  --hover: rgba(51, 255, 51, 0.10); --paper-shadow: rgba(0, 255, 0, 0.15); --paper-line: rgba(0, 255, 0, 0.10);
}
[data-theme="blueprint"] {
  --bg: #0a1f3a; --bg-2: #06142a; --input-bg: #0d2540;
  --panel-bg: #051124; --modal-bg: #051124;
  --paper: #1e3a5f; --ink: #fff;
  --text: #fff; --text-dim: #a0c0e0; --text-strong: #fff;
  --accent: #66b3ff; --accent-2: #99ccff;
  --border: rgba(102, 179, 255, 0.20); --border-strong: rgba(102, 179, 255, 0.36);
  --input-border: rgba(102, 179, 255, 0.26);
  --paper-shadow: rgba(0, 0, 0, 0.5); --paper-line: rgba(255, 255, 255, 0.30);
}
[data-theme="cyberpunk"] {
  --bg: #0d001a; --bg-2: #050010; --input-bg: #1a0033;
  --panel-bg: #050010; --modal-bg: #050010;
  --paper: #1f0040; --ink: #ff80ff;
  --text: #ff80ff; --text-dim: #aa00aa; --text-strong: #fff;
  --accent: #ff00ff; --accent-2: #00ffff;
  --border: rgba(255, 0, 255, 0.28); --border-strong: rgba(255, 0, 255, 0.50);
  --input-border: rgba(255, 0, 255, 0.36); --hover: rgba(255, 0, 255, 0.12);
  --paper-shadow: rgba(255, 0, 255, 0.25); --paper-line: rgba(255, 0, 255, 0.10);
}
[data-theme="newspaper"] {
  --bg: #1a1a1a; --bg-2: #0a0a0a; --input-bg: #1f1f1f;
  --panel-bg: #0a0a0a; --modal-bg: #0a0a0a;
  --paper: #f5f0e2; --ink: #0a0a0a;
  --text: #f0ece1; --text-dim: #a8a498; --text-strong: #fff;
  --accent: #8b0000; --accent-2: #c00000;
  --border: rgba(240, 236, 225, 0.16); --border-strong: rgba(240, 236, 225, 0.30);
  --input-border: rgba(240, 236, 225, 0.22);
  --paper-shadow: rgba(0, 0, 0, 0.4); --paper-line: rgba(0, 0, 0, 0.12);
}
[data-theme="vintage"] {
  --bg: #2d1f15; --bg-2: #1f1408; --input-bg: #2a1d11;
  --panel-bg: #1a0f05; --modal-bg: #1a0f05;
  --paper: #f0dcb0; --ink: #3d2817;
  --text: #f0dcb0; --text-dim: #b8a070; --text-strong: #fff5d8;
  --accent: #6b3410; --accent-2: #8b4513;
  --border: rgba(240, 220, 176, 0.16); --border-strong: rgba(240, 220, 176, 0.30);
  --input-border: rgba(240, 220, 176, 0.22);
  --paper-shadow: rgba(0, 0, 0, 0.4); --paper-line: rgba(107, 52, 16, 0.18);
}

html, body { height: 100%; width: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
::selection { background: var(--selection); color: var(--text-strong); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* SPLASH */
.splash {
  position: fixed; inset: 0; z-index: 10000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-content { text-align: center; }
.splash-logo { font-size: 80px; color: var(--accent); margin-bottom: 20px; animation: typewriter-wiggle 2s ease-in-out infinite; line-height: 1; }
@keyframes typewriter-wiggle { 0%,100% { transform: translateY(0) rotate(0deg); } 25% { transform: translateY(-5px) rotate(-2deg); } 75% { transform: translateY(-3px) rotate(2deg); } }
.splash-title { font-family: 'Courier Prime', monospace; font-size: 24px; letter-spacing: 4px; margin-bottom: 30px; color: var(--text); }
.splash-loader { width: 200px; height: 2px; background: var(--border); margin: 0 auto; position: relative; overflow: hidden; }
.splash-loader::after { content: ''; position: absolute; inset: 0; background: var(--accent); animation: splash-loading 1.5s ease-in-out infinite; }
@keyframes splash-loading { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

.app-container { display: flex; flex-direction: column; height: 100vh; height: 100dvh; opacity: 0; transition: opacity 0.5s ease 0.2s; }
.app-container.visible { opacity: 1; }

/* TOP BAR — non-hideable, always visible */
.top-bar {
  display: flex; align-items: center;
  height: 52px; flex-shrink: 0;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  padding: 0 12px; gap: 12px;
  position: relative; z-index: 50;
}
.top-bar-left, .top-bar-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 8px; padding: 0 8px; }
.brand-icon { font-size: 22px; color: var(--accent); }
.brand-name { font-family: 'Courier Prime', monospace; font-size: 16px; font-weight: 700; letter-spacing: 1px; color: var(--text); }
.doc-tabs-container { flex: 1; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.doc-tabs { display: flex; gap: 4px; padding: 8px 0; }
.doc-tab {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; cursor: pointer; white-space: nowrap;
  color: var(--text-dim); transition: all 0.2s;
  font-family: 'Courier Prime', monospace;
}
.doc-tab:hover { color: var(--text); border-color: var(--border-strong); }
.doc-tab.active { background: var(--accent); color: white; border-color: var(--accent); }
.doc-tab-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.doc-tab-close { opacity: 0.7; padding: 0 2px; }
.doc-tab-close:hover { opacity: 1; }

/* PAGE NAV (top bar) */
.page-nav {
  display: flex; align-items: center; gap: 4px;
  padding: 4px 8px; margin-left: 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  font-family: 'Courier Prime', monospace; font-size: 13px;
  color: var(--text);
}
.page-nav-btn {
  width: 26px; height: 26px; padding: 0;
  background: transparent; border: none;
  color: var(--text-dim); cursor: pointer; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  transition: all 0.15s;
}
.page-nav-btn:hover { background: var(--hover); color: var(--text); }
.page-nav-input {
  width: 44px; text-align: center;
  background: var(--input-bg); color: var(--text);
  border: 1px solid var(--input-border); border-radius: 4px;
  padding: 3px 4px; font-family: inherit; font-size: 13px;
}
.page-nav-input:focus { outline: none; border-color: var(--accent); }
.page-nav-sep { color: var(--text-dim); padding: 0 2px; }
.page-nav-total { color: var(--text); min-width: 16px; text-align: center; }
.page-nav-pct { color: var(--accent); padding-left: 6px; border-left: 1px solid var(--border); margin-left: 4px; font-weight: 600; min-width: 36px; text-align: center; }

.icon-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 6px;
  color: var(--text-dim); cursor: pointer; font-size: 16px;
  transition: all 0.2s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn-sm { width: 28px; height: 28px; font-size: 14px; }

/* FORMATTING TOOLBAR — new */
.format-toolbar {
  display: flex; align-items: center; gap: 4px;
  height: 40px; flex-shrink: 0;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  padding: 0 12px; overflow-x: auto;
  transition: opacity 0.2s;
}
.fmt-group { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.fmt-divider { width: 1px; height: 20px; background: var(--border); flex-shrink: 0; margin: 0 6px; }
.fmt-btn {
  min-width: 30px; height: 28px; padding: 0 6px;
  background: transparent; border: 1px solid transparent; border-radius: 4px;
  color: var(--text-dim); cursor: pointer; font-size: 13px;
  font-family: inherit; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.fmt-btn:hover { background: var(--hover); color: var(--text); border-color: var(--border); }
.fmt-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.fmt-btn:active { transform: scale(0.95); }
.fmt-icon { font-size: 14px; }

/* MAIN */
.main-content { flex: 1; display: flex; overflow: hidden; position: relative; }

/* SIDE PANELS — collapsed by default */
.side-panel {
  width: 280px; flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: margin 0.3s ease, transform 0.3s ease;
  overflow: hidden;
  color: var(--text);
}
.side-panel-right {
  border-right: none; border-left: 1px solid var(--border);
}
.side-panel.collapsed {
  margin-left: -280px;
}
.side-panel-right.collapsed {
  margin-left: 0;
  margin-right: -280px;
}
.side-panel-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.side-panel-header h3 {
  flex: 1;
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 1px; color: var(--text);
}
.side-panel-close {
  width: 24px; height: 24px;
  background: transparent; border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-dim); cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.side-panel-close:hover { background: var(--hover); color: var(--text); }
.sidebar-count {
  background: var(--accent); color: white;
  padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600;
}
.side-panel-body { padding: 12px; overflow-y: auto; flex: 1; }

/* Doc list inside side panel */
.doc-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; margin-bottom: 4px;
  background: transparent; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent; transition: all 0.2s;
  color: var(--text);
}
.doc-item:hover { background: var(--hover); border-color: var(--border-strong); }
.doc-item.active { background: var(--paper); color: var(--ink); border-color: var(--accent); }
.doc-item-info { flex: 1; min-width: 0; }
.doc-item-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: 'Courier Prime', monospace; }
.doc-item-meta { font-size: 11px; opacity: 0.65; margin-top: 2px; }
.doc-item-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.2s; }
.doc-item:hover .doc-item-actions { opacity: 1; }
.doc-item-action { background: transparent; border: none; padding: 4px; color: inherit; cursor: pointer; border-radius: 4px; font-size: 12px; }
.doc-item-action:hover { background: rgba(0, 0, 0, 0.2); }

/* PAPER */
.paper-wrapper {
  flex: 1; overflow: hidden;
  display: flex; flex-direction: column;
  background: radial-gradient(ellipse at top, var(--bg-2), var(--bg) 70%);
  position: relative;
  min-width: 0; /* Important: allow flex shrink */
}
.paper-scroll { flex: 1; overflow-y: auto; padding: 30px 20px; scroll-behavior: smooth; }
.paper-stack {
  display: flex; flex-direction: column;
  align-items: center; gap: 20px;
  max-width: var(--paper-width);
  margin: 0 auto; min-height: 60vh; position: relative;
}
.paper-page {
  background: var(--paper); color: var(--ink);
  width: 100%; height: auto; min-height: var(--paper-height);
  padding: 60px; position: relative;
  box-shadow: 0 8px 30px var(--paper-shadow), 0 0 0 1px var(--border-strong), inset 0 0 60px rgba(0, 0, 0, 0.03);
  border-radius: 2px;
  transition: box-shadow 0.3s ease; flex-shrink: 0; overflow: visible;
}
/* Page background appearance — selectable in Settings */
.paper-page[data-bg="lines"] {
  background-image: repeating-linear-gradient(0deg,
    transparent, transparent calc(var(--line-height) * 1em - 1px),
    var(--paper-line) calc(var(--line-height) * 1em - 1px),
    var(--paper-line) calc(var(--line-height) * 1em)
  );
}
.paper-page[data-bg="grid"] {
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent calc(var(--line-height) * 1em - 1px), var(--paper-line) calc(var(--line-height) * 1em - 1px), var(--paper-line) calc(var(--line-height) * 1em)),
    repeating-linear-gradient(90deg, transparent, transparent 27px, var(--paper-line) 27px, var(--paper-line) 28px);
}
.paper-page[data-bg="dots"] {
  background-image: radial-gradient(var(--paper-line) 1px, transparent 1px);
  background-size: 20px calc(var(--line-height) * 1em);
}
.paper-page[data-bg="blank"] { background-image: none; }
.paper-page.active { box-shadow: 0 12px 40px var(--paper-shadow), 0 0 0 2px var(--accent), inset 0 0 60px rgba(0, 0, 0, 0.03); }
.paper-page.tap { animation: paper-tap 0.06s ease; }
@keyframes paper-tap { 0%,100% { transform: translate(0, 0); } 50% { transform: translate(0, -0.5px); } }

/* Page-break overlay — visual divider lines computed from the real
   rendered content height. The document is one continuous editable
   area; nothing is ever clipped. */
.page-breaks-overlay { position: absolute; top: 60px; left: 0; right: 0; bottom: 0; pointer-events: none; z-index: 3; }
.page-break-line { position: absolute; left: 40px; right: 40px; height: 0; border-top: 1px dashed var(--paper-line); }
.page-break-label {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-family: var(--font-family); font-size: 11px;
  color: var(--ink); opacity: 0.45; letter-spacing: 1px;
}

/* EDITOR + content styles for rich text */
.paper-page-content {
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
  color: var(--ink);
  word-wrap: break-word; overflow-wrap: break-word;
  min-height: 800px; outline: none; caret-color: var(--accent);
  display: block; width: 100%; position: relative; z-index: 2;
}
.paper-page-content:focus { outline: none; }
/* Rich text defaults for headings, lists etc. */
.paper-page-content h1 { font-size: 1.8em; font-weight: 700; margin: 0.5em 0 0.3em; }
.paper-page-content h2 { font-size: 1.5em; font-weight: 700; margin: 0.5em 0 0.3em; }
.paper-page-content h3 { font-size: 1.25em; font-weight: 600; margin: 0.5em 0 0.3em; }
.paper-page-content p { margin: 0 0 0.5em; }
.paper-page-content blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  margin: 8px 0; color: var(--ink); opacity: 0.85; font-style: italic;
}
.paper-page-content ul, .paper-page-content ol { margin: 0 0 0.5em 24px; }
.paper-page-content li { margin: 0.2em 0; }
.paper-page-content table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.paper-page-content td, .paper-page-content th { border: 1px solid var(--paper-line); padding: 8px; min-width: 40px; min-height: 24px; vertical-align: top; }
.paper-page-content img { max-width: 100%; height: auto; border-radius: 2px; margin: 4px 0; display: block; }
.paper-page-content a { color: var(--accent); text-decoration: underline; }
.paper-page-content code { font-family: monospace; background: rgba(0,0,0,0.06); padding: 1px 4px; border-radius: 3px; }

/* Placeholder */
.paper-editor-input:empty:not(:focus)::before {
  content: attr(data-placeholder); color: var(--ink); opacity: 0.35; font-style: italic;
  pointer-events: none; position: absolute; top: 0; left: 0;
}

/* ============================================
   STATUS BAR — NEW: pill-shaped stats, calmer
   ============================================ */
.status-bar {
  display: flex; align-items: center; justify-content: space-between;
  height: 36px; flex-shrink: 0;
  background: var(--bg-2); border-top: 1px solid var(--border);
  padding: 0 14px; font-size: 12px;
}
.status-left, .status-right, .status-center { display: flex; align-items: center; gap: 6px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: 'Courier Prime', monospace;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}
.status-pill b { color: var(--text); font-weight: 600; }
.status-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}
.status-saved {
  color: var(--success); font-weight: 600; font-size: 12px;
  padding: 3px 10px; background: rgba(92, 184, 92, 0.10);
  border-radius: 12px;
}
.status-saved.saving { color: var(--warning); background: rgba(240, 173, 78, 0.10); }
.status-version { font-family: 'Courier Prime', monospace; font-size: 11px; color: var(--text-dim); opacity: 0.7; padding: 0 8px; }

/* GOAL SIDEBAR */
.stat-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px; margin-bottom: 10px;
  transition: all 0.2s; color: var(--text);
}
.stat-card:hover { border-color: var(--accent); }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-dim); margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text-strong); font-family: 'Courier Prime', monospace; line-height: 1.1; }
.stat-sub { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.stat-progress .stat-value { margin-bottom: 8px; }
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); width: 0%; transition: width 0.5s ease; }

/* SETTINGS PANEL */
.settings-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 380px; max-width: 90vw;
  background: var(--panel-bg); border-left: 1px solid var(--border-strong);
  transform: translateX(100%); transition: transform 0.3s ease;
  z-index: 100; display: flex; flex-direction: column;
  box-shadow: -10px 0 30px var(--shadow); color: var(--text);
}
.settings-panel.open { transform: translateX(0); }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  background: var(--panel-bg); color: var(--text-strong);
}
.panel-header h3 { font-size: 18px; font-weight: 600; color: var(--text-strong); }
.panel-body { flex: 1; overflow-y: auto; padding: 16px 20px; color: var(--text); }
.settings-section { margin-bottom: 28px; }
.settings-section h4 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--accent); margin-bottom: 14px; font-weight: 600; }
.setting-row { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.setting-row > label { font-size: 13px; color: var(--text); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.setting-value { font-size: 12px; color: var(--text-dim); font-family: 'Courier Prime', monospace; }
.setting-select, .setting-input-inline {
  background: var(--input-bg); color: var(--text-strong);
  border: 1px solid var(--input-border); border-radius: 6px;
  padding: 8px 12px; font-size: 13px; font-family: inherit;
  width: 100%; transition: border-color 0.2s;
}
.setting-input-inline { display: inline-block; width: auto; flex: 1; }
.setting-select:focus, .setting-input-inline:focus { outline: none; border-color: var(--accent); }
.setting-row input[type="range"] { width: 100%; accent-color: var(--accent); }

/* THEME GRID */
.theme-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.theme-swatch { aspect-ratio: 1; border: 2px solid transparent; border-radius: 8px; cursor: pointer; overflow: hidden; position: relative; transition: all 0.2s; }
.theme-swatch:hover { transform: translateY(-2px); }
.theme-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(0,0,0,0.2); }
.theme-swatch-bg { height: 60%; }
.theme-swatch-preview { height: 40%; padding: 4px; font-size: 9px; font-family: monospace; white-space: nowrap; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.sw-classic .theme-swatch-bg { background: #2c2825; } .sw-classic .theme-swatch-preview { background: #f4ecd8; color: #2c1810; }
.sw-white .theme-swatch-bg { background: #fafafa; } .sw-white .theme-swatch-preview { background: #fff; color: #1a1a1a; }
.sw-paper .theme-swatch-bg { background: #d4c5a0; } .sw-paper .theme-swatch-preview { background: #fff; color: #1a1a1a; }
.sw-dark .theme-swatch-bg { background: #0f0f0f; } .sw-dark .theme-swatch-preview { background: #1f1f1f; color: #e8e8e8; }
.sw-sepia .theme-swatch-bg { background: #3a2e1f; } .sw-sepia .theme-swatch-preview { background: #f4e4bc; color: #5b4636; }
.sw-midnight .theme-swatch-bg { background: #0a1929; } .sw-midnight .theme-swatch-preview { background: #122e4f; color: #c0d8ff; }
.sw-forest .theme-swatch-bg { background: #1a2e1a; } .sw-forest .theme-swatch-preview { background: #2d4a2d; color: #d0e6d0; }
.sw-retro .theme-swatch-bg { background: #000; } .sw-retro .theme-swatch-preview { background: #0d2210; color: #5cff5c; }
.sw-blueprint .theme-swatch-bg { background: #0a1f3a; } .sw-blueprint .theme-swatch-preview { background: #1e3a5f; color: #fff; }
.sw-cyberpunk .theme-swatch-bg { background: #0d001a; } .sw-cyberpunk .theme-swatch-preview { background: #1f0040; color: #ff80ff; }
.sw-newspaper .theme-swatch-bg { background: #1a1a1a; } .sw-newspaper .theme-swatch-preview { background: #f5f0e2; color: #0a0a0a; }
.sw-vintage .theme-swatch-bg { background: #2d1f15; } .sw-vintage .theme-swatch-preview { background: #f0dcb0; color: #3d2817; }

/* SWITCH */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; cursor: pointer; inset: 0; background: var(--border-strong); border-radius: 24px; transition: 0.3s; }
.switch-slider:before { position: absolute; content: ''; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.3s; }
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider:before { transform: translateX(20px); }

/* BUTTONS */
.btn {
  background: var(--input-bg); color: var(--text-strong);
  border: 1px solid var(--input-border); border-radius: 8px;
  padding: 10px 16px; cursor: pointer; font-size: 13px;
  font-family: inherit; font-weight: 500;
  transition: all 0.2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { background: var(--hover); border-color: var(--accent); color: var(--text-strong); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); color: white; }
.btn-secondary { background: var(--bg-2); color: var(--text-strong); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #c93030; border-color: #c93030; color: white; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }

/* MODALS */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: opacity 0.2s, visibility 0.2s; }
.modal.open { opacity: 1; visibility: visible; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.modal-content { position: relative; background: var(--modal-bg); border: 1px solid var(--border-strong); border-radius: 12px; width: 90%; max-width: 480px; max-height: 85vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px var(--shadow-strong); animation: modal-pop 0.3s ease; color: var(--text); }
.modal-content-sm { max-width: 380px; }
@keyframes modal-pop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { color: var(--text-strong); font-size: 18px; }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; color: var(--text); }
.modal-body-center { text-align: center; }
.modal-body > p { color: var(--text-dim); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--border); }
.export-option { display: flex; align-items: center; gap: 16px; padding: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; text-align: left; transition: all 0.2s; font-family: inherit; color: var(--text); }
.export-option:hover { background: var(--hover); border-color: var(--accent); transform: translateX(2px); color: var(--text-strong); }
.export-option-icon { font-size: 24px; }
.export-option-title { font-weight: 600; font-size: 14px; margin-bottom: 2px; color: var(--text-strong); }
.export-option-desc { font-size: 12px; color: var(--text-dim); }

.goal-presets { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 16px 0; }
.goal-preset { background: var(--bg); color: var(--text-strong); border: 1px solid var(--border); border-radius: 6px; padding: 10px; cursor: pointer; font-family: 'Courier Prime', monospace; font-weight: 600; transition: all 0.2s; }
.goal-preset:hover { border-color: var(--accent); transform: translateY(-2px); }
.goal-preset.active { background: var(--accent); color: white; border-color: var(--accent); }
.goal-custom { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.goal-custom input { flex: 1; background: var(--bg); color: var(--text-strong); border: 1px solid var(--border); border-radius: 6px; padding: 10px; text-align: center; font-family: 'Courier Prime', monospace; font-size: 16px; }
.goal-custom-label { font-size: 12px; color: var(--text-dim); }

/* TABLE PICKER */
.table-picker { display: grid; grid-template-columns: repeat(8, 22px); gap: 3px; justify-content: center; margin: 16px 0; }
.table-cell-pick { width: 22px; height: 22px; border: 1px solid var(--border); border-radius: 3px; cursor: pointer; transition: all 0.1s; background: var(--bg); }
.table-cell-pick.active { background: var(--accent); border-color: var(--accent); }
.table-cell-pick:hover { border-color: var(--accent); }
.table-size-label { font-family: 'Courier Prime', monospace; font-size: 14px; color: var(--text-strong); margin: 8px 0; }

/* ABOUT */
.about-block { text-align: center; padding: 12px 0; }
.about-logo { font-size: 48px; color: var(--accent); margin-bottom: 8px; }
.about-name { font-size: 18px; font-weight: 700; font-family: 'Courier Prime', monospace; margin-bottom: 4px; color: var(--text-strong); }
.about-version { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; font-family: 'Courier Prime', monospace; }
.about-dev { font-size: 13px; margin-bottom: 4px; color: var(--text); }
.about-email { font-size: 13px; margin-bottom: 16px; }
.about-email a { color: var(--accent); text-decoration: none; }
.about-email a:hover { text-decoration: underline; }
.about-desc { font-size: 12px; color: var(--text-dim); font-style: italic; padding: 0 12px; }

/* NOTIFICATIONS */
.notifications { position: fixed; top: 70px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.notification { background: var(--panel-bg); color: var(--text-strong); border: 1px solid var(--border-strong); border-left: 4px solid var(--accent); border-radius: 8px; padding: 12px 16px; box-shadow: 0 10px 30px var(--shadow-strong); display: flex; align-items: center; gap: 10px; animation: notif-slide 0.3s ease; font-size: 13px; font-weight: 500; }
.notification.success { border-left-color: var(--success); }
.notification.warning { border-left-color: var(--warning); }
.notification.error { border-left-color: var(--danger); }
.notification.info { border-left-color: var(--accent); }
.notification-icon { font-size: 16px; flex-shrink: 0; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; color: var(--text-strong); }
.notification-text { color: var(--text-strong); flex: 1; }
@keyframes notif-slide { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.notification.out { animation: notif-slide-out 0.3s ease forwards; }
@keyframes notif-slide-out { to { transform: translateX(120%); opacity: 0; } }

.install-prompt { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 999; max-width: 90vw; animation: install-pop 0.5s ease; }
.install-prompt.hidden { display: none; }
@keyframes install-pop { from { transform: translate(-50%, 100%); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.install-prompt-content { background: var(--panel-bg); color: var(--text-strong); border: 1px solid var(--border-strong); border-radius: 12px; padding: 14px 20px; display: flex; align-items: center; gap: 16px; box-shadow: 0 10px 30px var(--shadow-strong); }
.install-prompt-text strong { display: block; font-size: 14px; }
.install-prompt-text small { font-size: 11px; color: var(--text-dim); }
.install-prompt-actions { display: flex; gap: 8px; }

/* FOCUS MODE — header + toolbar fully collapse out of the layout when
   idle, and expand back in on mouse movement. */
body.focus-mode .top-bar,
body.focus-mode .format-toolbar {
  height: 0; min-height: 0; padding-top: 0; padding-bottom: 0; border-bottom-width: 0;
  opacity: 0; overflow: hidden; pointer-events: none;
  transition: height 0.35s ease, opacity 0.25s ease, padding 0.35s ease;
}
body.focus-mode.show-ui .top-bar { height: 52px; opacity: 1; pointer-events: auto; padding: 0 12px; border-bottom-width: 1px; }
body.focus-mode.show-ui .format-toolbar { height: 40px; opacity: 1; pointer-events: auto; padding: 0 12px; border-bottom-width: 1px; }
body.focus-mode .status-bar { opacity: 0.3; transition: opacity 0.5s ease; }
body.focus-mode.show-ui .status-bar { opacity: 1; }
body.focus-mode .side-panel { transform: translateX(-100%); }
body.focus-mode .side-panel-right { transform: translateX(100%); }
body.focus-mode .settings-panel { display: none; }

/* HEADER HIDE — fully collapses the top bar + toolbar; a small tab
   reappears to bring it back. */
body.header-hidden .top-bar,
body.header-hidden .format-toolbar { display: none; }
.header-expand-btn {
  display: none;
  position: fixed; top: 8px; left: 50%; transform: translateX(-50%);
  z-index: 60; width: 32px; height: 18px;
  align-items: center; justify-content: center;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 0 0 8px 8px; color: var(--text-dim);
  cursor: pointer; opacity: 0.5; transition: opacity 0.2s;
  font-size: 12px;
}
.header-expand-btn:hover { opacity: 1; }
body.header-hidden .header-expand-btn { display: flex; }

/* RESPONSIVE */
@media (max-width: 900px) {
  .format-toolbar { padding: 0 8px; }
  .fmt-btn { min-width: 26px; }
}
@media (max-width: 768px) {
  .format-toolbar { display: none; }
  .page-nav { padding: 4px 6px; font-size: 12px; }
  .page-nav-input { width: 36px; }
  .brand-name { display: none; }
}
@media (max-width: 600px) {
  .top-bar { padding: 0 6px; gap: 4px; }
  .settings-panel { width: 100%; }
  .status-pill { padding: 3px 6px; font-size: 10px; }
  .side-panel { width: 240px; }
  .side-panel.collapsed { margin-left: -240px; }
  .side-panel-right.collapsed { margin-right: -240px; }
}
@media (max-width: 400px) {
  .paper-page { padding: 30px 20px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .top-bar { height: 44px; }
  .format-toolbar { height: 36px; }
}

/* PRINT */
@media print {
  .top-bar, .format-toolbar, .status-bar, .side-panel, .settings-panel, .modal, .notifications, .install-prompt, .page-breaks-overlay { display: none !important; }
  body, body[data-theme] { background: white !important; color: black !important; overflow: visible !important; }
  .app-container { height: auto !important; }
  .main-content { overflow: visible !important; display: block !important; }
  .paper-wrapper { padding: 0 !important; overflow: visible !important; }
  .paper-scroll { overflow: visible !important; padding: 0 !important; }
  .paper-stack { gap: 0 !important; max-width: none !important; }
  .paper-page { box-shadow: none !important; margin: 0 !important; padding: 30px !important; height: auto !important; min-height: auto !important; width: 100% !important; background: white !important; color: black !important; border-radius: 0 !important; page-break-after: always !important; background-image: none !important; }
  .paper-page:last-child { page-break-after: avoid !important; }
  .paper-page-content { color: black !important; font-family: Georgia, serif !important; line-height: 1.6 !important; }
}

/* IMAGE TOOLS — select, resize handle, floating toolbar, crop */
.paper-editor-input img { cursor: pointer; max-width: 100%; }
.paper-editor-input img.img-selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.img-toolbar {
  position: absolute; z-index: 50; display: flex; gap: 4px;
  background: var(--modal-bg); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 4px; box-shadow: 0 6px 20px var(--shadow-strong);
}
.img-toolbar button {
  border: none; background: transparent; color: var(--text); font-size: 12px;
  padding: 5px 8px; border-radius: 5px; cursor: pointer; white-space: nowrap;
}
.img-toolbar button:hover { background: var(--hover); }
.img-resize-handle {
  position: absolute; z-index: 50; width: 12px; height: 12px;
  background: var(--accent); border: 2px solid var(--paper); border-radius: 50%;
  cursor: nwse-resize;
}
.crop-stage { position: relative; display: inline-block; max-width: 100%; user-select: none; }
.crop-stage img { display: block; max-width: 100%; max-height: 60vh; }
.crop-box { position: absolute; border: 2px dashed var(--accent); box-shadow: 0 0 0 9999px rgba(0,0,0,0.45); cursor: move; }
.crop-box-handle {
  position: absolute; right: -6px; bottom: -6px; width: 14px; height: 14px;
  background: var(--accent); border: 2px solid #fff; border-radius: 50%; cursor: nwse-resize;
}

/* HELP MODAL */
.help-body { max-height: 65vh; }
.help-section { margin-bottom: 18px; }
.help-section:last-child { margin-bottom: 0; }
.help-section h4 { font-size: 14px; color: var(--text-strong); margin-bottom: 6px; }
.help-section p { font-size: 13px; color: var(--text-dim); line-height: 1.6; }
.help-shortcuts { width: 100%; border-collapse: collapse; font-size: 13px; }
.help-shortcuts td { padding: 5px 8px; color: var(--text-dim); border-bottom: 1px solid var(--border); }
.help-shortcuts td:first-child { white-space: nowrap; width: 1%; }
kbd {
  display: inline-block; padding: 2px 6px; font-family: var(--font-family, monospace);
  font-size: 11px; background: var(--bg-2); border: 1px solid var(--border-strong);
  border-radius: 4px; color: var(--text);
}
