:root {
  --bg: #f1efe9;
  --bg-2: #e8e5dc;
  --ink: #16170f;
  --ink-soft: #4a4b41;
  --muted: #8a8b81;
  --line: rgba(22, 23, 15, 0.12);
  --accent: #16170f;
  --danger: #a83b2a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  display: flex;
}

.stage {
  width: 100%;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  padding: 28px 48px 24px;
}

/* ---------- top bar ---------- */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}
.logo {
  font-weight: 700;
  letter-spacing: -0.02em;
  font-size: 28px;
  color: var(--ink);
}
.tag {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- hero ---------- */
.hero {
  position: relative;
  display: grid;
  grid-template-columns: 1fr minmax(320px, 560px) 1fr;
  align-items: stretch;
  gap: 36px;
  padding: 24px 0 12px;
  min-height: 60vh;
}

.hero-copy {
  display: flex;
  flex-direction: column;
  padding-top: 12px;
}
.hero-copy.left h1 {
  margin: 0;
  font-size: clamp(22px, 2.4vw, 34px);
  line-height: 1.15;
  font-weight: 400;
  letter-spacing: -0.01em;
}
.hero-copy.right {
  align-items: flex-end;
  text-align: right;
}
.hero-copy.right p {
  margin: 0;
  max-width: 280px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
}

.portrait {
  position: relative;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
  /* lock the slot so img and video share the same footprint */
  aspect-ratio: 3 / 4;
  max-height: 70vh;
  margin-top: -40px;
}
.portrait img,
.portrait-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  transition: opacity 500ms ease;
  /* no filters, so the PNG and the video frame match pixel-for-pixel */
}
.portrait img {
  opacity: 1;
  z-index: 2; /* image on top until the video is "primed" */
}
.portrait-video {
  opacity: 1;
  z-index: 1; /* sitting underneath, already showing its own first frame */
  background: transparent;
  outline: none;
  pointer-events: none;
}
/* hide native controls on every engine */
.portrait-video::-webkit-media-controls,
.portrait-video::-webkit-media-controls-panel,
.portrait-video::-webkit-media-controls-play-button,
.portrait-video::-webkit-media-controls-start-playback-button,
.portrait-video::-webkit-media-controls-overlay-play-button {
  display: none !important;
  -webkit-appearance: none;
}

/* Once the video has buffered + seeked to its first frame, fade the
   still image away. The video already shows the exact same pixels
   underneath, so there is no visible change — just the PNG dissolving
   to reveal the (still-paused) video frame. */
.portrait.is-ready #portraitImg { opacity: 0; }

/* When playback starts, nothing else has to move — the same element
   that was acting as the "still" simply begins to play. No swap, no jump. */

/* ---------- ask box ---------- */
.ask {
  position: relative;
  padding: 22px 0 14px;
  border-top: 1px solid var(--line);
}
.ask-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
.ask-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--muted);
}
.ask-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  padding: 6px 6px 6px 22px;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.ask-row:focus-within {
  border-color: var(--ink);
  background: #fff;
}
#questionInput {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  color: var(--ink);
  font-size: 17px;
  padding: 12px 0;
}
#questionInput::placeholder { color: var(--muted); }

#askButton,
#micButton {
  border: 0;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.2s ease;
  flex: 0 0 44px;
}
#askButton {
  background: var(--ink);
  color: #f7f4ec;
}
#askButton:hover { transform: translateX(1px); }
#askButton:disabled { opacity: 0.5; cursor: progress; }

#micButton {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
#micButton:hover { background: rgba(22, 23, 15, 0.05); }
#micButton[hidden] { display: none; }
#micButton.listening {
  background: var(--ink);
  color: #f7f4ec;
  box-shadow: 0 0 0 0 rgba(22, 23, 15, 0.35);
  animation: micPulse 1.4s ease-out infinite;
}
@keyframes micPulse {
  0%   { box-shadow: 0 0 0 0   rgba(22, 23, 15, 0.45); }
  100% { box-shadow: 0 0 0 14px rgba(22, 23, 15, 0); }
}

.status {
  min-height: 18px;
  margin: 2px 22px 0;
  font-size: 13px;
  color: var(--ink-soft);
}
.status.error { color: var(--danger); }
.status.thinking::after {
  content: "";
  display: inline-block;
  margin-left: 6px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink);
  animation: blink 1.2s infinite ease-in-out;
  vertical-align: middle;
}
@keyframes blink {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}

/* ---------- Conversation thread ---------- */
.thread-box {
  position: absolute;
  bottom: calc(100% + 8px);   /* sits just above the ask bar */
  left: 50%;
  transform: translateX(-50%);
  width: min(760px, 100%);
  max-height: 120px;           /* compact — won't cover Mika's face */
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  /* clear glass */
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(22, 23, 15, 0.08);
  z-index: 10;
  /* hidden until there are messages */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  scroll-behavior: smooth;
}
.thread-box.has-messages {
  opacity: 1;
  pointer-events: auto;
}
/* Individual thread entries */
.thread-entry {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: threadFadeIn 0.3s ease forwards;
}
@keyframes threadFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.thread-q {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.01em;
}
.thread-a {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
}
/* Curated entries get a subtle left accent */
.thread-entry.curated .thread-a {
  color: var(--ink-soft);
  font-style: italic;
}

/* ---------- footer ---------- */
.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 18px;
  margin-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.footer-hint { font-style: italic; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .stage { padding: 18px 20px; }
  .hero {
    grid-template-columns: 1fr;
    text-align: left;
    gap: 16px;
  }
  .hero-copy.right { align-items: flex-start; text-align: left; }
  .hero-copy.right p { max-width: none; }
  .portrait img { max-height: 50vh; }
}

@media (max-width: 520px) {
  #questionInput { font-size: 15px; }
  .ask-row { padding-left: 16px; }
  .footer { flex-direction: column; gap: 6px; align-items: flex-start; }
}
