/* base.css — 2030 design system: dark dimensional base, luminous accents,
   geometric display type, glass surfaces, tasteful motion.
   Clarity comes first; the drama is in the materials, not the layout. */

:root {
  /* ─── Surfaces ──────────────────────────────────────────── */
  --bg-0:           #07070b;                       /* deepest — page bg base */
  --bg-1:           #0e0f17;                       /* cards / panels */
  --bg-2:           #181a26;                       /* elevated / inputs */
  --bg-3:           #20232f;                       /* hover surface */

  --hairline:       rgba(255, 255, 255, 0.07);
  --hairline-strong:rgba(255, 255, 255, 0.14);

  --glass-bg:       linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.012));
  --glass-bg-hover: linear-gradient(180deg, rgba(255,255,255,0.060), rgba(255,255,255,0.020));

  /* ─── Accents — mint + warm gold (matches main brain dashboard) ─── */
  --accent-1:       #5DCAA5;                       /* mint — for "live", "active", primary accents */
  --accent-1-soft:  rgba(93, 202, 165, 0.14);
  --accent-1-glow:  rgba(93, 202, 165, 0.35);
  --accent-2:       #C9A55C;                       /* gold — for secondary accents / "elevated" */
  --accent-2-soft:  rgba(201, 165, 92, 0.14);
  --accent-grad:    linear-gradient(135deg, #5DCAA5 0%, #C9A55C 100%);
  --accent-grad-soft: linear-gradient(135deg, rgba(93,202,165,0.18), rgba(201,165,92,0.18));

  /* ─── Text ──────────────────────────────────────────────── */
  --text-1:         #f1f4fb;                       /* AAA on bg-0 (14.8:1) */
  --text-2:         #b9bfd1;                       /* AAA on bg-0 (~10.5:1) */
  --text-3:         #9aa1b5;                       /* AAA-small on bg-0 (~7.2:1) — bumped from #7a8197 in CP4 */

  /* ─── State ─────────────────────────────────────────────── */
  --danger:         #ff6b8a;
  --good:           #5cf2a8;

  /* ─── Type ──────────────────────────────────────────────── */
  --display:        "Space Grotesk", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --body:           "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;

  --t-xs:   11px;
  --t-sm:   13px;
  --t-base: 15px;
  --t-lg:   18px;
  --t-xl:   22px;
  --t-2xl:  30px;
  --t-3xl:  42px;

  /* ─── Motion (Feel-brief A.5) ────────────────────────────
   * One motion language. Two ease curves: a clean exponential out
   * (default UI) + a single sweet-spot spring (only for the moments
   * that should land — habit tick, capture chip, primary CTA).
   * Three durations: 120 / 200 / 340ms. Define once, use everywhere.
   * Anything ad-hoc gets noticed; anything off-rhythm reads as wrong. */
  --dur-fast:    120ms;
  --dur-base:    200ms;
  --dur-slow:    340ms;
  --ease-out:    cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Legacy aliases — older CSS calls these by their pre-A.5 names.
   * Point them at the new canonical tokens so the whole app moves
   * together; new code prefers --dur-* + --ease-*. */
  --motion-fast: var(--dur-fast);
  --motion-base: var(--dur-base);
  --motion-slow: var(--dur-slow);
  --ease-bounce: var(--ease-spring);

  /* ─── Column widths (D2 cohesion pass) ───────────────────
   * Two canonical widths every room picks from.
   *   --col-w-standard — reading-column rooms (Today, Money, Notes,
   *                       Brain, Habits, Health, etc.). 580 hits the
   *                       sweet spot for one tight column on desktop
   *                       and lets mobile fill the viewport via gutter.
   *   --col-w-wide     — the home dashboard, which carries multiple
   *                       cards side-by-side and wants more air.       */
  --col-w-standard: 580px;
  --col-w-wide:     760px;

  /* ─── Legacy aliases — existing CSS files reference these.
        They now point at the dark theme so pages we haven't fully
        restyled yet still render coherently. The semantic-named tokens
        above are what the polished CP1 pages use. ─────────── */
  --cream:      var(--bg-0);
  --cream-2:    var(--bg-1);
  --gold:       var(--accent-2);
  --gold-soft:  var(--accent-2-soft);
  --text:       var(--text-1);
  /* --text-2 already exists above with the dark-theme value (#b9bfd1). */
  --muted:      var(--text-3);
  --border:     var(--hairline);
  --card:       var(--bg-1);
  --card-2:     var(--bg-2);
  --serif:      var(--display);
  --sans:       var(--body);
}

/* ─── Reset / globals ─────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { overflow-x: hidden; }     /* CP4: belt-and-braces — keep wide glows from causing horizontal scroll on narrow phones */
body {
  font-family: var(--body);
  font-size: var(--t-base);
  color: var(--text-1);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  overflow-x: hidden;

  /* Dimensional base: two soft accent glows over a deep near-black.
     Fixed so it doesn't tile or scroll-jank on mobile. */
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(93, 202, 165, 0.10), transparent 60%),
    radial-gradient(900px 700px at 100% 110%, rgba(201, 165, 92, 0.10), transparent 55%),
    var(--bg-0);
  background-attachment: fixed;
}

::selection { background: var(--accent-1-soft); color: var(--text-1); }

/* ─── Reduced-motion (A.5 / accessibility) ────────────────────
 * Honour the OS setting at the token level: every component using
 * --dur-* collapses to 0ms automatically. Ambient breathing and
 * staggered reveals also need explicit cuts further down — but
 * 80% of UI motion folds into this one rule. */
@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 0ms;
    --dur-base: 0ms;
    --dur-slow: 0ms;
  }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ─── One focus ring (E / a11y) ───────────────────────────────
 * Polished AND accessible. Only shows for keyboard focus
 * (:focus-visible). Tap focus stays clean. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent-1);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ─── [hidden] insurance ──────────────────────────────────────
 * Earlier we hit a real bug where .ideas-loading[hidden] failed to
 * hide because the class selector beat the UA stylesheet's
 * *[hidden]{display:none}. This raises the floor: any element with
 * the `hidden` attribute is genuinely hidden, full stop. */
[hidden] { display: none !important; }

/* ─── Card lift (B.3) ──────────────────────────────────────────
 * Every glass-tile card gets the same desktop-hover behaviour for free
 * IF the page opts in via .home-card / .dash-row / .h-row classes.
 * (We only add the lift here — colour rules stay per-component.) */
@media (hover: hover) {
  .home-card,
  .dash-row,
  .h-row {
    transition: transform var(--dur-base) var(--ease-out),
                box-shadow var(--dur-base) var(--ease-out),
                background-color var(--dur-fast) var(--ease-out),
                border-color var(--dur-fast) var(--ease-out);
    will-change: transform;
  }
  .home-card:hover,
  .dash-row:hover,
  .h-row:hover {
    transform: translateY(-2px);
    box-shadow:
      0 4px 0 -2px rgba(0,0,0,0.20),
      0 16px 32px -10px rgba(0,0,0,0.35);
  }
}
.home-card:active,
.dash-row:active,
.h-row:active {
  transform: translateY(0) scale(0.995);
  transition-duration: var(--dur-fast);
}

/* ─── Staggered reveal (B.5) ───────────────────────────────────
 * Add .stagger to a parent and its children fade-rise in sequence.
 * Cap at the first 12 children so a 100-row list doesn't wave
 * forever. Calm cascade, not a bounce. */
@keyframes stagger-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.stagger > * {
  animation: stagger-in var(--dur-base) var(--ease-out) both;
}
.stagger > *:nth-child(1)  { animation-delay:  20ms; }
.stagger > *:nth-child(2)  { animation-delay:  50ms; }
.stagger > *:nth-child(3)  { animation-delay:  80ms; }
.stagger > *:nth-child(4)  { animation-delay: 110ms; }
.stagger > *:nth-child(5)  { animation-delay: 140ms; }
.stagger > *:nth-child(6)  { animation-delay: 170ms; }
.stagger > *:nth-child(7)  { animation-delay: 200ms; }
.stagger > *:nth-child(8)  { animation-delay: 230ms; }
.stagger > *:nth-child(9)  { animation-delay: 260ms; }
.stagger > *:nth-child(10) { animation-delay: 290ms; }
.stagger > *:nth-child(11) { animation-delay: 320ms; }
.stagger > *:nth-child(12) { animation-delay: 340ms; }

/* ─── Tabular numbers (E) ──────────────────────────────────────
 * Money totals, streaks, days-since — any number that ticks/tweens.
 * Stops the digit-jitter where 9 → 10 visibly shifts the column. */
.num,
.tabular,
[data-tabular] {
  font-variant-numeric: tabular-nums;
}

/* ─── Safe-area insets (D.3 mobile / PWA) ──────────────────────
 * Phone home-indicator + notch padding. Two CSS vars the app-shell
 * + bottom-nav + sticky elements read so we don't have to repeat
 * env(safe-area-inset-*) in every component. */
:root {
  --safe-top:    env(safe-area-inset-top,    0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left,   0px);
  --safe-right:  env(safe-area-inset-right,  0px);
}
@supports (padding: max(0px)) {
  body { padding-left: max(0px, var(--safe-left)); padding-right: max(0px, var(--safe-right)); }
}

/* ─── Loading skeletons (D3 cohesion) ──────────────────────
   Used by rooms that BL.get-populate so users see structure
   immediately instead of a flat-empty area then a sudden flash
   of content. Pure CSS — no JS coordination required. Markup
   pattern: render N <div class="skeleton skeleton-row"></div>
   into the same host that the real rows will replace. */
@keyframes skeleton-shimmer {
  0%   { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}
.skeleton {
  background-color: rgba(255,255,255,0.04);
  background-image: linear-gradient(
    90deg,
    rgba(255,255,255,0.00) 0%,
    rgba(255,255,255,0.06) 40%,
    rgba(255,255,255,0.10) 50%,
    rgba(255,255,255,0.06) 60%,
    rgba(255,255,255,0.00) 100%
  );
  background-size: 200px 100%;
  background-repeat: no-repeat;
  animation: skeleton-shimmer 1.2s linear infinite;
  border-radius: 10px;
}
.skeleton-row     { height: 42px;  margin-bottom: 8px; }
.skeleton-line    { height: 14px;  margin-bottom: 8px; }
.skeleton-line.sm { height: 10px; width: 60%; }
.skeleton-tile    { height: 84px; border-radius: 14px; margin-bottom: 8px; }
.skeleton-circle  { width: 44px; height: 44px; border-radius: 50%; }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

h1, h2, h3, h4 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-1);
  margin: 0;
}

.brand {
  font-family: var(--display);
  font-weight: 500;
  letter-spacing: -0.03em;
}

/* ─── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 12px 22px;
  border: 1px solid var(--hairline-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-1);
  font-family: var(--body);
  font-size: var(--t-sm); font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform var(--motion-fast) var(--ease-out),
    background-color var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out),
    box-shadow var(--motion-fast) var(--ease-out);
}
.btn:hover { background: var(--glass-bg-hover); border-color: var(--text-3); }
/* B.2 — press → scale .97 with spring-back. Touch must be INSTANT
 * so the user feels their tap; transition only kicks in on release. */
.btn:active {
  transform: scale(0.97);
  transition-duration: var(--dur-fast);
  transition-timing-function: var(--ease-spring);
}
.btn:focus-visible {
  outline: 2px solid var(--accent-1);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }

.btn.primary {
  background: var(--accent-grad);
  color: #06080d;
  border-color: transparent;
  font-weight: 700;
  box-shadow:
    0 0 0 1px rgba(93, 202, 165,0.30) inset,
    0 8px 24px rgba(93, 202, 165,0.18),
    0 1px 0 rgba(255,255,255,0.30) inset;
}
.btn.primary:hover {
  filter: brightness(1.05);
  box-shadow:
    0 0 0 1px rgba(93, 202, 165,0.50) inset,
    0 10px 32px rgba(93, 202, 165,0.32),
    0 1px 0 rgba(255,255,255,0.40) inset;
}
/* B.2 — primary press intensifies the glow (the green means "alive";
 * pressing it should feel like it answers you back). */
.btn.primary:active {
  box-shadow:
    0 0 0 1px rgba(93, 202, 165,0.60) inset,
    0 4px 18px rgba(93, 202, 165,0.40),
    0 0 0 4px rgba(93, 202, 165,0.10);
}

.btn.ghost { background: transparent; }

.btn.danger {
  color: var(--danger);
  border-color: rgba(255, 107, 138, 0.45);
}
.btn.danger:hover {
  background: rgba(255, 107, 138, 0.08);
  border-color: var(--danger);
}

/* ─── Inputs ──────────────────────────────────────────────── */
.input, input.input, textarea.input, select.input {
  display: block; width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--hairline);
  background: var(--bg-2);
  color: var(--text-1);
  font-family: var(--body);
  font-size: var(--t-base);
  transition:
    border-color var(--motion-fast) var(--ease-out),
    box-shadow var(--motion-fast) var(--ease-out),
    background-color var(--motion-fast) var(--ease-out);
}
.input::placeholder { color: var(--text-3); }
.input:hover { border-color: var(--hairline-strong); }
.input:focus {
  outline: none;
  border-color: var(--accent-1);
  background: var(--bg-3);
  box-shadow: 0 0 0 4px var(--accent-1-soft);
}
textarea.input { resize: vertical; min-height: 96px; line-height: 1.5; }

label.field {
  display: block; margin-top: 16px;
  font-family: var(--body);
  font-size: var(--t-xs); font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-3);
}
label.field .input, label.field input, label.field textarea, label.field select {
  margin-top: 6px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

/* ─── Error pill ──────────────────────────────────────────── */
.err {
  margin-top: 12px;
  padding: 10px 14px; border-radius: 12px;
  background: rgba(255, 107, 138, 0.10);
  color: var(--danger);
  border: 1px solid rgba(255, 107, 138, 0.30);
  font-family: var(--body); font-size: var(--t-sm);
}
.err[hidden] { display: none; }

/* ─── Glass surface utility ──────────────────────────────── */
.glass {
  position: relative;
  background: var(--glass-bg);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.05) inset,
    0 24px 60px rgba(0, 0, 0, 0.35),
    0 1px 2px rgba(0, 0, 0, 0.4);
}

/* ─── Motion primitives ──────────────────────────────────── */
@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-1-glow); }
  50%      { box-shadow: 0 0 24px 0 var(--accent-1-glow); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
