/* Ask Me Anything — Kim. Mobile-first, three themes.
   Clean, calm chat UI in the style of Muse: light neutral background,
   minimal borders, generous spacing, system sans-serif.
   Base layout targets a 390px phone; it widens gracefully on desktop. */
:root {
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Theme: light (default) — clean, Muse-like */
[data-theme="light"] {
  --bg: #f7f7f5; --panel: #ffffff; --text: #1f1f1f; --muted: #6f6f6f;
  --accent: #1a1a1a; --accent-text: #ffffff;
  --bubble-user: #1a1a1a; --bubble-user-text: #ffffff;
  --bubble-bot: #f0f0ee; --bubble-bot-text: #1f1f1f;
  --border: #e5e5e1; --input-bg: #ffffff; --shadow: 0 1px 2px rgba(0, 0, 0, .04);
}

/* Theme: dark */
[data-theme="dark"] {
  --bg: #171717; --panel: #212121; --text: #ececec; --muted: #a3a3a3;
  --accent: #ececec; --accent-text: #171717;
  --bubble-user: #ececec; --bubble-user-text: #171717;
  --bubble-bot: #2f2f2f; --bubble-bot-text: #ececec;
  --border: #333333; --input-bg: #2a2a2a; --shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

/* Theme: minimal */
[data-theme="minimal"] {
  --bg: #ffffff; --panel: #ffffff; --text: #222222; --muted: #888888;
  --accent: #222222; --accent-text: #ffffff;
  --bubble-user: #222222; --bubble-user-text: #ffffff;
  --bubble-bot: #f4f4f4; --bubble-bot-text: #222222;
  --border: #e8e8e8; --input-bg: #ffffff; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
.sr-only {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.app { max-width: 720px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.identity { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 auto; }

/* Looping avatar: ~72px, rounded corners, online dot.
   The animation is pure CSS on the still portrait (guaranteed faceless —
   no video), so the loop is smooth: front -> slight head tilt (thinking)
   -> back to centre -> a breathing pause that stays alive -> dip down to
   the laptop as it slides up -> typing -> ease back to front. 11s loop,
   ease-in-out throughout, so there are no frozen frames or jumps. */
.avatar-wrap { position: relative; flex: 0 0 auto; width: 72px; height: 72px; }
.avatar-frame {
  position: relative; width: 72px; height: 72px; border-radius: 18px; overflow: hidden;
  background: var(--bubble-bot); border: 1px solid var(--border);
}
.avatar-img {
  width: 72px; height: 72px; border-radius: 18px; object-fit: cover; display: block;
  transform-origin: 50% 85%; /* pivot at the neck / centre-bottom */
  animation: avatar-loop 11s ease-in-out infinite;
  will-change: transform;
}
.avatar-initials {
  width: 72px; height: 72px; border-radius: 18px; display: none;
  align-items: center; justify-content: center;
  background: var(--bubble-bot); color: var(--muted);
  font-weight: 700; font-size: 24px;
}
/* Laptop that slides up at the bottom edge of the avatar frame while typing */
.avatar-laptop {
  position: absolute; left: 50%; bottom: 0; width: 54px; margin-left: -27px;
  transform: translateY(110%); opacity: 0;
  animation: avatar-laptop-peek 11s ease-in-out infinite;
  pointer-events: none;
}
.laptop-screen {
  display: block; height: 20px; background: #1f2937; border-radius: 3px 3px 0 0;
  border: 1px solid #374151; border-bottom: none; position: relative; overflow: hidden;
}
.laptop-caret {
  position: absolute; left: 6px; top: 5px; width: 14px; height: 2px; background: #4ade80;
  animation: laptop-caret-blink 0.9s steps(2, start) infinite;
}
.laptop-base { display: block; height: 4px; background: #374151; border-radius: 0 0 3px 3px; }
@keyframes laptop-caret-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

@keyframes avatar-loop {
  /* 0–9%: face front, settle */
  0%, 9%     { transform: rotate(0deg) translateY(0) scale(1); }
  /* 9–18%: tilt head slightly while thinking */
  18%        { transform: rotate(-6deg) translateY(0) scale(1); }
  /* 18–27%: ease back to centre */
  27%        { transform: rotate(0deg) translateY(0) scale(1); }
  /* 27–55%: PAUSE facing front — gentle breathing only, so it stays alive */
  36%        { transform: rotate(0deg) translateY(0) scale(1.008); }
  45%        { transform: rotate(0deg) translateY(0) scale(1); }
  55%        { transform: rotate(0deg) translateY(0) scale(1.012); }
  /* 55–64%: dip down slightly towards the laptop */
  64%        { transform: rotate(2deg) translateY(3px) scale(1); }
  /* 64–82%: typing — head stays dipped with a tiny bob */
  70%        { transform: rotate(2deg) translateY(2px) scale(1); }
  76%        { transform: rotate(2deg) translateY(3px) scale(1); }
  82%        { transform: rotate(2deg) translateY(2px) scale(1); }
  /* 82–100%: ease back to front and settle into the loop */
  91%, 100%  { transform: rotate(0deg) translateY(0) scale(1); }
}
@keyframes avatar-laptop-peek {
  /* hidden until the head dips, visible while typing, slides away after */
  0%, 54%    { transform: translateY(110%); opacity: 0; }
  64%, 82%   { transform: translateY(0); opacity: 1; }
  91%, 100%  { transform: translateY(110%); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .avatar-img, .avatar-laptop, .laptop-caret { animation: none; }
  .avatar-laptop { display: none; }
}
.online-dot {
  position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px;
  border-radius: 50%; background: #22c55e; border: 2px solid var(--panel);
}
.identity-text { min-width: 0; }
.app-header h1 { font-size: 18px; margin: 0; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
.subtitle { margin: 2px 0 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.theme-picker select {
  font: inherit; font-size: 13px; color: var(--muted);
  background: var(--input-bg); border: 1px solid var(--border);
  border-radius: 999px; padding: 6px 8px; max-width: 118px;
}

.screen { flex: 1; display: flex; flex-direction: column; padding: 16px; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; width: 100%;
}
.panel h2 { margin: 0 0 8px; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.panel p { line-height: 1.6; margin: 0 0 12px; }
.hint { color: var(--muted); font-size: 14px; }
.note { color: var(--muted); font-size: 13px; }
.fineprint { color: var(--muted); font-size: 12px; margin: 10px 2px 0; text-align: center; }
.turnstile-box { margin: 16px 0 8px; min-height: 65px; display: flex; align-items: center; justify-content: center; }

.btn {
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
  border-radius: 999px; padding: 10px 18px; border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: var(--accent-text); width: 100%; }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-small { padding: 6px 12px; font-size: 14px; width: auto; }

/* Chat */
#chatScreen { display: flex; flex-direction: column; padding: 12px; background: transparent; border: none; box-shadow: none; }
.messages {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  min-height: 45dvh; padding: 4px 2px 12px;
}
.msg { max-width: 85%; padding: 10px 14px; border-radius: 18px; line-height: 1.55; font-size: 15px; white-space: pre-wrap; word-wrap: break-word; }
.msg.bot { background: var(--bubble-bot); color: var(--bubble-bot-text); align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.user { background: var(--bubble-user); color: var(--bubble-user-text); align-self: flex-end; border-bottom-right-radius: 6px; }
.msg .meta { display: block; font-size: 11px; opacity: .6; margin-top: 4px; }
.msg.typing { opacity: .7; font-style: italic; }

.idle-banner {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 14px;
}
.quick-replies { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer;
}
.chip:active { background: var(--bubble-bot); }
.composer {
  display: flex; gap: 8px; align-items: center;
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 6px 6px 16px; box-shadow: var(--shadow);
}
.composer input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; /* 16px stops iOS zoom */
  padding: 8px 0; border: none; outline: none;
  background: transparent; color: var(--text);
}
.composer input::placeholder { color: var(--muted); }
.composer .btn {
  width: 36px; height: 36px; flex: 0 0 36px; padding: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1;
}

/* Slots */
.slot-list { display: grid; gap: 8px; margin: 12px 0; }
.slot-btn {
  font: inherit; font-size: 15px; text-align: left; padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); cursor: pointer; width: 100%;
}
.slot-btn:hover, .slot-btn:active { border-color: var(--accent); }
.slot-btn:disabled { opacity: .45; cursor: not-allowed; }
.slot-day { font-weight: 700; margin: 14px 0 4px; font-size: 14px; color: var(--muted); }

.confirm-text { font-size: 17px; font-weight: 600; }

@media (max-width: 400px) {
  /* Keep the 72px avatar + actions fitting a narrow phone */
  .app-header { padding: 10px 12px; gap: 8px; }
  .identity { gap: 10px; }
  .theme-picker select { max-width: 88px; font-size: 12px; padding: 5px 6px; }
  .header-actions .btn-ghost { padding: 8px 10px; font-size: 13px; }
  .screen { padding: 12px; }
}

@media (min-width: 560px) {
  .screen { padding: 24px; }
  .slot-list { grid-template-columns: 1fr 1fr; }
  .msg { max-width: 75%; }
}
