:root {
  --bg: #12100e;
  --surface: #1c1916;
  --surface-2: #262019;
  --text: #f3ede2;
  --muted: #a89f90;
  --accent: #e9d8a6;
  --accent-ink: #12100e;
  --user-bubble: #33291d;
  --line: #2f2820;
  --danger: #e5867a;
  --radius: 16px;
  --font-display: Georgia, "Times New Roman", serif;
  --font-text: "Hanken Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-synthesis: none;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf6ee;
    --surface: #fffdf8;
    --surface-2: #f1ead9;
    --text: #1e1a14;
    --muted: #6b6153;
    --accent: #7a5b13;
    --accent-ink: #fffdf8;
    --user-bubble: #ece2c9;
    --line: #e2d8c2;
    --danger: #b5493f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font: inherit; cursor: pointer; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---- Brand mark ---- */
.mark { display: block; color: var(--accent); }
.mark--lg { width: 66px; height: 66px; margin: 0 auto 6px; }
.mark--sm { width: 30px; height: 30px; flex-shrink: 0; }
.mark-n { font-family: var(--font-display); font-size: 88px; fill: var(--accent-ink); }
.mark-dot { fill: var(--accent-ink); }

/* ---- Landing ---- */
.landing {
  align-items: center; justify-content: center; text-align: center; padding: 24px;
  background:
    radial-gradient(60% 42% at 50% 32%, rgba(233, 216, 166, 0.06), transparent 70%),
    var(--bg);
}
.landing-inner { max-width: 30rem; margin: auto; display: flex; flex-direction: column; gap: 12px; }
.wordmark {
  font-family: var(--font-display); font-weight: 400;
  font-size: clamp(2.7rem, 12vw, 4.1rem); margin: 0 0 2px; letter-spacing: -0.02em; line-height: 1;
}
.wordmark span, .brand span { color: var(--accent); }
.tagline { font-family: var(--font-display); font-size: 1.4rem; margin: 2px 0 0; }
.lede { margin: 0; color: var(--text); text-wrap: pretty; }
.lede.muted, .muted { color: var(--muted); }
.cta {
  margin: 20px auto 8px; padding: 14px 24px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 1.02rem;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 8px 24px -10px rgba(233, 216, 166, 0.5);
  transition: transform .15s ease, box-shadow .15s ease, filter .15s ease;
}
.cta:hover { filter: brightness(1.04); transform: translateY(-1px); box-shadow: 0 12px 30px -10px rgba(233, 216, 166, 0.6); }
.cta:active { transform: translateY(0); }
.cta svg { transition: transform .15s ease; }
.cta:hover svg { transform: translateX(2px); }
.reassure { margin: 0; color: var(--muted); }
.langs { margin: 8px 0 0; color: var(--muted); font-size: 0.88rem; letter-spacing: 0.02em; }
.landing-footer { padding: 18px; color: var(--muted); font-size: 0.78rem; text-align: center; line-height: 1.7; }
.landing-footer a, .chat-foot a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.landing-footer a:hover, .chat-foot a:hover { color: var(--accent); }

.landing-inner > * { animation: rise .5s cubic-bezier(.22,.61,.36,1) both; }
.landing-inner > :nth-child(1) { animation-delay: .02s; }
.landing-inner > :nth-child(2) { animation-delay: .08s; }
.landing-inner > :nth-child(3) { animation-delay: .13s; }
.landing-inner > :nth-child(4) { animation-delay: .18s; }
.landing-inner > :nth-child(5) { animation-delay: .24s; }
.landing-inner > :nth-child(6) { animation-delay: .30s; }
.landing-inner > :nth-child(7) { animation-delay: .35s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---- Chat ---- */
.chat { max-width: 46rem; margin: 0 auto; width: 100%; }
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.brand { font-family: var(--font-display); font-size: 1.35rem; }
.demo-pill {
  font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em;
  background: var(--surface-2); color: var(--muted); padding: 3px 8px; border-radius: 999px;
}
.menu { margin-left: auto; position: relative; }
#menu-btn {
  background: none; border: 0; color: var(--muted); padding: 6px; border-radius: 8px;
  display: inline-flex; transition: color .15s ease, background .15s ease;
}
#menu-btn:hover { color: var(--text); background: var(--surface); }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px; min-width: 12rem; box-shadow: 0 16px 40px -12px rgba(0,0,0,.5);
  animation: rise .16s ease both;
}
.menu-panel button { width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 10px 12px; border-radius: 8px; font-size: 0.92rem; }
.menu-panel button:hover { background: var(--surface-2); }

.log { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 22px 16px; display: flex; flex-direction: column; gap: 12px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.log::-webkit-scrollbar { width: 8px; }
.log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.msg {
  max-width: 85%; padding: 11px 15px; border-radius: var(--radius); white-space: pre-wrap;
  word-wrap: break-word; overflow-wrap: anywhere; animation: msg-in .3s cubic-bezier(.22,.61,.36,1) both;
}
.msg.user { align-self: flex-end; background: var(--user-bubble); border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.system-note {
  align-self: center; background: transparent; color: var(--muted); font-size: 0.9rem;
  text-align: center; font-family: var(--font-display); padding: 6px 0;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.typing { display: inline-flex; gap: 5px; padding: 2px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.3s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 70%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-2px); } }

.error-line { align-self: center; color: var(--danger); font-size: 0.9rem; display: flex; gap: 10px; align-items: center; }
.error-line button { background: none; border: 1px solid var(--danger); color: var(--danger); border-radius: 8px; padding: 4px 12px; }

/* ---- Referral card ---- */
.card {
  align-self: flex-start; max-width: 23rem; width: 100%; border: 1px solid var(--line);
  background: var(--surface-2); border-radius: 14px; padding: 16px 18px;
  animation: msg-in .3s cubic-bezier(.22,.61,.36,1) both;
}
.card h3 { margin: 0 0 6px; font-size: 0.82rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }
.card p { margin: 3px 0; font-size: 0.9rem; color: var(--text); }
.card p.muted { color: var(--muted); }
.card .card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.card .card-actions a {
  font-size: 0.85rem; text-decoration: none; background: var(--accent); color: var(--accent-ink);
  padding: 7px 14px; border-radius: 999px; font-weight: 600;
}
.card .unverified { color: var(--muted); font-size: 0.78rem; margin-top: 10px; line-height: 1.45; }

/* ---- Chips ---- */
.chips { display: flex; gap: 8px; padding: 0 16px 10px; flex-wrap: wrap; }
.chip {
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  padding: 8px 13px; border-radius: 999px; font-size: 0.85rem;
  transition: background .15s ease, border-color .15s ease, transform .15s ease;
}
.chip:hover { background: var(--surface-2); border-color: var(--muted); transform: translateY(-1px); }

/* ---- Composer ---- */
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg); position: sticky; bottom: 0;
}
#input {
  flex: 1; resize: none; max-height: 40vh; padding: 12px 14px; border-radius: 16px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit;
  line-height: 1.5; transition: border-color .15s ease;
}
#input::placeholder { color: var(--muted); }
#input:focus { outline: none; border-color: var(--accent); }
#send {
  border: 0; border-radius: 50%; width: 44px; height: 44px; flex-shrink: 0;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center;
  transition: filter .15s ease, transform .15s ease, opacity .15s ease;
}
#send:hover:not(:disabled) { filter: brightness(1.05); transform: scale(1.04); }
#send:disabled { opacity: .45; cursor: default; }
.chat-foot { text-align: center; font-size: 0.72rem; margin: 4px 0 8px; }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 20; animation: fade .15s ease both; }
.modal-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px; max-width: 22rem; width: 100%; box-shadow: 0 24px 60px -16px rgba(0,0,0,.6); animation: rise .2s ease both; }
.modal-title { font-weight: 600; margin: 0 0 4px; font-size: 1.02rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions button { flex: 1; padding: 11px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-weight: 500; }
.modal-actions .danger { background: var(--danger); color: #fff; border-color: var(--danger); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (min-width: 640px) {
  .msg { max-width: 74%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .typing i { animation: blink 1.3s infinite ease-in-out; }
}
