:root {
  --bg: #0E1022;
  --surface: #171A33;
  --surface-2: #1B1F3D;
  --line: #252A4A;
  --line-2: #3A3F6B;
  --text: #EDEEF7;
  --text-2: #D4D7EC;
  --muted: #A3A8C9;
  --lav: #9AA4D6;
  --gold: #E9C46A;
  --gold-2: #F4D98F;
  --night-bg: #07070D;
  --night: #D9826B;
  --night-2: #B86C56;
  --danger: #F08A7E;
  --tab-h: 74px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
}
h1, h2, h3, .display { font-family: Sora, Inter, sans-serif; margin: 0; }
p { margin: 0; }
a { color: var(--gold); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

#app {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(24px + var(--safe-t)) 20px calc(var(--tab-h) + var(--safe-b) + 28px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
body.night #app { padding-bottom: calc(28px + var(--safe-b)); min-height: 100dvh; }
body.night, body.night html { background: var(--night-bg); }
body.night #tabbar { display: none; }

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center;
  background: #121530; border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + var(--safe-b));
  z-index: 10;
}
#tabbar a {
  flex: 1; max-width: 130px; min-height: 54px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: 11px; font-weight: 500; text-decoration: none; color: var(--muted);
}
#tabbar a[aria-current="page"] { color: var(--gold); font-weight: 600; }
#tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- common ---------- */
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--lav); }
.eyebrow.gold { color: var(--gold); }
.title { font-size: 26px; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; }
.h2 { font-size: 17px; font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.card.raised { background: var(--surface-2); border-color: var(--line-2); }
.card.gold { background: var(--gold); color: var(--bg); border: 0; }
.card.gold .eyebrow { color: var(--bg); }
a.card { text-decoration: none; color: var(--text); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 12px; }
.stat b { display: block; font-family: Sora, sans-serif; font-size: 22px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--surface-2); font-size: 13px; }
.chip.outline { background: transparent; border: 1px solid var(--line-2); color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; background: var(--surface-2); font-size: 13px; font-weight: 600; color: var(--gold); }
.bar { height: 8px; border-radius: 999px; background: #2C3160; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
.divider { border-top: 1px solid var(--line); }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; border-top: 1px solid var(--line); }
.list-item:first-of-type { border-top: 0; }

.btn {
  min-height: 48px; padding: 0 18px; border-radius: 14px;
  border: 1px solid var(--line-2); background: var(--surface-2); color: var(--text);
  font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none;
}
.btn.primary { background: var(--gold); color: var(--bg); border: 0; }
.btn.ghost { background: transparent; }
.btn.dark { background: var(--bg); color: var(--gold); border: 0; border-radius: 999px; min-height: 44px; }
.btn.round { border-radius: 999px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); display: inline-flex; align-items: center; justify-content: center; color: var(--text); }
.iconbtn svg, .btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px;
  padding: 12px 14px; color: var(--text); font-size: 16px;
}
textarea { min-height: 140px; resize: vertical; line-height: 1.5; }

/* ---------- tonight ---------- */
.home { min-height: calc(100dvh - var(--tab-h) - var(--safe-b) - var(--safe-t) - 80px); display: flex; flex-direction: column; justify-content: center; gap: 36px; }
.home .hero { padding-top: 0; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 26px; padding: 22px 0 8px; }
.choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; width: 100%; max-width: 380px; }
.choice { display: flex; flex-direction: column; align-items: center; gap: 12px; text-decoration: none; color: var(--text); padding: 8px 0; }
.ring {
  width: 136px; height: 136px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.ring svg { width: 52px; height: 52px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ring.speak { background: var(--gold); color: var(--bg); box-shadow: 0 0 0 10px rgba(233,196,106,.12), 0 0 0 22px rgba(233,196,106,.05); }
.ring.type { background: var(--surface-2); color: var(--gold); border: 2px solid var(--gold); box-shadow: 0 0 0 10px rgba(233,196,106,.06); }
.choice:active .ring { transform: scale(.96); }
.choice-label { font-family: Sora, sans-serif; font-size: 17px; font-weight: 600; }
@media (max-width: 360px) { .ring { width: 116px; height: 116px; } }
.hero .label { text-align: center; display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }

/* ---------- night capture ---------- */
.night-wrap { color: var(--night); display: flex; flex-direction: column; align-items: center; gap: 24px; min-height: calc(100dvh - 60px); }
.night-wrap .muted { color: var(--night-2); }
.night-wrap a, .night-wrap button.link { color: var(--night); background: none; border: 0; min-height: 44px; font-size: 14px; text-decoration: none; padding: 0; display: inline-flex; align-items: center; }
.savebtn {
  width: 100%; max-width: 420px; min-height: 60px; border: 0; border-radius: 18px;
  background: var(--night); color: var(--night-bg); font-size: 18px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.nightbtn {
  min-height: 48px; padding: 0 22px; border-radius: 999px; border: 1.5px solid var(--night-2);
  background: transparent; color: var(--night) !important; font-size: 15px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
body.night :focus-visible, .night-wrap textarea:focus { outline: 2px solid var(--night-2); outline-offset: 2px; }
body.night #toast { bottom: calc(24px + var(--safe-b)); }
.timer { font-family: Sora, sans-serif; font-size: 56px; letter-spacing: .02em; }
.wave { display: flex; align-items: center; gap: 5px; height: 72px; }
.wave span { width: 5px; border-radius: 3px; background: var(--night); height: 10px; transition: height .15s; }
.live { font-size: 16px; line-height: 1.6; color: var(--night-2); text-align: center; max-width: 340px; min-height: 80px; }
.night-wrap textarea { background: #0F0F18; border-color: #3a2420; color: var(--night); }
.stopbtn { width: 112px; height: 112px; border-radius: 50%; border: 2px solid var(--night); background: transparent; display: flex; align-items: center; justify-content: center; }
.stopbtn span { width: 38px; height: 38px; border-radius: 8px; background: var(--night); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--night); animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- report ---------- */
.lenses { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface); }
.lenses button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 600; font-size: 13px; }
.lenses button[aria-pressed="true"] { background: #2C3160; color: var(--gold); }
.reading { font-size: 15px; line-height: 1.6; color: var(--text-2); }
.safety { background: #3A1E24; border: 1px solid #6B3440; border-radius: 16px; padding: 16px; color: #FFE3DF; }
.spinner { flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.transcript { white-space: pre-wrap; font-size: 14px; color: var(--text-2); }

/* ---------- profile ---------- */
.fact { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 40px; }
.fact .x { width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); }
.step { display: flex; gap: 12px; align-items: flex-start; min-height: 44px; padding: 6px 0; }
.step input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--gold); flex-shrink: 0; }
.step.done span { color: var(--muted); text-decoration: line-through; }

/* ---------- lucid ---------- */
.week { display: flex; align-items: center; gap: 12px; }
.week i { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-2); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-style: normal; font-size: 12px; font-weight: 700; }
.week.done i { background: var(--gold); border-color: var(--gold); color: var(--bg); }
.week.now i { border-color: var(--gold); }
.week.now span { color: var(--gold); font-weight: 600; }
.week.later span { color: var(--muted); }

/* ---------- chat ---------- */
.msgs { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 12px 14px; border-radius: 16px; white-space: pre-wrap; line-height: 1.5; }
.msg.me { align-self: flex-end; background: #2C3160; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 48px; height: 48px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text); padding: 12px 16px; border-radius: 12px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 20; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.empty { text-align: center; padding: 30px 10px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.diag { white-space: pre-wrap; word-break: break-word; font: 11.5px/1.45 ui-monospace, Menlo, monospace; color: var(--text-2);
  background: #0A0C1A; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 6px 0 0; max-height: 420px; overflow: auto; }

/* ---------- journal calendar ---------- */
.months { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.mcell { min-height: 52px; border: 1px solid var(--line-2); border-radius: 12px; background: transparent; color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 0; }
.mcell .mname { font-size: 13px; font-weight: 600; }
.mcell .mcount { font-size: 12px; font-weight: 700; color: var(--gold); min-height: 15px; }
.mcell.future { opacity: .45; }
.mcell.sel { background: var(--gold); border-color: var(--gold); color: var(--bg); }
.mcell.sel .mcount { color: var(--bg); }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .wd { text-align: center; font-size: 11px; font-weight: 600; color: var(--muted); padding-bottom: 2px; }
.dcell { min-height: 48px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 0; }
.dcell .dnum { font-size: 14px; }
.dcell .dmarks { display: flex; gap: 4px; min-height: 13px; align-items: center; }
.dcell .dcount, .dcell .tcount { font-size: 11px; font-weight: 700; line-height: 1; }
.dcell .dcount { color: var(--gold); }
.dcell .tcount { color: #B9A7FF; }
.dcell .tcount::before { content: '✓'; font-size: 9px; margin-right: 1px; }
.legend { display: flex; justify-content: center; gap: 18px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.lg-dream { background: var(--gold); } .lg-task { background: #B9A7FF; }
.dcell.has { background: var(--surface-2); color: var(--text); }
.dcell.today .dnum { color: var(--gold); font-weight: 700; }
.dcell.sel { background: #2C3160; outline: 2px solid var(--gold); outline-offset: -2px; }
.dcell[disabled] { cursor: default; }

/* ---------- back button at the bottom of every page ---------- */
body.has-back #app { padding-bottom: 14px; }
#backbar { max-width: 520px; margin: 0 auto; padding: 4px 20px calc(var(--tab-h) + var(--safe-b) + 28px); }
#backbar svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
body.night #backbar { display: none; }

/* ---------- tasks ---------- */
.tasks-card { background: rgba(233,196,106,.07); border-color: rgba(233,196,106,.22); gap: 4px; }
.task-sugg { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.task-sugg:first-of-type { border-top: 0; }
.task-sugg p { font-size: 14px; line-height: 1.45; color: var(--text-2); flex: 1; }
.accept { flex-shrink: 0; min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid rgba(233,196,106,.55);
  background: transparent; color: var(--gold); font-size: 13px; font-weight: 600; }
.accept.on { border-color: transparent; background: rgba(233,196,106,.14); }
.task { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.task:first-of-type { border-top: 0; }
.task-main { display: flex; gap: 12px; align-items: flex-start; flex: 1; cursor: pointer; }
.task-main input { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--gold); flex-shrink: 0; }
.task.done .task-main > .stack > span:first-child { text-decoration: line-through; color: var(--muted); }
.task .x { width: 36px; height: 36px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); flex-shrink: 0; }

.btn.round svg { width: 15px; height: 15px; }
