:root {
  --night: #0E0B22;
  --night-2: #17123A;
  --night-3: #211B4D;
  --line: #2E2763;
  --moon: #ECE7FF;
  --haze: #A39CD0;
  --dim: #6F68A3;
  --lucid: #5EF2E0;   /* awake / recording */
  --rem: #FF4FA3;     /* dream / AI */
  --danger: #FF7A7A;

  --display: "Unbounded", system-ui, sans-serif;
  --body: "Manrope", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;

  --r-sm: 10px;
  --r-md: 18px;
  --r-lg: 28px;
  --ease: cubic-bezier(.2,.8,.2,1);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--night);
  color: var(--moon);
  font: 400 16px/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
a { color: var(--lucid); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--lucid); outline-offset: 3px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--haze); }

/* faint dot grid + one glow. no animation. */
.sky {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(600px 420px at 50% 28%, rgba(255,79,163,.10), transparent 70%),
    radial-gradient(800px 600px at 85% 110%, rgba(94,242,224,.07), transparent 70%),
    radial-gradient(circle at 1px 1px, rgba(163,156,208,.13) 1px, transparent 1.4px) 0 0 / 28px 28px,
    var(--night);
}

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 999px; padding: .8rem 1.4rem; cursor: pointer;
  font-weight: 700; letter-spacing: .01em; transition: transform .15s var(--ease), opacity .15s, box-shadow .2s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn-lucid { background: var(--lucid); color: #062823; }
.btn-rem { background: var(--rem); color: #2A0518; box-shadow: 0 6px 24px -8px rgba(255,79,163,.7); }
.btn-ghost { background: transparent; color: var(--moon); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--haze); }
.btn-sm { padding: .45rem .9rem; font-size: .85rem; }
.linklike { background: none; border: 0; color: var(--haze); cursor: pointer; text-decoration: underline; padding: 0; }

/* ---------- brand mark: a crescent made of two circles ---------- */
.mark { width: 56px; height: 56px; border-radius: 50%; background: var(--moon); position: relative; overflow: hidden; }
.mark span { position: absolute; width: 100%; height: 100%; border-radius: 50%; background: var(--night); top: -14%; left: 28%; }
.mark.small { width: 20px; height: 20px; display: inline-block; vertical-align: -3px; margin-right: .5rem; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: min(360px, 100%); display: grid; gap: .9rem; justify-items: center; text-align: center; }
.wordmark { font: 800 2.6rem/1 var(--display); letter-spacing: -.03em; margin: .4rem 0 0; }
.login-card input {
  width: 100%; padding: .9rem 1.1rem; border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--night-2); color: var(--moon); font-size: 1rem;
}
.login-card .btn { width: 100%; }
.form-error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: .92rem; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: max(.9rem, env(safe-area-inset-top)) clamp(1rem, 4vw, 2.5rem) .9rem;
  background: linear-gradient(var(--night) 60%, transparent);
}
.brand { font: 600 1.15rem var(--display); color: var(--moon); text-decoration: none; letter-spacing: -.02em; }
.tabs { display: flex; gap: .25rem; background: var(--night-2); border: 1px solid var(--line); border-radius: 999px; padding: .25rem; }
.tabs a {
  color: var(--haze); text-decoration: none; font-weight: 600; font-size: .9rem;
  padding: .45rem .95rem; border-radius: 999px; transition: background .2s, color .2s;
}
.tabs a[aria-current="page"] { background: var(--night-3); color: var(--moon); }

.view { width: min(1120px, 100%); margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2.5rem) 4rem; }

/* ================= RECORD ================= */
.record { display: flex; flex-direction: column; align-items: center; max-width: 760px; }
.greet {
  font: 600 clamp(1.5rem, 4.6vw, 2.4rem)/1.15 var(--display); letter-spacing: -.035em;
  text-align: center; margin: clamp(.5rem, 3vh, 2rem) 0 clamp(1.2rem, 4vh, 2.5rem); max-width: 18ch;
}
.orb-wrap { display: grid; justify-items: center; gap: .4rem; }
.orb {
  --size: clamp(200px, 56vw, 268px);
  --level: 0;
  width: var(--size); height: var(--size); border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  position: relative; display: grid; place-items: center; background: transparent;
  -webkit-tap-highlight-color: transparent;
}
.orb-ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--rem), #8A5CFF, var(--lucid), #8A5CFF, var(--rem));
  padding: 3px;
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  opacity: .55; transition: opacity .3s;
}
.orb-core {
  position: absolute; inset: 14px; border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,.18), transparent 40%),
    radial-gradient(circle at 70% 75%, rgba(94,242,224,.35), transparent 55%),
    radial-gradient(circle at 30% 80%, rgba(255,79,163,.45), transparent 60%),
    var(--night-3);
  box-shadow: inset 0 0 40px rgba(0,0,0,.5), 0 20px 80px -20px rgba(255,79,163,.45);
  transition: transform .12s linear, box-shadow .3s;
}
.orb-icon { position: relative; width: 64px; height: 64px; fill: var(--moon); }
.orb-icon svg { position: absolute; inset: 0; width: 100%; height: 100%; transition: opacity .2s, transform .25s var(--ease); }
.orb .i-stop, .orb .i-check { opacity: 0; transform: scale(.6); }
.orb:hover .orb-ring { opacity: .85; }

.orb.is-recording .orb-ring { opacity: 1; animation: spin 3.2s linear infinite; }
.orb.is-recording .orb-core {
  transform: scale(calc(1 + var(--level) * .12));
  box-shadow: inset 0 0 40px rgba(0,0,0,.4), 0 0 calc(40px + var(--level) * 90px) -10px rgba(94,242,224,.55);
}
.orb.is-recording .i-mic { opacity: 0; transform: scale(.6); }
.orb.is-recording .i-stop { opacity: 1; transform: none; }
.orb.is-saved .i-mic { opacity: 0; transform: scale(.6); }
.orb.is-saved .i-check { opacity: 1; transform: none; fill: var(--lucid); }
.orb.is-busy .orb-ring { animation: spin 1s linear infinite; opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

.orb-status { margin: .6rem 0 0; color: var(--haze); font-weight: 600; min-height: 1.5em; text-align: center; }
.timer { margin: 0; font: 500 .95rem var(--mono); color: var(--dim); font-variant-numeric: tabular-nums; }
.orb.is-recording ~ .timer, .timer.live { color: var(--lucid); }

.transcript {
  width: 100%; margin-top: clamp(1.2rem, 4vh, 2rem); position: relative;
  background: rgba(23,18,58,.75); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 1.1rem 1.2rem .9rem; backdrop-filter: blur(8px);
  transition: border-color .3s;
}
.transcript.live { border-color: rgba(94,242,224,.5); }
.transcript textarea {
  width: 100%; min-height: 9.5rem; resize: vertical; border: 0; outline: 0; background: transparent;
  color: var(--moon); font: 400 1rem/1.7 var(--mono); caret-color: var(--lucid);
}
.transcript textarea::placeholder { color: var(--dim); }
.interim { margin: 0; font: 400 1rem/1.7 var(--mono); color: var(--dim); min-height: 0; }
.interim:not(:empty)::after { content: "▍"; color: var(--lucid); animation: blink 1s steps(1) infinite; margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }

.record-actions {
  width: 100%; display: flex; align-items: center; gap: .8rem 1rem; flex-wrap: wrap; margin-top: 1rem;
}
.record-actions .btn-rem { margin-left: auto; padding: .95rem 1.8rem; }
.save-note { min-height: 1.5em; color: var(--haze); text-align: center; margin: 1rem 0 0; }
.save-note a { font-weight: 700; }

.toggle { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; color: var(--haze); font-weight: 600; font-size: .92rem; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-ui { width: 40px; height: 24px; border-radius: 99px; background: var(--night-3); border: 1px solid var(--line); position: relative; transition: background .2s; }
.toggle-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--haze); transition: transform .2s var(--ease), background .2s; }
.toggle input:checked + .toggle-ui { background: rgba(94,242,224,.25); border-color: var(--lucid); }
.toggle input:checked + .toggle-ui::after { transform: translateX(16px); background: var(--lucid); }
.toggle input:focus-visible + .toggle-ui { outline: 2px solid var(--lucid); outline-offset: 2px; }

.mode { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.mode button { background: none; border: 0; padding: .35rem .8rem; border-radius: 99px; font-size: .82rem; font-weight: 600; color: var(--dim); cursor: pointer; }
.mode button[aria-checked="true"] { background: var(--night-3); color: var(--moon); }

/* ================= JOURNAL ================= */
.journal-head { display: flex; gap: .8rem; align-items: center; margin-top: .5rem; }
.search { flex: 1; position: relative; }
.search svg { position: absolute; left: 1rem; top: 50%; translate: 0 -50%; width: 20px; fill: var(--dim); }
.search input {
  width: 100%; padding: .9rem 1rem .9rem 2.8rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--night-2); color: var(--moon); font-size: 1rem;
}
.search input:focus { border-color: var(--haze); outline: none; }

.filters { display: flex; gap: .4rem; margin: 1rem 0 1.4rem; overflow-x: auto; scrollbar-width: none; }
.filters button {
  white-space: nowrap; background: none; border: 1px solid var(--line); border-radius: 99px;
  padding: .4rem .85rem; color: var(--haze); font-size: .88rem; font-weight: 600; cursor: pointer;
}
.filters button[aria-selected="true"] { background: var(--moon); color: var(--night); border-color: var(--moon); }
.filters span { opacity: .6; font-variant-numeric: tabular-nums; }

/* analysis console: the one place we go "terminal" */
.console {
  border: 1px solid rgba(255,79,163,.35); border-radius: var(--r-md); background: #0A0819;
  padding: .9rem 1.1rem; margin-bottom: 1.4rem; font: 400 .85rem/1.6 var(--mono);
}
.console-bar { display: flex; justify-content: space-between; color: var(--rem); font-weight: 500; }
.progress { height: 3px; background: var(--night-3); border-radius: 3px; margin: .6rem 0 .7rem; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--rem), var(--lucid)); transition: width .4s var(--ease); }
.console ol { list-style: none; padding: 0; margin: 0; max-height: 9.6em; overflow-y: auto; color: var(--haze); }
.console li.ok::before { content: "✓ "; color: var(--lucid); }
.console li.err { color: var(--danger); }
.console li.err::before { content: "✗ "; }
.console li.work::before { content: "› "; color: var(--rem); }

.threads { margin-bottom: 1.8rem; }
.threads h2, .your-signs h2 { font: 600 1.05rem var(--display); letter-spacing: -.02em; margin: 0 0 .4rem; }
.overview { color: var(--haze); margin: 0 0 .9rem; max-width: 70ch; }
.thread-chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  display: inline-flex; align-items: center; gap: .45rem; border: 1px solid var(--line); background: var(--night-2);
  border-radius: 99px; padding: .35rem .8rem; font-size: .88rem; color: var(--moon); cursor: pointer;
}
.chip:hover { border-color: var(--haze); }
.chip b { font: 500 .75rem var(--mono); color: var(--night); background: var(--rem); border-radius: 99px; padding: .05rem .42rem; }
.chip[data-kind="person"] b { background: var(--lucid); }
.chip[data-kind="place"] b { background: #B9A6FF; }
.chip[data-kind="event"] b { background: var(--rem); }
.chip[data-kind="theme"] b, .chip[data-kind="symbol"] b, .chip[data-kind="emotion"] b { background: #FFC36B; }
.chip[data-kind="dream_sign"] b { background: var(--moon); }
.chip.static { cursor: default; }
.chip .kind { color: var(--dim); font-size: .78rem; }

.active-filter {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--night-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: .6rem .9rem; margin-bottom: 1rem; color: var(--haze);
}
.active-filter strong { color: var(--moon); }

.month { font: 600 .95rem var(--display); color: var(--haze); letter-spacing: -.01em; margin: 1.8rem 0 .7rem; }
.month:first-child { margin-top: 0; }
.dream-row {
  display: grid; grid-template-columns: 4.2rem 1fr 72px; gap: 1rem; align-items: center; width: 100%; text-align: left;
  background: none; border: 0; border-top: 1px solid var(--line); padding: 1rem .2rem; cursor: pointer;
}
.dream-row:hover .dr-title { color: var(--lucid); }
.dr-date { display: grid; line-height: 1.1; }
.dr-date strong { font: 800 1.6rem var(--display); letter-spacing: -.04em; }
.dr-date span { color: var(--dim); font: 500 .74rem var(--mono); margin-top: .25rem; }
.dr-main { min-width: 0; }
.dr-title { font-weight: 700; font-size: 1.05rem; transition: color .15s; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.dr-snip { color: var(--haze); margin: .2rem 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: .94rem; }
.dr-thumb { width: 72px; height: 72px; border-radius: 14px; object-fit: cover; background: var(--night-2); border: 1px solid var(--line); }
.dr-thumb.empty { display: grid; place-items: center; color: var(--dim); font-size: 1.4rem; }
.tag { font: 500 .7rem var(--mono); border-radius: 6px; padding: .1rem .4rem; border: 1px solid currentColor; }
.tag.lucid { color: var(--lucid); }
.tag.pending { color: var(--dim); }
mark { background: rgba(94,242,224,.22); color: var(--moon); border-radius: 3px; padding: 0 2px; }

.empty { text-align: center; color: var(--haze); padding: 3rem 1rem; }
.journal-foot { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; padding-top: 1.2rem; border-top: 1px solid var(--line); font-size: .9rem; }
.journal-foot a { color: var(--haze); }

/* ---------- drawer ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(5,4,15,.6); backdrop-filter: blur(3px); z-index: 40; }
.drawer {
  position: fixed; z-index: 41; top: 0; right: 0; bottom: 0; width: min(620px, 100%);
  background: var(--night); border-left: 1px solid var(--line); overflow-y: auto;
  animation: slideIn .28s var(--ease);
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } }
.drawer-close { position: sticky; top: .8rem; float: right; margin: .8rem .8rem 0 0; z-index: 2; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--night-2); cursor: pointer; display: grid; place-items: center; }
.drawer-close svg { width: 20px; fill: var(--moon); }
.drawer-body { padding: 1.4rem clamp(1.2rem, 4vw, 2rem) 3rem; }
.d-when { font: 500 .82rem var(--mono); color: var(--haze); margin: 0; }
.d-title { font: 600 clamp(1.5rem, 4vw, 2rem)/1.15 var(--display); letter-spacing: -.035em; margin: .5rem 0 1.2rem; max-width: 20ch; }
.d-art { width: 100%; aspect-ratio: 1; border-radius: var(--r-lg); object-fit: cover; border: 1px solid var(--line); background: var(--night-2); display: block; }
.d-art-empty { width: 100%; aspect-ratio: 16/9; border-radius: var(--r-lg); border: 1px dashed var(--line); display: grid; place-items: center; text-align: center; color: var(--dim); padding: 1rem; }
.d-section { margin-top: 1.8rem; }
.d-section h3 { font: 600 .92rem var(--display); letter-spacing: -.01em; color: var(--haze); margin: 0 0 .5rem; }
.d-section p { margin: 0 0 .7rem; }
.d-text { font: 400 .95rem/1.75 var(--mono); white-space: pre-wrap; background: var(--night-2); border-radius: var(--r-md); padding: 1rem 1.1rem; border: 1px solid var(--line); }
.d-text-edit { width: 100%; min-height: 12rem; font: 400 .95rem/1.75 var(--mono); background: var(--night-2); color: var(--moon); border: 1px solid var(--lucid); border-radius: var(--r-md); padding: 1rem; }
.d-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .7rem; }
.d-list li { padding-left: 1rem; border-left: 2px solid var(--rem); }
.d-list small { display: block; color: var(--dim); font: 500 .75rem var(--mono); margin-top: .15rem; }
.d-sym { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; }
.d-sym dt { font-weight: 700; color: var(--lucid); }
.d-sym dd { margin: 0; color: var(--haze); }
.d-tip { background: rgba(94,242,224,.08); border: 1px solid rgba(94,242,224,.3); border-radius: var(--r-md); padding: .9rem 1rem; }
.d-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 2rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.d-actions .danger { color: var(--danger); border-color: rgba(255,122,122,.4); margin-left: auto; }
.d-pending { text-align: center; padding: 1.5rem; border: 1px dashed var(--line); border-radius: var(--r-md); color: var(--haze); }
.d-meta { color: var(--dim); font: 500 .72rem var(--mono); margin-top: 1.2rem; }

/* ================= LUCID ================= */
.lucid .prose { max-width: 68ch; margin: 0 auto; }
.prose h1 { font: 800 clamp(2rem, 6vw, 3.4rem)/1.02 var(--display); letter-spacing: -.045em; margin: 1rem 0 1rem; }
.prose h2 { font: 600 clamp(1.2rem, 3vw, 1.5rem)/1.2 var(--display); letter-spacing: -.03em; margin: 3rem 0 .8rem; }
.prose h3 { font-size: 1.05rem; margin: 0 0 .25rem; }
.prose p, .prose li { color: #D7D1F5; }
.lede { font-size: 1.18rem; line-height: 1.6; color: var(--moon) !important; }
.fine { font-size: .85rem; color: var(--dim) !important; margin-top: .4rem; }
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 2rem; }
.stat-row div { border-top: 2px solid var(--lucid); padding-top: .8rem; }
.stat-row div + div { border-color: var(--rem); }
.stat-row strong { display: block; font: 800 clamp(2.4rem, 7vw, 3.6rem)/1 var(--display); letter-spacing: -.05em; }
.stat-row span { color: var(--haze); font-size: .95rem; }
.steps { list-style: none; counter-reset: s; padding: 0; margin: 1.2rem 0; display: grid; gap: 1.1rem; }
.steps li { counter-increment: s; display: grid; grid-template-columns: 2.6rem 1fr; gap: .2rem .9rem; }
.steps li::before {
  content: counter(s); grid-row: span 2; width: 2.2rem; height: 2.2rem; border-radius: 50%; display: grid; place-items: center;
  font: 600 .95rem var(--display); background: var(--night-3); color: var(--lucid); border: 1px solid var(--line);
}
.steps li > * { grid-column: 2; }
.steps p { margin: 0; }
.steps.compact li::before { color: var(--rem); }
.callout { border-left: 3px solid var(--rem); padding: .2rem 0 .2rem 1rem; }
.checks, .findings { padding-left: 1.1rem; display: grid; gap: .6rem; }
.checks li::marker, .findings li::marker { color: var(--lucid); }
.prose strong { color: var(--moon); }
.sources { font-size: .88rem; padding-left: 1.3rem; display: grid; gap: .45rem; }
.sources a { color: var(--haze); }
.your-signs { margin-top: 2.4rem; padding: 1.2rem 1.3rem; border: 1px solid rgba(255,79,163,.35); border-radius: var(--r-md); background: rgba(255,79,163,.05); }
.your-signs p { margin: 0 0 .9rem; color: var(--haze); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(1.4rem, env(safe-area-inset-bottom)); translate: -50% 0; z-index: 60;
  background: var(--moon); color: var(--night); font-weight: 700; padding: .75rem 1.2rem; border-radius: 99px;
  box-shadow: 0 10px 40px rgba(0,0,0,.5); animation: rise .25s var(--ease); max-width: calc(100% - 2rem); text-align: center;
}
.toast.err { background: var(--danger); }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }

/* ---------- small screens ---------- */
@media (max-width: 560px) {
  .brand { font-size: 0; }
  .brand .mark.small { margin: 0; width: 24px; height: 24px; }
  .tabs a { padding: .45rem .8rem; }
  .record-actions .btn-rem { width: 100%; margin-left: 0; order: 3; }
  .dream-row { grid-template-columns: 3.4rem 1fr 56px; gap: .8rem; }
  .dr-thumb { width: 56px; height: 56px; }
  .journal-head { flex-wrap: wrap; }
  .journal-head .btn { flex: 0 0 auto; }
  .drawer { border-left: 0; }
}

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

/* fixes after screenshot review */
.prose .your-signs h2 { margin-top: 0; }
.d-when { padding-right: 3rem; }
@media (max-width: 560px) {
  .search { flex: 1 1 100%; }
  .journal-head .btn { width: 100%; }
}
