/* ═══════════════════════════════════════════════════
   THEME VARIABLES
═══════════════════════════════════════════════════ */
:root {
  --bg: #f5f4f1;
  --bg2: #ffffff;
  --surface: #ffffff;
  --surface2: #f0eeeb;
  --border: #e2dfd9;
  --border2: #cbc7bf;
  --text: #1a1816;
  --muted: #726d64;
  --faint: #aaa59b;
  --accent: #6c63ff;
  --accent-soft: rgba(108,99,255,.10);
  --accent-dark: #5148e0;
  --green: #16a34a;
  --red: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.07);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.13);
  --sans: 'DM Sans', system-ui, sans-serif;
  --display: 'Fraunces', Georgia, serif;
  --mono: 'JetBrains Mono', monospace;
  --nav-h: 58px;
  --transition: background .2s, color .2s, border-color .2s;
}
[data-theme="dark"] {
  --bg: #0f1014;
  --bg2: #16181e;
  --surface: #1a1c23;
  --surface2: #20222b;
  --border: rgba(255,255,255,.08);
  --border2: rgba(255,255,255,.14);
  --text: #eaecf2;
  --muted: #8b90a6;
  --faint: #50556e;
  --accent: #7c72ff;
  --accent-soft: rgba(124,114,255,.13);
  --accent-dark: #6b60f0;
  --shadow: 0 2px 8px rgba(0,0,0,.25), 0 8px 28px rgba(0,0,0,.3);
  --shadow-lg: 0 8px 40px rgba(0,0,0,.55);
}

/* ═══════════════════════════════════════════════════
   BASE
═══════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition: var(--transition);
  /* Flex column → footer sticks to bottom when content is short */
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
button, input, textarea { font-family: inherit; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ═══════════════════════════════════════════════════
   NAV
═══════════════════════════════════════════════════ */
.nav {
  height: var(--nav-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
  transition: var(--transition);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--display); font-size: 20px; font-weight: 500;
  color: var(--text); letter-spacing: -.02em; white-space: nowrap;
}
.brand-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 10px var(--accent);
  flex-shrink: 0;
}
.brand em { font-style: italic; color: var(--accent); font-weight: 300; }
.nav-links { display: flex; gap: 2px; margin-left: 6px; }
.nav-links a {
  color: var(--muted); font-size: 14px; font-weight: 500;
  padding: 6px 11px; border-radius: 9px; transition: .13s;
}
.nav-links a:hover { color: var(--text); background: var(--surface2); }
.nav-links a.active { color: var(--accent); background: var(--accent-soft); }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* theme toggle */
.theme-btn {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1.5px solid var(--border); background: var(--surface2);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 15px; transition: .15s; flex-shrink: 0;
}
.theme-btn:hover { border-color: var(--accent); }

/* avatar / auth area */
.avatar-btn {
  width: 33px; height: 33px; border-radius: 50%;
  border: 2px solid var(--border2); background: var(--accent);
  color: white; font-size: 13px; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: .15s; position: relative; flex-shrink: 0;
}
.avatar-btn:hover { border-color: var(--accent); }
.dropdown {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  min-width: 200px; padding: 6px; z-index: 100; display: none;
  transition: var(--transition);
}
.dropdown.open { display: block; }
.dropdown-header { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dropdown-header .name { font-weight: 600; font-size: 14px; }
.dropdown-header .email { font-size: 12px; color: var(--muted); }
.dropdown a, .dropdown button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  text-align: left; padding: 8px 10px; border-radius: 9px;
  font-size: 13.5px; color: var(--text); background: transparent;
  border: 0; cursor: pointer; transition: .12s;
}
.dropdown a:hover, .dropdown button:hover { background: var(--surface2); }
.dropdown .danger:hover { color: var(--red); background: rgba(220,38,38,.07); }
.sign-in-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 9px;
  background: var(--accent); border: 0; color: white;
  font-size: 13.5px; font-weight: 600; cursor: pointer; transition: .15s;
}
.sign-in-btn:hover { background: var(--accent-dark); }

/* ═══════════════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 10px; font-size: 13.5px; font-weight: 600;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.sm { padding: 7px 13px; font-size: 12.5px; border-radius: 8px; }
.btn.xs { padding: 4px 9px; font-size: 11.5px; border-radius: 6px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface2); }
.btn.danger:hover { color: var(--red); background: rgba(220,38,38,.07); border-color: transparent; }
.btn-full { width: 100%; }

/* ═══════════════════════════════════════════════════
   MODAL / AUTH OVERLAY
═══════════════════════════════════════════════════ */
.modal-bg {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-bg.open { display: flex; }
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 32px 30px 28px;
  width: 100%; max-width: 400px;
  box-shadow: var(--shadow-lg);
  position: relative;
}
.modal-close {
  position: absolute; top: 14px; right: 14px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--muted); font-size: 20px; line-height: 1;
  width: 30px; height: 30px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  transition: .12s;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-card h2 { font-family: var(--display); font-size: 20px; font-weight: 500; margin-bottom: 18px; }

/* gate logo */
.gate-logo { text-align: center; margin-bottom: 22px; }
.gate-logo .big-dot {
  width: 50px; height: 50px; background: var(--accent);
  border-radius: 15px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(108,99,255,.4);
}
.gate-logo .big-dot svg { color: white; }
.gate-logo h1 {
  font-family: var(--display); font-size: 25px; font-weight: 500; letter-spacing: -.02em;
}
.gate-logo h1 em { font-style: italic; color: var(--accent); font-weight: 300; }
.gate-logo p { font-size: 13.5px; color: var(--muted); margin-top: 4px; }

/* tabs */
.gate-tabs { display: flex; gap: 0; margin-bottom: 20px; background: var(--surface2); border-radius: 10px; padding: 4px; }
.gate-tab {
  flex: 1; padding: 8px; font-size: 13.5px; font-weight: 600;
  border: 0; background: transparent; border-radius: 7px;
  cursor: pointer; color: var(--muted); transition: .15s;
}
.gate-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.1); }

/* form fields */
.form-row { margin-bottom: 13px; }
.form-row label {
  display: block; font-size: 11.5px; font-weight: 600; color: var(--muted);
  margin-bottom: 5px; letter-spacing: .05em; text-transform: uppercase;
}
.form-row input {
  width: 100%; background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 10px 13px; font-size: 14px; color: var(--text);
  outline: 0; transition: .15s;
}
.form-row input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-row input::placeholder { color: var(--faint); }
.form-err { font-size: 13px; color: var(--red); margin-top: 8px; text-align: center; min-height: 18px; }
.pw-strength { display: flex; gap: 4px; margin-top: 6px; }
.pw-bar { height: 3px; flex: 1; border-radius: 2px; background: var(--border); transition: .3s; }
.pw-bar.fill-weak   { background: var(--red); }
.pw-bar.fill-ok     { background: var(--accent); }
.pw-bar.fill-strong { background: var(--green); }

/* ═══════════════════════════════════════════════════
   SAVE PROMPT (guest → sign up nudge)
═══════════════════════════════════════════════════ */
.save-prompt-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--accent); color: white;
  padding: 14px 24px;
  display: flex; align-items: center; gap: 14px;
  transform: translateY(100%); transition: .3s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 -4px 24px rgba(108,99,255,.4);
}
.save-prompt-banner.show { transform: translateY(0); }
.save-prompt-banner p { font-size: 14px; font-weight: 500; flex: 1; }
.save-prompt-banner p strong { font-weight: 700; }
.save-prompt-banner .close-banner {
  background: rgba(255,255,255,.2); border: 0; color: white;
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  font-size: 16px; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════════════ */
#app {
  /* Grow to fill the body's flex column. Flex column itself so home/editor view can stretch. */
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}

/* ── HOME VIEW ── */
#home-view {
  display: none;
  /* When shown (via JS), be a flex column that grows so footer can sit at bottom */
  flex: 1;
  flex-direction: column;
}
#home-view.home-active {
  display: flex;
}
.home-new-strip {
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 16px 28px;
}
.home-new-strip h2 {
  font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 14px;
}
.new-templates { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 4px; }
.new-templates::-webkit-scrollbar { height: 0; }
.template-card { flex-shrink: 0; width: 116px; cursor: pointer; transition: .15s; }
.template-card:hover .template-thumb { border-color: var(--accent); box-shadow: 0 4px 14px rgba(108,99,255,.2); }
.template-thumb {
  width: 116px; height: 150px; border: 2px solid var(--border); border-radius: 8px;
  background: var(--bg2); display: flex; align-items: center; justify-content: center;
  transition: .15s; overflow: hidden; position: relative;
}
.template-thumb .lines { position: absolute; left: 12px; right: 12px; top: 22px; display: flex; flex-direction: column; gap: 5px; }
.template-thumb .line { height: 6px; border-radius: 3px; background: var(--border2); }
.template-thumb .line.title { height: 9px; width: 68%; background: var(--accent); opacity: .35; }
.template-thumb .line.short { width: 55%; }
.template-thumb .plus-icon { color: var(--accent); opacity: .5; }
.template-label { font-size: 12px; color: var(--muted); margin-top: 7px; text-align: center; font-weight: 500; }

/* recent grid */
.home-recent { padding: 24px 28px 48px; }
.section-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.section-header h2 {
  font-size: 11.5px; font-weight: 600; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
}
.section-header .sep { flex: 1; height: 1px; background: var(--border); }

/* tagbar */
.tagbar-wrap { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tagchip {
  font-family: var(--mono); font-size: 11.5px; font-weight: 500;
  padding: 4px 11px; border-radius: 20px; border: 1.5px solid var(--border2);
  color: var(--muted); background: var(--surface); cursor: pointer; transition: .13s;
}
.tagchip:hover { border-color: var(--accent); color: var(--accent); }
.tagchip.active { background: var(--accent); border-color: var(--accent); color: white; }

/* notes grid */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 13px; }
.note-card {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: .2s;
  overflow: hidden; position: relative;
  aspect-ratio: 3/4; display: flex; flex-direction: column;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.note-card:hover { border-color: var(--accent); box-shadow: 0 6px 24px rgba(108,99,255,.15); transform: translateY(-2px); }
.note-card.pinned::after {
  content: ''; position: absolute; top: 10px; right: 10px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 6px var(--accent);
}
.note-card-top { flex: 1; padding: 14px 14px 10px; overflow: hidden; }
.note-card-title {
  font-weight: 600; font-size: 14px; line-height: 1.4; margin-bottom: 7px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.note-card-snippet {
  font-size: 12px; color: var(--muted); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden;
}
.note-card-foot {
  padding: 8px 14px 10px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.note-card-date { font-family: var(--mono); font-size: 10px; color: var(--faint); margin-right: auto; }
.note-card-tag {
  font-family: var(--mono); font-size: 9.5px; padding: 2px 6px; border-radius: 5px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500;
}
.note-card-color-bar { height: 4px; border-radius: 4px 4px 0 0; flex-shrink: 0; }
.note-card[data-color="lavender"] { background: #f3f0ff; }
.note-card[data-color="mint"]     { background: #ecfdf5; }
.note-card[data-color="rose"]     { background: #fff1f2; }
.note-card[data-color="sky"]      { background: #eff6ff; }
.note-card[data-color="sand"]     { background: #fffbeb; }
[data-theme="dark"] .note-card[data-color="lavender"] { background: #1e1b38; }
[data-theme="dark"] .note-card[data-color="mint"]     { background: #0d2118; }
[data-theme="dark"] .note-card[data-color="rose"]     { background: #2a0d12; }
[data-theme="dark"] .note-card[data-color="sky"]      { background: #0d1e38; }
[data-theme="dark"] .note-card[data-color="sand"]     { background: #241d06; }
.empty-state { text-align: center; padding: 60px 16px; color: var(--muted); grid-column: 1/-1; }
.empty-state svg { margin-bottom: 14px; opacity: .35; }
.empty-state h3 { font-family: var(--display); font-size: 22px; font-weight: 500; color: var(--text); margin-bottom: 6px; }

/* ── EDITOR VIEW — uses CSS grid so heights are explicit, not collapsing ── */
#editor-view { display: none; }
#editor-view.visible { display: block; flex: 1; min-height: 0; }
.editor-shell {
  display: grid;
  grid-template-columns: 272px 1fr;
  height: calc(100vh - var(--nav-h));
  overflow: hidden;
}
.editor-sidebar {
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  background: var(--surface);
  overflow: hidden;
  min-height: 0;
  transition: var(--transition);
}
.sidebar-head { padding: 12px; border-bottom: 1px solid var(--border); display: flex; gap: 8px; flex-shrink: 0; }
.sidebar-search {
  flex: 1; display: flex; align-items: center; gap: 6px;
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: 9px; padding: 0 10px; height: 34px;
}
.sidebar-search:focus-within { border-color: var(--accent); }
.sidebar-search input { border: 0; background: transparent; outline: 0; font-size: 13px; color: var(--text); width: 100%; }
.sidebar-search input::placeholder { color: var(--faint); }
.sidebar-tags { padding: 10px 12px 8px; border-bottom: 1px solid var(--border); display: flex; gap: 6px; flex-wrap: wrap; flex-shrink: 0; }
.sidebar-tag {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  padding: 3px 8px; border-radius: 20px; cursor: pointer;
  border: 1.5px solid var(--border2); color: var(--muted); background: transparent; transition: .12s;
}
.sidebar-tag:hover { border-color: var(--accent); color: var(--accent); }
.sidebar-tag.active { background: var(--accent); border-color: var(--accent); color: white; }
.note-list { flex: 1; overflow-y: auto; padding: 6px 7px; min-height: 0; }
.nitem {
  padding: 10px 11px; border-radius: 10px; cursor: pointer;
  border: 1.5px solid transparent; margin-bottom: 2px; transition: background .12s, border-color .12s;
  display: grid;
  grid-template-columns: 16px 1fr 14px;
  gap: 8px;
  align-items: start;
  position: relative;
}
.nitem:hover { background: var(--surface2); }
.nitem.active { background: var(--accent-soft); border-color: rgba(108,99,255,.22); }
.nitem.dragging { opacity: 0.4; }

/* Drop indicators when drag-hovering an item */
.nitem.drop-above::before,
.nitem.drop-below::before {
  content: ''; position: absolute; left: 8px; right: 8px;
  height: 2px; background: var(--accent); border-radius: 2px;
  box-shadow: 0 0 0 2px var(--accent-soft);
  pointer-events: none;
}
.nitem.drop-above::before { top: -2px; }
.nitem.drop-below::before { bottom: -2px; }

/* Pin button per item */
.nitem-pin {
  background: transparent; border: 0; cursor: pointer;
  width: 18px; height: 18px; padding: 0; margin-top: 1px;
  border-radius: 5px;
  color: var(--faint); opacity: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, color .15s, background .12s, transform .15s;
}
.nitem:hover .nitem-pin { opacity: 0.7; }
.nitem-pin:hover { background: var(--accent-soft); color: var(--accent); opacity: 1 !important; }
.nitem-pin svg { display: block; }
/* Always show pin when note is pinned */
.nitem.pinned .nitem-pin { opacity: 1; color: var(--accent); transform: rotate(45deg); }
.nitem.pinned .nitem-pin:hover { transform: rotate(0deg); }

.nitem-body { min-width: 0; }
.nitem-title { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nitem-snip { font-size: 11.5px; color: var(--muted); margin-top: 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.nitem-meta { display: flex; gap: 6px; align-items: center; margin-top: 5px; }
.nitem-date { font-family: var(--mono); font-size: 10px; color: var(--faint); }
.nitem-tags { display: flex; gap: 3px; }
.nitem-tags span { font-family: var(--mono); font-size: 9.5px; color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 1px 5px; }

/* Drag handle (visible on hover) */
.nitem-drag {
  color: var(--faint); opacity: 0;
  cursor: grab;
  align-self: center;
  transition: opacity .15s, color .15s;
}
.nitem-drag:active { cursor: grabbing; }
.nitem:hover .nitem-drag { opacity: 0.7; }
.nitem-drag:hover { color: var(--text); opacity: 1 !important; }

/* Topbar pin button: filled+tinted when pinned */
.icon-btn.pinned { color: var(--accent); background: var(--accent-soft); }
.icon-btn.pinned svg { transform: rotate(45deg); transition: transform .15s; }
.icon-btn.pinned:hover svg { transform: rotate(0deg); }
.icon-btn svg { transition: transform .15s; }

.list-empty { color: var(--faint); font-size: 13px; text-align: center; padding: 24px 12px; }

/* Sidebar footer — small links at bottom of editor sidebar */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  align-items: center;
}
.sidebar-footer a {
  font-size: 11.5px; color: var(--muted); white-space: nowrap;
}
.sidebar-footer a:hover { color: var(--text); }
.sidebar-footer-copy {
  font-size: 11px; color: var(--faint); margin-left: auto;
  font-family: var(--mono);
}

/* ── EDITOR MAIN: absolute positioning — most reliable for full-fill layouts ── */
.editor-main {
  position: relative;
  overflow: hidden;
  background: var(--bg2);
  min-height: 0;
}
.ed-placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; color: var(--faint);
}
.ed-placeholder svg { opacity: .3; }
.ed-placeholder p { font-size: 14px; }

/* The whole editor is absolutely positioned over editor-main. Uses flex col for inner layout. */
.ed-wrap {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg2);
}
.ed-wrap.visible { display: flex; }

.ed-topbar {
  flex-shrink: 0;
  padding: 10px 20px 8px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; background: var(--surface);
}
.ed-title-input {
  flex: 1; border: 0; background: transparent; outline: 0;
  font-family: var(--display); font-size: 22px; font-weight: 500;
  color: var(--text); letter-spacing: -.02em;
}
.ed-title-input::placeholder { color: var(--faint); }
.ed-actions { display: flex; gap: 6px; }

.ed-tags-row {
  flex-shrink: 0;
  padding: 8px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap; background: var(--surface);
}
.ed-tag {
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  background: var(--accent-soft); border: 1.5px solid rgba(108,99,255,.22);
  color: var(--accent); border-radius: 20px; padding: 3px 7px 3px 10px;
  display: inline-flex; align-items: center; gap: 5px;
}
.ed-tag b { cursor: pointer; font-weight: 700; color: var(--faint); }
.ed-tag b:hover { color: var(--red); }
.ed-tag-input {
  border: 0; background: transparent; outline: 0;
  font-family: var(--mono); font-size: 12px; color: var(--text);
  min-width: 110px; padding: 3px;
}
.ed-tag-input::placeholder { color: var(--faint); }

.toolbar {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: 5px 16px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.toolbar button {
  width: 28px; height: 28px; background: transparent;
  border: 1.5px solid transparent; border-radius: 7px; color: var(--muted);
  font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: .12s;
}
.toolbar button svg { display: block; }
.toolbar button:hover { background: var(--surface2); color: var(--text); }
.tb-sep { width: 1px; height: 16px; background: var(--border); margin: 0 3px; }

/* THE WRITING AREA — fills remaining space, scrolls internally */
.ed-body-wrap {
  flex: 1 1 0;
  min-height: 200px;
  overflow-y: auto;
  cursor: text;
  background: var(--bg2);
}
.ed-body {
  min-height: 100%;
  padding: 32px 48px 80px;
  max-width: 880px;          /* readable line length */
  /* no margin: auto — left-aligned within the scroll wrapper */
  outline: 0;
  font-size: 16px; line-height: 1.8; color: var(--text);
  cursor: text;
  caret-color: var(--accent);
  box-sizing: border-box;
  position: relative;
}
.ed-body[data-empty="true"]::before {
  content: attr(data-ph);
  color: var(--faint);
  pointer-events: none;
  position: absolute;
  left: 48px;
  top: 32px;
}
.ed-body:focus { outline: 0; }
.ed-body h1 { font-family: var(--display); font-size: 28px; font-weight: 500; margin: 1em 0 .3em; }
.ed-body h2 { font-family: var(--display); font-size: 22px; font-weight: 500; margin: .8em 0 .3em; }
.ed-body h3 { font-size: 17px; font-weight: 600; margin: .8em 0 .3em; }
.ed-body img { max-width: 100%; border-radius: 10px; margin: 10px 0; display: block; }
.ed-body a { color: var(--accent); text-decoration: underline; }
.ed-body code { font-family: var(--mono); font-size: 13px; background: var(--accent-soft); padding: 2px 6px; border-radius: 5px; color: var(--accent); }
.ed-body blockquote { border-left: 3px solid var(--accent); margin: .8em 0; padding: 4px 16px; color: var(--muted); }
.ed-body ul, .ed-body ol { padding-left: 24px; }
.ed-body p { margin: 0 0 .6em; min-height: 1.5em; }

.ed-foot {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 14px; padding: 8px 20px;
  border-top: 1px solid var(--border); font-size: 12px; color: var(--faint);
  font-family: var(--mono); background: var(--surface);
}
.color-picker { display: flex; gap: 6px; }
.color-dot { width: 17px; height: 17px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: .12s; }
.color-dot:hover, .color-dot.active { border-color: var(--accent); transform: scale(1.2); }
.color-dot[data-c=""]         { background: var(--surface2); border-color: var(--border2); }
.color-dot[data-c="lavender"] { background: #c4b5fd; }
.color-dot[data-c="mint"]     { background: #6ee7b7; }
.color-dot[data-c="rose"]     { background: #fda4af; }
.color-dot[data-c="sky"]      { background: #93c5fd; }
.color-dot[data-c="sand"]     { background: #fcd34d; }

/* guest unsaved indicator */
.guest-badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  padding: 3px 10px; border-radius: 20px;
  background: rgba(251,191,36,.15); border: 1px solid rgba(251,191,36,.4);
  color: #b45309;
}
[data-theme="dark"] .guest-badge { color: #fbbf24; background: rgba(251,191,36,.12); }

/* Share dropdown */
.share-wrap { position: relative; }
.share-menu {
  display: none;
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; box-shadow: 0 12px 36px rgba(0,0,0,.12);
  min-width: 200px; z-index: 60;
  padding: 5px;
  animation: shareIn .14s ease-out;
}
[data-theme="dark"] .share-menu { box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.share-menu.open { display: block; }
@keyframes shareIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.share-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 11px; border: 0; background: transparent;
  border-radius: 7px; cursor: pointer; color: var(--text);
  font-size: 13.5px; text-align: left; transition: background .1s;
}
.share-item:hover { background: var(--surface2); }
.share-item svg {
  width: 15px; height: 15px; color: var(--muted); flex-shrink: 0;
}
.share-item:hover svg { color: var(--accent); }
.share-sep {
  height: 1px; background: var(--border); margin: 5px 8px;
}

/* ── Auto-save pill (replaces Save button for logged-in users) ── */
.autosave-pill {
  display: none;  /* shown only when logged in (set via body[data-guest="false"]) */
  align-items: center; gap: 7px;
  padding: 6px 12px 6px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px; font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.autosave-pill:hover {
  border-color: var(--border2);
  color: var(--text);
}
.autosave-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #16a34a; /* green = saved / steady state */
  box-shadow: 0 0 0 2px rgba(22,163,74,.18);
  transition: background .2s, box-shadow .2s;
  flex-shrink: 0;
}
/* States */
.autosave-pill[data-state="modified"] .autosave-dot {
  background: #f59e0b; /* amber = unsaved changes pending */
  box-shadow: 0 0 0 2px rgba(245,158,11,.2);
  animation: autosavePulse 1.4s ease-in-out infinite;
}
.autosave-pill[data-state="saving"] .autosave-dot {
  background: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
  animation: autosavePulse 0.8s ease-in-out infinite;
}
.autosave-pill[data-state="error"] .autosave-dot {
  background: #dc2626;
  box-shadow: 0 0 0 2px rgba(220,38,38,.2);
}
@keyframes autosavePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.15); opacity: 0.7; }
}

/* Toggle which control shows based on auth state */
body[data-guest="false"] .autosave-pill { display: inline-flex; }
body[data-guest="false"] #saveBtn       { display: none; }
body[data-guest="true"]  .autosave-pill { display: none; }
body[data-guest="true"]  #saveBtn       { display: inline-flex; }

/* ── GUEST TEASER (templates + CTA shown below editor when not logged in) ── */
#guestTeaser { display: none; }
body[data-guest="true"] #guestTeaser { display: block; }
/* When a guest is in the editor view, make page scrollable so teaser is reachable */
body[data-guest="true"] #editor-view { display: block; }
body[data-guest="true"] .editor-shell {
  height: auto;
  min-height: calc(100vh - var(--nav-h));
}

.guest-teaser-section {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 40px 32px;
}
.teaser-label {
  font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 16px;
}
.teaser-cards {
  display: flex; gap: 14px;
  overflow-x: auto; padding-bottom: 6px;
  margin-bottom: 32px;
}
.teaser-cards::-webkit-scrollbar { height: 0; }
.teaser-card {
  flex-shrink: 0; width: 120px; cursor: pointer; transition: .15s;
}
.teaser-card:hover .teaser-thumb { border-color: var(--accent); box-shadow: 0 4px 16px rgba(108,99,255,.2); transform: translateY(-2px); }
.teaser-thumb {
  width: 120px; height: 158px; border: 2px solid var(--border); border-radius: 8px;
  background: var(--bg2); display: flex; align-items: center; justify-content: center;
  transition: .15s; overflow: hidden; position: relative;
}
.teaser-thumb .lines { position: absolute; left: 12px; right: 12px; top: 22px; display: flex; flex-direction: column; gap: 5px; }
.teaser-thumb .line { height: 6px; border-radius: 3px; background: var(--border2); }
.teaser-thumb .line.title { height: 9px; width: 70%; background: var(--accent); opacity: .35; }
.teaser-thumb .line.short { width: 55%; }
.teaser-thumb .plus-icon { color: var(--accent); opacity: .5; }
.teaser-label-card { font-size: 12px; color: var(--muted); margin-top: 7px; text-align: center; font-weight: 500; }

/* Sign-up CTA panel */
.teaser-cta {
  background: linear-gradient(135deg, var(--accent) 0%, #8b80ff 100%);
  color: white;
  border-radius: 16px;
  padding: 28px 32px;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  box-shadow: 0 12px 36px rgba(108,99,255,.25);
}
.teaser-cta-text { flex: 1; min-width: 240px; }
.teaser-cta-text h3 {
  font-family: var(--display); font-weight: 500; font-size: 24px;
  letter-spacing: -.01em; margin-bottom: 6px;
}
.teaser-cta-text h3 em { font-style: italic; font-weight: 300; }
.teaser-cta-text p { font-size: 14px; opacity: .92; line-height: 1.6; }
.teaser-cta-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.teaser-cta-actions .btn {
  background: white; color: var(--accent); border-color: white; font-weight: 700;
}
.teaser-cta-actions .btn:hover { background: rgba(255,255,255,.92); }
.teaser-cta-actions .btn.outline {
  background: transparent; color: white; border-color: rgba(255,255,255,.5);
}
.teaser-cta-actions .btn.outline:hover { background: rgba(255,255,255,.13); border-color: white; }

.teaser-features {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px; margin-top: 32px;
}
.teaser-feature h4 {
  font-family: var(--display); font-size: 16px; font-weight: 500; margin-bottom: 4px; color: var(--text);
}
.teaser-feature p { font-size: 13px; color: var(--muted); line-height: 1.55; }
.teaser-feature .icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 10px;
}

/* ── User templates strip — shown below editor for logged-in users ── */
#userTemplates { display: none; }
body[data-guest="false"] #userTemplates { display: block; }
/* When this strip shows, let editor-shell flex-grow instead of being viewport-fixed,
   so the page can scroll down to reveal the templates strip */
body[data-guest="false"] .editor-shell {
  height: auto;
  min-height: calc(100vh - var(--nav-h));
}

.user-templates-section {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 28px 32px 36px;
}
.user-templates-label {
  font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 16px;
}
.user-templates-cards {
  display: flex; gap: 12px; flex-wrap: wrap;
}
.user-tpl-card {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px 10px 12px;
  background: var(--bg2); border: 1.5px solid var(--border);
  border-radius: 10px; cursor: pointer;
  transition: .15s;
}
.user-tpl-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(108,99,255,.12);
}
.user-tpl-thumb {
  width: 32px; height: 32px; border-radius: 7px;
  background: var(--surface); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-tpl-name {
  font-size: 13.5px; font-weight: 500; color: var(--text);
  white-space: nowrap;
}

/* Teaser footer — site nav links at the very bottom for guests */
.teaser-footer {
  margin-top: 36px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 12px 26px;
  font-size: 13px;
}
.teaser-footer a { color: var(--muted); }
.teaser-footer a:hover { color: var(--text); }
.teaser-footer-copy {
  margin-left: auto;
  font-family: var(--mono); font-size: 11.5px; color: var(--faint);
}

/* "Learn more" link below features → goes to /about */
.teaser-learn-more {
  text-align: center;
  margin: 40px 0 20px;
  font-size: 14px;
}
.teaser-learn-more a {
  color: var(--accent); font-weight: 600;
  padding: 8px 16px; border-radius: 8px;
  transition: .15s;
}
.teaser-learn-more a:hover { background: var(--accent-soft); }

/* ── FOOTER ── */
.site-footer {
  border-top: 1px solid var(--border); background: var(--surface);
  padding: 16px 28px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  /* Push footer to the bottom of home-view's flex column */
  margin-top: auto;
}
.site-footer .brand-small { font-family: var(--display); font-size: 14px; font-weight: 500; color: var(--muted); font-style: italic; margin-right: auto; }
.site-footer a { font-size: 13px; color: var(--muted); }
.site-footer a:hover { color: var(--text); }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 22px; left: 50%;
  transform: translateX(-50%) translateY(14px);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 50px; font-size: 13px;
  opacity: 0; transition: .25s; pointer-events: none; z-index: 300; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── PROFILE MODAL ── */
.profile-modal .form-row { margin-bottom: 12px; }
.profile-modal .modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ── RESPONSIVE ── */
@media (max-width: 740px) {
  .editor-shell { grid-template-columns: 1fr; }
  .editor-sidebar { display: none; }
  .editor-shell.show-list .editor-sidebar { display: flex; }
  .editor-shell.show-list .editor-main { display: none; }
  .ed-body { padding: 16px 20px; }
  .nav-links { display: none; }
}
