/* =========================================================================
   LUMEN — design tokens
   Palette discipline (60-30-10):
     60%  canvas/paper  (warm near-neutral, calm — analogous/near-mono)
     30%  ink + chrome  (text & structural surfaces)
     10%  iris accent   (interaction: focus, active, primary action)
      <1% gold          (reserved ONLY for the earned celebratory peak)
   Every text/background pair below targets WCAG 2.2 AA (>=4.5:1 body).
   ========================================================================= */
:root {
  /* — type — */
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-read: ui-serif, "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;

  /* modular type scale (limited; <=3 active per view) */
  --t-meta: .8125rem;   /* 13px */
  --t-body: .9375rem;   /* 15px */
  --t-read: 1.0625rem;  /* 17px editor body */
  --t-title: 1.5rem;    /* 24px note title */
  --t-display: 2rem;    /* 32px empty-state hero */

  /* — spacing (8pt rhythm, 4px base) — */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;

  /* — radius — */
  --r-1: 6px; --r-2: 10px; --r-3: 14px; --r-pill: 999px;

  /* — motion — */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --ease-soft: cubic-bezier(.33, 1, .68, 1);
  --d-1: 120ms; --d-2: 180ms; --d-3: 260ms;

  /* — elevation — */
  --shadow-1: 0 1px 2px rgba(20, 18, 28, .05), 0 1px 1px rgba(20, 18, 28, .04);
  --shadow-2: 0 6px 16px -6px rgba(20, 18, 28, .14), 0 2px 6px -2px rgba(20, 18, 28, .08);
  --shadow-pop: 0 18px 50px -12px rgba(20, 18, 28, .28);

  /* fixed brand hues */
  --gold: #d9982f;
  --gold-glow: rgba(224, 162, 61, .55);
}

/* ── LIGHT THEME ─────────────────────────────────────────────────────── */
:root, [data-theme="light"] {
  --paper:      #fbfaf8;  /* 60% canvas */
  --surface:    #ffffff;
  --chrome:     #f3f1ec;  /* sidebar */
  --chrome-2:   #ece9e2;  /* hover wells */
  --ink:        #1f1d26;  /* primary text   ~15:1 on paper */
  --ink-soft:   #5b5766;  /* secondary text ~6.4:1 */
  --ink-faint:  #6e6a78;  /* meta text      ~5.0:1 */
  --line:       rgba(31, 29, 38, .09);
  --line-strong:rgba(31, 29, 38, .16);
  --accent:     #5b53e0;  /* iris — active text/icon ~5.6:1 on paper */
  --accent-ink: #4b43c8;  /* iris text on paper      ~6.6:1 */
  --accent-bg:  #5b53e0;  /* iris button fill (white text ~5.4:1) */
  --accent-bg-hover:#4f47d4;
  --accent-wash:#efedfd;  /* tint behind active row */
  --accent-ring:#5b53e0;
  --danger:     #c23a36;  /* white text ~5.0:1 */
  --danger-bg:  #c23a36;
  --on-accent:  #ffffff;
  --sel:        rgba(91, 83, 224, .18);
  /* toast is a deliberate elevated dark surface in BOTH themes (consistent snackbar) */
  --toast-bg:        #2b2933;
  --toast-ink:       #f4f2ee;
  --toast-accent:    #b8b2ff;  /* ~7:1 on --toast-bg */
  --toast-accent-bg: rgba(184, 178, 255, .18);
  --toast-accent-bg-hover: rgba(184, 178, 255, .30);
}

/* ── DARK THEME ──────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --paper:      #161519;
  --surface:    #1e1c24;
  --chrome:     #121116;
  --chrome-2:   #232129;
  --ink:        #ecebf2;  /* ~14:1 on paper */
  --ink-soft:   #a7a3b3;  /* ~7.2:1 */
  --ink-faint:  #948fa0;  /* ~5.4:1 on paper, ~5.0:1 on active-row wash */
  --line:       rgba(236, 235, 242, .10);
  --line-strong:rgba(236, 235, 242, .20);
  --accent:     #9a93ff;  /* iris on dark — ~7:1 */
  --accent-ink: #aaa4ff;
  --accent-bg:  #6a61ee;  /* white text ~4.8:1 */
  --accent-bg-hover:#7a72f2;
  --accent-wash:#241f3d;
  --accent-ring:#9a93ff;
  --danger:     #ef6f69;  /* on dark ~5.4:1 */
  --danger-bg:  #c4423c;
  --on-accent:  #ffffff;
  --sel:        rgba(154, 147, 255, .26);
  /* toast: a slightly elevated dark surface, distinct from --paper */
  --toast-bg:        #2e2c38;
  --toast-ink:       #ecebf2;
  --toast-accent:    #b8b2ff;  /* ~6.5:1 on --toast-bg */
  --toast-accent-bg: rgba(184, 178, 255, .20);
  --toast-accent-bg-hover: rgba(184, 178, 255, .32);
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 8px 22px -8px rgba(0,0,0,.6);
  --shadow-pop: 0 22px 60px -14px rgba(0,0,0,.7);
}

/* =========================================================================
   Reset & base
   ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; } /* ensure attribute beats component display rules */
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}
::selection { background: var(--sel); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
  border-radius: var(--r-1);
}
kbd {
  font-family: var(--font-ui); font-size: .75em; line-height: 1;
  padding: 3px 6px; border-radius: 5px;
  background: var(--chrome-2); border: 1px solid var(--line);
  color: var(--ink-soft); box-shadow: 0 1px 0 var(--line);
}

.skip-link {
  position: fixed; left: 50%; top: -60px; transform: translateX(-50%);
  z-index: 100; padding: 10px 16px; border-radius: var(--r-2);
  background: var(--accent-bg); color: var(--on-accent); font-weight: 600;
  transition: top var(--d-2) var(--ease);
}
.skip-link:focus-visible { top: 12px; }

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; display: block; }

/* =========================================================================
   App shell
   ========================================================================= */
.app {
  display: grid;
  grid-template-columns: clamp(264px, 24vw, 320px) 1fr;
  grid-template-rows: minmax(0, 1fr);   /* row fills viewport so panes stretch + scroll */
  height: 100dvh;
  background: var(--paper);
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--chrome);
  border-right: 1px solid var(--line);
  padding: var(--s-4) var(--s-3) var(--s-2);
  gap: var(--s-3);
}
.sidebar__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-1) var(--s-2);
}
.brand { display: flex; align-items: center; gap: var(--s-2); }
.brand__mark {
  width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, var(--paper) 0 22%, var(--accent) 30% 100%);
  box-shadow: 0 0 0 1px var(--line-strong), 0 0 14px -2px var(--accent);
}
.brand__name { font-weight: 650; letter-spacing: -.01em; font-size: 1.0625rem; }

.search { position: relative; display: flex; align-items: center; }
.search__icon {
  position: absolute; left: 11px; width: 17px; height: 17px;
  fill: none; stroke: var(--ink-faint); stroke-width: 1.8;
  stroke-linecap: round; pointer-events: none;
}
.search__input {
  width: 100%; padding: 9px 34px 9px 34px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-2); color: var(--ink);
  transition: border-color var(--d-1) var(--ease), box-shadow var(--d-1) var(--ease);
}
.search__input::placeholder { color: var(--ink-faint); }
.search__input:focus-visible {
  outline: none; border-color: var(--accent-ring);
  box-shadow: 0 0 0 3px var(--accent-wash);
}
.search__hint {
  position: absolute; right: 10px; pointer-events: none;
  transition: opacity var(--d-1) var(--ease);
}
.search__input:focus-visible ~ .search__hint,
.search__input:not(:placeholder-shown) ~ .search__hint { opacity: 0; }

.new-note {
  display: flex; align-items: center; justify-content: center; gap: var(--s-2);
  padding: 10px; width: 100%;
  background: var(--accent-bg); color: var(--on-accent);
  border-radius: var(--r-2); font-weight: 600;
  box-shadow: var(--shadow-1);
  transition: background var(--d-1) var(--ease), transform var(--d-1) var(--ease), box-shadow var(--d-2) var(--ease);
}
.new-note .icon { width: 18px; height: 18px; stroke-width: 2; }
.new-note:hover { background: var(--accent-bg-hover); box-shadow: var(--shadow-2); }
.new-note:active { transform: translateY(1px) scale(.99); }

.list-wrap { flex: 1; min-height: 0; overflow-y: auto; margin: 0 calc(var(--s-2) * -1);
  padding: var(--s-1) var(--s-2); scrollbar-width: thin; }
.note-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.note-item {
  position: relative; display: block; width: 100%; text-align: left;
  padding: 10px var(--s-3); border-radius: var(--r-2);
  color: var(--ink); transition: background var(--d-1) var(--ease);
}
.note-item:hover { background: var(--chrome-2); }
.note-item[aria-current="true"] { background: var(--accent-wash); }
.note-item[aria-current="true"] .note-item__title { color: var(--accent-ink); }
/* selected = soft wash + iris title + a clean full-height rail flush to the left edge */
.note-item[aria-current="true"]::before {
  content: ""; position: absolute; left: 0; top: 7px; bottom: 7px;
  width: 3px; border-radius: 0 var(--r-pill) var(--r-pill) 0; background: var(--accent);
}
.note-item__row { display: flex; align-items: center; gap: var(--s-2); }
.note-item__title {
  font-weight: 600; font-size: var(--t-body); letter-spacing: -.006em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0;
}
.note-item__pin { width: 13px; height: 13px; flex: none; color: var(--accent); fill: var(--accent); stroke: none; opacity: 0; }
.note-item[data-pinned="true"] .note-item__pin { opacity: 1; }
.note-item__preview {
  font-size: var(--t-meta); color: var(--ink-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px;
}
/* search match highlight */
mark { background: transparent; color: var(--accent-ink); font-weight: 700; }

.empty-list { padding: var(--s-4) var(--s-3); color: var(--ink-faint); font-size: var(--t-meta); }
.sidebar__foot { padding: var(--s-2) var(--s-3) var(--s-1); }
.note-count { font-size: var(--t-meta); color: var(--ink-faint); letter-spacing: .01em; }

.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px;
  border-radius: var(--r-2); color: var(--ink-soft);
  transition: background var(--d-1) var(--ease), color var(--d-1) var(--ease), transform var(--d-1) var(--ease);
}
.icon-btn:hover { background: var(--chrome-2); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }
.icon-btn--danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn[aria-pressed="true"] .icon { fill: color-mix(in srgb, var(--accent) 22%, transparent); }

/* theme toggle icon swap */
#theme-toggle .icon { position: absolute; transition: opacity var(--d-2) var(--ease), transform var(--d-3) var(--ease); }
#theme-toggle { position: relative; }
.icon--moon { opacity: 0; transform: rotate(-40deg) scale(.6); }
[data-theme="dark"] .icon--sun  { opacity: 0; transform: rotate(40deg) scale(.6); }
[data-theme="dark"] .icon--moon { opacity: 1; transform: rotate(0) scale(1); }

/* =========================================================================
   Editor
   ========================================================================= */
.editor { position: relative; min-width: 0; display: flex; flex-direction: column; background: var(--paper); }
.editor__pane { display: flex; flex-direction: column; height: 100%; min-height: 0; animation: paneIn var(--d-3) var(--ease); }
@keyframes paneIn { from { opacity: 0; } to { opacity: 1; } }

.editor__bar {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--line);
}
.editor__back { display: none; }
.saved-status {
  flex: 1; font-size: var(--t-meta); color: var(--ink-faint);
  display: inline-flex; align-items: center; gap: 6px;
  opacity: 0; transition: opacity var(--d-2) var(--ease);
}
.saved-status[data-show="true"] { opacity: 1; }
.saved-status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold); box-shadow: 0 0 8px var(--gold-glow);
}
.saved-status[data-state="saving"]::before { background: var(--ink-faint); box-shadow: none; }
.editor__actions { display: flex; gap: var(--s-1); }

.editor__scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; }
.editor__sheet {
  max-width: 70ch; margin: 0 auto;
  padding: var(--s-7) var(--s-6) var(--s-8);
  display: flex; flex-direction: column; gap: var(--s-3);
}
.editor__title {
  border: 0; background: none; width: 100%;
  font-family: var(--font-read); font-size: var(--t-title); font-weight: 700;
  letter-spacing: -.02em; line-height: 1.25; color: var(--ink);
}
.editor__title::placeholder { color: var(--ink-faint); opacity: .65; }
.editor__body {
  border: 0; background: none; width: 100%; resize: none;
  font-family: var(--font-read); font-size: var(--t-read); line-height: 1.7;
  color: var(--ink); min-height: 50vh;
}
.editor__body::placeholder { color: var(--ink-faint); opacity: .7; }
.editor__title:focus-visible, .editor__body:focus-visible { outline: none; }

.editor__meta {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-3) var(--s-4); border-top: 1px solid var(--line);
  font-size: var(--t-meta); color: var(--ink-faint);
}
.editor__meta .dot { opacity: .5; }

/* ── Empty / welcome state ──────────────────────────────────────────── */
.empty-state {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center;
  padding: var(--s-6); gap: var(--s-3);
}
.empty-state__art { position: relative; width: 96px; height: 96px; margin-bottom: var(--s-2); }
.empty-state__art .core {
  position: absolute; inset: 38px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 26px -2px var(--accent);
}
.empty-state__art .halo {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1.5px solid var(--accent); opacity: .25;
  animation: breathe 4.5s var(--ease-soft) infinite;
}
.empty-state__art .halo--2 { inset: 18px; opacity: .18; animation-delay: -2.25s; }
@keyframes breathe { 0%,100% { transform: scale(.9); opacity: .28; } 50% { transform: scale(1.08); opacity: .12; } }

.empty-state__title {
  font-family: var(--font-read); font-size: var(--t-display); font-weight: 700;
  letter-spacing: -.025em; margin: 0; color: var(--ink);
}
.empty-state__sub { max-width: 40ch; color: var(--ink-soft); margin: 0; }
.cta {
  display: inline-flex; align-items: center; gap: var(--s-2);
  margin-top: var(--s-3); padding: 12px 22px;
  background: var(--accent-bg); color: var(--on-accent);
  border-radius: var(--r-pill); font-weight: 600; box-shadow: var(--shadow-2);
  transition: background var(--d-1) var(--ease), transform var(--d-2) var(--ease), box-shadow var(--d-2) var(--ease);
}
.cta .icon { width: 18px; height: 18px; stroke-width: 2.2; }
.cta:hover { background: var(--accent-bg-hover); transform: translateY(-1px); box-shadow: var(--shadow-pop); }
.cta:active { transform: translateY(0) scale(.98); }
.empty-state__hint { font-size: var(--t-meta); color: var(--ink-faint); margin: var(--s-2) 0 0; display: flex; gap: 4px; align-items: center; }

/* =========================================================================
   Toast (undo) & celebration
   ========================================================================= */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px);
  display: flex; align-items: center; gap: var(--s-4);
  padding: 12px 14px 12px 18px; border-radius: var(--r-pill);
  background: var(--toast-bg); color: var(--toast-ink);
  box-shadow: var(--shadow-pop); opacity: 0; pointer-events: none;
  transition: opacity var(--d-2) var(--ease), transform var(--d-3) var(--ease); z-index: 80;
}
.toast[data-show="true"] { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast__msg { font-size: var(--t-body); }
.toast__undo {
  font-weight: 650; color: var(--toast-accent);
  min-height: 36px; padding: 8px 16px; border-radius: var(--r-pill);
  background: var(--toast-accent-bg);
  transition: background var(--d-1) var(--ease);
}
.toast__undo:hover { background: var(--toast-accent-bg-hover); }

.celebrate { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }
.spark {
  position: absolute; top: 0; width: 7px; height: 7px; border-radius: 2px;
  will-change: transform, opacity;
  animation: fall var(--dur, 1100ms) var(--ease-soft) forwards;
}
@keyframes fall {
  0%   { transform: translateY(-10px) rotate(0); opacity: 1; }
  100% { transform: translateY(var(--travel, 60vh)) rotate(var(--spin, 360deg)); opacity: 0; }
}

/* =========================================================================
   Responsive — collapse to single pane (mobile)
   ========================================================================= */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .editor { position: fixed; inset: 0; z-index: 40;
    transform: translateX(100%); transition: transform var(--d-3) var(--ease);
    box-shadow: var(--shadow-pop); }
  .app[data-view="editor"] .editor { transform: translateX(0); }
  .editor__back { display: grid; }
  .editor__sheet { padding: var(--s-5) var(--s-4) var(--s-7); }
  .new-note { position: sticky; bottom: 0; }
}

/* =========================================================================
   Reduced motion — honour the user's setting
   ========================================================================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
  .celebrate { display: none; }
}

/* Scrollbar polish (webkit) */
.list-wrap::-webkit-scrollbar, .editor__scroll::-webkit-scrollbar { width: 10px; }
.list-wrap::-webkit-scrollbar-thumb, .editor__scroll::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: var(--r-pill);
  border: 3px solid transparent; background-clip: content-box;
}
.list-wrap::-webkit-scrollbar-thumb:hover, .editor__scroll::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); background-clip: content-box; }
