/* Lamplight — the page is lit by light.js; colours come from CSS variables it writes. */
:root {
  --serif: "Lora", Georgia, "Times New Roman", serif;
  --ui: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --page: #07060a;
  --fg: #e9dfd0; --fg-soft: rgba(233, 223, 208, .68); --fg-faint: rgba(233, 223, 208, .45);
  --panel: rgba(255, 255, 255, .045); --panel-strong: rgba(255, 255, 255, .08);
  --line: rgba(255, 255, 255, .11);
  --accent: rgb(var(--glow, 255, 150, 60));
  --user-bubble: rgba(var(--glow, 255, 150, 60), .16);
  --radius: 18px;
  color-scheme: dark;
}
:root[data-tone="light"] {
  --fg: #2a2118; --fg-soft: rgba(42, 33, 24, .72); --fg-faint: rgba(42, 33, 24, .5);
  --panel: rgba(255, 255, 255, .55); --panel-strong: rgba(255, 255, 255, .75);
  --line: rgba(42, 33, 24, .14);
  --accent: #a4561c;
  --user-bubble: rgba(214, 140, 70, .2);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--page); color: var(--fg); font-family: var(--ui); font-size: 16px; line-height: 1.5;
  transition: color .8s ease;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
       padding: max(14px, env(safe-area-inset-top)) 18px 10px; max-width: 980px; margin: 0 auto; }
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex-wrap: wrap; }
.brand-mark { width: 10px; height: 14px; border-radius: 50% 50% 45% 45%; background: radial-gradient(circle at 50% 70%, #fff3d6, #ffb15a 55%, transparent 72%);
              align-self: center; box-shadow: 0 0 14px 4px rgba(255, 160, 70, .45); animation: flicker 3.2s ease-in-out infinite; }
.brand-name { font-family: var(--serif); font-size: 1.15rem; letter-spacing: .06em; }
.chapter-date { font-size: .78rem; color: var(--fg-faint); }
.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.pill { font-size: .7rem; padding: 4px 10px; border-radius: 999px; border: 1px dashed var(--line); color: var(--fg-soft); }

.icon-btn { width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
            display: grid; place-items: center; cursor: pointer; transition: transform .15s, background .3s, opacity .3s; flex-shrink: 0; }
.icon-btn svg { width: 19px; height: 19px; fill: currentColor; }
.icon-btn:hover { transform: translateY(-1px); background: var(--panel-strong); }
.icon-btn[aria-pressed="false"] { opacity: .5; }
.icon-btn[aria-pressed="false"] .wave { display: none; }
.icon-btn.listening { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(var(--glow), .2); }
.text-btn { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; cursor: pointer;
            font-size: .82rem; color: var(--fg-soft); min-height: 38px; transition: color .2s, border-color .2s; }
.text-btn:hover { color: var(--fg); border-color: var(--accent); }
.primary-btn { border: 1px solid var(--accent); background: rgba(var(--glow), .16); border-radius: 999px; padding: 12px 22px;
               cursor: pointer; font-weight: 500; min-height: 46px; transition: transform .15s, background .3s; }
.primary-btn:hover { transform: translateY(-1px); background: rgba(var(--glow), .26); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 640px) {
  body.in-talk .chapter-date { display: none; }
  body.in-talk .brand { flex-wrap: nowrap; }
  body.in-story .composer { display: none; }
  .top { padding-left: 14px; padding-right: 14px; }
  .text-btn#closeBtn { padding: 6px 12px; }
}

/* ---------- layout ---------- */
.layout { max-width: 980px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 18px; }

/* ---------- stage ---------- */
.stage { position: relative; width: 100%; aspect-ratio: 16 / 8; border-radius: 22px; overflow: hidden; isolation: isolate;
         box-shadow: 0 30px 80px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(255, 255, 255, .06); background: #000; }
@media (max-width: 640px) { .stage { aspect-ratio: 4 / 3; border-radius: 18px; } }
.scene { position: absolute; inset: 0; opacity: 0; transition: opacity 1.6s ease; }
.scene.on { opacity: 1; }
.scene-svg { width: 100%; height: 100%; display: block; }
.scene-svg .flame { animation: flame 2.4s ease-in-out infinite; }
.scene-svg .beam { animation: sweep 9s ease-in-out infinite alternate; }
.scene-svg .smoke { animation: drift 7s ease-in-out infinite alternate; }
.stage-level { position: absolute; top: 12px; left: 14px; font-size: .62rem; letter-spacing: .24em; text-transform: uppercase;
               color: rgba(255, 238, 215, .82); text-shadow: 0 1px 8px rgba(0, 0, 0, .7); }
.stage-status { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px;
                padding: 9px 16px; border-radius: 999px; background: rgba(0, 0, 0, .45); color: #f5e9d6; font-family: var(--serif);
                font-style: italic; font-size: .92rem; backdrop-filter: blur(6px); white-space: nowrap; }
.status-flame { width: 9px; height: 13px; border-radius: 50% 50% 45% 45%; background: radial-gradient(circle at 50% 70%, #fff3d6, #ffb15a 55%, transparent 72%);
                box-shadow: 0 0 12px 4px rgba(255, 160, 70, .5); animation: flicker 1.6s ease-in-out infinite; }

/* breathing */
.breath { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .25); }
.breath-orb { width: 22%; aspect-ratio: 1; border-radius: 50%;
              background: radial-gradient(circle, rgba(255, 246, 225, .95), rgba(var(--glow), .55) 45%, transparent 72%);
              transform: scale(.55); transition: transform 4s ease-in-out; filter: blur(1px); }
.breath-label { position: absolute; bottom: 18%; font-family: var(--serif); font-size: clamp(1rem, 2.6vw, 1.4rem); color: #fff6e6;
                text-shadow: 0 2px 12px rgba(0, 0, 0, .6); }
.breath-skip { position: absolute; right: 12px; bottom: 12px; color: #f5e9d6; border-color: rgba(255, 255, 255, .3); }

/* While talking, the room stays in view: the stage sticks to the top and the chat scrolls beneath. */
body.in-talk .top { position: sticky; top: 0; z-index: 6; background: var(--page); }
body.in-talk .stage { position: sticky; top: var(--top-h, 64px); z-index: 5; aspect-ratio: auto; height: min(40vh, 360px); }
@media (max-width: 640px) { body.in-talk .stage { height: 30vh; } }
body.in-talk .story, body.in-talk .card, body.in-talk .msg { scroll-margin-top: calc(min(40vh, 360px) + var(--top-h, 64px) + 20px); }

/* ---------- panels ---------- */
.panel { width: min(720px, 100%); margin: 0 auto; }
.landing, .closed { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 6px; }
h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(1.5rem, 4.2vw, 2.2rem); margin: 0; letter-spacing: .01em; }
.lede { margin: 0; max-width: 34em; color: var(--fg-soft); font-size: 1rem; }
.fine { font-size: .75rem; color: var(--fg-faint); text-align: center; margin: 6px 0 0; line-height: 1.6; }

.paths { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; margin-top: 6px; }
@media (max-width: 560px) { .paths { grid-template-columns: 1fr; } }
.path { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; text-align: left;
        padding: 16px 18px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); cursor: pointer;
        transition: transform .2s, border-color .3s, background .3s; }
.path:hover { transform: translateY(-2px); border-color: var(--accent); background: var(--panel-strong); }
.path-icon { grid-row: span 2; font-size: 1.6rem; align-self: center; }
.path-title { font-family: var(--serif); font-size: 1.15rem; }
.path-desc { font-size: .84rem; color: var(--fg-soft); }

/* ---------- conversation ---------- */
.talk { display: flex; flex-direction: column; gap: 14px; }
.log { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 86%; padding: 11px 16px; border-radius: 18px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word;
       animation: rise .45s ease both; }
.msg.agent { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 6px;
             font-family: var(--serif); font-size: 1.04rem; }
.msg.user { align-self: flex-end; background: var(--user-bubble); border-bottom-right-radius: 6px; }
.msg.agent.typing::after { content: "▍"; opacity: .5; animation: blink 1s steps(2) infinite; }

.card { align-self: stretch; border-radius: var(--radius); padding: 18px 20px; background: var(--panel); border: 1px solid var(--line);
        animation: rise .5s ease both; }
.card-kicker { font-size: .66rem; letter-spacing: .2em; text-transform: uppercase; color: var(--fg-faint); margin-bottom: 8px; }
.card-big { font-family: var(--serif); font-size: 1.16rem; line-height: 1.55; margin: 0; }
.card-ref { font-size: .8rem; color: var(--fg-soft); margin-top: 10px; }
.card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.card.crisis { border-color: rgba(255, 196, 120, .55); background: rgba(255, 196, 120, .08); }
.card.crisis .card-big { font-size: 1.02rem; }
.card.story-record summary { cursor: pointer; font-family: var(--serif); font-size: 1.05rem; list-style: none; }
.card.story-record summary::-webkit-details-marker { display: none; }
.card.story-record summary::before { content: "📖  "; }
.card.story-record p { font-family: var(--serif); color: var(--fg-soft); line-height: 1.75; margin: 12px 0 0; }

/* ---------- story view ---------- */
.story { text-align: center; padding: 6px 4px 2px; animation: rise .6s ease both; }
.story-kicker { font-size: .66rem; letter-spacing: .24em; text-transform: uppercase; color: var(--fg-faint); }
.story-title { font-family: var(--serif); font-weight: 500; font-size: clamp(1.2rem, 3vw, 1.55rem); margin: 6px 0 14px; }
.story-text { font-family: var(--serif); font-size: clamp(1.08rem, 2.5vw, 1.26rem); line-height: 1.85; margin: 0 auto; max-width: 36em;
              text-wrap: pretty; min-height: 6em; }
.w { opacity: .16; transition: opacity .5s ease, color .35s; }
.w.on { opacity: 1; }
.w.now { color: var(--accent); }
.story-end { margin: 22px auto 0; max-width: 34em; }
.story-end .verse { font-family: var(--serif); font-size: clamp(1.15rem, 2.8vw, 1.4rem); line-height: 1.6; margin: 0; }
.story-end .ref { font-size: .82rem; color: var(--fg-soft); margin-top: 10px; }
.story-end .bridge { color: var(--fg-soft); font-style: italic; margin-top: 12px; font-family: var(--serif); }
.story-controls { display: flex; justify-content: center; gap: 10px; margin-top: 18px; }

/* ---------- composer ---------- */
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px; border-radius: 22px;
            background: color-mix(in srgb, var(--page) 90%, transparent); box-shadow: 0 -10px 24px color-mix(in srgb, var(--page) 80%, transparent);
            border: 1px solid var(--line); position: sticky; bottom: max(10px, env(safe-area-inset-bottom)); backdrop-filter: blur(10px); }
.composer textarea { flex: 1; min-width: 0; resize: none; border: 0; background: transparent; color: var(--fg); font: inherit;
                     font-size: 1rem; padding: 9px 10px; max-height: 160px; line-height: 1.45; }
.composer textarea::placeholder { color: var(--fg-faint); }
.composer textarea:focus { outline: none; }
.send-btn { width: 42px; height: 42px; border-radius: 999px; border: 0; background: var(--accent); color: #1a120b; display: grid;
            place-items: center; cursor: pointer; flex-shrink: 0; transition: transform .15s, opacity .2s; }
.send-btn svg { width: 18px; height: 18px; fill: currentColor; }
.send-btn:disabled { opacity: .35; cursor: default; }
.composer.busy { opacity: .7; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; padding: 16px; z-index: 20;
         backdrop-filter: blur(4px); }
.modal-card { width: min(560px, 100%); border-radius: 22px; padding: 22px; background: #15100c; color: #f1e6d6;
              border: 1px solid rgba(255, 200, 140, .25); box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
.modal-kicker { font-size: .66rem; letter-spacing: .22em; text-transform: uppercase; opacity: .6; }
.modal-card h2 { font-family: var(--serif); font-weight: 500; margin: 6px 0 12px; }
.modal-card textarea { width: 100%; border-radius: 14px; border: 1px solid rgba(255, 220, 180, .2); background: rgba(255, 255, 255, .04);
                       color: inherit; font-family: var(--serif); font-size: 1.05rem; line-height: 1.7; padding: 14px; resize: vertical; }
.modal-card .fine { color: rgba(241, 230, 214, .55); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }
.modal-card .text-btn { color: rgba(241, 230, 214, .8); border-color: rgba(255, 220, 180, .25); }
.modal-card .primary-btn { color: #f8eddc; border-color: #e0a060; background: rgba(224, 160, 96, .18); }
.letter.releasing textarea { animation: release 1.8s ease forwards; }

/* ---------- motion ---------- */
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes flicker { 0%, 100% { transform: scale(1); opacity: 1; } 45% { transform: scale(.92, 1.06); opacity: .85; } 70% { transform: scale(1.04, .96); } }
@keyframes flame { 0%, 100% { transform: scale(1, 1); } 30% { transform: scale(.94, 1.06); } 60% { transform: scale(1.05, .95); } }
@keyframes twinkle { 0%, 100% { opacity: .9; } 50% { opacity: .25; } }
@keyframes sweep { from { transform: rotate(-4deg); } to { transform: rotate(5deg); } }
@keyframes drift { from { transform: translate(0, 0); } to { transform: translate(14px, -18px); } }
@keyframes release { to { opacity: 0; filter: blur(6px); transform: translateY(-30px) scale(.98); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; }
  .scene { transition: opacity .3s !important; }
}
