/* Who Is Asking — the world.
   Two typefaces, one question, an ocean of dark. DESIGN.md is the law here;
   where it was silent I chose the more austere option. */

@font-face {
  font-family: "Cormorant"; font-style: normal; font-weight: 300;
  font-display: swap; src: url("/fonts/cormorant-300.woff2") format("woff2");
}
@font-face {
  font-family: "Cormorant"; font-style: normal; font-weight: 400;
  font-display: swap; src: url("/fonts/cormorant-400.woff2") format("woff2");
}
@font-face {
  font-family: "Cormorant"; font-style: normal; font-weight: 500;
  font-display: swap; src: url("/fonts/cormorant-500.woff2") format("woff2");
}
@font-face {
  font-family: "Cormorant"; font-style: italic; font-weight: 400;
  font-display: swap; src: url("/fonts/cormorant-400-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Plex Mono"; font-style: normal; font-weight: 400;
  font-display: swap; src: url("/fonts/plex-mono-400.woff2") format("woff2");
}

:root {
  --ground: #0c0a09;         /* charcoal with brown underneath, never pure black */
  --mirror: #e7e5e4;         /* warm off-white — the Mirror's words */
  --person: #a8a29e;         /* dimmer — the visitor is not the protagonist */
  --ember-deep: #7c2d12;     /* deep rust */
  --ember-lit: #c2410c;      /* dim orange */
  --serif: "Cormorant", "Spectral", Georgia, "Times New Roman", serif;
  --mono: "Plex Mono", "SF Mono", "IBM Plex Mono", Menlo, Consolas, monospace;
  --column: 40rem;           /* ~640px */
  --reveal: 500ms;           /* per-character fade duration */
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--ground);
  color: var(--mirror);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

body {
  display: flex; flex-direction: column;
  min-height: 100dvh;
  /* a barely-there warmth pooled at the base, like the fire is below the frame */
  background-image: radial-gradient(120% 80% at 50% 118%, rgba(124, 45, 18, 0.16), transparent 60%);
}

/* ---- the ember field ---- */
#embers {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  z-index: 0; pointer-events: none;
  opacity: 0;                         /* faded in by JS over ~3s on arrival */
  transition: opacity 3s ease;
}

/* ---- the column ---- */
#well {
  position: relative; z-index: 1;
  flex: 1 1 auto;
  width: 100%; max-width: var(--column);
  margin: 0 auto;
  padding: max(8vh, 3rem) clamp(1.25rem, 5vw, 2.5rem) 1rem;
  overflow-y: auto;
  scrollbar-width: none;
  display: flex; flex-direction: column;
  gap: 1.9rem;
}
#well::-webkit-scrollbar { width: 0; height: 0; }

#question {
  margin: 0;
  font-weight: 300;
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  letter-spacing: 0.01em;
  line-height: 1.1;
  color: var(--mirror);
  opacity: 0; transform: translateY(0.4rem);
  transition: opacity 2.4s ease, transform 2.4s ease;
}
#question.here { opacity: 1; transform: none; }

/* ---- exchanges ---- */
.exchange {
  --dim: 1;
  opacity: var(--dim);
  transition: opacity 2.2s ease;
  display: flex; flex-direction: column; gap: 1.1rem;
}
.person, .mirror { margin: 0; }

.person {
  font-family: var(--mono);
  font-size: 1rem;                    /* raw input, honest, never below 16px */
  line-height: 1.6;
  color: var(--person);
  white-space: pre-wrap; word-break: break-word;
}

.mirror {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.35rem, 4.4vw, 1.6rem);   /* 20–24px+, read slowly */
  line-height: 1.55;
  color: var(--mirror);
  white-space: pre-wrap;
}
.mirror em { font-style: italic; }

/* the decode — each character flickers through ember glyphs, then settles from
   ember into a human off-white. Words materializing out of the fire. */
.mirror .ch { opacity: 0; }
.mirror .ch.scramble {
  opacity: 0.85; color: var(--ember-lit);
  text-shadow: 0 0 8px rgba(194, 65, 12, 0.35);
}
.mirror .ch.lit {
  opacity: 1; color: var(--mirror);
  transition: color 0.5s ease, text-shadow 0.5s ease;
  text-shadow: 0 0 0 transparent;
}

/* the thinking cue — the same glyph-flicker, resolving to nothing yet */
.mirror.thinking {
  color: var(--ember-lit); opacity: 0.75;
  letter-spacing: 0.18em;
}
.mirror.thinking .ch {
  opacity: 0.85; color: var(--ember-lit);
  text-shadow: 0 0 8px rgba(194, 65, 12, 0.3);
}

/* the floor: plain, legible, no theatrics, links tappable */
.mirror.floor { color: var(--mirror); }
.mirror.floor .ch { opacity: 1; transition: none; }
.mirror.floor a {
  color: var(--ember-lit);
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}

/* ---- the input ---- */
#composer {
  position: relative; z-index: 1;
  width: 100%; max-width: var(--column);
  margin: 0 auto;
  padding: 0.4rem clamp(1.25rem, 5vw, 2.5rem) max(6vh, 2.2rem);
  display: flex; align-items: flex-start;
}
#input {
  flex: 1 1 auto;
  min-height: 1.9em; max-height: 40vh;
  margin: 0; padding: 0; border: 0; outline: 0;
  background: transparent; resize: none; overflow-y: auto;
  font-family: var(--mono);
  font-size: 1rem; line-height: 1.6;
  color: var(--person);
  caret-color: var(--ember-lit);
}
#input::placeholder { color: transparent; }

/* the bare blinking cursor before the person has spoken */
#beacon {
  position: absolute; z-index: 2;
  left: clamp(1.25rem, 5vw, 2.5rem); top: 0.4rem;
  width: 0.5ch; height: 1.5em;
  background: var(--ember-lit);
  opacity: 0.85;
  animation: blink 1.15s steps(1) infinite;
  pointer-events: none;
}
@keyframes blink { 0%, 55% { opacity: 0.8; } 56%, 100% { opacity: 0; } }
#composer.spoken #beacon { display: none; }

/* ---- silence: the conversation hushes to embers — but the voice stays. The
   person can always speak; the input just recedes to a whisper until touched. */
body.hushed #well { opacity: 0.08; transition: opacity 1.6s ease; }
body.hushed #composer { opacity: 0.4; transition: opacity 1.2s ease; }
#composer:focus-within { opacity: 1 !important; }

/* ---- ending: dim toward black — the input remains; typing brings it back ---- */
body.ending #well { opacity: 0; transition: opacity 26s ease; }
body.ending #composer { opacity: 0.4; transition: opacity 2s ease; }
body.ending #disclosure-link { opacity: 0.12; transition: opacity 6s ease; }

/* ---- disclosure: the one quiet exception to no-nav ---- */
#disclosure-link {
  position: fixed; z-index: 2;
  right: 1rem; bottom: 0.7rem;
  padding: 0.4rem;
  border: 0; background: transparent;
  font-family: var(--mono); font-size: 0.8rem;
  letter-spacing: 0.03em;
  color: var(--person);
  opacity: 0.32; cursor: pointer;
  transition: opacity 0.6s ease;
}
#disclosure-link:hover, #disclosure-link:focus-visible { opacity: 0.7; outline: 0; }

#disclosure {
  max-width: 34rem; margin: auto;
  padding: 2rem 2rem 1.4rem;
  border: 1px solid rgba(168, 162, 158, 0.18);
  border-radius: 2px;
  background: #100d0b;
  color: var(--mirror);
}
#disclosure::backdrop { background: rgba(6, 5, 4, 0.72); backdrop-filter: blur(2px); }
#disclosure h2 {
  margin: 0 0 0.9rem; font-weight: 300;
  font-size: 1.5rem; color: var(--person);
}
#disclosure p {
  margin: 0 0 1.4rem; font-family: var(--mono);
  font-size: 0.95rem; line-height: 1.7; color: var(--mirror);
}
#disclosure em { font-family: var(--serif); font-style: italic; font-size: 1.1em; }
#disclosure-close {
  border: 0; background: transparent; cursor: pointer;
  font-family: var(--mono); font-size: 0.85rem; color: var(--ember-lit);
  padding: 0.3rem 0;
}
#disclosure:not([open]) { display: none; }

/* ---- accessibility: the costume never sacrifices the person under it ---- */
:focus-visible { outline: 1px solid rgba(194, 65, 12, 0.7); outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  #embers { transition: none; }
  #question { transition: opacity 0.01ms; transform: none; }
  .exchange { transition: none; }
  .mirror .ch { transition: none; opacity: 1; }
  #beacon { animation: none; opacity: 0.7; }
  body.ending #well { transition: opacity 1.5s ease; }
}

@media (prefers-contrast: more) {
  :root { --person: #c9c4c0; }
  .exchange { --dim: 1 !important; }
}

/* ---- mobile: this is visited at 1am on a phone ---- */
/* Honor the notch and the home indicator so the input is never under either. */
#composer {
  padding-bottom: max(env(safe-area-inset-bottom, 0px) + 1rem, 2.2rem);
  padding-left: max(clamp(1.25rem, 5vw, 2.5rem), env(safe-area-inset-left, 0px));
  padding-right: max(clamp(1.25rem, 5vw, 2.5rem), env(safe-area-inset-right, 0px));
}
#well { padding-top: max(env(safe-area-inset-top, 0px) + 2rem, 3rem); }
#beacon { top: 0.42rem; }

@media (max-width: 34rem) {
  #well { gap: 1.6rem; }
  .mirror { font-size: 1.35rem; line-height: 1.5; }   /* ≥16px, comfortable thumb-scroll reading */
  .person { font-size: 1rem; }                          /* 16px — no iOS zoom-on-focus */
  #question { font-size: clamp(2.3rem, 13vw, 3rem); }
  #disclosure {
    margin: auto 0.6rem;
    padding: 1.5rem 1.4rem 1.1rem;
    max-height: 84dvh; overflow-y: auto;
  }
  #disclosure-link {
    right: max(0.6rem, env(safe-area-inset-right, 0px));
    bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
    padding: 0.55rem;                                    /* larger tap target */
  }
}

/* Coarse pointers (touch): give the tiny link a real thumb target. */
@media (pointer: coarse) {
  #disclosure-link { padding: 0.6rem; opacity: 0.4; }
  #input { font-size: 16px; }                            /* belt-and-suspenders against iOS zoom */
}
