/* Spill The Tea — Full Page Display
 * Phone-mockup CSS below is kept identical to the local generator pipeline's
 * HTML_TEMPLATE (pipeline/generate_textingstory.py) so posts imported from
 * data/stories.json render pixel-identical to the original mockups. */

:root {
  --stone: #ECE4D6;
  --stone-dim: #DCD2BF;
  --ink: #15110D;
  --ink-dim: #211B14;
  --copper: #B8733B;
  --copper-soft: #D79A63;
  --bezel: #1C1B19;
  --bezel-edge: #38352F;
  --screen-bg: #FBF8F3;
  --screen-header: #F3EEE5;
  --hairline: rgba(20, 16, 10, 0.09);
  --sent-bubble: #3457C7;
  --sent-text: #FBF9F7;
  --recv-bubble: #E7E0D3;
  --recv-text: #1E1B15;
  --meta-text: #4A4234;
  --meta-dim: #8A7F6A;
  --timestamp: #9C9182;
  --page-fg: #221D14;
  --page-fg-dim: #6B6252;
  --focus: #B8733B;
}

:root[data-theme="dark"] {
  --page-bg-a: var(--ink);
  --page-bg-b: #1B140D;
  --screen-bg: #0C0C0D;
  --screen-header: #141415;
  --hairline: rgba(255, 255, 255, 0.08);
  --sent-bubble: #4C74E8;
  --sent-text: #FBF9F7;
  --recv-bubble: #26221C;
  --recv-text: #F1ECE2;
  --meta-text: #E8DFCE;
  --meta-dim: #A79A80;
  --timestamp: #8A8072;
  --page-fg: #EFE7D8;
  --page-fg-dim: #B3A88F;
  --kb-bg: #1C1C1E;
  --kb-key: #3A3A3C;
  --kb-key-text: #F2F2F2;
  --kb-key-shadow: rgba(0, 0, 0, 0.5);
}

:root[data-theme="light"] {
  --page-bg-a: var(--stone);
  --page-bg-b: var(--stone-dim);
  --screen-bg: #FBF8F3;
  --screen-header: #F3EEE5;
  --hairline: rgba(20, 16, 10, 0.09);
  --sent-bubble: #3457C7;
  --sent-text: #FBF9F7;
  --recv-bubble: #E7E0D3;
  --recv-text: #1E1B15;
  --meta-text: #4A4234;
  --meta-dim: #8A7F6A;
  --timestamp: #9C9182;
  --page-fg: #221D14;
  --page-fg-dim: #6B6252;
  --kb-bg: #D3D5DA;
  --kb-key: #FFFFFF;
  --kb-key-text: #1C1C1E;
  --kb-key-shadow: rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: light) {
  :root {
    --page-bg-a: var(--stone);
    --page-bg-b: var(--stone-dim);
    --kb-bg: #D3D5DA;
    --kb-key: #FFFFFF;
    --kb-key-text: #1C1C1E;
    --kb-key-shadow: rgba(0, 0, 0, 0.25);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --page-bg-a: var(--ink);
    --page-bg-b: #1B140D;
    --screen-bg: #0C0C0D;
    --screen-header: #141415;
    --hairline: rgba(255, 255, 255, 0.08);
    --sent-bubble: #4C74E8;
    --sent-text: #FBF9F7;
    --recv-bubble: #26221C;
    --recv-text: #F1ECE2;
    --meta-text: #E8DFCE;
    --meta-dim: #A79A80;
    --timestamp: #8A8072;
    --page-fg: #EFE7D8;
    --page-fg-dim: #B3A88F;
    --kb-bg: #1C1C1E;
    --kb-key: #3A3A3C;
    --kb-key-text: #F2F2F2;
    --kb-key-shadow: rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body.stt-full-page {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh; /* accounts for mobile browser chrome (address bar) showing/hiding — plain 100vh overestimates the visible area on load and can push content above the fold */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px 48px;
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, ui-sans-serif, system-ui, sans-serif;
  background:
    radial-gradient(ellipse 60% 45% at 50% 8%, color-mix(in srgb, var(--copper) 22%, transparent), transparent 70%),
    linear-gradient(180deg, var(--page-bg-a), var(--page-bg-b));
  color: var(--page-fg);
  overflow-x: hidden;
}

/* On short viewports (phones) the phone mockup + surrounding UI is taller
   than the screen — centering then pushes the top of the phone above the
   fold. Top-align instead so the header is always the first thing visible. */
@media (max-height: 900px) {
  body.stt-full-page {
    justify-content: flex-start;
  }
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: 100%;
  max-width: 420px;
}

.meta { text-align: center; display: flex; flex-direction: column; gap: 6px; }

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--copper-soft);
}

.meta h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-wrap: balance;
  color: var(--page-fg);
}

.meta .sub {
  margin: 0;
  font-size: 13px;
  color: var(--page-fg-dim);
}

.meta .scripture {
  margin: 4px 0 0;
  font-size: 17px;
  font-weight: 600;
  font-style: italic;
  color: var(--copper-soft);
  letter-spacing: 0.01em;
}

/* BLB ScriptTagger wraps the matched reference in its own <a> — inherit our
   styling rather than BLB's default link colors/underline. */
.meta .scripture a,
.meta .scripture a:visited {
  color: inherit;
  font: inherit;
}

.phone {
  position: relative;
  width: 360px;
  max-width: 100%;
  border-radius: 46px;
  background: linear-gradient(160deg, var(--bezel-edge), var(--bezel) 40%);
  padding: 12px;
  box-shadow:
    0 30px 60px -20px rgba(0, 0, 0, 0.55),
    0 4px 16px rgba(0, 0, 0, 0.35),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.screen {
  position: relative;
  border-radius: 36px;
  overflow: hidden;
  background: var(--screen-bg);
  display: flex;
  flex-direction: column;
  height: 620px;
}

.notch {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: 90px;
  height: 22px;
  background: var(--bezel);
  border-radius: 14px;
  z-index: 5;
}

/* Title/tagline intro shown on the phone screen itself before the text
   sequence starts (duration set via Settings → Splash Screen). Sits above
   the chat chrome underneath but below the notch, since the notch is
   phone hardware, not app content. */
.splash {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 30px;
  text-align: center;
  background: var(--screen-bg);
  opacity: 1;
  transition: opacity 0.5s ease;
}

.splash.hide {
  opacity: 0;
  pointer-events: none;
}

.splash-title {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--page-fg);
  text-wrap: balance;
}

.splash-sub {
  font-size: 16px;
  font-style: italic;
  color: var(--page-fg-dim);
  text-wrap: balance;
}

@media (prefers-reduced-motion: reduce) {
  .splash { transition: none; }
}

.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 26px 4px;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--page-fg);
  flex-shrink: 0;
}

.statusbar .icons { display: flex; gap: 5px; align-items: center; opacity: 0.85; }

.chatheader {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 12px;
  border-bottom: 1px solid var(--hairline);
  background: var(--screen-header);
  flex-shrink: 0;
}

.chatheader .back {
  border: none;
  background: none;
  color: var(--sent-bubble);
  font-size: 24px;
  line-height: 1;
  padding: 0 2px;
  cursor: default;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(155deg, var(--copper-soft), var(--copper));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.contactname {
  font-size: 15px;
  font-weight: 600;
  color: var(--page-fg);
  flex: 1;
}

.headericon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sent-bubble);
  font-size: 14px;
}

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
}

.thread::-webkit-scrollbar { width: 0; }

.daylabel {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--timestamp);
  margin: 6px 0 10px;
  font-variant-numeric: tabular-nums;
}

.thread .timeskip {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--timestamp);
  margin: 14px 0 12px;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.thread .timeskip.show { opacity: 1; transform: translateY(0); }

.thread .row { display: flex; width: 100%; }
.thread .row.sent { justify-content: flex-end; }
.thread .row.recv { justify-content: flex-start; }

.thread .bubble {
  max-width: 74%;
  padding: 8px 13px;
  border-radius: 18px;
  font-size: 15.5px;
  line-height: 1.32;
  letter-spacing: -0.002em;
  opacity: 0;
  transform: translateY(6px) scale(0.98);
  transition: opacity 0.28s ease, transform 0.28s ease;
  margin-bottom: 5px;
}

.thread .bubble.show { opacity: 1; transform: translateY(0) scale(1); }

.thread .row.sent .bubble {
  background: var(--sent-bubble);
  color: var(--sent-text);
  border-bottom-right-radius: 5px;
}

.thread .row.recv .bubble {
  background: var(--recv-bubble);
  color: var(--recv-text);
  border-bottom-left-radius: 5px;
}

.thread .typing {
  display: flex;
  gap: 4px;
  align-items: center;
  background: var(--recv-bubble);
  padding: 11px 14px;
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  width: fit-content;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  margin-bottom: 5px;
}

.thread .typing.show { opacity: 1; transform: translateY(0); }

.thread .typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--meta-dim);
  animation: bounce 1.1s infinite ease-in-out;
}

.thread .typing span:nth-child(2) { animation-delay: 0.15s; }
.thread .typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.inputbar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 16px;
  border-top: 1px solid var(--hairline);
  background: var(--screen-header);
}

.inputbar .pill {
  flex: 1;
  min-height: 34px;
  /* ~7-8 lines before it caps and starts scrolling internally — most story
     messages should just grow, never hit this. */
  max-height: 152px;
  border-radius: 18px;
  background: var(--screen-bg);
  border: 1px solid var(--hairline);
  /* Deliberately block, not flex — the compose caret is a ::after on this
     element, and needs to sit inline right after the last text character
     (wrapping onto the current line with it), not as a separate flex item
     floating beside the whole wrapped paragraph. */
  padding: 8px 14px;
  font-size: 13.5px;
  line-height: 1.3;
  color: var(--meta-dim);
  overflow-y: auto;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  transition: border-color 0.2s ease;
}

.inputbar .pill::-webkit-scrollbar { width: 0; }

/* Mid-compose: real message text, not the dim placeholder, with a blinking
   caret so it reads as someone actively typing rather than a static label. */
.inputbar .pill.typed {
  color: var(--page-fg);
  border-color: color-mix(in srgb, var(--copper) 45%, var(--hairline));
}

.inputbar .pill.typed::after {
  content: '';
  display: inline-block;
  width: 1px;
  height: 15px;
  margin-left: 2px;
  background: currentColor;
  animation: caret-blink 0.9s steps(1) infinite;
}

@keyframes caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.inputbar .send {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--sent-bubble);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  transition: transform 0.14s ease;
}

.inputbar .send.sending { transform: scale(0.82); }

@media (prefers-reduced-motion: reduce) {
  .inputbar .pill.typed::after { animation: none; }
}

/* ── Decorative on-screen keyboard, shown while a long outgoing message is
   being "typed" into the compose pill. Purely visual — no key does
   anything — it just sells the illusion that someone is actively texting.
   Collapsed via max-height so it pushes .thread up the same way a real
   keyboard does, rather than overlapping it. ── */

.stt-keyboard {
  flex-shrink: 0;
  max-height: 0;
  overflow: hidden;
  background: var(--kb-bg);
  transition: max-height 0.25s ease;
}

.stt-keyboard.show { max-height: 224px; }

.stt-keyboard-inner {
  padding: 8px 4px 4px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 0 4px;
}

.kb-row.indent { padding: 0 20px; }

.kb-key {
  flex: 1;
  min-width: 0;
  height: 38px;
  border-radius: 5px;
  background: var(--kb-key);
  color: var(--kb-key-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  box-shadow: 0 1px 0 var(--kb-key-shadow);
  transition: background-color 0.08s ease, transform 0.08s ease, color 0.08s ease;
}

.kb-key.wide { flex: 1.6; font-size: 12px; }
.kb-key.space { flex: 6; }
.kb-key.dim { background: transparent; box-shadow: none; font-size: 19px; }
.kb-spacer { flex: 5; }

/* Momentary "just pressed" flash, synced to each character as it's typed
   into the compose pill — see typeIntoPill()/flashKey() in stt-frontend.js. */
.kb-key.active {
  background: var(--copper-soft);
  color: #fff;
  transform: scale(0.92);
}

@media (prefers-reduced-motion: reduce) {
  .stt-keyboard { transition: none; }
  .kb-key { transition: none; }
}

.controls {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}

.replaybtn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--copper) 45%, transparent);
  background: color-mix(in srgb, var(--copper) 14%, transparent);
  color: var(--page-fg);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.replaybtn:hover { background: color-mix(in srgb, var(--copper) 24%, transparent); }
.replaybtn:active { transform: scale(0.97); }
.replaybtn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.watch-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--copper) 45%, transparent);
  background: var(--copper);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  align-self: center;
  transition: background 0.15s, transform 0.1s;
}
.watch-link:hover { background: var(--copper-soft); }
.watch-link:active { transform: scale(0.97); }
.watch-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.follow-row { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

.follow-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--copper) 45%, transparent);
  background: color-mix(in srgb, var(--copper) 14%, transparent);
  color: var(--page-fg);
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.2s ease;
}
.follow-link:hover { background: color-mix(in srgb, var(--copper) 24%, transparent); }
.follow-link:active { transform: scale(0.97); }
.follow-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.speedtoggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--page-fg-dim);
  cursor: pointer;
  user-select: none;
}

.speedtoggle input { accent-color: var(--copper); }

@media (prefers-reduced-motion: reduce) {
  .thread .bubble, .thread .typing, .thread .timeskip { transition: none !important; }
}

/* ── Rotation countdown (new — page-level, not part of the original mockup) ── */

/* On short/mobile viewports the page has to scroll to reach this — without
   enough clearance after it, scrolling all the way down puts it right
   under .stt-footer, which is position:fixed at the viewport bottom. The
   footer's own link has pointer-events:auto (so the credit link stays
   clickable), so without this gap a tap on "Next →" lands on the footer
   link instead — confirmed by measuring both elements' bounding boxes at
   max scroll on an emulated mobile viewport; body's existing 48px bottom
   padding wasn't actually producing this much real scrollable clearance
   in practice. */
.stt-countdown-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 12px;
  color: var(--page-fg-dim);
  margin-bottom: 60px;
}

.stt-countdown-bar-wrap {
  width: 100px;
  height: 3px;
  border-radius: 2px;
  background: color-mix(in srgb, var(--page-fg) 15%, transparent);
  overflow: hidden;
}

.stt-countdown-bar {
  height: 100%;
  border-radius: 2px;
  background: var(--copper);
  transition: width 1s linear;
}

#stt-countdown-text { min-width: 34px; text-align: left; font-variant-numeric: tabular-nums; }

.stt-skip-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--page-fg-dim);
  opacity: 0.75;
  text-decoration: underline;
  font-family: inherit;
  transition: opacity 0.2s;
}

.stt-skip-btn:hover { opacity: 1; }

/* ── "See another story" (single-story permalink pages only — these don't
   auto-rotate like the homepage kiosk, so this is the manual equivalent) ── */
.stt-discover-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 60px; /* same clearance as .stt-countdown-wrap, see note above */
}

.discover-link {
  font-size: 12px;
  color: var(--page-fg-dim);
  opacity: 0.75;
  text-decoration: underline;
  transition: opacity 0.2s;
}

.discover-link:hover { opacity: 1; }
.discover-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ── Footer credit ── */

.stt-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 20px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.01em;
  color: var(--page-fg-dim);
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--page-bg-b) 65%, transparent) 45%);
  pointer-events: none;
}

.stt-footer a {
  color: var(--copper-soft);
  text-decoration: none;
  pointer-events: auto;
}

.stt-footer a:hover { text-decoration: underline; }
