:root {
  --ink: #f4efff;
  --muted: rgba(244, 239, 255, 0.6);
  --accent: #ff2bd6;
  --accent-2: #6a00ff;
  --card: rgba(20, 12, 36, 0.82);
  --line: rgba(244, 239, 255, 0.14);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #0d0716;
  color: var(--ink);
  font-family: "Space Grotesk", system-ui, sans-serif;
  overflow-x: hidden;
  /* kills double-tap zoom on iOS while keeping scroll/pan */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body.link-modal-open {
  overflow: hidden;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* ---------- Composer (page 1) ---------- */

.composer {
  position: relative;
  z-index: 2;
  max-width: 680px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.home-link {
  color: var(--muted);
  text-decoration: none;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
}
.home-link:hover { color: var(--ink); }

.composer-head h1 {
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(34px, 8vw, 56px);
  line-height: 1.02;
  margin: 18px 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.composer-head h1 span {
  color: var(--accent);
  text-shadow: 0 0 24px rgba(255, 43, 214, 0.55);
}
.tagline {
  color: var(--muted);
  margin: 0 0 26px;
  max-width: 46ch;
}

.composer-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  backdrop-filter: blur(10px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.field-label {
  display: block;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.compose-mode {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 18px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
}

.compose-mode-btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.compose-mode-btn.is-active {
  color: var(--ink);
  background: linear-gradient(135deg, rgba(255, 43, 214, 0.92), rgba(106, 0, 255, 0.92));
  box-shadow: 0 8px 22px rgba(255, 43, 214, 0.24);
}

.message-field {
  position: relative;
  margin-bottom: 20px;
}

#message-input {
  width: 100%;
  resize: none;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font-family: inherit;
  font-size: 22px;
  padding: 14px 16px 34px;
  outline: none;
}
#message-input:focus { border-color: var(--accent); }

.char-count {
  position: absolute;
  right: 14px;
  bottom: 12px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}

.doodle-block {
  margin: 0 0 20px;
}

.doodle-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.doodle-head .field-label {
  margin-bottom: 8px;
}

.doodle-block .field-label em {
  font-style: normal;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0.72;
}

.doodle-pad-wrap {
  position: relative;
  border-radius: 16px;
  padding: 10px;
  background:
    radial-gradient(circle at top, rgba(255, 43, 214, 0.2), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.doodle-pad {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.16);
  background:
    linear-gradient(transparent 95%, rgba(255, 255, 255, 0.05) 95%),
    linear-gradient(90deg, transparent 95%, rgba(255, 255, 255, 0.05) 95%),
    rgba(6, 3, 16, 0.9);
  background-size: 18px 18px, 18px 18px, auto;
  cursor: crosshair;
}

.doodle-pad:focus {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.doodle-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.doodle-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.doodle-preset {
  padding: 9px 14px;
  font-size: 13px;
}

.style-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 22px;
}

/* Mobile: allow the whole composer to scroll so the keyboard/doodle cannot trap controls off-screen */
@media (max-width: 640px) {
  .composer {
    min-height: 100dvh;
    overflow-y: auto;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  }
  .composer-head h1 {
    font-size: clamp(24px, 7vw, 34px);
    margin: 10px 0 4px;
  }
  .tagline {
    font-size: 13px;
    margin-bottom: 14px;
  }
  .composer-card {
    padding: 16px;
  }
  .compose-mode {
    margin-bottom: 14px;
  }
  #message-input {
    font-size: 18px;
    padding: 10px 12px;
  }
  .message-field { margin-bottom: 12px; }
  .doodle-block { margin-bottom: 14px; }
  .style-grid {
    grid-template-columns: repeat(2, 1fr);
    max-height: min(42dvh, 360px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    align-content: start;
    margin-bottom: 14px;
    padding-right: 2px;
    overscroll-behavior: contain;
  }
  .style-chip { padding: 10px; }
  /* scroll-edge fades so it's obvious the grid scrolls */
  .style-grid.fade-top {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 26px);
    mask-image: linear-gradient(to bottom, transparent 0, #000 26px);
  }
  .style-grid.fade-bottom {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent 100%);
    mask-image: linear-gradient(to bottom, #000 calc(100% - 26px), transparent 100%);
  }
  .style-grid.fade-top.fade-bottom {
    -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
  }
  .composer-actions .btn { padding: 11px 18px; font-size: 14px; }
  .composer-actions {
    position: sticky;
    bottom: 0;
    padding-top: 10px;
    background: linear-gradient(180deg, rgba(20, 12, 36, 0), rgba(20, 12, 36, 0.96) 24px);
  }
  .link-modal-card {
    width: min(100%, calc(100vw - 28px));
    padding: 18px 16px 16px;
  }
  .link-modal-actions {
    grid-template-columns: 1fr;
  }
}

.style-chip {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.25);
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.style-chip:hover { transform: translateY(-2px); }
.style-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.style-chip:has(input:checked) {
  border-color: var(--accent);
  background: rgba(255, 43, 214, 0.12);
  box-shadow: 0 0 0 1px var(--accent), 0 0 22px rgba(255, 43, 214, 0.25);
}
.chip-emoji { font-size: 20px; }
.chip-name { font-weight: 700; font-size: 14px; }
.chip-desc { font-size: 11px; color: var(--muted); }

.composer-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 12px 22px;
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: transparent;
  transition: transform 0.12s, box-shadow 0.12s;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  box-shadow: 0 8px 26px rgba(255, 43, 214, 0.35);
}
.btn-ghost:hover { border-color: var(--accent); }

.link-modal {
  position: fixed;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 4, 14, 0.72);
  backdrop-filter: blur(14px);
}

.link-modal-card {
  position: relative;
  width: min(520px, calc(100vw - 40px));
  padding: 22px 22px 20px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background:
    radial-gradient(circle at top, rgba(255, 43, 214, 0.18), transparent 45%),
    rgba(20, 12, 36, 0.96);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.5);
}

.link-warning {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255, 209, 102, 0.28);
  background: rgba(255, 209, 102, 0.1);
  color: #ffe4aa;
  font-size: 13px;
  line-height: 1.4;
}

.link-modal-close {
  position: absolute;
  top: max(14px, env(safe-area-inset-top, 0px) + 8px);
  right: max(14px, env(safe-area-inset-right, 0px) + 8px);
  z-index: 1;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(16, 10, 28, 0.86);
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.link-modal-copy {
  margin-bottom: 14px;
}

.link-modal-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.link-modal-actions .btn {
  width: 100%;
}

#link-output {
  flex: 1;
  width: 100%;
  min-width: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  padding: 12px 14px;
}

/* ---------- Player ---------- */

.player {
  position: fixed;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 24px;
  pointer-events: none;
}

.caption {
  position: absolute;
  bottom: 18vh;
  left: 0;
  right: 0;
  text-align: center;
  font-family: "IBM Plex Mono", monospace;
  font-size: clamp(14px, 2.6vw, 20px);
  letter-spacing: 0.14em;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.5s;
  padding: 0 16px;
}
.caption.show { opacity: 1; }

.reveal {
  position: relative;
  z-index: 2;
  text-align: center;
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(30px, 7.5vw, 88px);
  line-height: 1.08;
  max-width: 16ch;
  text-transform: uppercase;
  word-break: break-word;
}

.reveal-doodle {
  position: absolute;
  inset: 50% auto auto 50%;
  width: min(72vw, 560px);
  transform: translate(-50%, -56%);
  color: rgba(255, 255, 255, 0.78);
  opacity: 0;
  pointer-events: none;
  filter: drop-shadow(0 0 28px rgba(255, 255, 255, 0.18));
  animation: doodle-arrive 0.85s 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.reveal-doodle svg {
  display: block;
  width: 100%;
  height: auto;
}

.reveal-doodle path {
  opacity: 0;
  transform: translateY(var(--path-jitter, 0));
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation:
    doodle-path 0.9s calc(0.1s + var(--path-delay, 0ms)) ease forwards,
    doodle-float 4.4s calc(1s + var(--path-delay, 0ms)) ease-in-out infinite;
}
.reveal .word {
  display: inline-block;
  white-space: nowrap;
}
.reveal .ch {
  display: inline-block;
  opacity: 0;
}

.player-actions {
  position: absolute;
  bottom: max(32px, env(safe-area-inset-bottom, 0px) + 24px);
  display: flex;
  gap: 12px;
  pointer-events: auto;
  opacity: 0;
  animation: fade-up 0.7s 0.4s forwards;
}

.skip-btn {
  position: absolute;
  top: max(18px, env(safe-area-inset-top, 0px) + 10px);
  right: 18px;
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  cursor: pointer;
}
.skip-btn:hover { color: var(--ink); }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes doodle-arrive {
  from { opacity: 0; transform: translate(-50%, -52%) scale(0.92); }
  to { opacity: 1; transform: translate(-50%, -56%) scale(1); }
}

@keyframes doodle-path {
  from { opacity: 0; stroke-dashoffset: 1; }
  to { opacity: 1; stroke-dashoffset: 0; }
}

@keyframes doodle-float {
  0%, 100% { transform: translateY(var(--path-jitter, 0)); }
  50% { transform: translateY(calc(var(--path-jitter, 0) - 7px)); }
}

/* ---------- Theme reveal flavours ---------- */

/* '80s neon */
body.theme-80s .reveal {
  color: #fff;
  text-shadow:
    0 0 8px #ff2bd6,
    0 0 28px #ff2bd6,
    0 0 60px #6a00ff,
    0 4px 0 #2b0a4d;
  font-style: italic;
}
body.theme-80s .reveal .ch.on {
  animation: neon-pop 0.55s cubic-bezier(0.2, 1.6, 0.4, 1) forwards;
}
@keyframes neon-pop {
  0% { opacity: 0; transform: scale(2.6) rotate(-6deg); filter: blur(6px); }
  100% { opacity: 1; transform: scale(1) rotate(0); filter: blur(0); }
}
body.theme-80s .caption { color: #ffd166; text-shadow: 0 0 12px rgba(255, 209, 102, 0.6); }

/* modern */
body.theme-modern { background: #eef0f4; }
body.theme-modern .reveal {
  color: #14151a;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  text-transform: none;
  letter-spacing: -0.02em;
  text-shadow: 0 0 18px rgba(255, 255, 255, 0.9), 0 0 50px rgba(255, 255, 255, 0.7);
}
body.theme-modern .reveal .ch.on {
  animation: clean-rise 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes clean-rise {
  0% { opacity: 0; transform: translateY(32px); }
  100% { opacity: 1; transform: translateY(0); }
}
body.theme-modern .caption { color: rgba(20, 21, 26, 0.55); }
body.theme-modern .skip-btn { color: rgba(20, 21, 26, 0.6); border-color: rgba(20, 21, 26, 0.2); background: rgba(255, 255, 255, 0.5); }
body.theme-modern .btn-ghost { color: #14151a; border-color: rgba(20, 21, 26, 0.25); }
body.theme-modern .reveal-doodle { color: rgba(20, 21, 26, 0.45); filter: drop-shadow(0 0 24px rgba(255, 255, 255, 0.7)); }

/* hacker */
body.theme-hacker .reveal {
  color: #38ff6e;
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
  text-transform: none;
  text-shadow: 0 0 10px rgba(56, 255, 110, 0.8), 0 0 40px rgba(56, 255, 110, 0.35);
}
body.theme-hacker .reveal .ch { opacity: 1; }
body.theme-hacker .caption { color: #38ff6e; text-shadow: 0 0 8px rgba(56, 255, 110, 0.6); }
body.theme-hacker .btn-primary { background: #0d2; background: linear-gradient(135deg, #16c94f, #0a7a2f); box-shadow: 0 8px 26px rgba(56, 255, 110, 0.3); }
body.theme-hacker .reveal-doodle { color: rgba(56, 255, 110, 0.88); filter: drop-shadow(0 0 26px rgba(56, 255, 110, 0.3)); }

/* cozy */
body.theme-cozy .reveal {
  color: #ffe5b8;
  font-family: "Caveat", cursive;
  font-size: clamp(44px, 10vw, 120px);
  text-transform: none;
  text-shadow: 0 0 22px rgba(255, 170, 70, 0.55), 0 0 70px rgba(255, 120, 30, 0.3);
}
body.theme-cozy .reveal .ch.on {
  animation: ember-glow 1.1s ease forwards;
}
@keyframes ember-glow {
  0% { opacity: 0; filter: blur(10px); transform: translateY(8px); }
  100% { opacity: 1; filter: blur(0); transform: translateY(0); }
}
body.theme-cozy .caption { color: #e8b87f; }
body.theme-cozy .btn-primary { background: linear-gradient(135deg, #ff9a3c, #c1440e); box-shadow: 0 8px 26px rgba(255, 154, 60, 0.35); }

/* crafty */
body.theme-crafty { background: #fdf3e3; }
body.theme-crafty .reveal {
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
body.theme-crafty .reveal .ch {
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.12);
  color: #ff6b6b;
}
body.theme-crafty .reveal .ch:nth-child(5n+2) { color: #f7b32b; }
body.theme-crafty .reveal .ch:nth-child(5n+3) { color: #2bb5ab; }
body.theme-crafty .reveal .ch:nth-child(5n+4) { color: #9b5de5; }
body.theme-crafty .reveal .ch:nth-child(5n) { color: #55a630; }
body.theme-crafty .reveal .ch.on {
  animation: paper-bounce 0.65s cubic-bezier(0.2, 1.8, 0.45, 1) forwards;
}
@keyframes paper-bounce {
  0% { opacity: 0; transform: translateY(-60px) rotate(14deg) scale(0.4); }
  100% { opacity: 1; transform: translateY(0) rotate(0) scale(1); }
}
body.theme-crafty .caption { color: #8a6b4f; }
body.theme-crafty .skip-btn { color: #8a6b4f; border-color: rgba(138, 107, 79, 0.35); background: rgba(255, 255, 255, 0.55); }
body.theme-crafty .btn-ghost { color: #5b4632; border-color: rgba(138, 107, 79, 0.4); }
body.theme-crafty .btn-primary { background: linear-gradient(135deg, #ff6b6b, #f7b32b); box-shadow: 0 8px 26px rgba(247, 179, 43, 0.4); }
body.theme-crafty .reveal-doodle { color: rgba(65, 40, 27, 0.42); filter: none; }

/* cosmos */
body.theme-cosmos .reveal {
  color: #f3eaff;
  font-weight: 200;
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-shadow: 0 0 10px #b48cff, 0 0 34px #2de2e6;
}
body.theme-cosmos .reveal .ch.on {
  animation: star-form 0.7s ease-out forwards;
}
@keyframes star-form {
  0% { opacity: 0; transform: scale(0.2); filter: blur(8px) brightness(3); }
  60% { opacity: 1; filter: blur(0) brightness(2); }
  100% { opacity: 1; transform: scale(1); filter: blur(0) brightness(1); }
}
body.theme-cosmos .caption { color: #b48cff; text-shadow: 0 0 10px rgba(180, 140, 255, 0.6); }
body.theme-cosmos .btn-primary { background: linear-gradient(135deg, #b44cff, #2de2e6); box-shadow: 0 8px 26px rgba(180, 76, 255, 0.35); }

/* drive-in */
body.theme-drivein .reveal {
  color: #fff3d6;
  font-family: Georgia, "Iowan Old Style", serif;
  font-style: italic;
  letter-spacing: 0.05em;
  text-shadow: 0 0 14px rgba(255, 179, 71, 0.8), 0 0 44px rgba(255, 79, 126, 0.45), 0 3px 0 rgba(0, 0, 0, 0.4);
}
body.theme-drivein .reveal .ch.on {
  animation: marquee-warm 0.55s ease-out forwards;
}
@keyframes marquee-warm {
  0% { opacity: 0; transform: scale(1.5); filter: blur(4px); }
  45% { opacity: 1; }
  60% { opacity: 0.45; }
  100% { opacity: 1; transform: scale(1); filter: blur(0); }
}
body.theme-drivein .caption { color: #ffb347; text-shadow: 0 0 10px rgba(255, 179, 71, 0.5); }
body.theme-drivein .btn-primary { background: linear-gradient(135deg, #ff4f7e, #ffb347); box-shadow: 0 8px 26px rgba(255, 79, 126, 0.35); }

/* premiere */
body.theme-premiere .reveal {
  color: #ffd166;
  font-family: Didot, "Playfair Display", Georgia, serif;
  letter-spacing: 0.08em;
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.7), 0 0 40px rgba(255, 158, 74, 0.4), 0 3px 0 rgba(60, 20, 10, 0.6);
}
body.theme-premiere .reveal .ch.on {
  animation: bulb-flicker 0.5s ease-out forwards;
}
@keyframes bulb-flicker {
  0% { opacity: 0; transform: translateY(10px) scale(1.12); }
  35% { opacity: 1; }
  50% { opacity: 0.3; }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
body.theme-premiere .caption {
  color: #e8c9a0;
  font-variant: small-caps;
  letter-spacing: 0.22em;
}
body.theme-premiere .btn-primary { background: linear-gradient(135deg, #a4133c, #c9962e); box-shadow: 0 8px 26px rgba(164, 19, 60, 0.45); }

/* circus */
body.theme-circus .reveal {
  color: #fff3d6;
  text-shadow: 0 5px 0 #1a0f45, -2px 0 0 rgba(255, 71, 87, 0.55), 2px 0 0 rgba(41, 211, 194, 0.55);
  letter-spacing: 0.02em;
}
body.theme-circus .reveal .ch:nth-child(4n+1) { color: #ff4757; }
body.theme-circus .reveal .ch:nth-child(4n+2) { color: #ffd23f; }
body.theme-circus .reveal .ch:nth-child(4n+3) { color: #29d3c2; }
body.theme-circus .reveal .ch.on {
  animation: circus-pop 0.5s cubic-bezier(0.2, 1.8, 0.4, 1) forwards;
}
body.theme-circus .reveal .ch:nth-child(2n).on { animation-name: circus-pop-alt; }
@keyframes circus-pop {
  0% { opacity: 0; transform: scale(0) rotate(-14deg) translateY(0.4em); }
  100% { opacity: 1; transform: none; }
}
@keyframes circus-pop-alt {
  0% { opacity: 0; transform: scale(0) rotate(14deg) translateY(-0.4em); }
  100% { opacity: 1; transform: none; }
}
/* the digital-circus signature: a few letters keep glitching forever */
body.theme-circus .reveal .ch:nth-child(7n+3).on {
  animation: circus-pop 0.5s cubic-bezier(0.2, 1.8, 0.4, 1) forwards,
             circus-glitch 2.8s steps(2, jump-none) 1.2s infinite;
}
@keyframes circus-glitch {
  0%, 92%, 100% { transform: none; filter: none; }
  94% { transform: translate(2px, -2px) skewX(-8deg); color: #ff5ce1; }
  96% { transform: translate(-2px, 1px); filter: blur(1px); }
}
body.theme-circus .caption {
  color: #ffd23f;
  font-style: italic;
  text-shadow: 0 2px 0 #1a0f45, 0 0 14px rgba(255, 210, 63, 0.45);
}
body.theme-circus .btn-primary { background: linear-gradient(135deg, #ff4757, #ffd23f); box-shadow: 0 8px 26px rgba(255, 71, 87, 0.4); }

@media (prefers-reduced-motion: reduce) {
  .reveal .ch, .reveal .ch.on { animation: none !important; opacity: 1 !important; }
  .reveal-doodle, .reveal-doodle path { animation: none !important; opacity: 1 !important; stroke-dashoffset: 0 !important; }
}

/* ---------- Reply chains ---------- */

.composer-meta-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin: 8px 0 20px;
}

.name-field .field-label {
  margin-bottom: 6px;
}

.name-field .field-label em {
  font-style: normal;
  letter-spacing: 0;
  text-transform: none;
  opacity: 0.72;
}

#name-input {
  width: min(260px, 100%);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  padding: 10px 12px;
  outline: none;
}

#name-input:focus { border-color: var(--accent); }

.reply-context {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
}

.reply-summary {
  color: var(--ink);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-btn {
  margin: 8px 0 0;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}

.text-btn:hover { color: var(--ink); }

.thread-history {
  position: relative;
  z-index: 2;
  width: min(620px, calc(100vw - 32px));
  max-height: min(28vh, 240px);
  margin: 14px auto 0;
  padding: 14px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 18px;
  background: rgba(6, 4, 14, 0.58);
  backdrop-filter: blur(10px);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.3);
}

.thread-history-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.thread-history-item {
  display: grid;
  grid-template-columns: minmax(70px, 0.28fr) minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.thread-history-name {
  color: rgba(255, 255, 255, 0.66);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-history-message {
  color: rgba(255, 255, 255, 0.9);
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .composer-meta-row {
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 12px;
  }
  .thread-history {
    max-height: 22vh;
    font-size: 13px;
  }
  .thread-history-item {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}

/* aurora */
body.theme-aurora .reveal {
  color: #ecfff6;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 0 16px rgba(116, 255, 202, 0.9), 0 0 58px rgba(123, 107, 255, 0.75);
}
body.theme-aurora .reveal .ch.on { animation: aurora-rise 0.75s ease-out forwards; }
@keyframes aurora-rise {
  0% { opacity: 0; transform: translateY(0.5em) skewX(-12deg); filter: blur(10px) hue-rotate(90deg); }
  100% { opacity: 1; transform: none; filter: blur(0) hue-rotate(0); }
}
body.theme-aurora .caption { color: #9dffe1; text-shadow: 0 0 14px rgba(157, 255, 225, 0.55); }
body.theme-aurora .btn-primary { background: linear-gradient(135deg, #58ffd4, #7b6bff); box-shadow: 0 8px 26px rgba(88, 255, 212, 0.3); }

/* deep sea */
body.theme-deepsea .reveal {
  color: #d6fffb;
  font-family: "IBM Plex Mono", monospace;
  text-shadow: 0 0 12px rgba(49, 255, 231, 0.9), 0 0 46px rgba(23, 94, 255, 0.55);
}
body.theme-deepsea .reveal .ch.on { animation: biolume-pop 0.7s ease-out forwards; }
@keyframes biolume-pop {
  0% { opacity: 0; transform: scale(0.5); filter: blur(8px) brightness(2); }
  55% { opacity: 1; filter: blur(0) brightness(2.4); }
  100% { opacity: 1; transform: scale(1); filter: blur(0) brightness(1); }
}
body.theme-deepsea .caption { color: #7df7ff; text-shadow: 0 0 12px rgba(125, 247, 255, 0.5); }
body.theme-deepsea .btn-primary { background: linear-gradient(135deg, #0bd8d1, #2458ff); box-shadow: 0 8px 26px rgba(11, 216, 209, 0.3); }

/* storm */
body.theme-storm .reveal {
  color: #f4f8ff;
  letter-spacing: 0.05em;
  text-shadow: 0 0 10px rgba(244, 248, 255, 0.95), 0 0 50px rgba(76, 195, 255, 0.75), 3px 3px 0 rgba(8, 20, 48, 0.75);
}
body.theme-storm .reveal .ch.on { animation: lightning-strike 0.55s ease-out forwards; }
@keyframes lightning-strike {
  0% { opacity: 0; transform: translateY(-0.6em) scale(1.25); filter: blur(5px) brightness(4); }
  30% { opacity: 1; }
  48% { opacity: 0.35; }
  100% { opacity: 1; transform: none; filter: blur(0) brightness(1); }
}
body.theme-storm .caption { color: #bfe8ff; text-shadow: 0 0 12px rgba(76, 195, 255, 0.55); }
body.theme-storm .btn-primary { background: linear-gradient(135deg, #4cc3ff, #3b4dff); box-shadow: 0 8px 26px rgba(76, 195, 255, 0.35); }

/* abduction */
body.theme-abduction .reveal {
  color: #f3fff1;
  font-family: "IBM Plex Mono", monospace;
  text-transform: uppercase;
  text-shadow: 0 0 10px rgba(164, 255, 118, 0.9), 0 0 48px rgba(96, 255, 168, 0.8);
}
body.theme-abduction .reveal .ch.on { animation: tractor-lock 0.65s cubic-bezier(0.2, 1.8, 0.4, 1) forwards; }
@keyframes tractor-lock {
  0% { opacity: 0; transform: translateY(-1.2em) rotate(4deg); filter: blur(6px); }
  100% { opacity: 1; transform: none; filter: blur(0); }
}
body.theme-abduction .caption { color: #b6ff8e; text-shadow: 0 0 14px rgba(182, 255, 142, 0.55); }
body.theme-abduction .btn-primary { background: linear-gradient(135deg, #9dff57, #20df9f); box-shadow: 0 8px 26px rgba(157, 255, 87, 0.32); }

/* seance */
body.theme-seance .reveal {
  color: #f1e7ff;
  font-family: Georgia, "Iowan Old Style", serif;
  letter-spacing: 0.08em;
  text-shadow: 0 0 12px rgba(196, 157, 255, 0.9), 0 0 44px rgba(123, 255, 200, 0.45);
}
body.theme-seance .reveal .ch.on { animation: spirit-materialize 0.82s ease-out forwards; }
@keyframes spirit-materialize {
  0% { opacity: 0; transform: translateY(0.4em) scale(1.08); filter: blur(12px); }
  70% { opacity: 0.82; filter: blur(1px); }
  100% { opacity: 1; transform: none; filter: blur(0); }
}
body.theme-seance .caption { color: #d9c0ff; text-shadow: 0 0 14px rgba(217, 192, 255, 0.5); }
body.theme-seance .btn-primary { background: linear-gradient(135deg, #9d6bff, #36e8b0); box-shadow: 0 8px 26px rgba(157, 107, 255, 0.36); }

/* kaiju */
body.theme-kaiju .reveal {
  color: #fff5e4;
  font-family: "Archivo Black", sans-serif;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-shadow: 0 6px 0 rgba(58, 13, 10, 0.8), 0 0 28px rgba(255, 107, 53, 0.8), 0 0 70px rgba(61, 220, 151, 0.35);
}
body.theme-kaiju .reveal .ch.on { animation: kaiju-roar 0.58s cubic-bezier(0.16, 1.6, 0.36, 1) forwards; }
@keyframes kaiju-roar {
  0% { opacity: 0; transform: scale(2.2) rotate(-2deg); filter: blur(3px); }
  100% { opacity: 1; transform: none; filter: blur(0); }
}
body.theme-kaiju .caption { color: #ffbf8a; text-shadow: 0 0 14px rgba(255, 107, 53, 0.55); }
body.theme-kaiju .btn-primary { background: linear-gradient(135deg, #ff6b35, #3ddc97); box-shadow: 0 8px 26px rgba(255, 107, 53, 0.38); }

/* pixel */
body.theme-pixel .reveal {
  color: #fff6a8;
  font-family: "IBM Plex Mono", monospace;
  font-size: clamp(32px, 7.8vw, 92px);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow: 4px 4px 0 #24135f, 0 0 22px rgba(255, 246, 168, 0.72);
  image-rendering: pixelated;
}
body.theme-pixel .reveal .ch.on { animation: pixel-blip 0.42s steps(3, end) forwards; }
@keyframes pixel-blip {
  0% { opacity: 0; transform: translateY(0.6em) scale(0.75); }
  66% { opacity: 1; transform: translateY(-0.1em) scale(1.08); }
  100% { opacity: 1; transform: none; }
}
body.theme-pixel .caption { color: #fff6a8; text-shadow: 3px 3px 0 #24135f; }
body.theme-pixel .btn-primary { background: linear-gradient(135deg, #ff5cc8, #49e25f); box-shadow: 0 8px 26px rgba(255, 92, 200, 0.34); }

@media (prefers-reduced-motion: reduce) {
  .reveal .ch, .reveal .ch.on { animation: none !important; opacity: 1 !important; }
}

/* polaroid */
body.theme-polaroid .reveal {
  color: #ffe8b8;
  font-family: "Caveat", cursive;
  font-size: clamp(40px, 9vw, 110px);
  text-transform: none;
  text-shadow: 0 0 18px rgba(201, 138, 75, 0.55), 0 2px 0 rgba(36, 21, 9, 0.7);
}
body.theme-polaroid .reveal .ch.on {
  animation: develop 1.3s ease-out forwards;
}
@keyframes develop {
  0% { opacity: 0; filter: blur(9px) sepia(1) brightness(0.4); transform: translateY(6px); }
  60% { opacity: 1; filter: blur(2px) sepia(0.6) brightness(0.9); }
  100% { opacity: 1; filter: blur(0) sepia(0) brightness(1); transform: translateY(0); }
}
body.theme-polaroid .caption { color: #c98a4b; }
body.theme-polaroid .btn-primary { background: linear-gradient(135deg, #c98a4b, #8a5a28); box-shadow: 0 8px 26px rgba(201, 138, 75, 0.4); }

/* mixtape */
body.theme-mixtape .reveal {
  color: #f5ecd7;
  font-family: "Caveat", "Comic Sans MS", cursive;
  font-size: clamp(42px, 9.5vw, 112px);
  text-transform: none;
  text-shadow: 0 0 16px rgba(255, 95, 162, 0.6), 0 3px 0 rgba(22, 16, 43, 0.8);
}
body.theme-mixtape .reveal .ch.on {
  animation: scribble-in 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) forwards;
}
body.theme-mixtape .reveal .ch:nth-child(2n).on { animation-name: scribble-in-alt; }
@keyframes scribble-in {
  0% { opacity: 0; transform: scale(1.4) rotate(-7deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes scribble-in-alt {
  0% { opacity: 0; transform: scale(1.4) rotate(7deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}
body.theme-mixtape .caption { color: #ff5fa2; text-shadow: 0 0 10px rgba(255, 95, 162, 0.45); }
body.theme-mixtape .btn-primary { background: linear-gradient(135deg, #ff5fa2, #ffd23f); box-shadow: 0 8px 26px rgba(255, 95, 162, 0.4); }

/* ---------- Echoes: the chain flies past mid-journey ---------- */

.echo {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.echo-item {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: min(80vw, 560px);
  text-align: center;
  animation: echo-pass 2000ms ease-in-out forwards;
  will-change: transform, opacity, filter;
}

.echo-name {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  opacity: 0.75;
}

.echo-message {
  font-family: "Space Grotesk", sans-serif;
  font-weight: 500;
  font-size: clamp(18px, 4vw, 32px);
  line-height: 1.25;
  overflow-wrap: anywhere;
  text-shadow: 0 0 18px currentColor;
}

@keyframes echo-pass {
  0% { opacity: 0; transform: scale(0.62) translateY(34px); filter: blur(10px); }
  30% { opacity: 0.95; transform: scale(1) translateY(0); filter: blur(0); }
  62% { opacity: 0.95; transform: scale(1.06) translateY(-6px); filter: blur(0); }
  100% { opacity: 0; transform: scale(1.7) translateY(-40px); filter: blur(8px); }
}

/* signature under the reveal */
.reveal-from {
  margin-top: 14px;
  font-family: "IBM Plex Mono", monospace;
  font-size: clamp(13px, 2.4vw, 18px);
  letter-spacing: 0.18em;
  opacity: 0;
  animation: fade-up 0.8s 0.9s forwards;
}

/* the post-reveal history: a ghost trail, not a box */
.thread-history {
  border: none;
  background: transparent;
  backdrop-filter: none;
  box-shadow: none;
  text-align: center;
  padding: 6px 14px;
  max-height: min(24vh, 200px);
  -webkit-mask-image: linear-gradient(to bottom, #000 75%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 75%, transparent 100%);
}

.thread-history-title {
  opacity: 0.7;
  letter-spacing: 0.22em;
}

.thread-history-item {
  display: block;
  border-top: none;
  padding: 4px 0;
  opacity: 0;
  animation: fade-up 0.6s forwards;
}

.thread-history-name {
  white-space: normal;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.thread-history-name::after { content: " · "; opacity: 0.5; }

.thread-history-message {
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5);
}

@media (prefers-reduced-motion: reduce) {
  .echo-item { animation-duration: 1ms !important; }
  .thread-history-item { animation: none; opacity: 1; }
}
