:root {
  color-scheme: dark;
  --bg: #0d0c0a;
  --panel-raised: #1c1913;
  --ink: #f5f1e4;
  --ink-dim: #cfc9b8;
  --muted: #9d968a;
  --lime: #cdf43f;
  --lime-bright: #dcff5c;
  --purple: #a78bfa;
  --line: rgba(245, 241, 228, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(720px 420px at 50% -8%, rgba(167, 139, 250, 0.16), transparent 65%),
    radial-gradient(640px 360px at 88% 108%, rgba(205, 244, 63, 0.1), transparent 65%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

/* The chat app is a fixed-height shell: the document never scrolls and
   .chat-log is the only scroll container. */
body.app-page {
  overflow: hidden;
  overscroll-behavior: none;
}

button, textarea, input { font: inherit; }
::selection { background: var(--lime); color: #12110f; }
body a { color: var(--lime-bright); }

.noscript-note { max-width: 42rem; margin: 2rem auto; padding: 1rem; color: var(--ink); }

.legal-page {
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top, 0px)) 0 max(40px, env(safe-area-inset-bottom, 0px));
  color: var(--ink);
  line-height: 1.65;
}
.legal-page .wordmark { display: inline-block; margin-bottom: 28px; }
.legal-page h1 { font-size: clamp(2rem, 8vw, 3rem); line-height: 1.1; }
.legal-page h2 { margin-top: 2rem; font-size: 1.2rem; }
.legal-page p, .legal-page li { color: var(--ink-dim); }
.legal-page .legal-updated { color: var(--muted); font-size: 0.88rem; }
.legal-page a { color: var(--lime-bright); }

.app {
  /* Height tracks the usable viewport. JS sets --app-height from
     window.visualViewport when available (keyboard, zoom); dvh/vh are the
     CSS-only fallbacks. */
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  transform: translateY(var(--app-offset-top, 0px));
  min-height: 0;
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding-top: 18px;
  padding-bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.wordmark {
  color: var(--ink);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.wordmark-dot { color: var(--lime); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.ai-disclosure {
  margin: -4px 2px 0;
  color: var(--ink-dim);
  font-size: 0.82rem;
  line-height: 1.4;
}

.guest-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.guest-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 10px rgba(205, 244, 63, 0.7);
}

.reset-button {
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}
.reset-button:hover { color: var(--ink); }
.reset-button:disabled { opacity: 0.5; cursor: wait; }

.start-button:focus-visible,
.send-button:focus-visible,
.reset-button:focus-visible,
.prompt-chip:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: 2px;
}

.chat {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(28, 25, 19, 0.72), rgba(20, 18, 14, 0.92));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(245, 241, 228, 0.18) transparent;
}

.welcome {
  margin: auto;
  max-width: 460px;
  padding: 12px 0 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
}

.prompt-cards {
  width: min(100%, 420px);
  display: grid;
  gap: 8px;
  margin-top: 2px;
}

.prompt-chip {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(13, 12, 10, 0.62);
  color: var(--ink-dim);
  text-align: left;
  line-height: 1.4;
  cursor: pointer;
}
.prompt-chip:hover { border-color: rgba(205, 244, 63, 0.55); color: var(--ink); }

.mascot {
  width: clamp(160px, 42vw, 212px);
  height: auto;
  filter: drop-shadow(0 18px 40px rgba(205, 244, 63, 0.18));
}

.brandmark {
  margin: 0;
  font-size: clamp(2rem, 9vw, 3.2rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  line-height: 0.95;
  text-transform: uppercase;
}
.brandmark-dot { color: var(--lime); }

.tagline {
  margin: 0;
  font-size: clamp(1.1rem, 4.6vw, 1.5rem);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.tagline em { color: var(--lime); font-style: italic; }

.invite {
  margin: 0;
  max-width: 34ch;
  color: var(--ink-dim);
  font-size: 0.98rem;
  line-height: 1.6;
}

.start-button {
  min-height: 46px;
  margin-top: 2px;
  padding: 12px 26px;
  border: 0;
  border-radius: 999px;
  background: var(--lime);
  color: #101208;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}
.start-button:hover { background: var(--lime-bright); transform: translateY(-1px); }
.start-button:active { transform: translateY(0); }

.fineprint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.02em;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 100%;
  animation: rise 160ms ease-out;
}
.user-message { justify-content: flex-end; }

.message-avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(205, 244, 63, 0.14);
  color: var(--lime);
  font-size: 0.9rem;
}

.message-content {
  max-width: min(84%, 560px);
  padding: 12px 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-raised);
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.message-content p { margin: 0; }
.message-note { display: block; margin-top: 8px; color: var(--muted); font-size: 0.75rem; font-style: normal; }

.jump-button {
  position: absolute;
  right: 20px;
  bottom: 92px; /* JS keeps this above the composer as it grows */
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 16px;
  border: 1px solid rgba(205, 244, 63, 0.35);
  border-radius: 999px;
  background: rgba(13, 12, 10, 0.94);
  color: var(--lime-bright);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.jump-button:hover { border-color: rgba(205, 244, 63, 0.6); }
.jump-button:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; }

.user-message .message-content {
  border-color: transparent;
  background: var(--lime);
  color: #101208;
  font-weight: 600;
}

.assistant-message .message-content { border-color: rgba(205, 244, 63, 0.18); }
.message-pending .message-content { color: var(--muted); font-style: italic; }
.message-error .message-content { border-color: rgba(255, 138, 110, 0.5); color: #ffc9bd; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 0 14px 14px;
  padding: 8px 8px 8px 16px;
  border: 1px solid rgba(245, 241, 228, 0.18);
  border-radius: 20px;
  background: rgba(13, 12, 10, 0.85);
  transition: border-color 140ms ease;
}
.composer:focus-within {
  border-color: var(--lime);
  box-shadow: 0 0 0 3px rgba(205, 244, 63, 0.15);
}

#message-input {
  flex: 1;
  min-width: 0;
  max-height: 160px;
  max-height: min(160px, 32dvh); /* keep the message list usable on short screens */
  padding: 10px 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  outline: none;
}
#message-input::placeholder { color: var(--muted); }

.send-button {
  flex: 0 0 auto;
  min-width: 96px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  background: var(--lime);
  color: #101208;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
}
.send-button:hover { background: var(--lime-bright); }
.send-button:disabled { opacity: 0.55; cursor: wait; }

.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
}
.footer a { color: var(--ink-dim); }

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

@keyframes rise {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 560px) {
  .app {
    width: min(100% - 20px, 760px);
    padding-top: 12px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    gap: 10px;
  }
  .chat { border-radius: 20px; }
  .chat-log { padding: 18px 14px 12px; }
  .composer { margin: 0 10px 10px; }
  .send-button { min-width: 64px; }
  .message-content { max-width: 88%; }
  .footer { flex-direction: column; gap: 4px; padding: 0 6px; }
  .topbar-actions { gap: 4px; }
  .reset-button { padding: 8px; }
  .ai-disclosure { font-size: 0.78rem; }
  .jump-button { right: 14px; }
}

@media (max-width: 360px) {
  /* The decorative guest pill is the only element that cannot fit beside the
     wordmark and reset control at the narrowest supported width. */
  .guest-pill { display: none; }
  .wordmark { letter-spacing: 0.1em; }
}

@media (max-height: 620px) {
  .app { padding-top: 10px; gap: 10px; }
  .chat-log { padding: 14px 14px 10px; }
  .welcome { padding: 4px 0 8px; gap: 10px; }
  .mascot { width: clamp(110px, 24vh, 150px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
