*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body { touch-action: manipulation; }
button, a, [role="button"] { touch-action: manipulation; }

:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #111111;
  --text-secondary: #444444;
  --text-muted: #666666;
  --accent: #f9bd2b;
  --accent-text: #111111;
  --error: #e5484d;
  --sidebar-width: 240px;
  --radius: 14px;
  --radius-sm: 8px;
  --radius-pill: 100px;
  /* Typography */
  --font-ui: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  --font-reading: 'Charter', Cambria, Georgia, serif;
  /* Surfaces — tokenised for dark mode */
  --surface-raised: rgba(0,0,0,0.05);
  --surface-hover: rgba(0,0,0,0.08);
  --border-subtle: rgba(0,0,0,0.06);
  /* Liquid Glass */
  --glass-bg: rgba(255,255,255,0.72);
  --glass-blur: blur(32px) saturate(180%);
  --glass-border: rgba(255,255,255,0.5);
}

html { scroll-behavior: smooth; }

/* Decorative gradient layer — gives glass effects something to blur against */
html::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 50% at 15% 10%, rgba(249,189,43,0.13) 0%, transparent 70%),
    radial-gradient(ellipse 50% 60% at 85% 85%, rgba(120,160,255,0.09) 0%, transparent 65%),
    radial-gradient(ellipse 40% 40% at 70% 15%, rgba(255,120,160,0.07) 0%, transparent 60%);
}
@media (prefers-color-scheme: dark) {
  html::before {
    background:
      radial-gradient(ellipse 60% 50% at 15% 10%, rgba(249,189,43,0.08) 0%, transparent 70%),
      radial-gradient(ellipse 50% 60% at 85% 85%, rgba(100,140,255,0.07) 0%, transparent 65%),
      radial-gradient(ellipse 40% 40% at 70% 15%, rgba(220,100,140,0.05) 0%, transparent 60%);
  }
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  font-size: 15px;
  isolation: isolate;
}


.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-muted);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s, background 0.1s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-raised); }

/* ── Layout ── */

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Sidebar (mobile: horizontal strip at top) ── */

.sidebar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  padding: 0;
  /* Solid bg on mobile — backdrop-filter would trap position:fixed children */
  background: var(--bg);
  border-bottom: 1px solid var(--border-subtle);
}


/* ── Calendar widget ── */

.cal-widget {
  padding: 14px 16px 8px;
}

.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.cal-month-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.cal-nav {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s, background 0.1s;
}
.cal-nav:hover { color: var(--text); background: var(--surface-raised); }

.cal-strip {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.cal-strip::-webkit-scrollbar { display: none; }

.cal-day {
  flex-shrink: 0;
  width: 30px;
  height: 34px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, color 0.1s;
}
.cal-day:hover { background: var(--surface-raised); color: var(--text); }
.cal-day.today { color: var(--text); font-weight: 700; }
.cal-day.today::before {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: calc(var(--radius-sm) - 2px);
  border: 1.5px solid var(--border-subtle);
  pointer-events: none;
}
.cal-day.active {
  background: var(--accent);
  color: var(--accent-text);
}
.cal-day.active::before { display: none; }
.cal-day.has-dot::after {
  content: '';
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--accent);
  position: absolute;
  bottom: 4px;
}
.cal-day.active::after { background: var(--accent-text); opacity: 0.6; }

/* ── Tags bar ── */

.tags-bar {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tags-bar::-webkit-scrollbar { display: none; }
.tags-bar[hidden] { display: none; }

.tag-thumb {
  flex-shrink: 0;
  width: 68px; height: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: var(--surface-raised);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
  padding: 6px 4px;
}
.tag-thumb:hover { background: var(--surface-hover); }
.tag-thumb.active { background: var(--accent); }

.tag-thumb-count {
  font-size: 20px; font-weight: 700; line-height: 1;
  color: var(--text);
  font-family: var(--font-ui);
}
.tag-thumb-name {
  font-size: 10px; font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 60px; text-align: center;
  font-family: var(--font-ui);
}
.tag-thumb.active .tag-thumb-count,
.tag-thumb.active .tag-thumb-name { color: var(--accent-text); }

/* ── FAB (mobile: fixed bottom-center) ── */

.fab {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius-pill);
  padding: 13px 32px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  z-index: 20;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.1s, transform 0.1s, box-shadow 0.1s;
}
.fab:active {
  transform: translateX(-50%) translateY(2px);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

/* ── Journal ── */

main {
  flex: 1;
  padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
}

.empty {
  text-align: center;
  padding: 80px 32px 40px;
}
.empty p {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: -0.02em;
  opacity: 0.7;
}
.empty-hint {
  font-size: 13px;
  font-weight: 500;
  margin-top: 10px;
  color: var(--text-muted);
  opacity: 0.6;
}

/* Date group */

.date-group {
  margin: 6px 12px 0;
  background: rgba(255,254,249,0.72);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid rgba(249,189,43,0.22);
  border-radius: 16px;
  overflow: hidden;
}
.date-group:first-child { margin-top: 8px; }
.date-group + .date-group { margin-top: 4px; }

.date-sep {
  padding: 6px 14px 2px 14px;
}

.date-sep span {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #b07d00;
}

/* Entry */

.entry {
  padding: 7px 14px;
  border-radius: 0;
  transition: background 0.1s;
}
.entry + .entry { border-top: 1px solid rgba(249,189,43,0.14); }
.entry:hover { background: rgba(249,189,43,0.05); }

/* Private */
.entry.private .entry-body {
  filter: blur(5px);
  user-select: none;
  transition: filter 0.3s;
  cursor: pointer;
}
.entry.private.revealed .entry-body { filter: none; user-select: auto; cursor: default; }

.private-badge {
  display: none;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
}
.entry.private .private-badge { display: block; }

/* Entry body */
.entry-body {
  font-family: var(--font-reading);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  word-break: break-word;
  /* Truncate long entries in the feed */
  display: -webkit-box;
  -webkit-line-clamp: 7;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* Full expansion in detail view and when editing */
.detail-body, .entry-body.expanded {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}
.entry-body > *:last-child { margin-bottom: 0; }
.entry-body p { margin-bottom: 0.5em; }
.entry-body h1, .entry-body h2, .entry-body h3 {
  font-family: var(--font-ui);
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  margin-bottom: 0.4em; color: var(--text-secondary);
}
.entry-body ul, .entry-body ol { padding-left: 1.4em; margin-bottom: 0.5em; }
.entry-body li { margin-bottom: 0.15em; }
.entry-body code {
  font-size: 13px; font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--surface-raised); padding: 1px 5px; border-radius: var(--radius-sm);
}
.entry-body pre {
  background: var(--surface-raised); border-radius: var(--radius);
  padding: 12px 14px; overflow-x: auto; margin-bottom: 0.5em;
}
.entry-body pre code { background: none; padding: 0; }
.entry-body strong { font-weight: 700; }
.entry-body em { font-style: italic; }
.entry-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px; color: var(--text-muted); margin-bottom: 0.5em;
}

/* Entry footer */
.entry-footer { display: flex; align-items: center; gap: 6px; margin-top: 5px; }
.entry-tags { flex: 1; display: flex; gap: 4px; flex-wrap: wrap; }
.entry-tag {
  font-size: 13px; font-weight: 500;
  color: #9a6c00;
  background: rgba(249,189,43,0.15);
  border-radius: var(--radius-sm); padding: 1px 7px;
}
.entry-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.copy-act, .expand-act { display: none; } /* revealed on desktop hover below */
.entry-act {
  background: none; border: none; cursor: pointer;
  padding: 3px; color: rgba(0,0,0,0.4);
  display: flex; align-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s; border-radius: var(--radius-sm);
}
.entry-act:hover, .entry-act:active { color: var(--text-muted); }

@media (hover: hover) and (pointer: fine) {
  .entry { position: relative; }
  .entry-footer { opacity: 0; transition: opacity 0.12s; }
  .entry:hover .entry-footer { opacity: 1; }
  .copy-act, .expand-act { display: flex; }
  .entry-act { padding: 5px; border-radius: var(--radius); }
  .entry-act:hover { background: var(--surface-raised); color: var(--text); }
}

.entry-time {
  font-size: 11px; font-weight: 500; color: var(--text-muted);
  flex-shrink: 0; display: flex; align-items: center; gap: 4px;
}
.entry-edited {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted);
  opacity: 0.7;
}

/* ── Entry detail overlay ── */

.entry-detail {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 50;
  transform: translateX(100%);
  transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.entry-detail.open { transform: translateX(0); }

.detail-header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px 0 8px;
  height: 52px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
}
.detail-meta {
  flex: 1; font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-align: center;
}
.detail-tags { display: flex; gap: 5px; flex-wrap: wrap; padding: 12px 24px 0; }
.detail-tags:empty { display: none; }

.detail-body {
  padding: 24px 28px 88px;
  font-family: var(--font-reading);
  font-size: 16px; line-height: 1.82;
  color: var(--text); word-break: break-word;
}
.detail-body > *:last-child { margin-bottom: 0; }
.detail-body p { margin-bottom: 0.6em; }
.detail-body h1, .detail-body h2, .detail-body h3 {
  font-family: var(--font-ui);
  font-size: 13px; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase;
  margin-bottom: 0.5em; color: var(--text-secondary);
}
.detail-body ul, .detail-body ol { padding-left: 1.4em; margin-bottom: 0.6em; }
.detail-body li { margin-bottom: 0.2em; }
.detail-body strong { font-weight: 700; }
.detail-body em { font-style: italic; }
.detail-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px; color: var(--text-muted); margin-bottom: 0.6em;
}
.detail-body code {
  font-size: 13px; font-family: 'SF Mono', 'Fira Code', monospace;
  background: var(--surface-raised); padding: 1px 5px; border-radius: var(--radius-sm);
}
.detail-body pre {
  background: var(--surface-raised); border-radius: var(--radius);
  padding: 14px 16px; overflow-x: auto; margin-bottom: 0.6em;
}
.detail-body pre code { background: none; padding: 0; }

/* ── Capture sheet ── */

.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.18);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease; z-index: 30;
  backdrop-filter: blur(8px) saturate(120%);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.bottom-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--glass-border);
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 40;
}
.bottom-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px; height: 5px;
  background: rgba(0,0,0,0.14);
  border-radius: var(--radius-pill); margin: 0 auto 16px;
}

.sheet-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.tag-input-wrap {
  flex: 1; display: flex; align-items: center; gap: 5px;
  background: var(--surface-raised); border-radius: var(--radius);
  padding: 6px 10px; min-height: 36px; flex-wrap: wrap; cursor: text;
  transition: background 0.1s;
}
.tag-input-wrap:focus-within { background: var(--surface-hover); }
.tag-input-wrap::before {
  content: '#'; font-size: 13px; font-weight: 700;
  color: rgba(0,0,0,0.25); flex-shrink: 0; line-height: 1;
}

.tag-chip {
  display: flex; align-items: center; gap: 3px;
  font-size: 11px; font-weight: 700;
  color: var(--accent-text); background: var(--accent);
  border-radius: var(--radius-sm); padding: 2px 7px;
}
.tag-chip-remove {
  background: none; border: none; cursor: pointer;
  color: inherit; padding: 0; line-height: 1; opacity: 0.6; font-size: 14px;
}

.tag-inline-input {
  flex: 1; min-width: 60px; border: none; outline: none;
  /* 16px prevents iOS Safari auto-zoom on focus */
  font-size: 16px; font-weight: 400; color: var(--text);
  background: transparent; font-family: inherit; padding: 0;
  line-height: 1;
}
.tag-inline-input::placeholder { color: rgba(0,0,0,0.25); font-weight: 400; }

.private-toggle {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  background: var(--surface-raised); border: none;
  border-radius: var(--radius); padding: 0 12px; height: 36px;
  cursor: pointer; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, color 0.1s; font-family: inherit;
}
.private-toggle:hover { background: var(--surface-hover); }
.private-toggle.on { background: var(--accent); color: var(--accent-text); }

.bottom-sheet textarea {
  width: 100%; min-height: 100px; max-height: 40dvh;
  background: var(--surface-raised); border: none; border-radius: var(--radius);
  padding: 12px 14px; font-size: 16px; font-family: inherit;
  line-height: 1.6; resize: none; outline: none; color: var(--text);
  transition: background 0.1s; display: block;
}
.bottom-sheet textarea:focus { background: var(--surface-hover); }
.bottom-sheet textarea::placeholder { color: rgba(0,0,0,0.25); }

.sheet-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }

.btn-cancel {
  background: none; border: none;
  font-size: 13px; font-weight: 400; color: var(--text-muted);
  cursor: pointer; padding: 8px 4px;
  -webkit-tap-highlight-color: transparent; font-family: inherit;
}
.btn-cancel:hover { color: var(--text); }

.btn-send {
  background: var(--accent); color: var(--accent-text); border: none;
  border-radius: var(--radius); font-size: 13px; font-weight: 700;
  padding: 10px 24px; cursor: pointer;
  -webkit-tap-highlight-color: transparent; font-family: inherit;
  box-shadow: 0 3px 0 rgba(0,0,0,0.1);
  transition: transform 0.1s, box-shadow 0.1s;
}
.btn-send:active { transform: translateY(1px); box-shadow: 0 2px 0 rgba(0,0,0,0.1); }

body.sheet-open { overflow: hidden; }

/* ══ TABLET (768px+) ══════════════════════════════════════════════════════ */

@media (min-width: 768px) {

  .app-layout {
    flex-direction: row;
    max-width: 1100px;
    margin: 0 auto;
    min-height: 100dvh;
  }

  /* Left sidebar */
  .sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-bottom: none;
    padding-bottom: 24px;
  }


  .tags-bar {
    padding: 6px 20px;
    flex: none;
  }

  /* Sidebar FAB — inline, not fixed */
  .fab {
    position: relative;
    bottom: auto;
    left: auto;
    transform: none;
    margin: auto 16px 0;
    width: calc(100% - 32px);
    border-radius: var(--radius);
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  }
  .fab:active {
    transform: translateY(1px);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  }

  /* Journal */
  main {
    flex: 1;
    min-width: 0;
    padding-bottom: 60px;
  }

  .date-group { margin: 6px 20px 0; }
  .entry { padding: 7px 18px; }
  .date-sep { padding: 6px 18px 2px; }
  .detail-body { padding: 36px 52px 100px; }

  /* Sheet becomes a centered floating dialog on tablet */
  .bottom-sheet {
    max-width: 680px;
    left: 50%; right: auto;
    transform: translateX(-50%) translateY(100%);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    bottom: 40px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 4px 16px rgba(0,0,0,0.08);
  }
  .bottom-sheet.open { transform: translateX(-50%) translateY(0); }
  .bottom-sheet textarea { min-height: 200px; max-height: 60vh; }
}

/* ── Undo toast ── */
.undo-toast {
  position: fixed; bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  background: rgba(30,30,30,0.82);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  color: rgba(255,255,255,0.9);
  font-size: 13px; font-weight: 400;
  padding: 10px 18px; border-radius: var(--radius-pill);
  border: 1px solid rgba(255,255,255,0.12);
  display: flex; align-items: center; gap: 14px;
  z-index: 60; white-space: nowrap;
  animation: toast-in 0.2s ease-out;
}
.undo-toast button {
  background: none; border: none; color: var(--accent);
  font-size: 13px; font-weight: 700; cursor: pointer;
  padding: 0; font-family: inherit;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Expand button (sheet → rich editor) ── */
.btn-expand {
  background: none; border: none; cursor: pointer;
  padding: 8px; color: var(--text-muted);
  border-radius: var(--radius-sm); display: flex; align-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.1s, background 0.1s;
}
.btn-expand:hover { color: var(--text); background: var(--surface-raised); }

/* ── Rich text editor overlay ── */
.rich-editor {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 45;
  display: flex; flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
}
.rich-editor.open { transform: translateY(0); }

.rich-editor-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 0 10px; height: 52px; flex-shrink: 0;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border-subtle);
}

.editor-toolbar {
  flex: 1; display: flex; align-items: center; gap: 1px;
  overflow-x: auto; scrollbar-width: none;
}
.editor-toolbar::-webkit-scrollbar { display: none; }

.tb-btn {
  flex-shrink: 0; background: none; border: none; cursor: pointer;
  padding: 0; width: 30px; height: 28px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 700; font-family: var(--font-ui);
  color: var(--text-muted); line-height: 1;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, color 0.1s;
}
.tb-btn:hover { background: var(--surface-raised); color: var(--text); }
.tb-btn.active { background: var(--accent); color: var(--accent-text); }
.tb-bold { font-weight: 900; }
.tb-italic { font-style: italic; font-weight: 600; }
.tb-sep { width: 1px; height: 16px; background: var(--border-subtle); flex-shrink: 0; margin: 0 2px; }

.rich-editor-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 20px 20px 0;
}
#editorMount { min-height: 100%; padding-bottom: 40px; }

/* ProseMirror base */
.ProseMirror {
  outline: none; min-height: 180px;
  font-family: var(--font-reading); font-size: 16px; font-weight: 400;
  line-height: 1.82; color: var(--text);
  caret-color: var(--accent);
  word-break: break-word; white-space: pre-wrap;
}
.ProseMirror > * + * { margin-top: 0.7em; }
.ProseMirror p { margin: 0; }
/* Real heading hierarchy for authoring — not the feed's label style */
.ProseMirror h1 {
  font-family: var(--font-ui); font-size: 22px; font-weight: 700;
  letter-spacing: -0.02em; line-height: 1.2;
  color: var(--text); margin-bottom: 0;
}
.ProseMirror h2 {
  font-family: var(--font-ui); font-size: 17px; font-weight: 700;
  letter-spacing: -0.01em; line-height: 1.3;
  color: var(--text); margin-bottom: 0;
}
.ProseMirror h3 {
  font-family: var(--font-ui); font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.06em; line-height: 1.4;
  color: var(--text-secondary); margin-bottom: 0;
}
.ProseMirror ul, .ProseMirror ol { padding-left: 1.5em; margin: 0; }
.ProseMirror li { margin-bottom: 0.2em; }
.ProseMirror li > p { margin: 0; }
.ProseMirror blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px; color: var(--text-muted); margin: 0;
}
.ProseMirror code {
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px;
  background: var(--surface-raised); padding: 1px 5px; border-radius: var(--radius-sm);
}
.ProseMirror pre {
  background: var(--surface-raised); border-radius: var(--radius);
  padding: 14px 16px; overflow-x: auto; margin: 0;
}
.ProseMirror pre code { background: none; padding: 0; font-size: 13px; }
.ProseMirror strong { font-weight: 700; }
.ProseMirror em { font-style: italic; }
.ProseMirror hr { border: none; border-top: 1px solid var(--border-subtle); }
.ProseMirror-selectednode { outline: 2px solid var(--accent); outline-offset: 2px; }

.rich-editor-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-subtle);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  flex-shrink: 0;
}

/* Tablet: centered modal */
@media (min-width: 768px) {
  .rich-editor {
    inset: auto;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%) scale(0.96);
    width: min(680px, 90vw); height: min(82vh, 720px);
    border-radius: var(--radius);
    border: 1px solid var(--border-subtle);
    box-shadow: 0 24px 80px rgba(0,0,0,0.2), 0 4px 20px rgba(0,0,0,0.1);
    opacity: 0;
    transition: transform 0.25s cubic-bezier(0.32,0.72,0,1), opacity 0.25s;
  }
  .rich-editor.open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}

/* ── Detail delete button ── */
.detail-delete {
  background: none; border: none; cursor: pointer;
  padding: 6px; color: var(--text-muted);
  border-radius: var(--radius); display: flex; align-items: center;
  transition: color 0.1s, background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.detail-delete:hover { color: var(--error); background: rgba(229,72,77,0.06); }

/* ── New entry flash ── */
@keyframes entry-flash {
  0%   { background: rgba(249,189,43,0.18); }
  100% { background: transparent; }
}
.entry.new { animation: entry-flash 0.8s ease-out forwards; }

/* ── Send button disabled ── */
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* ══ DESKTOP (1100px+) ════════════════════════════════════════════════════ */

@media (min-width: 1100px) {
  :root { --sidebar-width: 260px; }

  .app-layout { max-width: 1280px; }
  .tags-bar { padding: 0 24px; }
  .fab { margin: auto 20px 0; width: calc(100% - 40px); }
}

/* ══ DARK MODE ════════════════════════════════════════════════════════════ */

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --surface: #1c1c1e;
    --text: rgba(255,255,255,0.9);
    --text-secondary: rgba(255,255,255,0.62);
    --text-muted: rgba(255,255,255,0.42);
    --error: #ff6b6b;
    /* Surfaces flip to white-alpha */
    --surface-raised: rgba(255,255,255,0.08);
    --surface-hover: rgba(255,255,255,0.13);
    --border-subtle: rgba(255,255,255,0.09);
    /* Glass darkens */
    --glass-bg: rgba(28,28,30,0.88);
    --glass-border: rgba(255,255,255,0.1);
  }

  html { color-scheme: dark; }

  .date-group {
    background: rgba(38,30,8,0.72);
    border-color: rgba(249,189,43,0.15);
  }
  .date-sep span { color: rgba(249,189,43,0.7); }
  .entry + .entry { border-top-color: rgba(249,189,43,0.08); }
  .entry:hover { background: rgba(249,189,43,0.04); }
  .entry-tag { background: rgba(249,189,43,0.12); color: rgba(249,189,43,0.75); }

  .tags-bar { background: transparent; }

  .entry-act { color: rgba(255,255,255,0.35); }
  .entry-act:hover, .entry-act:active { color: var(--text-muted); }
  @media (hover: hover) and (pointer: fine) {
    .entry-act:hover { background: rgba(255,255,255,0.08); color: var(--text); }
  }

  .sheet-backdrop { background: rgba(0,0,0,0.5); }
  .sheet-handle { background: rgba(255,255,255,0.18); }

  .tag-input-wrap::before { color: rgba(255,255,255,0.22); }
  .tag-inline-input::placeholder { color: rgba(255,255,255,0.22); }
  .bottom-sheet textarea::placeholder { color: rgba(255,255,255,0.22); }

  .detail-delete:hover { color: var(--error); background: rgba(255,100,100,0.1); }

  .undo-toast { background: rgba(50,50,52,0.92); }

  @keyframes entry-flash {
    0%   { background: rgba(249,189,43,0.12); }
    100% { background: transparent; }
  }
}
