: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);
}

/* API key button */
.api-key-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.api-key-btn:hover {
  background: rgba(22, 23, 15, 0.06);
  color: var(--ink);
}
.api-key-btn.has-key {
  border-color: #3a7d44;
  color: #3a7d44;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(22, 23, 15, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-backdrop[hidden] { display: none !important; }
.modal {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 16px 48px rgba(22, 23, 15, 0.18);
}
.modal h2 {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.modal-desc {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.modal input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  outline: none;
  margin-bottom: 16px;
  transition: border-color 0.2s ease;
}
.modal input[type="password"]:focus {
  border-color: var(--ink);
}
.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.modal-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.modal-btn:hover { background: rgba(22, 23, 15, 0.06); }
.modal-btn.primary {
  background: var(--ink);
  color: #f7f4ec;
  border-color: var(--ink);
}
.modal-btn.primary:hover { opacity: 0.85; }
.modal-btn.danger { color: var(--danger); border-color: var(--danger); }
.modal-btn.danger:hover { background: rgba(168, 59, 42, 0.06); }

/* ---------- hero ---------- */
.hero {
  position: relative;
  display: grid;
  grid-template-columns: 1fr minmax(320px, 560px) 1fr;
  align-items: center;
  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;
  width: 100%;
  max-width: 640px;
  margin-inline: auto;
  /* Fixed height prevents any layout jump — nothing inside can change the container size */
  height: min(80vh, 720px);
  margin-top: -40px;
  flex-shrink: 0;
}
.portrait-bg,
.portrait-video,
.portrait-overlay-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}
/* Static background image — always visible, never moves */
.portrait-bg {
  z-index: 0;
  opacity: 1;
  pointer-events: none;
  -webkit-user-drag: none;
}
.portrait-video {
  opacity: 1;
  z-index: 1; /* sits on top of the bg image */
  background: transparent;
  outline: none;
  pointer-events: none;
  transition: opacity 300ms ease;
}
/* 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;
}


/* Overlay image (e.g. project bird) — sits on top of everything */
.portrait-overlay-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
  border: none;
  outline: none;
  background: transparent;
}
.portrait-overlay-img[hidden] {
  display: none !important;
}
.portrait-overlay-img.visible {
  opacity: 1;
}

/* 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);
  overflow: visible;
}
.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: fixed;
  bottom: 140px;               /* floats above the ask bar */
  left: 50%;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 96px));
  max-height: 80px;
  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: 100;
  /* 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: 16px 20px 20px;
    grid-template-rows: auto auto auto auto;
  }
  .hero {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    align-items: start;
    gap: 12px;
    min-height: unset;
    padding: 8px 0 0;
  }
  /* Order: title → portrait → description */
  .hero-copy.left  { order: 1; }
  .portrait        { order: 2; }
  .hero-copy.right { order: 3; }

  .hero-copy.left h1 {
    font-size: clamp(18px, 5vw, 26px);
  }
  .hero-copy.right {
    align-items: flex-start;
    text-align: left;
  }
  .hero-copy.right p { max-width: none; font-size: 13px; }

  .portrait {
    height: min(55vw, 340px);
    max-width: 100%;
    margin-top: 0;
  }

  .thread-box {
    bottom: 120px;
    width: calc(100vw - 40px);
  }

  .footer-hint { display: none; }
}

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

  .portrait {
    height: min(60vw, 300px);
  }

  .thread-box {
    bottom: 110px;
    width: calc(100vw - 32px);
    max-height: 70px;
  }
}
