:root {
  color-scheme: dark;
  --bg: #0b0d11;
  --bg-elev: #14181f;
  --text: #f4f1ea;
  --muted: #a8b0be;
  --line: rgba(142, 186, 255, 0.32);
  --accent: #8ebfff;
  --accent-ink: #0c1524;
  --warm: #ffe7c4;
  --user-bg: #1a2433;
  --bot-bg: #151b26;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.4);
  --font-ui: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  --font-display: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  --neon: #ff4d9d;
  --crt: #7af6ff;
}

html[data-theme="eighties"] {
  --bg: #1a0c14;
  --bg-elev: #2a1220;
  --text: #fff6f1;
  --muted: #f0c4c0;
  --line: rgba(255, 160, 140, 0.4);
  --accent: #ffb089;
  --accent-ink: #2a120c;
  --user-bg: #3a1a28;
  --bot-bg: #241018;
  --font-display: "Righteous", "Outfit", "Arial Black", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(720px 440px at 0% 0%, rgba(70, 130, 255, 0.24), transparent 56%),
    radial-gradient(640px 400px at 100% 8%, rgba(255, 236, 210, 0.14), transparent 50%),
    var(--bg);
}

html[data-theme="eighties"] body {
  background:
    radial-gradient(980px 540px at 0% -8%, rgba(255, 110, 170, 0.46), transparent 52%),
    radial-gradient(860px 500px at 100% 0%, rgba(255, 176, 120, 0.4), transparent 48%),
    var(--bg);
}

html[data-theme="eighties"] body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.045) 0 1px,
    transparent 1px 4px
  );
}

::selection { background: rgba(142, 191, 255, 0.35); }

html[data-theme="eighties"] ::selection { background: rgba(255, 176, 137, 0.45); }

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

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 6px 10px;
  z-index: 50;
}

.skip:focus { top: 8px; }

.disclaimer {
  position: relative;
  z-index: 30;
  margin: 0;
  padding: 10px 16px;
  text-align: center;
  font-size: 0.84rem;
  line-height: 1.4;
  background: #10141c;
  color: #f7f1e6;
  border-bottom: 3px solid var(--accent);
}

html[data-theme="eighties"] .disclaimer {
  background: #2a1020;
  color: #ffe8dc;
  border-bottom-color: var(--neon);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.app {
  flex: 1;
  min-height: 0;
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 16px;
  background: var(--bg-elev);
  border-right: 1px solid var(--line);
  min-height: 0;
  overflow: auto;
}

html[data-theme="eighties"] .stage {
  background:
    linear-gradient(rgba(255, 120, 160, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 176, 120, 0.08) 1px, transparent 1px),
    var(--bg-elev);
  background-size: 22px 22px, 22px 22px, auto;
}

.avatar-frame {
  position: relative;
  width: min(100%, 260px);
  aspect-ratio: 300 / 340;
  overflow: hidden;
  border-radius: 22px;
  box-shadow: 0 0 0 1px rgba(142, 191, 255, 0.4), 0 0 28px rgba(255, 231, 196, 0.12), var(--shadow);
  background: #0c1016;
}

html[data-theme="eighties"] .avatar-frame {
  border-radius: 18px;
  box-shadow:
    0 0 0 3px #2a1020,
    0 0 0 6px #ff6ea8,
    0 0 28px rgba(255, 176, 120, 0.55);
}

html[data-theme="eighties"] .avatar-frame::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 12px;
  background: linear-gradient(transparent, rgba(255, 255, 255, 0.28), transparent);
  animation: tracking 3.6s linear infinite;
  pointer-events: none;
}

.avatar { width: 100%; height: 100%; }
.avatar svg { width: 100%; height: 100%; display: block; }

html[data-theme="modern"] .avatar.eighties,
html[data-theme="eighties"] .avatar.modern { display: none; }

.stage-copy { width: 100%; text-align: center; }

.on-air {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5c534a;
}

.stage.is-talking .led {
  background: #ff4d4d;
  box-shadow: 0 0 8px #ff4d4d;
}

.stage.is-thinking .led {
  background: var(--accent);
  animation: pulse 0.8s ease-in-out infinite alternate;
}

.avatar-name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  color: var(--accent);
}

html[data-theme="eighties"] .avatar-name {
  text-shadow: 2px 0 var(--neon), -2px 0 var(--crt);
  color: #fff;
}

.avatar-blurb {
  margin: 4px 0 10px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.vu {
  display: flex;
  gap: 4px;
  height: 18px;
  align-items: flex-end;
  justify-content: center;
  margin-bottom: 12px;
}

.vu span {
  width: 5px;
  height: 30%;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0.35;
  transform-origin: center bottom;
}

.stage.is-talking .vu span {
  opacity: 1;
  animation: eq 0.34s ease-in-out infinite alternate;
}

.stage.is-talking .vu span:nth-child(2) { animation-delay: 0.08s; }
.stage.is-talking .vu span:nth-child(3) { animation-delay: 0.16s; }
.stage.is-talking .vu span:nth-child(4) { animation-delay: 0.05s; }
.stage.is-talking .vu span:nth-child(5) { animation-delay: 0.12s; }

.picker {
  display: flex;
  gap: 8px;
}

.picker button {
  flex: 1;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: 999px;
  padding: 8px 10px;
  cursor: pointer;
}

.picker button[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: color-mix(in srgb, var(--bg) 88%, black);
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding: 16px 18px 8px;
}

.voice-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  max-width: 16rem;
  margin-bottom: 4px;
}

.voice-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

.voice-toggle[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.voice-icon { display: block; flex: 0 0 auto; }
.voice-toggle[aria-pressed="false"] .voice-waves { display: none; }
.voice-toggle[aria-pressed="true"] .voice-off { display: none; }

.voice-note {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: right;
  color: var(--muted);
}

.kicker {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2.1rem;
  letter-spacing: -0.03em;
  color: var(--warm);
  text-shadow: 0 0 18px rgba(142, 191, 255, 0.45);
}

html[data-theme="eighties"] h1 {
  font-weight: 400;
  letter-spacing: 0.03em;
  color: #ffe4d2;
  text-shadow: 2px 0 var(--neon), -2px 0 var(--crt);
}

.log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-color: var(--accent) transparent;
}

.msg { max-width: min(100%, 640px); }
.msg.user { align-self: flex-end; }
.msg.bot, .msg.status { align-self: flex-start; }

.who {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.play {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}

.play svg { display: block; }
.play .icon-stop { display: none; }
.play.is-playing {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.play.is-playing .icon-play { display: none; }
.play.is-playing .icon-stop { display: block; }
.play:disabled { opacity: 0.4; cursor: default; }

.parody-tag {
  display: inline-block;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
  letter-spacing: 0.08em;
}

.bubble {
  border-radius: 16px;
  padding: 10px 14px 12px;
  line-height: 1.45;
}

.msg.user .bubble {
  background: var(--user-bg);
  border-bottom-right-radius: 5px;
}

.msg.bot .bubble {
  background: var(--bot-bg);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}

.msg.status .bubble {
  background: transparent;
  border: 1px dashed var(--line);
  color: var(--muted);
}

.body { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.fineprint {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--accent);
}

.composer {
  padding: 8px 16px 14px;
  border-top: 1px solid var(--line);
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
}

.chip {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
}

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

.row { display: flex; gap: 8px; align-items: stretch; }

textarea {
  flex: 1;
  resize: none;
  min-height: 52px;
  max-height: 140px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #10141c;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
  padding: 12px 14px;
}

html[data-theme="eighties"] textarea { background: #241018; }

button.send {
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 700;
  padding: 0 18px;
  cursor: pointer;
}

button.send:disabled { opacity: 0.55; cursor: default; }

.meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.texty {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  padding: 2px 0;
}

.texty:hover { color: var(--accent); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.mouth-cavity {
  transform-box: fill-box;
  transform-origin: center;
  transform: scaleY(0.32);
}

.avatar.modern .mouth-cavity { transform: scaleY(0.78); }

.avatar.is-talking .mouth-cavity {
  animation: yap 0.16s ease-in-out infinite alternate;
}

.avatar.modern.is-talking .mouth-cavity { animation-name: yap-open; }

.avatar.eighties .hair,
.avatar.eighties .bangs {
  transform-box: fill-box;
  transform-origin: 50% 80%;
  animation: sway 3.4s ease-in-out infinite;
}

.avatar.eighties.is-talking .hair,
.avatar.eighties.is-talking .bangs { animation-duration: 0.42s; }

.headphones {
  transform-box: fill-box;
  transform-origin: center top;
}

.avatar.modern.is-talking .headphones {
  animation: cans 0.28s ease-in-out infinite alternate;
}

.avatar.modern .wave rect {
  transform-box: fill-box;
  transform-origin: center bottom;
}

.avatar.modern.is-talking .wave rect { animation: eq 0.32s ease-in-out infinite alternate; }
.avatar.modern.is-talking .wave rect:nth-child(2) { animation-delay: 0.08s; }
.avatar.modern.is-talking .wave rect:nth-child(3) { animation-delay: 0.14s; }
.avatar.modern.is-talking .wave rect:nth-child(4) { animation-delay: 0.04s; }
.avatar.modern.is-talking .wave rect:nth-child(5) { animation-delay: 0.18s; }

.avatar.modern.is-talking .boom {
  transform-box: fill-box;
  transform-origin: 0 0;
  animation: boom 0.28s ease-in-out infinite alternate;
}

.avatar.modern.is-talking .gesture {
  transform-box: fill-box;
  transform-origin: 20% 80%;
  animation: gesture 0.42s ease-in-out infinite alternate;
}

.eyelid {
  transform-box: fill-box;
  transform-origin: center top;
  transform: scaleY(0.14);
  transition: transform 0.1s ease-in;
}

.avatar.eighties.is-blinking .eyelid {
  transform: scaleY(1);
  transition-duration: 0.07s;
}

.avatar.modern .eyelid {
  transform: scaleY(0.24);
  transition: transform 0.045s linear;
}

.avatar.modern.is-blinking .eyelid { transform: scaleY(1); }

@keyframes yap {
  from { transform: scaleY(0.28); }
  to { transform: scaleY(1.12); }
}

@keyframes yap-open {
  from { transform: scaleY(0.5); }
  to { transform: scaleY(1.15); }
}

@keyframes gesture {
  from { transform: rotate(-6deg); }
  to { transform: rotate(7deg); }
}

@keyframes sway {
  0%, 100% { transform: rotate(-1.4deg); }
  50% { transform: rotate(1.4deg); }
}

@keyframes cans {
  from { transform: translateY(0); }
  to { transform: translateY(-4px); }
}

@keyframes boom {
  from { transform: rotate(0deg); }
  to { transform: rotate(-5deg); }
}

@keyframes eq {
  from { transform: scaleY(0.4); }
  to { transform: scaleY(1); }
}

@keyframes pulse {
  from { opacity: 0.45; }
  to { opacity: 1; }
}

@keyframes tracking {
  0% { top: -8%; }
  100% { top: 108%; }
}

@media (max-width: 800px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
  }

  .stage {
    flex-direction: row;
    align-items: center;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    gap: 12px;
    overflow: visible;
  }

  .avatar-frame { width: 104px; flex: 0 0 104px; }
  .stage-copy { text-align: left; }
  .avatar-blurb, .vu { display: none; }
  .on-air { margin-bottom: 2px; }
  .avatar-name { font-size: 1.05rem; }
  .picker { margin-top: 6px; }
  .chat-head {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 14px 0;
  }
  .voice-bar { align-items: flex-start; max-width: none; }
  .voice-note { text-align: left; }
  h1 { font-size: 1.55rem; }
  .disclaimer { font-size: 0.75rem; padding: 8px 12px; }
  .log, .composer { padding-left: 12px; padding-right: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
