/* ── Dark theme (default) — land4 SaaS style ── */
:root,
[data-theme="dark"] {
  --bg-r: 15;
  --bg-g: 23;
  --bg-b: 42;
  --card: #1e293b;
  --card-hover: #243150;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: rgba(200, 215, 238, 0.72) !important;
  --indigo: #06b6d4;
  --indigo-dark: #0891b2;
  --indigo-light: #67e8f9;
  --amber: #f59e0b;
  --gradient: linear-gradient(135deg,#06b6d4 0%,#22d3ee 50%,#67e8f9 100%);
  --radius: 16px;
  --radius-sm: 10px;
  --font-scale: 1;
  --muted-r: 148;
  --muted-g: 163;
  --muted-b: 184;
}

/* ── Light theme — light version of the dark theme ── */
[data-theme="light"] {
  --bg-r: 246;
  --bg-g: 246;
  --bg-b: 248;
  --card: #fff;
  --card-hover: #f0f0f0;
  --border: #d4d4d4;
  --text: #2c2c2c;
  --text-muted: rgba(100, 100, 100, 0.6) !important;
  /* Chart colours match dark theme for consistent visualization */
  --indigo: #06b6d4;
  --indigo-dark: #0891b2;
  --indigo-light: #67e8f9;
  --amber: #f59e0b;
  --gradient: linear-gradient(135deg,#06b6d4 0%,#22d3ee 50%,#67e8f9 100%);
  --muted-r: 100;
  --muted-g: 100;
  --muted-b: 100;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  background: rgb(var(--bg-r), var(--bg-g), var(--bg-b));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  padding-bottom: 0;
  overflow-x: hidden;
}

/* ── Auth ── */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; padding: 40px 20px; }
.auth-box { width: 100%; max-width: 400px; margin: 0 auto; }
.auth-box .logo { font-size: calc(28px * var(--font-scale)); font-weight: 700; background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; text-align: center; margin-bottom: 4px; }
.auth-box .tagline { text-align: center; color: var(--text-muted); font-size: calc(14px * var(--font-scale)); margin-bottom: 28px; }
.auth-tabs { display: flex; background: var(--card); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 24px; }
.auth-tabs button { flex: 1; padding: 10px; border: none; background: transparent; color: var(--text-muted); font-size: calc(14px * var(--font-scale)); font-weight: 600; border-radius: 8px; cursor: pointer; transition: .2s; }
.auth-tabs button.active { background: var(--indigo); color: #fff; }

@keyframes slideMenu { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }
@keyframes slideMenuLeft { from { opacity:0; transform:translateX(-20px); } to { opacity:1; transform:translateX(0); } }

/* ── Pulse ring animation for home button ── */
.pulse-ring {
  animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse-ring {
  0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,.3), 0 0 0 0 rgba(99,102,241,.4); }
  50% { box-shadow: 0 2px 8px rgba(0,0,0,.3), 0 0 0 8px rgba(99,102,241,0); }
}

/* ── Page container ── */
.page { padding: 20px 16px 20px; max-width: 720px; margin: 0 auto; font-size: calc(14px * var(--font-scale)); }
.page h1 { font-size: calc(22px * var(--font-scale)); font-weight: 700; margin-bottom: 4px; }
.page .subtitle { color: var(--text-muted); font-size: calc(13px * var(--font-scale)); margin-bottom: 20px; }
.narrative-text { font-size: calc(14px * var(--font-scale)); line-height: 1.7; }
.correlation-item { font-size: calc(14px * var(--font-scale)); line-height: 1.5; padding: 4px 0; }
.generate-prompt { font-size: calc(13px * var(--font-scale)); color: var(--text-muted); }
.loading-xs { font-size: calc(12px * var(--font-scale)); }

/* ── Cards ── */
.card-e { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem; transition: .2s; }
.card-e.hover:hover { background: var(--card-hover); cursor: pointer; }
.card-e.card-e-open { border-color: var(--indigo); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.card-e-header { display: flex; align-items: center; gap: 8px; padding: .65rem .75rem; border-bottom: 1px solid var(--border); font-weight: 600; font-size: calc(14px * var(--font-scale)); }

/* ── Form ── */
.form-e { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; width: 100%; color: var(--text); font-size: calc(15px * var(--font-scale)); outline: none; transition: .2s; }
.form-e:focus { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(6,182,212,.15); }
.form-e::placeholder { color: var(--text-muted); opacity: .5; }
textarea.form-e { resize: vertical; min-height: 180px; line-height: 1.7; }

/* ── Buttons ── */
.btn-e {
  border: none; padding: 10px 24px; border-radius: var(--radius-sm);
  font-size: calc(14px * var(--font-scale)); font-weight: 600; cursor: pointer; transition: .2s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-e.primary { background: var(--gradient); color: #fff; }
.btn-e.primary:hover { transform: translateY(-1px); box-shadow: 0 4px 20px rgba(6,182,212,.35); }
.btn-e.primary:disabled { opacity: .5; transform: none; box-shadow: none; }
.btn-e.outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-e.outline:hover, .btn-e.outline.active { border-color: var(--indigo); color: var(--indigo-light); }
.btn-e.danger { background: #dc2626; color: #fff; }
.btn-e.sm { padding: 6px 14px; font-size: calc(12px * var(--font-scale)); }

/* ── Mood picker ── */
.mood-row { display: flex; justify-content: center; gap: 1px; flex-wrap: wrap; }
.mood-btn {
  width: 64px; padding: 8px 0 6px; border-radius: 12px; border: 2px solid var(--border);
  background: var(--card); cursor: pointer; transition: .2s;
  display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 2px;
}
.mood-btn .emoji { font-size: calc(30px * var(--font-scale)); line-height: 1; padding: 2px; }
.mood-btn .label { font-size: calc(10px * var(--font-scale)); color: var(--text-muted); font-weight: 500; line-height: 1.2; }
.mood-btn:hover { border-color: var(--indigo); transform: translateY(-2px); }
.mood-btn.selected { border-color: var(--indigo); box-shadow: 0 0 0 3px rgba(6,182,212,.2); background: rgba(6,182,212,.1); }

/* ── Entry list ── */
.entry-item { margin-bottom: 10px; }
.entry-item .meta { display: flex; align-items: center; gap: 8px; font-size: calc(11px * var(--font-scale)); color: var(--text-muted); margin-bottom: 4px; }
.entry-item .preview { font-size: calc(14px * var(--font-scale)); color: var(--text-muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.entry-item .preview-full { font-size: calc(14px * var(--font-scale)); color: var(--text-muted); line-height: 1.5; }
.card-e-open .preview { -webkit-line-clamp: unset; display: block; overflow: visible; }
.entry-item .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.entry-highlight .card-e { border-color: var(--indigo); box-shadow: inset 3px 0 0 var(--indigo), 0 0 12px rgba(6,182,212,.15); }
.entry-new .card-e { border-color: var(--indigo-light); box-shadow: 0 0 0 2px rgba(6,182,212,.15), 0 0 20px rgba(6,182,212,.25); animation: fade-glow 2.5s ease-out forwards; }
@keyframes fade-glow { 0% { box-shadow: 0 0 0 3px rgba(6,182,212,.35), 0 0 24px rgba(6,182,212,.3); } 100% { box-shadow: 0 0 0 2px rgba(6,182,212,.15), 0 0 20px rgba(6,182,212,.25); } }
.tag-e { display: inline-block; padding: 2px 8px; border-radius: 8px; border: 1px solid #888; font-size: calc(12px * var(--font-scale)); font-weight: 500; background: rgba(6,182,212,.75); color: #FFF; }
.tag-e.pending { background: rgba(245,158,11,.12); color: #f59e0b; }
.tag-e.failed { background: rgba(239,68,68,.12); color: #ef4444; }

/* ── Analysis display ── */
.analysis-box { background: rgba(6,182,212,.06); border: 1px solid rgba(6,182,212,.15); padding: 16px; }
.analysis-box .label { font-size: calc(11px * var(--font-scale)); font-weight: 600; color: var(--indigo-light); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.analysis-box .mood-score { font-size: calc(32px * var(--font-scale)); font-weight: 700; }
.analysis-box .score-row { display: flex; justify-content: center; gap: 24px; margin-bottom: 12px; }
.analysis-box .score-item { text-align: center; }
.analysis-box .score-item small { display: block; font-size: calc(10px * var(--font-scale)); color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.entry-analysis-expanded { border: 1px solid var(--indigo);border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;margin-bottom: 10px;overflow: hidden; }
.entry-actions { display: flex; gap: 8px; padding: 10px 12px; background: var(--card); border-bottom: 0; }
.entry-actions .btn-e { margin: 0; }
.journal-actions { display: flex; gap: 8px; }

/* ── Calendar (land4 heatmap style) ── */
@media (max-width: 576px) {
  .cal-scroll { max-height: 72vh; overflow-y: auto; }
}
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-header h3 { font-size: calc(13px * var(--font-scale)); font-weight: 700; margin: 0; letter-spacing: .3px; text-transform: uppercase; color: var(--text-muted); }
.cal-header h3 i { margin-right: 4px; }
.cal-header .nav { display: flex; gap: 4px; }
.cal-header .nav button { width: 28px; height: 28px; border-radius: 4px; border: 1px solid var(--border); background: var(--card); color: var(--text-muted); cursor: pointer; font-size: calc(12px * var(--font-scale)); transition: .15s; display:flex;align-items:center;justify-content:center; }
.cal-header .nav button:hover { border-color: var(--indigo); color: var(--indigo-light); }
.cal-grid { display: grid; grid-template-columns: repeat(7,1fr); gap: 3px; }
.cal-grid .day-h { text-align: center; font-size: calc(9px * var(--font-scale)); color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; padding: 2px 0 4px; font-weight: 600; }
.cal-grid .day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: 3px; font-size: calc(10px * var(--font-scale)); cursor: pointer; transition: .15s;
  color: var(--text); border: 1px solid transparent;
}
.cal-grid .day:hover { border-color: rgba(148,163,184,.3); }
.cal-grid .day.other { color: var(--text-muted); opacity: .3; }
.cal-grid .day.today { font-weight: 700; border-color: var(--indigo); color: var(--indigo-light); }
/* Heatmap intensity levels */
.cal-grid .day.lvl1 { background: rgba(6,182,212,.15); color: var(--text); }
.cal-grid .day.lvl2 { background: rgba(6,182,212,.32); color: var(--text); }
.cal-grid .day.lvl3 { background: rgba(6,182,212,.55); color: #fff; }
.cal-grid .day.lvl4 { background: var(--indigo); color: #0f172a; font-weight: 700; }
/* Legend */
.cal-legend { display: flex; gap: 14px; font-size: calc(10px * var(--font-scale)); color: var(--text-muted); margin-top: 10px; justify-content: center; }
.cal-legend .cl { display: flex; align-items: center; gap: 4px; }
.cal-legend .cl .sq { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.cal-legend .cl .sq.lvl1 { background: rgba(6,182,212,.15); }
.cal-legend .cl .sq.lvl2 { background: rgba(6,182,212,.32); }
.cal-legend .cl .sq.lvl3 { background: rgba(6,182,212,.55); }
.cal-legend .cl .sq.lvl4 { background: var(--indigo); }
.cal-day-entries { margin-top: 16px; }
.cal-day-entries h4 { font-size: calc(13px * var(--font-scale)); color: var(--text-muted); margin-bottom: 8px; letter-spacing: .3px; }
/* Remove old mood dot styles no longer used */

/* ── Search layout: calendar + entries side by side on desktop ── */
@media (min-width: 768px) {
  .search-layout { display: flex; gap: 24px; align-items: flex-start; }
  .search-cal { flex-shrink: 0; width: 340px; }
  .search-entries { flex: 1; min-width: 0; }
}
@media (max-width: 767px) {
  .search-cal { width: 100%; }
  .search-entries { width: 100%; }
}

/* ── Mood vs Energy dual chart ── */
.dual-chart { padding: 4px 0; }
.dc-row { display: flex; align-items: flex-end; gap: 6px; height: 90px; }
.dc-group { flex: 1; display: flex; gap: 2px; align-items: flex-end; justify-content: center; height: 100%; }
.dc-bar {
  width: 40%; border-radius: 3px 3px 0 0;
  position: relative; transition: height .3s;
  display: flex; align-items: flex-start; justify-content: center;
}
.dc-bar.mood { background: var(--indigo); }
.dc-bar.energy { background: var(--amber); }
.dc-bar .dc-val {
  position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  font-size: calc(8px * var(--font-scale)); font-weight: 700; white-space: nowrap; margin-bottom: 1px;
  color: var(--text);
}
.dc-labels { display: flex; gap: 6px; margin-top: 4px; }
.dc-labels span { flex: 1; text-align: center; font-size: calc(8px * var(--font-scale)); color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.dc-legend { display: flex; gap: 14px; justify-content: center; margin-top: 6px; font-size: calc(10px * var(--font-scale)); color: var(--text-muted); }
.dcl { display: flex; align-items: center; gap: 4px; }
.dcl-sq { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.dcl-sq.mood { background: var(--indigo); }
.dcl-sq.energy { background: var(--amber); }
.dcl { opacity: .4; transition: opacity .2s; }
.dcl-active { opacity: 1; }

/* ── Energy Score SVG donut ── */
.donut-wrap { display: flex; justify-content: center; }
.donut-svg { width: 72px; height: 72px; transform: rotate(-90deg); }
.donut-track { fill: none; stroke: rgba(148,163,184,.12); stroke-width: 3.5; }
.donut-fill { fill: none; stroke: var(--indigo); stroke-width: 3.5; stroke-linecap: round; transition: stroke-dasharray .6s; }
.donut-text { fill: var(--text); font-size: calc(6px * var(--font-scale)); font-weight: 700; text-anchor: middle; transform: rotate(90deg); transform-origin: 18px 18px; }

/* ── Analysis donuts ── */
.wd-donut { width: 84px; height: 84px; transform: rotate(-90deg); display: block; margin: 0 auto; }
.wd-track { fill: none; stroke: rgba(148,163,184,.1); stroke-width: 3; }
.wd-fill { fill: none; stroke: var(--indigo); stroke-width: 3; stroke-linecap: round; transition: stroke-dasharray .6s; }
.wd-fill.energy { stroke: var(--amber); }
.wd-text { fill: var(--text); font-size: calc(10px * var(--font-scale)); font-weight: 700; text-anchor: middle; transform: rotate(90deg); transform-origin: 18px 18px; }
.analysis-donut { width: 48px; height: 48px; transform: rotate(-90deg); display: block; margin: 0 auto; }
.ad-track { fill: none; stroke: rgba(148,163,184,.1); stroke-width: 3; }
.ad-fill { fill: none; stroke: var(--indigo); stroke-width: 3; stroke-linecap: round; transition: stroke-dasharray .6s; }
.ad-fill.energy { stroke: var(--amber); }
.ad-text { fill: var(--text); font-size: calc(10px * var(--font-scale)); font-weight: 700; text-anchor: middle; transform: rotate(90deg); transform-origin: 24px 24px; }

/* ── Theme frequency bars ── */
.freq-bars { display: flex; flex-direction: column; gap: 6px; }
.freq-row { display: flex; align-items: center; gap: 8px; }
.fr-label { width: 80px; font-size: calc(11px * var(--font-scale)); font-weight: 600; color: var(--text-muted); flex-shrink: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fr-track { flex: 1; height: 18px; background: rgba(255,255,255,.04); border-radius: 4px; overflow: hidden; }
.fr-fill { display: block; height: 100%; border-radius: 4px; background: var(--indigo); transition: width .6s; }
.fr-fill.alt { background: var(--amber); }
.fr-count { width: 20px; font-size: calc(11px * var(--font-scale)); font-weight: 700; color: var(--text); text-align: right; }

/* ── Patterns / Week cards ── */
.period-toggle { display: flex; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; margin-bottom: 14px; }
.period-toggle button { flex: 1; padding: 8px; border: none; background: transparent; color: var(--text-muted); font-size: calc(13px * var(--font-scale)); font-weight: 600; border-radius: 8px; cursor: pointer; transition: .2s; }
.period-toggle button.active { background: var(--indigo); color: #fff; }
.week-card { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; overflow: hidden; }
.week-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; cursor: pointer; transition: .2s; font-size: calc(14px * var(--font-scale)); font-weight: 600; background: var(--card); }
.week-header:hover { background: var(--card-hover); }
.week-header.disabled { cursor: default; opacity: .45; }
.week-header.disabled:hover { background: var(--card); }
.week-header .chevron { color: var(--text-muted); font-size: calc(14px * var(--font-scale)); transition: transform .2s; }
.week-header .chevron.open { transform: rotate(180deg); }
.week-body { padding: 0 16px 14px; background: var(--card); }
.week-body .narrative { font-size: calc(14px * var(--font-scale)); line-height: 1.6; }

/* Week digest score row */
.week-score-row { display: flex; justify-content: center; gap: 32px; padding: 16px 0 8px; }
.week-score-item { text-align: center; }
.week-score-emoji { font-size: calc(28px * var(--font-scale)); display: block; line-height: 1.2; }
.week-score-val { font-size: calc(22px * var(--font-scale)); font-weight: 700; display: block; background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.week-score-item small { font-size: calc(10px * var(--font-scale)); color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; display: block; margin-top: 2px; }

/* Mini trend bar */
.week-trend { padding: 8px 0 4px; }
.week-trend-bar { display: flex; align-items: flex-end; gap: 3px; height: 100px; }
.week-trend-bar .wt-bar { flex: 1; border-radius: 3px 3px 0 0; min-height: 3px; background: var(--gradient); position: relative; transition: height .3s; }
.week-trend-bar .wt-bar .wt-val { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: calc(8px * var(--font-scale)); color: var(--text-muted); margin-bottom: 1px; white-space: nowrap; }
.week-trend-labels { display: flex; gap: 3px; margin-top: 2px; }
.week-trend-labels span { flex: 1; text-align: center; font-size: calc(8px * var(--font-scale)); color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }

/* Week narrative */
.week-narrative { font-size: calc(14px * var(--font-scale)); line-height: 1.7; padding: 8px 0; color: var(--text); }

/* Week sections (themes, correlations) */
.week-section { padding: 10px 0 4px; border-top: 1px solid var(--border); margin-top: 4px; }
.week-section-title { font-size: calc(11px * var(--font-scale)); font-weight: 600; color: var(--indigo-light); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.week-section-title i { margin-right: 4px; }
.week-body .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.week-correlation { font-size: calc(14px * var(--font-scale)); color: var(--text); line-height: 1.5; padding: 3px 0; }
.week-correlation .corr-icon { color: var(--indigo-light); margin-right: 4px; }

/* ── Settings ── */
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; }
.setting-row + .setting-row { border-top: 1px solid var(--border); }
.setting-row .sl { font-size: calc(14px * var(--font-scale)); font-weight: 500; }
.setting-row .sd { font-size: calc(12px * var(--font-scale)); color: var(--text-muted); }
.tier-badge { padding: 2px 10px; border-radius: 8px; font-size: calc(11px * var(--font-scale)); font-weight: 600; }
.tier-badge.free { background: rgba(245,158,11,.12); color: #f59e0b; }
.tier-badge.core { background: rgba(6,182,212,.12); color: var(--indigo-light); }
.tier-badge.deep { background: rgba(168,85,247,.12); color: #a855f7; }

/* ── Step indicator ── */
.step-indicator { display: flex; align-items: center; justify-content: center; gap: 0; margin-bottom: 20px; }
.step-dot {
  width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: calc(12px * var(--font-scale)); font-weight: 700; background: var(--card); border: 2px solid var(--border); color: var(--text-muted);
  transition: .2s; flex-shrink: 0;
}
.step-dot.active { border-color: var(--indigo); color: var(--indigo); }
.step-dot.done { background: var(--indigo); border-color: var(--indigo); color: #0f172a; }
.step-line {
  width: 40px; height: 2px; background: var(--border); transition: .2s; flex-shrink: 0;
}
.step-line.active { background: var(--indigo); }
.step-label { display: block; color: var(--text-muted); font-size: calc(11px * var(--font-scale)); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }

/* ── Toast ── */
.toast-e {
  position: fixed; top: 12px; left: 12px; right: 12px; z-index: 999;
  border-radius: var(--radius-sm);
  padding: 14px 18px; font-size: calc(14px * var(--font-scale));
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  transition: opacity .3s, transform .3s;
  opacity: 0; pointer-events: none; text-align: center;
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.toast-e.show { opacity: 1; }
.toast-e.success {
  background: rgba(34,197,94,.18);
  border-color: rgba(34,197,94,.5);
  color: #86efac;
}
.toast-e.error {
  background: rgba(239,68,68,.18);
  border-color: rgba(239,68,68,.5);
  color: #fca5a5;
}

/* ── Loading ── */
.spin-e { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--indigo-light); border-radius: 50%; animation: spin .6s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .6; transform: scale(1.1); } }
.pulse-mic { display: inline-block; animation: pulse 1.2s ease-in-out infinite; }
.loading-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; gap: 12px; color: var(--text-muted); font-size: calc(14px * var(--font-scale)); }

/* ── Mood trend chart (simple CSS bar chart) ── */
.trend-bar { display: flex; align-items: flex-end; gap: 4px; height: 80px; padding: 8px 0; }
.bar-stack { flex: 1; display: flex; flex-direction: column-reverse; align-items: center; height: 100%; position: relative; min-height: 4px; }
.trend-bar .bar-stack .bar {
  width: 80%; border-radius: 3px 3px 0 0; min-height: 3px;
  transition: height .4s; position: relative;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.12);
  border-bottom: none;
}
.trend-bar .bar-stack .val {
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  font-size: calc(9px * var(--font-scale)); font-weight: 600; white-space: nowrap;
}

/* ── Theme tag cloud ── */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cloud-tag { display: inline-block; padding: 3px 10px; border-radius: 20px; background: rgba(6,182,212,.12); color: var(--indigo-light); line-height: 1.4; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 40px 20px; }
.empty-state i { font-size: calc(40px * var(--font-scale)); color: var(--text-muted); opacity: .3; margin-bottom: 12px; }
.empty-state p { color: var(--text-muted); font-size: calc(14px * var(--font-scale)); }

/* ── Stat donut (mood in stats row) ── */
.stat-donut { width: 36px; height: 36px; transform: rotate(-90deg); display: block; margin: 0 auto 2px; }
.sd-track { fill: none; stroke: rgba(148,163,184,.1); stroke-width: 3; }
.sd-fill { fill: none; stroke: var(--indigo); stroke-width: 3; stroke-linecap: round; transition: stroke-dasharray .6s; }
.sd-fill.energy { stroke: var(--amber); }
.sd-text { fill: var(--text); font-size: calc(10px * var(--font-scale)); font-weight: 700; text-anchor: middle; transform: rotate(90deg); transform-origin: 18px 18px; }

/* ── Stat row (dashboard) ── */
.stat-row { display: flex; gap: 10px; margin-bottom: 16px; margin-top: 16px; }
.stat-item {
  flex: 1; background: var(--card);
  border-radius: 14px; padding: 12px 10px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.stat-icon { font-size: 2rem; margin-bottom: 6px; line-height: 1; }
.stat-val { font-weight: 700; font-size: calc(20px * var(--font-scale)); line-height: 1.2; margin-bottom: 2px; text-align: center; width: 100%; }
.stat-label { font-size: calc(9px * var(--font-scale)); color: var(--text-muted); line-height: 1.3; text-transform: uppercase; letter-spacing: .3px; text-align: center; width: 100%; }
.stat-delta { font-weight: 600; font-size: calc(12px * var(--font-scale)); line-height: 1.3; margin-top: 2px; text-align: center; }

/* Modal overlay */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.9);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 4px;
  overflow-y: auto;
}
.modal-content {
  background: var(--card);
  width: 100%; max-width: 100%; min-height: 100vh;
  padding: 10px; margin: 0;
  border: none; border-radius: 0;
}
@media (max-width: 576px) {
  .modal-content { padding: 5px; }
}

/* ── Footer donate ── */
.footer-donate .card {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
}

/* ── Offcanvas ── */
.offcanvas-overlay {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(0,0,0,.9);
  display: flex; justify-content: flex-start;
}
.offcanvas-panel {
  width: 280px; max-width: 80vw; height: 100%;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  animation: slideInLeft .2s ease-out;
}
@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }
.offcanvas-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.offcanvas-body { flex: 1; padding: 8px; overflow-y: auto; }
.offcanvas-item {
  display: flex; align-items: center; padding: 12px 14px;
  border-radius: 8px; cursor: pointer; font-size: calc(14px * var(--font-scale)); font-weight: 500;
  color: var(--text); transition: .15s;
}
.offcanvas-item:hover { background: var(--card-hover); }

/* ── Floating action button (Write) ── */
.fab-write {
  position: fixed;
  bottom: 24px;
  right: calc((100vw - min(720px, 100vw)) / 2 + 16px);
  z-index: 999;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #000;
  color: #fff;
  font-size: calc(24px * var(--font-scale));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}
.fab-write:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}
.fab-write:active {
  transform: scale(0.95);
}

/* ── Entity frequency grid (donuts) ── */
.entity-freq-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 6px; }
@media (max-width: 576px) { .entity-freq-grid { grid-template-columns: repeat(2, 1fr); } }
.entity-freq-donut { text-align: center; background: rgba(6,182,212,.06); border-radius: 10px; padding: 8px 6px; }
.ef-donut-name { font-size: calc(10px * var(--font-scale)); color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ef-donut-freq { font-size: calc(11px * var(--font-scale)); color: var(--text); font-weight: 600; }

/* ── Entity frequencies (legacy list) ── */
.entity-freq-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
@media (min-width: 768px) {
  .entity-freq-list { grid-template-columns: repeat(4, 1fr); }
}
.entity-freq-item {
  background: rgba(6,182,212,.06);
  border-radius: 10px; padding: 8px 10px;
}
.ef-header { display: flex; align-items: center; gap: 8px; width: 100%; }
.ef-name { font-weight: 600; font-size: calc(13px * var(--font-scale)); }
.ef-count { font-size: calc(11px * var(--font-scale)); color: var(--text-muted); margin-left: auto; }
.ef-mood { display: flex; align-items: center; gap: 4px; font-size: calc(12px * var(--font-scale)); color: var(--text-muted); }
.ef-mood-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.ef-bar-mood { height: 100%; transition: width .3s; }
.ef-sentiment { display: flex; gap: 2px; width: 100%; height: 4px; border-radius: 2px; overflow: hidden; }
.ef-dir { width: 100%; }
.dir-badge { font-size: calc(10px * var(--font-scale)); padding: 1px 6px; border-radius: 4px; text-transform: capitalize; }
.dir-up { background: rgba(34,197,94,.15); color: #22c55e; }
.dir-down { background: rgba(239,68,68,.15); color: #ef4444; }
.dir-new { background: rgba(6,182,212,.15); color: var(--indigo-light); }
.dir-flat { background: rgba(148,163,184,.15); color: var(--text-muted); }

/* ── Month-over-month ── */
.mom-row { display: flex; flex-wrap: wrap; gap: 8px; }
.mom-item {
  background: rgba(6,182,212,.06);
  border-radius: 10px; padding: 8px 12px;
  flex: 1; min-width: 100px;
  display: flex; flex-direction: column; gap: 2px;
}
.mom-label { font-size: calc(10px * var(--font-scale)); text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.mom-val { font-size: calc(14px * var(--font-scale)); font-weight: 600; }

/* ── Cumulative profile ── */
.profile-stats-row { display: flex; gap: 8px; margin-top: 12px; }
.profile-stat {
  background: var(--card); border-radius: 10px; padding: 10px;
  flex: 1; text-align: center;
}
.profile-stat-val { display: block; font-size: calc(20px * var(--font-scale)); font-weight: 700; }
.profile-stat-label { display: block; font-size: calc(9px * var(--font-scale)); color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; margin-top: 2px; }
.profile-section { margin-top: 12px; }
.profile-section-title { font-size: calc(12px * var(--font-scale)); font-weight: 600; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.profile-pattern-item {
  display: flex; align-items: flex-start; gap: 6px;
  padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,.05);
}
.profile-pattern-text { font-size: calc(13px * var(--font-scale)); line-height: 1.4; }
.conf-badge {
  font-size: calc(9px * var(--font-scale)); padding: 1px 5px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: .3px;
  white-space: nowrap; flex-shrink: 0; margin-top: 2px;
}
.conf-badge.high { background: rgba(34,197,94,.15); color: #22c55e; }
.conf-badge.medium { background: rgba(251,191,36,.15); color: #f59e0b; }
.conf-badge.low { background: rgba(148,163,184,.15); color: var(--text-muted); }

/* ── Frequency card (merged themes + entities) ── */
.wh-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 576px) { .wh-grid { grid-template-columns: repeat(2, 1fr); } }
.wh-card {
  background: rgba(99,102,241,.06);
  border-radius: 10px; padding: 10px 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.wh-name { font-size: calc(11px * var(--font-scale)); font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wh-row { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.wh-count { font-size: calc(18px * var(--font-scale)); font-weight: 700; color: var(--indigo-light); line-height: 1; }
.wh-sentiment { display: flex; gap: 2px; width: 100%; height: 4px; border-radius: 2px; overflow: hidden; }
.wh-bar { height: 100%; min-width: 2px; transition: width .3s; }

.profile-alert-item {
  display: flex; align-items: flex-start;
  padding: 6px 0; font-size: calc(13px * var(--font-scale)); line-height: 1.4;
}

/* ── Light theme overrides ── */
[data-theme="light"] .modal-overlay {
  background: rgba(0,0,0,.45);
}
[data-theme="light"] .fr-track {
  background: rgba(0,0,0,.06);
}
[data-theme="light"] .profile-pattern-item {
  border-bottom: 1px solid rgba(0,0,0,.06);
}
[data-theme="light"] .tag-e {
  background: rgba(14,116,144,.7);
}
[data-theme="light"] .analysis-box {
  background: rgba(14,116,144,.06);
  border-color: rgba(14,116,144,.15);
}
[data-theme="light"] .entity-freq-item {
  background: rgba(14,116,144,.06);
}
[data-theme="light"] .cloud-tag {
  background: rgba(14,116,144,.1);
  color: var(--indigo-dark);
}
[data-theme="light"] .cal-grid .day.lvl1 { background: rgba(14,116,144,.12); }
[data-theme="light"] .cal-grid .day.lvl2 { background: rgba(14,116,144,.28); }
[data-theme="light"] .cal-grid .day.lvl3 { background: rgba(14,116,144,.5); }
[data-theme="light"] .cal-grid .day.lvl4 { background: var(--indigo); color: #fff; }
[data-theme="light"] .cal-legend .cl .sq.lvl1 { background: rgba(14,116,144,.12); }
[data-theme="light"] .cal-legend .cl .sq.lvl2 { background: rgba(14,116,144,.28); }
[data-theme="light"] .cal-legend .cl .sq.lvl3 { background: rgba(14,116,144,.5); }
[data-theme="light"] .cal-grid .day:hover { border-color: rgba(0,0,0,.15); }
[data-theme="light"] .entry-highlight .card-e {
  box-shadow: inset 3px 0 0 var(--indigo), 0 0 12px rgba(14,116,144,.12);
}
[data-theme="light"] .entry-new .card-e {
  box-shadow: 0 0 0 2px rgba(14,116,144,.12), 0 0 20px rgba(14,116,144,.2);
}
@keyframes fade-glow-light {
  0% { box-shadow: 0 0 0 3px rgba(14,116,144,.3), 0 0 24px rgba(14,116,144,.25); }
  100% { box-shadow: 0 0 0 2px rgba(14,116,144,.12), 0 0 20px rgba(14,116,144,.2); }
}
[data-theme="light"] .entry-new .card-e {
  animation: fade-glow-light 2.5s ease-out forwards;
}
[data-theme="light"] .dir-up,
[data-theme="light"] .dir-new {
  color: #212529 !important;
}

/* ── Offcanvas section header ── */
.ofs-section {
  padding: 8px 14px;
  font-size: calc(11px * var(--font-scale));
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  margin: 0 -8px 8px;
}

/* ── Search patterns accordion ── */
.search-patterns {
  padding: 0 0 16px;
}

/* ── Something to think about! card ── */
.wh-card {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(148,163,184,.04);
  cursor: pointer;
  transition: border-color .2s;
}
.wh-card:hover {
  border-color: var(--indigo-light);
}