/* ── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  color-scheme: dark;
  --bg:         #000;
  --fg:         #fff;
  --lead:       rgba(255,255,255,0.72);
  --muted:      rgba(255,255,255,0.40);
  --faint:      rgba(255,255,255,0.40);
  --subtle:     rgba(255,255,255,0.40);
  --surface:    rgba(255,255,255,0.08);
  --border:     rgba(255,255,255,0.85);
  --menu-bg:    #111;
  --menu-hover: rgba(255,255,255,0.08);
  --sep:        rgba(255,255,255,0.10);
  --danger:     #ff453a;
  --sidebar-bg: #0d0d0d;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg:         #fff;
    --fg:         #000;
    --lead:       rgba(0,0,0,0.60);
    --muted:      rgba(0,0,0,0.40);
    --faint:      rgba(0,0,0,0.40);
    --subtle:     rgba(0,0,0,0.40);
    --surface:    rgba(0,0,0,0.08);
    --border:     rgba(0,0,0,0.85);
    --menu-bg:    #f5f5f5;
    --menu-hover: rgba(0,0,0,0.06);
    --sep:        rgba(0,0,0,0.10);
    --danger:     #ff3b30;
    --sidebar-bg: #eaeaea;
  }
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  overflow: hidden;
}
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }
.center {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 32px 24px; gap: 20px;
}

/* ── Mascot ─────────────────────────────────────────────────────────────────── */
/* Reusable text-symbol mascot ^_^ — fixed-width container, text-align drives animation */
.mascot {
  display: inline-block;
  width: 32px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
  font-family: inherit;
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
  cursor: default;
  color: var(--fg);
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

/* Large mascot for loading / signin screens */
.mascot--xl {
  font-size: 52px;
  width: 140px;
  height: auto;
  line-height: 1;
  display: block;
  letter-spacing: 0;
}

/* ── Landing / Sign-in ──────────────────────────────────────────────────────── */
#signin { gap: 32px; }
#signin .mascot--xl { margin-bottom: 4px; }

.loading-label {
  font-size: 12px; color: var(--muted);
  margin-top: 4px;
}

h1    { font-size: 32px; font-weight: 400; letter-spacing: -0.5px; }
.lead { max-width: 440px; font-size: 15px; color: var(--lead); line-height: 1.6; }

.disclaimer { max-width: 360px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.disclaimer a { color: var(--fg); }

/* Language dropdown on landing */
.lang-select {
  appearance: none; -webkit-appearance: none;
  background: none; border: none;
  color: var(--muted);
  font-family: inherit; font-size: 13px;
  text-align: center; cursor: pointer;
  padding: 6px 12px;
  outline: none;
}
.lang-select:hover { color: var(--fg); }
.lang-select option { background: var(--menu-bg); color: var(--fg); }

.auth-stack { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 320px; }
.auth-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; height: 48px; padding: 0 48px;
  background: none; color: var(--fg); border: 1.5px solid var(--border);
  font-family: inherit; font-size: 15px; font-weight: 500; cursor: pointer;
}
.auth-btn .auth-logo {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  display: inline-flex; width: 18px; height: 18px;
}
.auth-btn .auth-logo svg { width: 18px; height: 18px; display: block; }

.lang-switch { font-size: 13px; color: var(--muted); margin-top: -4px; }
.lang-switch a { color: var(--muted); text-decoration: none; }
.lang-switch a:hover { color: var(--fg); }
.lang-switch a.active { color: var(--fg); font-weight: 600; }

/* ── Chat layout ────────────────────────────────────────────────────────────── */
#chat { display: flex; flex-direction: row; }

/* Sidebar hidden in v1 — logic kept */
.sidebar         { display: none !important; }
.sidebar-overlay { display: none !important; }
.sidebar-toggle  { display: none !important; }

.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ── Topbar ─────────────────────────────────────────────────────────────────── */
.topbar {
  position: relative; z-index: 3; flex-shrink: 0;
  display: flex; align-items: center;
  height: 56px; padding: 0 16px;
  /* No border, no background fill */
}
.topbar .spacer { flex: 1; }

.topbar-brand { display: flex; align-items: center; gap: 12px; }
.brand-name   { font-size: 14px; font-weight: 500; color: var(--fg); letter-spacing: -0.1px; }
/* Header mascot a touch larger than the inline default */
.topbar-brand .mascot { font-size: 22px; width: 40px; }

.menu-wrap  { position: relative; }
.burger-btn {
  display: flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: none; background: none; color: var(--fg);
  cursor: pointer;
  /* No hover background */
}

/* ── Desktop: transparent floating header ───────────────────────────────────── */
/* Content scrolls underneath; header overlays with no fill */
@media (min-width: 1024px) {
  .chat-main { position: relative; }
  .topbar {
    position: absolute; top: 0; left: 0; right: 0;
    background: transparent;
    z-index: 10;
  }
  .thread { padding-top: 72px !important; }
}

/* ── Thread wrap ────────────────────────────────────────────────────────────── */
/* Wrapper allows scroll-down button to be positioned relative to thread area */
.thread-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
}

.thread {
  height: 100%; overflow-y: auto;
  padding: 24px 24px 16px;
  display: flex; flex-direction: column; gap: 24px;
  max-width: 800px; margin: 0 auto;
}

/* Scroll-to-bottom: always 16px above the bottom of the thread area */
.scroll-down {
  position: absolute; inset-inline-end: 20px; bottom: 16px; z-index: 4;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  background: var(--menu-bg); backdrop-filter: blur(12px);
  color: var(--fg); cursor: pointer;
}

.row { display: flex; }
.row.ai { justify-content: flex-start; }
.row.me { justify-content: flex-end; }

/* AI messages: plain text, no box */
.bubble-ai {
  max-width: 100%;
  font-size: 14px; line-height: 1.43;
  white-space: pre-wrap;
  color: var(--fg);
}

/* User messages: sharp rectangle with frosted glass */
.bubble-me {
  max-width: calc(100% - 56px);
  font-size: 14px; line-height: 1.43;
  white-space: pre-wrap;
  background: var(--surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 16px;
}

.row.fadein { animation: fadein .22s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Streaming greeting: paragraphs fade in one by one */
.stream-para {
  display: block;
  margin: 0;
  opacity: 0;
  animation: stream-in 0.5s ease forwards;
}
.stream-para + .stream-para { margin-top: 1em; }
@keyframes stream-in {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: none; }
}

/* Invite link inside an AI message: URL = share, copy icon = copy */
.invite-url {
  cursor: pointer;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  word-break: break-all;
}
.invite-copy {
  border: none; background: none; cursor: pointer; padding: 0;
  margin-inline-start: 6px;
  color: var(--muted);
  vertical-align: -2px;
}
.invite-copy:hover { color: var(--fg); }

/* Liked heart on an AI message */
.liked-heart { color: var(--danger); font-size: 12px; }

/* Typing indicator face — fixed width so the label never shifts as the face changes */
.typing-face {
  font-weight: 500;
  letter-spacing: -0.5px;
  flex-shrink: 0;
  display: inline-block;
  width: 2.6em;
  text-align: center;
}

/* Typing indicator */
.typing {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--muted);
}
.typing .dots { display: inline-flex; gap: 3px; }
.typing .dots i {
  width: 4px; height: 4px; background: currentColor;
  opacity: .3; animation: blink 1.2s infinite;
}
.typing .dots i:nth-child(2) { animation-delay: .2s; }
.typing .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

/* System separator */
.sys-sep { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0; }

/* ── Skeleton loading ────────────────────────────────────────────────────────── */
.skeleton { display: flex; flex-direction: column; gap: 20px; width: 100%; }
.sk-row { display: flex; opacity: 0; transform: translateY(8px); animation: sk-in .35s ease forwards; }
.sk-row:nth-child(1) { animation-delay: .04s; }
.sk-row:nth-child(2) { animation-delay: .16s; }
.sk-row:nth-child(3) { animation-delay: .28s; }
.sk-row:nth-child(4) { animation-delay: .40s; }
.sk-row:nth-child(5) { animation-delay: .52s; }
.sk-row:nth-child(6) { animation-delay: .64s; }
@keyframes sk-in { to { opacity: 1; transform: none; } }
.sk-row.sk-ai { justify-content: flex-start; }
.sk-row.sk-me { justify-content: flex-end; }
.sk-block {
  height: 14px;
  background: var(--surface);
  animation: sk-pulse 1.6s ease-in-out infinite;
}
.sk-block.sk-user { height: 46px; }
@keyframes sk-pulse {
  0%, 100% { opacity: 0.30; }
  50%       { opacity: 0.80; }
}

/* ── Anonymous banner ───────────────────────────────────────────────────────── */
.anon-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; max-width: 800px; margin: 0 auto; padding: 10px 24px;
  font-size: 13px; color: var(--lead);
}
.anon-banner button {
  border: 1.5px solid var(--fg); padding: 7px 16px; cursor: pointer;
  background: none; color: var(--fg); font-family: inherit; font-size: 13px; font-weight: 500; flex-shrink: 0;
}

/* ── Composer ───────────────────────────────────────────────────────────────── */
.composer {
  flex-shrink: 0;
  padding: 0 24px calc(12px + env(safe-area-inset-bottom, 0));
  width: 100%; max-width: 800px; margin: 0 auto;
  /* No border */
}

/* Input row — sharp rectangle. min-height reserves icon space so the bar
   doesn't jump when buttons appear (e.g. Firefox without SpeechRecognition). */
.input-bar {
  display: flex; align-items: flex-end; gap: 4px;
  min-height: 48px;
  background: var(--surface);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  padding: 12px 16px;
  margin-top: 12px;
}

#input {
  flex: 1; background: none; border: none; color: var(--fg);
  font-family: inherit; font-size: 14px; line-height: 1.43;
  resize: none; outline: none; max-height: 120px;
  padding: 0;
}
#input::placeholder { color: var(--faint); }

/* Caption: smaller, more transparent, non-breaking spaces force wrap at comma */
.input-caption {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.65;
  text-align: center;
  line-height: 1.4;
}

.mic-btn {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; flex-shrink: 0;
  border: none; background: none; color: var(--fg); cursor: pointer;
  padding: 0;
}
.mic-btn.recording { color: #ff453a; animation: mic-pulse 1s ease infinite; }
@keyframes mic-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

.send-btn {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; flex-shrink: 0;
  border: none; background: none; color: var(--fg);
  font-size: 18px; cursor: pointer; padding: 0;
}

.cancel-btn {
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; flex-shrink: 0;
  border: none; background: none; color: var(--fg);
  cursor: pointer; padding: 0; margin-right: 4px;
}

/* ── Dropdown menu ──────────────────────────────────────────────────────────── */
.menu {
  position: absolute; inset-inline-end: 0; top: 44px; min-width: 220px;
  background: var(--menu-bg);
  padding: 4px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  z-index: 10;
}
/* RTL: align menu text to the right */
[dir="rtl"] .menu button,
[dir="rtl"] .msg-menu button { text-align: right; }
.menu button {
  display: flex; width: 100%; text-align: left; gap: 10px;
  align-items: center; padding: 10px 12px; border: none;
  background: none; color: var(--fg); font-family: inherit; font-size: 14px;
  cursor: pointer;
}
.menu button:hover { background: var(--menu-hover); }
.menu button.danger { color: var(--danger); }
.menu .sep { height: 1px; background: var(--sep); margin: 4px 0; }

/* Language dropdown row inside the burger menu */
.menu .menu-lang {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px;
}
.menu .menu-lang select {
  flex: 1;
  appearance: none; -webkit-appearance: none;
  background: none; border: none;
  color: var(--fg);
  font-family: inherit; font-size: 14px;
  cursor: pointer; outline: none;
  padding: 4px 0;
}
.menu .menu-lang select option { background: var(--menu-bg); color: var(--fg); }

/* ── Save-progress modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-card {
  background: var(--menu-bg); border-radius: 20px;
  padding: 32px 28px; max-width: 360px; width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  text-align: center; box-shadow: 0 12px 48px rgba(0,0,0,0.45);
}
.modal-mascot { font-size: 28px; width: 72px; height: auto; line-height: 1; }
.modal-card p { font-size: 15px; line-height: 1.5; }
.later-btn {
  background: none; border: none; color: var(--muted);
  font-family: inherit; font-size: 14px; cursor: pointer; padding: 6px;
}

/* ── About page "try without account" link ──────────────────────────────────── */
.try-link {
  color: var(--muted); font-size: 13px;
  text-decoration: underline; text-underline-offset: 3px;
}

/* ── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--menu-bg); padding: 10px 16px;
  z-index: 20; font-size: 13px; box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  white-space: nowrap;
}

/* ── Message context menu ───────────────────────────────────────────────────── */
.msg-menu {
  position: fixed; z-index: 20; background: var(--menu-bg);
  padding: 4px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4); min-width: 200px;
}
.msg-menu button {
  display: flex; width: 100%; gap: 10px; text-align: left;
  padding: 10px 12px; border: none; background: none; color: var(--fg);
  font-family: inherit; font-size: 14px; cursor: pointer;
}
.msg-menu button:hover { background: var(--menu-hover); }
.msg-menu button.danger { color: var(--danger); }

/* ── Sidebar (hidden v1, kept for future) ───────────────────────────────────── */
.sidebar {
  width: 260px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--sidebar-bg);
}
.sidebar-hd {
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 12px;
  flex-shrink: 0;
}
.sidebar-brand { flex: 1; font-size: 14px; font-weight: 500; color: var(--fg); }
.rooms-list { flex: 1; overflow-y: auto; padding: 8px; }
.room-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px;
  border: none; background: none; color: var(--fg);
  font-family: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.room-item:hover { background: var(--menu-hover); }
.room-item.active { background: var(--surface); }
.room-ava {
  width: 32px; height: 32px; flex-shrink: 0;
  background: var(--surface); display: flex; align-items: center;
  justify-content: center; font-size: 14px; font-weight: 600; color: var(--muted);
}
.room-info { flex: 1; min-width: 0; }
.room-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-sub  { font-size: 12px; color: var(--muted); margin-top: 1px; }
.room-dot  { width: 6px; height: 6px; border-radius: 50%; background: #34c759; flex-shrink: 0; }
.icon-btn {
  width: 36px; height: 36px; border: none; background: none;
  color: var(--fg); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.icon-btn:hover { background: var(--menu-hover); }
