/* Moonwake design system — night & moonlight.
   Tokens first; every component below draws from them. Vanilla CSS,
   no build step. Class/id hooks are load-bearing (app.js, account.js,
   install.js) — rename nothing. */

:root {
  color-scheme: dark;

  /* night surfaces, layered lightest-last */
  --night-0: #101223;   /* page ground (brand indigo) */
  --night-1: #171a30;   /* resting surface */
  --night-2: #1e2142;   /* raised surface */
  --night-3: #282e57;   /* hover / highest surface */
  --field:   #0b0d1c;   /* input wells */

  /* ink */
  --ink:       #ece9df; /* primary text */
  --ink-soft:  #cfccdd; /* secondary text on raised surfaces */
  --muted:     #b7b4c7; /* secondary text */
  --faint:     #9d9ab2; /* labels, captions (AA on night-0/1) */

  /* accents */
  --gold:       #e8b04b; /* moonlight — primary accent */
  --gold-hi:    #f3c66d;
  --gold-soft:  rgba(232, 176, 75, 0.13);
  --lav:        #a79fe0; /* soft lavender — secondary accent */
  --lav-hi:     #c0baf0;
  --lav-soft:   rgba(167, 159, 224, 0.12);
  --rose:       #d99ab0;
  --sage:       #a8c8ad;
  --danger:     #ef9a8b;

  /* lines & depth */
  --line:        rgba(236, 233, 223, 0.11);
  --line-strong: rgba(236, 233, 223, 0.22);
  --shadow-card: 0 1px 2px rgba(2, 3, 10, 0.45), 0 16px 36px -18px rgba(2, 3, 10, 0.65);
  --shadow-lift: 0 2px 4px rgba(2, 3, 10, 0.5), 0 22px 44px -18px rgba(2, 3, 10, 0.75);

  /* type */
  --font-display: "Fraunces", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* shape & rhythm */
  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;
  --space: 24px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  background-color: var(--night-0);
  /* moon-glow at the top, then two faint starfields, then the base falloff */
  background-image:
    radial-gradient(1050px 560px at 80% -10%, rgba(167, 159, 224, 0.13), transparent 60%),
    radial-gradient(720px 460px at 6% -4%, rgba(232, 176, 75, 0.06), transparent 55%),
    radial-gradient(rgba(255, 255, 255, 0.42) 0.7px, transparent 1.15px),
    radial-gradient(rgba(190, 196, 255, 0.28) 0.55px, transparent 1px),
    linear-gradient(180deg, #151838 0%, var(--night-0) 480px);
  background-size: auto, auto, 132px 132px, 86px 86px, auto;
  background-position: 0 0, 0 0, 0 0, 41px 59px, 0 0;
  background-attachment: fixed;
}

::selection { background: rgba(232, 176, 75, 0.38); color: #fff; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

#app { max-width: 920px; margin: 0 auto; padding: 0 24px 72px; }

/* ---------- header ---------- */
header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px 22px;
  margin: 0 -24px; padding: 16px 24px 13px;
  background: rgba(13, 15, 29, 0.84);
  -webkit-backdrop-filter: blur(14px) saturate(1.25);
  backdrop-filter: blur(14px) saturate(1.25);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 13px; align-items: center; }
.moon { font-size: 32px; line-height: 1; color: var(--gold); text-shadow: 0 0 26px rgba(232, 176, 75, 0.55); }
h1 {
  font-family: var(--font-display); font-weight: 600; font-size: 27px;
  letter-spacing: 0.01em; margin: 0; line-height: 1.1;
}
.tagline {
  margin: 2px 0 0; color: var(--muted); font-size: 13px;
  font-family: var(--font-display); font-style: italic;
}

nav { display: flex; gap: 6px; }
nav button {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  font-size: 14.5px; font-weight: 550; padding: 8px 15px; border-radius: 999px; cursor: pointer;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}
nav button:hover { color: var(--ink); background: rgba(236, 233, 223, 0.05); }
nav button.active { background: var(--gold-soft); color: var(--gold-hi); border-color: rgba(232, 176, 75, 0.28); }

/* ---------- epigraph (index masthead quote) ---------- */
.epigraph {
  max-width: 600px; margin: 34px auto 4px; text-align: center;
}
.epigraph p {
  font-family: var(--font-display); font-style: italic; font-weight: 450;
  font-size: 18.5px; line-height: 1.55; color: var(--ink-soft); margin: 0 0 8px;
}
.epigraph cite {
  font-style: normal; font-size: 11.5px; font-weight: 600;
  letter-spacing: 0.13em; text-transform: uppercase; color: var(--faint);
}
.epigraph cite em { text-transform: none; letter-spacing: 0.03em; font-size: 12.5px; }

/* ---------- buttons ---------- */
button {
  font: inherit; font-size: 14.5px; font-weight: 550;
  color: var(--ink); background: var(--night-2);
  border: 1px solid var(--line-strong); border-radius: 999px;
  padding: 10px 18px; cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease,
              transform 0.12s ease, box-shadow 0.18s ease, filter 0.18s ease;
}
button:hover { background: var(--night-3); border-color: rgba(236, 233, 223, 0.34); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.55; cursor: default; transform: none; }

button.primary {
  background: linear-gradient(180deg, var(--gold-hi), var(--gold));
  color: #1c1503; border-color: rgba(232, 176, 75, 0.55); font-weight: 650;
  box-shadow: 0 6px 22px -8px rgba(232, 176, 75, 0.55);
}
button.primary:hover { background: linear-gradient(180deg, #f7d07c, #edb657); filter: brightness(1.04); }
button.primary:disabled { cursor: wait; box-shadow: none; }

button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { color: var(--ink); background: rgba(236, 233, 223, 0.05); border-color: rgba(236, 233, 223, 0.34); }
button.ghost.recording { color: var(--danger); border-color: rgba(239, 154, 139, 0.6); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.danger {
  background: transparent; border: 1px solid rgba(239, 154, 139, 0.45); color: var(--danger);
  border-radius: 999px; padding: 9px 17px; font-size: 13.5px; cursor: pointer;
}
.danger:hover { background: rgba(239, 154, 139, 0.1); border-color: rgba(239, 154, 139, 0.7); }
#delete-btn { border-color: rgba(239, 154, 139, 0.45); color: var(--danger); background: transparent; }
#delete-btn:hover { background: rgba(239, 154, 139, 0.1); border-color: rgba(239, 154, 139, 0.7); }

.linklike {
  background: none; border: none; color: var(--lav); font-size: 13px; font-weight: 500;
  cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: rgba(167, 159, 224, 0.45);
}
.linklike:hover { color: var(--lav-hi); background: none; transform: none; }

/* ---------- forms ---------- */
input[type="email"], input[type="password"], input[type="text"], textarea, select {
  width: 100%; background: var(--field); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 12px;
  padding: 12px 14px; font: inherit; font-size: 16px; line-height: 1.55;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input[type="email"]:focus, input[type="password"]:focus, input[type="text"]:focus,
textarea:focus, select:focus {
  outline: none; border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(232, 176, 75, 0.18);
}
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--gold); flex: none; margin-top: 3px; }
textarea { resize: vertical; }

.error { color: var(--danger); font-size: 14px; margin: 12px 0 0; }
.hint { color: var(--muted); font-size: 13.5px; margin: 0 0 12px; }

/* ---------- account panel ---------- */
#account-panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 55%), var(--night-1);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 24px 26px; margin: 26px 0 22px; box-shadow: var(--shadow-card);
}
#account-panel h2 { font-family: var(--font-display); font-weight: 550; font-size: 21px; margin: 0 0 6px; }
#account-panel h3 {
  font-size: 12px; font-weight: 700; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--gold); margin: 8px 0 14px;
}
#account-signed-out { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 30px; }
#account-signed-out > h2, #account-founders-out { grid-column: 1 / -1; }
#account-founders-out, #account-founders-in { color: var(--gold-hi); font-size: 13.5px; margin: 0 0 10px; }
#account-panel label {
  display: block; font-size: 11.5px; font-weight: 600; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 13px;
}
#account-panel label input { margin-top: 6px; text-transform: none; letter-spacing: normal; }
#account-panel label.check {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 13.5px; font-weight: 450; letter-spacing: normal; text-transform: none;
  color: var(--ink-soft); line-height: 1.45; cursor: pointer;
}
#account-panel label.check input { margin-top: 2px; }
#account-panel form button[type="submit"] { margin-top: 4px; }
#account-signed-in p { margin: 0 0 8px; color: var(--muted); font-size: 14.5px; }
#account-signed-in p strong { color: var(--ink); }
#account-signed-in button { margin: 10px 8px 0 0; }
#account-error { margin-top: 14px; }

/* ---------- capture & cards ---------- */
.view { animation: rise 0.32s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.capture-card, .card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 55%), var(--night-1);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 26px; margin-bottom: 18px; box-shadow: var(--shadow-card);
}
.capture-card { margin-top: 22px; }
.capture-card > label {
  display: block; font-family: var(--font-display); font-weight: 550;
  font-size: 26px; line-height: 1.25; margin-bottom: 6px;
}
.capture-card textarea { min-height: 168px; line-height: 1.7; }
.capture-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; align-items: center; }
#loop-result .card { margin-top: 4px; }

.section-title {
  font-family: var(--font-display); font-weight: 550; font-size: 21px;
  line-height: 1.3; margin: 30px 0 8px; color: var(--ink);
}
h3.section-title {
  font-family: var(--font-ui); font-size: 12px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold);
}
.section-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 10px; }

/* ---------- extraction chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 6px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 7px;
  font-size: 13px; padding: 5px 12px 6px; border-radius: 999px;
  background: var(--night-2); border: 1px solid var(--line-strong); color: var(--ink);
}
.chip .k {
  color: var(--faint); font-size: 10.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: 0.09em;
}
.chip.symbol { background: var(--lav-soft); border-color: rgba(167, 159, 224, 0.42); }
.chip.figure { background: var(--gold-soft); border-color: rgba(232, 176, 75, 0.42); }
.chip.affect { background: rgba(217, 154, 176, 0.11); border-color: rgba(217, 154, 176, 0.42); }
.chip.theme  { background: rgba(168, 200, 173, 0.1); border-color: rgba(168, 200, 173, 0.4); }

/* ---------- hypotheses ---------- */
.hypothesis {
  border-left: 3px solid var(--lav); padding: 6px 0 6px 18px; margin: 20px 0;
}
.hypothesis .lens {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.13em; color: var(--lav); margin-bottom: 5px;
}
.hypothesis h3 { font-family: var(--font-display); font-weight: 550; font-size: 19px; margin: 0 0 7px; line-height: 1.35; }
.hypothesis p { margin: 0 0 8px; font-size: 15px; color: var(--ink-soft); }
.hypothesis .invitation { font-size: 13px; color: var(--muted); font-style: italic; }
.hypothesis .cite { font-size: 12px; color: var(--faint); }
.hypothesis .counter { font-size: 13.5px; color: var(--muted); margin: 8px 0; }

.verdict-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 13px; }
.verdict-label { font-size: 13px; color: var(--muted); font-style: italic; }
.verdict-btn { font-size: 13px; padding: 7px 13px; }
.verdict-note { font-size: 13.5px; color: var(--sage); margin-top: 12px; }

details.why { margin-top: 12px; font-size: 13.5px; color: var(--muted); }
details.why summary { cursor: pointer; color: var(--lav); font-size: 13px; font-weight: 550; }
details.why summary:hover { color: var(--lav-hi); }
details.why p { margin: 8px 0 0; line-height: 1.6; }

.bg-note { font-style: italic; color: var(--muted); }
.cite-quote {
  border-left: 3px solid var(--gold); margin: 12px 0; padding: 8px 14px;
  font-family: var(--font-display); font-style: italic; font-size: 15.5px; color: var(--ink-soft);
}
.cite-quote cite {
  display: block; font-family: var(--font-ui); font-style: normal;
  font-size: 11.5px; letter-spacing: 0.06em; color: var(--faint); margin-top: 5px;
}

/* ---------- questions ---------- */
.question-block {
  background: var(--night-2); border: 1px solid var(--line);
  border-left: 3px solid var(--gold); border-radius: var(--r-md);
  padding: 18px 20px; margin: 16px 0; box-shadow: var(--shadow-card);
}
.question-block .q { font-family: var(--font-display); font-weight: 500; font-size: 17.5px; line-height: 1.5; margin: 0 0 12px; }
.question-block textarea { font-size: 15px; }
.answer-row { display: flex; justify-content: flex-end; margin-top: 10px; }
.answer-btn { font-size: 13.5px; }
.answer-error { margin-top: 10px; }
.qa-body { position: relative; }
.followups { margin-top: 4px; }
.followups:empty { margin-top: 0; }
.followup {
  margin: 12px 0 0 10px; padding-left: 14px; border-left: 2px solid var(--gold);
  font-style: italic; color: var(--ink-soft); font-size: 14.5px;
}
.saved-answer { color: var(--muted); font-size: 14px; margin: 10px 0 0; }
.saved-answer strong { color: var(--ink); font-weight: 600; }

.safety-note {
  background: rgba(217, 154, 176, 0.09); border: 1px solid rgba(217, 154, 176, 0.38);
  border-radius: var(--r-md); padding: 16px 18px; margin: 18px 0; font-size: 14.5px;
}

/* ---------- journal ---------- */
.dream-row {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 55%), var(--night-1);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 18px 20px; margin-bottom: 12px; cursor: pointer; box-shadow: var(--shadow-card);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.dream-row:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: rgba(232, 176, 75, 0.35); }
.dream-row h3 { font-family: var(--font-display); font-weight: 550; font-size: 18px; margin: 0 0 4px; }
.dream-row .meta { color: var(--faint); font-size: 12.5px; letter-spacing: 0.02em; }
.dream-row .snippet { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.empty {
  text-align: center; color: var(--muted);
  font-family: var(--font-display); font-style: italic; font-size: 18.5px; line-height: 1.55;
  padding: 58px 26px; margin: 22px 0;
  border: 1px dashed var(--line-strong); border-radius: var(--r-lg);
  background:
    radial-gradient(430px 210px at 50% -10%, rgba(232, 176, 75, 0.07), transparent 70%),
    var(--night-1);
}
.empty::before {
  content: "☾"; display: block; font-style: normal; font-size: 32px; line-height: 1;
  color: var(--gold); text-shadow: 0 0 24px rgba(232, 176, 75, 0.5); margin-bottom: 14px;
}
.row-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- patterns ---------- */
.bar-row { display: flex; align-items: center; gap: 12px; margin: 9px 0; font-size: 14px; }
.bar-row .lbl { width: 132px; flex: none; color: var(--ink-soft); text-transform: capitalize; }
.bar {
  height: 10px; border-radius: 5px; min-width: 4px;
  background: linear-gradient(90deg, var(--lav), var(--gold));
  box-shadow: 0 0 12px rgba(167, 159, 224, 0.25);
}
.bar-row .n { color: var(--faint); font-size: 13px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 10px; }
.stat {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 55%), var(--night-1);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 16px 18px; box-shadow: var(--shadow-card);
}
.stat .big { font-family: var(--font-display); font-weight: 550; font-size: 31px; color: var(--gold-hi); line-height: 1.15; }
.stat .cap { color: var(--muted); font-size: 12.5px; }
.timeline-row { font-size: 12.5px; color: var(--muted); padding: 2px 0 8px 12px; }
.tl-label { font-style: italic; margin-right: 4px; }
.tl-arrow { color: var(--lav); padding: 0 2px; }

/* ---------- footer ---------- */
footer { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--line); }
footer p { color: var(--faint); font-size: 12.5px; text-align: center; max-width: 540px; margin: 0 auto 8px; line-height: 1.6; }

/* ---------- onboarding ---------- */
#onboarding {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(9, 10, 22, 0.78);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto;
}
.onb-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 50%), var(--night-1);
  border: 1px solid var(--line-strong); border-radius: 20px;
  padding: 36px 32px; max-width: 540px; width: 100%;
  box-shadow: 0 34px 90px rgba(0, 0, 0, 0.6);
}
.onb-step { animation: rise 0.3s ease both; }
.onb-card h2 { font-family: var(--font-display); font-weight: 550; margin: 0 0 12px; font-size: 25px; }
.onb-card p { color: var(--muted); line-height: 1.65; }
.onb-card strong { color: var(--ink); }
.onb-moon { font-size: 44px; line-height: 1; color: var(--gold); text-shadow: 0 0 32px rgba(232, 176, 75, 0.6); margin-bottom: 12px; }
.onb-actions { display: flex; gap: 10px; margin-top: 24px; flex-wrap: wrap; }
.onb-principles > div { margin-bottom: 16px; }
.onb-principles p { margin: 4px 0 0; font-size: 14px; }
.onb-list { padding-left: 20px; color: var(--muted); line-height: 1.7; }
.onb-list li { margin-bottom: 8px; }

/* ---------- install banner (install.js injects inline styles;
   these harmonize its bar with the system) ---------- */
#moonwake-install-banner {
  background: var(--night-2) !important;
  border-top: 1px solid var(--line-strong) !important;
  color: var(--ink) !important;
  font-family: var(--font-ui) !important;
  box-shadow: 0 -14px 34px rgba(2, 3, 10, 0.5) !important;
}

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  #app { padding: 0 16px 56px; }
  header { margin: 0 -16px; padding: 13px 16px 11px; }
  h1 { font-size: 23px; }
  .moon { font-size: 27px; }
  .tagline { font-size: 12px; }
  nav { overflow-x: auto; gap: 4px; max-width: 100%; }
  nav button { font-size: 14px; padding: 9px 13px; white-space: nowrap; }
  .epigraph { margin-top: 26px; }
  .epigraph p { font-size: 16.5px; }
  #account-panel { padding: 20px 18px; }
  #account-signed-out { grid-template-columns: 1fr; }
  .capture-card, .card { padding: 20px 17px; }
  .capture-card > label { font-size: 23px; }
  .capture-card textarea { min-height: 150px; }
  .capture-actions { flex-direction: column; align-items: stretch; }
  .capture-actions button { min-height: 48px; }
  .capture-actions .primary { width: 100%; }
  button { min-height: 44px; }
  nav button, .verdict-btn, .linklike { min-height: 0; }
  .stat-grid { gap: 10px; }
  .stat .big { font-size: 26px; }
  .bar-row { gap: 8px; font-size: 13px; }
  .bar-row .lbl { width: 92px; font-size: 13px; }
  .timeline-row { padding-left: 0; line-height: 1.8; }
  .hypothesis { padding-left: 13px; }
  .hypothesis h3 { font-size: 17px; }
  .question-block { padding: 16px; }
  .question-block .q { font-size: 16px; }
  .verdict-row { gap: 6px; }
  .verdict-btn { font-size: 12.5px; padding: 8px 12px; }
  .onb-card { padding: 26px 20px; }
  .onb-card h2 { font-size: 22px; }
  .onb-actions .primary { width: 100%; }
  .empty { padding: 44px 20px; font-size: 17px; }
}

/* ---------- motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .dream-row:hover { transform: none; }
}
