/* ── tokens ──────────────────────────────────────────────────────────────
   A terminal grimoire: the mystic reading rendered through the same
   monospace/ANSI vocabulary apps/cli uses to print cards to a real
   terminal. Two restrained accents (gilt gold for upright, dusty umber for
   reversed) on a warm ink-violet void — never pure black, never neon. */
:root {
  --void: #100e17;
  --panel: #1a1722;
  --panel-2: #221e2c;
  --line: #2c2735;
  --ink: #e8e3da;
  --dim: #837a8f;
  --gold: #c6a15b;
  --umber: #a5645a;

  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --measure: 74ch;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--void);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--gold); color: var(--void); }

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

.container {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 100vh;
  height: 100dvh; /* mobile browser chrome-aware viewport */
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.statusbar, form { flex: none; } /* pinned — only .log scrolls */

/* ── statusbar ─────────────────────────────────────────────────────────── */
.statusbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.statusbar-label { color: var(--ink); font-weight: 700; }

.statusbar-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gold);
  animation: pulse 2.4s ease-in-out infinite;
  margin-left: auto;
}

@keyframes pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(198, 161, 91, 0.5); }
  50% { opacity: 0.55; box-shadow: 0 0 0 4px rgba(198, 161, 91, 0); }
}

/* ── log ───────────────────────────────────────────────────────────────── */
.log {
  flex: 1;
  padding: 1.5rem 0 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.log-empty {
  color: var(--dim);
  font-style: normal;
}

.turn { display: flex; flex-direction: column; gap: 1.1rem; }

.line { display: flex; gap: 0.6em; align-items: baseline; }

.line-glyph {
  flex: none;
  color: var(--dim);
  user-select: none;
}

.line-user .line-glyph { color: var(--dim); }
.line-assistant .line-glyph { color: var(--gold); }

.line p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.line-user p { color: var(--dim); }
.line-assistant p { color: var(--ink); }

/* streamed reply: text arrives as deltas (typewriter feel), then gets cut
   into per-sentence spans the moment that sentence's narration is queued —
   each finalized sentence is clickable (plays/replays its own audio clip)
   and lights up gold while its clip is the one actually playing. */
.sentence {
  cursor: pointer;
  border-radius: 2px;
  transition: color 0.25s ease, background 0.25s ease;
}

.sentence:hover { color: var(--gold); }

.sentence.active {
  color: var(--void);
  background: var(--gold);
}

.live-tail { animation: reveal 0.25s ease; }

@keyframes reveal {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── rendered inline markdown (see mdInline() in app.py's PAGE_SCRIPT) ───── */
.line-assistant strong { font-weight: 700; color: var(--ink); }
.line-assistant em { font-style: italic; color: var(--ink); }

.line-assistant code {
  background: var(--panel);
  color: var(--gold);
  padding: 0.05em 0.35em;
  font-size: 0.92em;
}

.md-heading {
  display: inline-block;
  color: var(--gold);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0.2rem 0;
}

.md-hr {
  display: block;
  height: 1px;
  background: var(--line);
  margin: 0.9rem 0;
}

/* ── spread / cards ────────────────────────────────────────────────────── */
.spread {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  margin: 0.25rem 0;
}

.card {
  background: var(--panel);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* the spread appears mid-reading as the tool actually fires — a real reveal,
   not a decorative flourish, since a card genuinely didn't exist a moment ago */
.spread {
  opacity: 0;
  transform: translateY(6px) scale(0.98);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.spread.in { opacity: 1; transform: translateY(0) scale(1); }

.card-label {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--dim);
}

.card-img {
  width: 100%;
  aspect-ratio: 3 / 5;
  object-fit: cover;
  border: 1px solid var(--line);
  filter: sepia(0.18) saturate(0.85) contrast(1.04);
  transition: transform 0.4s ease;
}

/* reversed cards are shown upside down, as in a real spread */
.card-img.reversed { transform: rotate(180deg); }

.card-meta { font-size: 0.82rem; }
.card-meta .k { color: var(--dim); }
.card-meta .v { color: var(--ink); }
.card-meta .v.reversed { color: var(--umber); }

/* ── narration equalizer (the signature) ──────────────────────────────────
   ANSI half-blocks are how apps/cli renders cards to a real terminal; this
   is the same vocabulary applied to voice — bars pulse only while Piper's
   audio is actually playing (JS toggles .playing on play/pause/ended). */
.eq {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 1.1rem;
  opacity: 0.25;
}

.eq span {
  width: 3px;
  background: var(--gold);
  height: 30%;
  transition: opacity 0.3s ease;
}

.eq.playing span {
  animation: eq-bounce 0.9s ease-in-out infinite;
}

.eq.playing { opacity: 1; }

.eq span:nth-child(1) { animation-delay: 0s; }
.eq span:nth-child(2) { animation-delay: 0.12s; }
.eq span:nth-child(3) { animation-delay: 0.24s; }
.eq span:nth-child(4) { animation-delay: 0.36s; }
.eq span:nth-child(5) { animation-delay: 0.48s; }

@keyframes eq-bounce {
  0%, 100% { height: 25%; }
  50% { height: 100%; }
}

.playback {
  display: flex;
  align-items: center;
  gap: 0.6em;
  margin-top: 0.15rem;
}

.play-toggle {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--gold);
  font: inherit;
  line-height: 1;
  padding: 0.3em 0.55em;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.play-toggle:hover { border-color: var(--gold); }

/* ── share affordance ─────────────────────────────────────────────────────
   Appears at the end of a reading (see PAGE_SCRIPT's `done` event) to offer
   the /share image via the Web Share API, or a PNG download as fallback.
   Same terminal vocabulary as .play-toggle / the send button. */
.share-slot { margin-top: 0.5rem; }

.share-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  font: inherit;
  font-size: 0.82rem;
  line-height: 1;
  padding: 0.4em 0.7em;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.share-btn:hover { border-color: var(--gold); color: var(--gold); }

.share-glyph { color: var(--gold); }

/* ── voice status (synthesizing / unavailable) ────────────────────────────
   Never silent: while a turn's audio is being synthesized this shows
   "sintetizando voz…" (replaced by the real .playback controls the moment
   the first clip is ready); if TTS was on but every clip failed, this shows
   "voz indisponível" instead of quietly doing nothing. */
.tts-status {
  color: var(--dim);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin-top: 0.15rem;
}

.tts-status.synthesizing::before {
  content: "▂▄▆";
  color: var(--gold);
  animation: think-cycle 1s steps(3) infinite;
}

.tts-status.unavailable {
  color: var(--umber);
}

.tts-status.unavailable::before {
  content: "✕";
}

/* ── loading indicator ─────────────────────────────────────────────────── */
.thinking {
  color: var(--dim);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5em;
  opacity: 0;
  transition: opacity 150ms ease;
}

.thinking.visible { opacity: 1; }

.thinking::before {
  content: "▂▄▆";
  color: var(--gold);
  animation: think-cycle 1s steps(3) infinite;
}

@keyframes think-cycle {
  0% { content: "▂▄▆"; }
  33% { content: "▄▆▂"; }
  66% { content: "▆▂▄"; }
}

/* ── input line ────────────────────────────────────────────────────────── */
form {
  display: flex;
  align-items: center;
  gap: 0.6em;
  padding: 1rem 0 1.25rem;
  border-top: 1px solid var(--line);
}

.prompt-glyph { color: var(--gold); flex: none; }

input[name="message"] {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* avoid iOS auto-zoom */
  caret-color: var(--gold);
  padding: 0.3em 0;
}

input[name="message"]::placeholder { color: var(--dim); }
input[name="message"]:focus { outline: none; }

button {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--dim);
  font: inherit;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.5em 0.9em;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

button:hover { border-color: var(--gold); color: var(--gold); }

/* ── responsive ────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .container { padding: 0 0.9rem; }
  .spread { grid-template-columns: 1fr 1fr; }
}
