/* Dream Interpreter — minimal, readable, dark-friendly */
:root {
  --bg: #0d1117;
  --fg: #e6edf3;
  --fg-dim: #9ba8b6;
  --accent: #4f8cff;
  --accent-dim: #2c4a8a;
  --card: #161b22;
  --border: #2a313a;
  --error: #f85149;
}


* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "ZCOOL XiaoWei", ui-serif, Georgia, "Times New Roman", serif;
  font-size: 17px;
  font-weight: 400;
  background-color: var(--bg);
  /* Composed dream-app background (10 layers, top → bottom):
       1.  top-left corner illumination (sun medallion + vines)
       2.  bottom-right corner illumination (crescent medallion + vines)
       3.  constellations centered (Orion, Cassiopeia, Plough, Lyra,
           Cygnus, Scorpius, Crux, Pleiades)
       4.  700-symbol gold scatter, tiled (ambient star-field)
       5.  vellum grain, tiled (aged-paper texture)
       6–10. five radial-gradient nebulae (gold, indigo, rose, teal,
           deep central wash) — drifting mist beneath everything else
     All layers fixed to the viewport. Section-divider sacred-geometry
     glyphs (vesica/triskele/ouroboros/mandala) live INSIDE the form
     between major sections; see .section-divider rules below. */
  background-image:
    url("/static/img/dream-illum-tl.svg"),
    url("/static/img/dream-illum-br.svg"),
    url("/static/img/dream-constellations.svg"),
    url("/static/img/dream-grain.svg"),
    radial-gradient(ellipse 65vw 55vh at 18% 26%, rgba(200, 168, 75, 0.22), transparent 60%),
    radial-gradient(ellipse 55vw 48vh at 82% 74%, rgba(110, 120, 200, 0.18), transparent 60%),
    radial-gradient(ellipse 50vw 42vh at 72% 18%, rgba(180, 100, 120, 0.15), transparent 58%),
    radial-gradient(ellipse 55vw 50vh at 26% 82%, rgba(80, 158, 158, 0.14), transparent 58%),
    radial-gradient(ellipse 95vw 75vh at 50% 50%, rgba(50, 36, 70, 0.12), transparent 70%);
  background-repeat:
    no-repeat, no-repeat, no-repeat, repeat,
    no-repeat, no-repeat, no-repeat, no-repeat, no-repeat;
  background-position:
    top left, bottom right, center center, top left,
    0 0, 0 0, 0 0, 0 0, 0 0;
  background-size:
    280px 220px,
    280px 220px,
    1800px 1300px,
    240px 240px,
    100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%;
  background-attachment:
    fixed, fixed, fixed, fixed,
    fixed, fixed, fixed, fixed, fixed;
  color: var(--fg);
  line-height: 1.55;
  font-size: 16px;
}

/* Pattern always reads against the dark base. */
body {
  background-blend-mode: screen;
}

/* Floating scatter layer — <img> so SMIL animations play (CSS background-image
   SVGs render statically). object-fit cover spans the viewport; pointer-events
   none keeps it click-through; z-index -1 sits behind the form. */
.dream-scatter-layer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  z-index: -1;
  user-select: none;
}

header {
  padding: 32px 24px 20px;
  text-align: center;
}

header h1 {
  margin: 0 0 6px;
  font-weight: 400;
  font-size: 2.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #c8a84b;
}

header .sub {
  margin: 0;
  color: var(--fg-dim);
  font-size: 1.05rem;
  font-style: italic;
  font-weight: 400;
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px;
}

footer {
  max-width: 880px;
  margin: 32px auto;
  padding: 0 24px 32px;
  font-size: 0.85rem;
  color: var(--fg-dim);
  text-align: center;
}

.caveat { margin: 0 0 8px; }
.status-line { margin: 0; font-size: 0.8rem; }

/* form */
form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  color: #c8a84b;
}

.mode-row {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.mode-toggle {
  flex: 1;
  min-width: 240px;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1rem;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.mode-toggle:hover {
  border-color: var(--accent);
}

.mode-toggle:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Hide the native radio — the whole pill is the toggle. */
.mode-toggle input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.mode-toggle:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.mode-toggle em {
  color: var(--fg-dim);
  font-style: normal;
  font-size: 0.85rem;
  font-weight: normal;
  margin-left: 4px;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field.check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.lbl {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.92rem;
}

.req {
  color: var(--accent);
  font-weight: normal;
  font-size: 0.8rem;
  font-style: normal;
  margin-left: 4px;
}

.opt {
  color: var(--fg-dim);
  font-weight: normal;
  font-size: 0.8rem;
  font-style: normal;
  margin-left: 4px;
}

textarea, input[type="text"], select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: #c8a84b;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.95rem;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, monospace;
  font-size: 0.93rem;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-dim) 50%),
                    linear-gradient(135deg, var(--fg-dim) 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.deep-fields {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin: 8px 0 20px;
}

.deep-fields legend {
  font-weight: 600;
  padding: 0 8px;
  color: var(--fg-dim);
  font-size: 0.85rem;
}

.hidden { display: none; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.88rem;
  user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chips label:hover {
  border-color: var(--accent);
}

.chips label:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* Hide the native checkbox itself — the pill IS the toggle. The input
   stays in the DOM for form submission and a11y, just visually removed. */
.chips input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.chips label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

/* OPTION 6 — section dividers between form sections. Hairline gradient
   leading to a centered sacred-geometry glyph. Four glyph variants. */
.section-divider {
  display: flex;
  align-items: center;
  margin: 28px 0;
  opacity: 0.7;
}
.section-divider::before,
.section-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, rgba(200, 168, 75, 0.45), transparent);
}
.section-divider::after {
  background: linear-gradient(to left, transparent, rgba(200, 168, 75, 0.45), transparent);
}
.section-divider .glyph {
  width: 32px;
  height: 32px;
  margin: 0 14px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  flex-shrink: 0;
}
.sd-vesica .glyph    { background-image: url("/static/img/divider-vesica.svg");    height: 22px; width: 40px; }
.sd-triskele .glyph  { background-image: url("/static/img/divider-triskele.svg"); }
.sd-ouroboros .glyph { background-image: url("/static/img/divider-ouroboros.svg"); }
.sd-mandala .glyph   { background-image: url("/static/img/divider-mandala.svg");  width: 34px; height: 34px; }

.mode-icon {
  vertical-align: -3px;
  margin-right: 2px;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

button:disabled,
button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(40%);
}

.status {
  color: var(--fg-dim);
  font-size: 0.9rem;
  font-style: italic;
}

.status.error {
  color: var(--error);
  font-style: normal;
}

/* output */
.output {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
}

.meta {
  font-size: 0.82rem;
  color: var(--fg-dim);
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.rendered h1, .rendered h2, .rendered h3 {
  margin-top: 1.4em;
  margin-bottom: 0.5em;
}

.rendered h2 {
  font-size: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.rendered h3 {
  font-size: 1.05rem;
  color: var(--accent);
}

.rendered p {
  margin: 0.7em 0;
}

.rendered ul, .rendered ol {
  padding-left: 24px;
}

.rendered code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
}

.evidence {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.evidence summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--fg-dim);
  font-size: 0.9rem;
}

.evidence summary:hover {
  color: var(--fg);
}

.streaming-hint {
  color: var(--fg-dim);
  font-style: italic;
}

.rendered::after {
  content: "▌";
  display: none;
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}

.output:has(.streaming-hint) .rendered::after,
form button:disabled ~ * .rendered::after {
  display: inline;
}

@keyframes blink {
  to { opacity: 0; }
}

#evidence {
  margin-top: 12px;
  font-size: 0.88rem;
}

/* ---- tap-to-reveal blocks ---- */

.spinner {
  color: var(--fg-dim);
  font-style: italic;
  padding: 24px 0;
  text-align: center;
}

.reveal-block,
.chat-block,
.continue-btn,
.answer-form {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.reveal-block.visible,
.chat-block.visible,
.continue-btn.visible,
.answer-form.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Server-rendered question / ack arrives as a chat-block wrapped inside a
   reveal-block. The inner element keeps its own opacity:0 transition until
   its parent reveal-block becomes visible — at which point we promote it
   too. */
.reveal-block.visible .chat-block {
  opacity: 1;
  transform: translateY(0);
}

.reveal-block {
  margin-bottom: 18px;
  color: #c8a84b;
}

.reveal-block h2 {
  margin-top: 24px;
  margin-bottom: 12px;
}

.reveal-caveat {
  font-style: italic;
  color: var(--fg-dim);
  border-left: 2px solid var(--border);
  padding-left: 12px;
  margin-top: 32px;
}

.reveal-caveat blockquote {
  margin: 0;
  padding: 0;
  border: 0;
}

.continue-btn {
  display: block;
  margin: 24px auto 8px;
  padding: 10px 28px;
  background: var(--accent, #4a7);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  letter-spacing: 0.02em;
}

.continue-btn:hover {
  filter: brightness(1.1);
}

.continue-btn:disabled {
  opacity: 0.55;
  cursor: progress;
  filter: none;
}

.continue-btn:disabled:hover {
  filter: none;
}

/* ---- chat bubbles ---- */

.chat-block {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 10px;
  line-height: 1.5;
}

.chat-bot {
  background: var(--bg-dim, #2a2d33);
  color: #c8a84b;
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

.chat-bot.intro,
.chat-bot.loading {
  font-style: italic;
  color: var(--fg-dim);
}

.chat-user {
  background: var(--accent, #4a7);
  color: white;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

/* "Thinking…" indicator shown while the LLM is processing an answer
   turn (especially the long refine after the final question). Three
   gold dots pulsing in a chat-bot bubble. */
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  width: auto;
  min-height: 0;
}
.chat-typing span {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #c8a84b;
  border-radius: 50%;
  opacity: 0.4;
  animation: chat-typing-pulse 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.18s; }
.chat-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes chat-typing-pulse {
  0%, 60%, 100% { opacity: 0.4; transform: scale(1); }
  30%          { opacity: 1;   transform: scale(1.35); }
}

.chat-user.skipped {
  background: var(--bg-dim, #2a2d33);
  color: var(--fg-dim);
  font-style: italic;
}

/* ---- answer input ---- */

.answer-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 24px;
}

.answer-form textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
}

.answer-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.answer-skip,
.answer-send {
  padding: 8px 18px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
}

.answer-skip {
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid var(--border);
}

.answer-send {
  background: var(--accent, #4a7);
  color: white;
}

.answer-send:hover {
  filter: brightness(1.1);
}

#evidence h4 {
  margin: 14px 0 6px;
  font-size: 0.95rem;
}

#evidence ul { padding-left: 20px; margin: 4px 0; }
#evidence li { margin: 3px 0; color: var(--fg-dim); }
#evidence li strong { color: var(--fg); }

/* P2: "Go deeper" collapsible body container. Keeps the deep multi-tradition
 * reading hidden by default so tired users see Headline + Question and can
 * skim out without scrolling past 200 words of prose they didn't ask for. */
.go-deeper {
  margin: 12px 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 280ms ease, transform 280ms ease;
}
.go-deeper.visible {
  opacity: 1;
  transform: translateY(0);
}
.go-deeper > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 500;
  color: var(--fg-dim);
  user-select: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.go-deeper > summary::-webkit-details-marker { display: none; }
.go-deeper > summary::before {
  content: "▸";
  display: inline-block;
  font-size: 0.8rem;
  transition: transform 180ms ease;
  color: var(--fg-dim);
}
.go-deeper[open] > summary::before {
  transform: rotate(90deg);
}
.go-deeper > summary:hover {
  color: var(--fg);
}
.go-deeper > .go-deeper-block {
  padding: 4px 16px;
}
.go-deeper > .go-deeper-block:last-child {
  padding-bottom: 14px;
}
