/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --purple:     #7B2FBE;
  --purple-dim: #5a1f8e;
  --purple-glow: rgba(123, 47, 190, .35);
  --bg:         #0e0e12;
  --surface:    #1a1a24;
  --surface-2:  #242434;
  --text:       #e8e6f0;
  --text-dim:   #9590a8;
  --user-bg:    #2a1f48;
  --bot-bg:     #1e1e2c;
  --radius:     14px;
  --header-h:   56px;
  --input-h:    72px;
}

html { font-size: 15px; }

/* CRITICAL: generic hidden utility — without this, every element that
   toggles class="hidden" (auth fields, error bar, app layout) stays visible. */
.hidden { display: none !important; }

body {
  /* System Hebrew faces only - no web fonts.
     Order matters: a Hebrew-capable face must come before Segoe UI,
     which has no Hebrew glyphs at all. */
  font-family: 'Segoe UI', 'Arial Hebrew', 'Noto Sans Hebrew', Arial, sans-serif;
  font-weight: 400;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh; /* dynamic viewport: excludes mobile browser chrome so the input bar stays visible */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  direction: rtl;
}

/* ===== Header ===== */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid #2a2a3a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 10;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-circle {
  animation: gentle-bounce 3s ease-in-out infinite;
}

@keyframes gentle-bounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .3px;
  color: var(--text);
}

.header-controls { display: flex; gap: 8px; }

.ctrl-btn {
  background: var(--surface-2);
  border: 1px solid #333348;
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .85rem;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all .2s;
}
.ctrl-btn:hover {
  border-color: var(--purple);
  color: var(--text);
  background: rgba(123,47,190,.12);
}

/* Transient "searching the web" note - disappears when the answer starts */
.searching-note {
  font-size: .78rem;
  color: var(--text-dim);
  padding: 4px 10px;
  margin-top: 4px;
  align-self: flex-start;
  animation: fade-in .25s ease;
}
.searching-note .dots span {
  animation: dot-pulse 1.2s ease-in-out infinite;
  display: inline-block;
}
.searching-note .dots span:nth-child(2) { animation-delay: .15s; }
.searching-note .dots span:nth-child(3) { animation-delay: .3s; }

/* ===== Chat container ===== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar { width: 6px; }
.chat-container::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

/* Welcome */
.welcome-msg {
  text-align: center;
  margin: auto;
  padding: 40px 20px;
}
.welcome-smiley { margin-bottom: 16px; animation: gentle-bounce 3s ease-in-out infinite; }
.welcome-msg h2 { font-size: 1.4rem; margin-bottom: 8px; }
.welcome-msg p  { color: var(--text-dim); font-size: .95rem; line-height: 1.6; }

/* Message bubbles */
.msg-row {
  display: flex;
  gap: 10px;
  max-width: min(88%, 48rem);
  animation: fade-slide-in .35s ease both;
}
/* short questions shouldn't stretch to full width */
.msg-row.user .msg-bubble { max-width: 100%; }
/* Both speakers align to the same edge - the conversation reads as one column
   instead of ping-ponging between sides. Speaker is distinguished by the
   avatar and the bubble colour, not by position. */
.msg-row.user  { align-self: flex-start; }
.msg-row.bot   { align-self: flex-start; }

@keyframes fade-slide-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  margin-top: 4px;
}
.msg-row.bot .msg-avatar  { background: var(--purple); }
.msg-row.user .msg-avatar { background: var(--surface-2); }

.msg-bubble {
  padding: 14px 18px;
  border-radius: var(--radius);
  line-height: 1.7;
  font-size: .95rem;
  font-weight: 400;
  position: relative;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ===== FIX 5: rendered markdown inside bubbles ===== */
.msg-bubble.md { white-space: normal; }

/* Text still streaming in - shown plain until it is complete */
.md-pending {
  white-space: pre-wrap;
  display: inline;
}
.md-done > *:first-child { margin-top: 0; }
.md-done > *:last-child  { margin-bottom: .35em; }

.msg-bubble.md > *:first-child { margin-top: 0; }
/* keep the first line clear of the copy pill */
.msg-row.bot .msg-bubble { padding-top: 16px; }
.msg-bubble.md > *:last-child  { margin-bottom: 0; }

.msg-bubble.md p {
  margin: 0 0 .85em;           /* real paragraph spacing */
}

.msg-bubble.md strong {
  font-weight: 600;
  color: #fff;                 /* emphasis actually reads as emphasis */
}

.msg-bubble.md em { font-style: italic; opacity: .95; }

.msg-bubble.md h1,
.msg-bubble.md h2,
.msg-bubble.md h3 {
  font-weight: 600;
  line-height: 1.35;
  margin: 1.1em 0 .5em;
  color: #fff;
}
.msg-bubble.md h1 { font-size: 1.25rem; }
.msg-bubble.md h2 { font-size: 1.15rem; }
.msg-bubble.md h3 { font-size: 1.05rem; }

.msg-bubble.md ul,
.msg-bubble.md ol {
  margin: .3em 0 .9em;
  padding-inline-start: 1.4em;
}
.msg-bubble.md li { margin: .3em 0; }

.msg-bubble.md hr {
  border: none;
  border-top: 1px solid rgba(123, 47, 190, .3);
  margin: 1.1em 0;
}

.msg-bubble.md blockquote {
  margin: .6em 0;
  padding-inline-start: 12px;
  border-inline-start: 3px solid var(--purple);
  color: var(--text-dim);
}

.msg-bubble.md code {
  background: rgba(0, 0, 0, .35);
  border: 1px solid #33334a;
  border-radius: 5px;
  padding: 1px 6px;
  font-family: 'SF Mono', Consolas, monospace;
  font-size: .88em;
  direction: ltr;
  display: inline-block;
}

.msg-bubble.md pre {
  background: #12121b;
  border: 1px solid #2a2a3a;
  border-radius: 10px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: .7em 0;
  direction: ltr;
  text-align: left;
}
.msg-bubble.md pre code {
  background: none;
  border: none;
  padding: 0;
  display: block;
  line-height: 1.55;
}

.msg-bubble.md a { color: #c89bff; text-decoration: underline; }
.msg-bubble.md a:hover { color: #e0bbff; }

.msg-bubble.md table {
  border-collapse: collapse;
  margin: .7em 0;
  font-size: .92em;
  width: 100%;
}
.msg-bubble.md th,
.msg-bubble.md td {
  border: 1px solid #33334a;
  padding: 6px 10px;
  text-align: start;
}
.msg-bubble.md th { background: rgba(123, 47, 190, .15); font-weight: 600; }
/* Both bubbles sit on the same side, so the speaker is signalled by colour
   and by a purple edge on the user's side rather than by position. */
.msg-row.user .msg-bubble {
  background: var(--user-bg);
  border-top-right-radius: 4px;
  border-inline-start: 2px solid var(--purple);
}
.msg-row.bot .msg-bubble {
  background: var(--bot-bg);
  border-top-right-radius: 4px;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}

/* Copy button - matches the pill styling used by suggestion chips and controls */
.copy-btn {
  position: absolute;
  top: 8px;
  left: 10px;
  background: var(--surface-2);
  border: 1px solid rgba(123, 47, 190, .4);
  color: var(--text-dim);
  border-radius: 14px;
  padding: 4px 11px;
  cursor: pointer;
  font-size: .74rem;
  font-family: inherit;
  line-height: 1.4;
  opacity: 0;
  transition: opacity .2s ease, border-color .2s ease,
              color .2s ease, background .2s ease, box-shadow .2s ease;
}
.msg-bubble:hover .copy-btn,
.copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover {
  color: var(--text);
  border-color: var(--purple);
  background: rgba(123, 47, 190, .16);
  box-shadow: 0 0 10px rgba(123, 47, 190, .3);
}
.copy-btn:active { transform: scale(.95); }

/* LTR: the button sits on the other side */
body[dir="ltr"] .copy-btn { left: auto; right: 10px; }

/* Typing indicator */
.typing-dots {
  display: inline-flex;
  gap: 5px;
  padding: 14px 18px;
}
.typing-dots span {
  width: 8px; height: 8px;
  background: var(--purple);
  border-radius: 50%;
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes dot-pulse {
  0%, 80%, 100% { transform: scale(.6); opacity: .4; }
  40%           { transform: scale(1);   opacity: 1; }
}

/* ===== Input bar ===== */
.input-bar {
  flex-shrink: 0;
  padding: 12px 20px 18px;
  background: var(--surface);
  border-top: 1px solid #2a2a3a;
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid #333348;
  border-radius: 14px;
  padding: 8px 14px;
  transition: border-color .25s;
}
.input-wrap:focus-within { border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-glow); }

#userInput {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: .95rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 140px;
  font-family: inherit;
  direction: rtl;
}
#userInput::placeholder { color: var(--text-dim); }

.send-btn {
  width: 40px; height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--purple);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s, transform .15s;
}
.send-btn:hover { background: var(--purple-dim); }
.send-btn:active { transform: scale(.93); }

/* ===== Memory Modal ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fade-in .2s ease;
}
.overlay.hidden { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid #333;
  border-radius: 16px;
  width: 420px;
  max-width: 92vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: modal-pop .25s ease;
}
@keyframes modal-pop {
  from { transform: scale(.92); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #2a2a3a;
}
.modal-header h3 { font-size: 1.05rem; }
.close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.4rem;
  cursor: pointer;
}
.close-btn:hover { color: var(--text); }

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.memory-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }

.mem-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: .9rem;
  animation: fade-slide-in .25s ease both;
}
.mem-item .mem-key {
  color: var(--purple);
  font-weight: 600;
  min-width: 60px;
}
.mem-item .mem-val { flex: 1; color: var(--text); }
.mem-item .mem-del {
  background: none;
  border: none;
  color: #c44;
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.mem-item .mem-del:hover { background: rgba(200,60,60,.15); }

.mem-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 20px;
  font-size: .9rem;
}

.memory-add {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.memory-add input {
  flex: 1;
  min-width: 80px;
  border: 1px solid #333;
  background: var(--bg);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: .88rem;
  outline: none;
}
.memory-add input:focus { border-color: var(--purple); }

.add-mem-btn {
  background: var(--purple);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .88rem;
  white-space: nowrap;
  transition: background .2s;
}
.add-mem-btn:hover { background: var(--purple-dim); }

/* ===== HTML file action bar ===== */
.html-file-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin: -6px 0 10px;
  margin-inline-start: 42px;
  background: var(--surface-2);
  border: 1px solid #333348;
  border-radius: 12px;
  animation: fade-slide-in .3s ease both;
  flex-wrap: wrap;
}
.html-file-label {
  font-size: .85rem;
  color: var(--text-dim);
  margin-inline-start: auto;
}
.html-file-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: .84rem;
  text-decoration: none;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}
.html-file-btn.open {
  background: var(--purple);
  color: #fff;
}
.html-file-btn.open:hover {
  background: var(--purple-dim);
}
.html-file-btn.download {
  background: var(--surface);
  color: var(--text);
  border: 1px solid #444;
}
.html-file-btn.download:hover {
  border-color: var(--purple);
  color: var(--purple);
}

/* ===== Arcs section ===== */
.arcs-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #2a2a3a;
}
.arcs-title {
  font-size: .92rem;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.arcs-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.arc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: .88rem;
  animation: fade-slide-in .25s ease both;
}
.arc-arrow {
  color: var(--purple);
  font-weight: 700;
  flex-shrink: 0;
}
.arc-from, .arc-to {
  color: var(--text);
}
.arc-date {
  color: var(--text-dim);
  font-size: .78rem;
  margin-right: auto;
  margin-left: 8px;
}
.arc-del {
  background: none;
  border: none;
  color: #c44;
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.arc-del:hover { background: rgba(200,60,60,.15); }
.arc-add { margin-top: 4px; }

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .msg-row { max-width: 92%; }
  .brand-name { font-size: .88rem; }
  .ctrl-btn span.ctrl-icon + span { display: none; }
  .modal { width: 96vw; }
  /* the header controls can overflow on narrow screens — let the row scroll
     horizontally instead of clipping buttons off the edge */
  .header { gap: 8px; }
  .header-controls {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;              /* hide the scrollbar (Firefox) */
    max-width: 100%;
    /* subtle fade on the leading edge as a hint that the row scrolls.
       purely visual (mask only affects painting, not layout or scrolling).
       RTL: content continues to the LEFT, so fade the left edge. */
    -webkit-mask-image: linear-gradient(to left, #000 82%, transparent 100%);
            mask-image: linear-gradient(to left, #000 82%, transparent 100%);
  }
  .header-controls::-webkit-scrollbar { display: none; }  /* hide (WebKit) */
  .header-controls .ctrl-btn,
  .header-controls .streak-chip { flex: 0 0 auto; }        /* don't shrink/clip */
}
/* LTR: content continues to the RIGHT, fade the right edge instead */
@media (max-width: 600px) {
  body[dir="ltr"] .header-controls {
    -webkit-mask-image: linear-gradient(to right, #000 82%, transparent 100%);
            mask-image: linear-gradient(to right, #000 82%, transparent 100%);
  }
}

/* ===== Auth screen ===== */
.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.auth-card {
  background: var(--surface);
  border: 1px solid #2a2a3a;
  border-radius: 20px;
  padding: 36px 32px;
  width: 360px;
  max-width: 92vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  animation: modal-pop .3s ease;
}
.auth-logo { animation: gentle-bounce 3s ease-in-out infinite; margin-bottom: 4px; }
.auth-card h2 { font-size: 1.25rem; margin-bottom: 4px; }
.auth-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #333348;
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  font-size: .95rem;
  outline: none;
  font-family: inherit;
}
.auth-input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px var(--purple-glow); }
.auth-submit {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--purple);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
  font-family: inherit;
}
.auth-submit:hover { background: var(--purple-dim); }
.auth-submit:disabled { opacity: .6; cursor: default; }
.auth-error {
  width: 100%;
  background: rgba(200,60,60,.12);
  border: 1px solid rgba(200,60,60,.35);
  color: #e58;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: .85rem;
  text-align: center;
}
.auth-switch { font-size: .85rem; color: var(--text-dim); }
.auth-switch a { color: var(--purple); text-decoration: none; margin-right: 4px; }
.auth-switch a:hover { text-decoration: underline; }

/* ===== App layout with sidebar ===== */
.app-layout { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 260px;
  flex-shrink: 0;
  /* use theme variables so the sidebar matches the selected theme */
  background: var(--surface);
  /* logical property: becomes left border in RTL, right border in LTR */
  border-inline-end: 1px solid var(--surface-2);
  display: flex;
  flex-direction: column;
  transition: margin-inline-start .25s ease;
}
.sidebar.collapsed { margin-inline-start: -260px; }

.sidebar-top { padding: 14px; }
.new-chat-btn {
  width: 100%;
  padding: 11px;
  border: 1px solid #333348;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
  font-size: .92rem;
  font-family: inherit;
  transition: all .2s;
}
.new-chat-btn:hover { border-color: var(--purple); background: rgba(123,47,190,.12); }

.conv-list { flex: 1; overflow-y: auto; padding: 0 8px; display: flex; flex-direction: column; gap: 3px;
  /* subtle bottom fade hints there are more conversations to scroll to.
     mask affects painting only — scrolling and layout are untouched. */
  -webkit-mask-image: linear-gradient(to bottom, #000 90%, transparent 100%);
          mask-image: linear-gradient(to bottom, #000 90%, transparent 100%);
}
.conv-list::-webkit-scrollbar { width: 5px; }
.conv-list::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .88rem;
  color: var(--text-dim);
  transition: all .15s;
}
.conv-item:hover { background: var(--surface-2); color: var(--text); }
.conv-item.active { background: rgba(123,47,190,.18); color: var(--text); }
.conv-item .conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .conv-del {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: .9rem; opacity: 0; padding: 2px 4px; border-radius: 4px;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-item .conv-del:hover { color: #c44; background: rgba(200,60,60,.15); }

.sidebar-bottom {
  padding: 12px 14px;
  border-top: 1px solid var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.user-chip { display: flex; align-items: center; gap: 8px; overflow: hidden; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--purple); display: flex; align-items: center; justify-content: center;
  font-size: .9rem; flex-shrink: 0;
}
.user-name { font-size: .88rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn {
  background: none; border: 1px solid #333348; color: var(--text-dim);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 1rem; flex-shrink: 0;
}
.logout-btn:hover { border-color: #c44; color: #c44; }

.main-col { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.sidebar-toggle {
  background: none; border: none; color: var(--text-dim);
  font-size: 1.3rem; cursor: pointer; padding: 0 4px; margin-left: 4px;
}
.sidebar-toggle:hover { color: var(--text); }

@media (max-width: 700px) {
  /* Mobile: sidebar is an overlay. Use PHYSICAL right/left + explicit pixel
     translate so RTL/LTR both hide correctly (translateX(%) flips under RTL,
     so we use fixed px values tied to the physical edge instead). */
  .sidebar { position: fixed; inset-block: 0; right: 0; left: auto;
             width: 260px;
             z-index: 150; box-shadow: -4px 0 20px rgba(0,0,0,.4);
             transition: transform .25s ease; margin-inline-start: 0;
             transform: translateX(0); }
  /* collapsed = pushed off the RIGHT edge by its own width */
  .sidebar.collapsed { transform: translateX(280px); margin-inline-start: 0; }
  /* backdrop: tap outside the open sidebar to close it */
  .sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.5);
    z-index: 140; opacity: 0; pointer-events: none; transition: opacity .25s ease;
  }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
}
/* LTR mobile: sidebar sits on the LEFT, hides to the left */
@media (max-width: 700px) {
  body[dir="ltr"] .sidebar { left: 0; right: auto; }
  body[dir="ltr"] .sidebar.collapsed { transform: translateX(-280px); }
}

/* ===== Language toggle ===== */
.lang-toggle-auth {
  position: fixed;
  top: 18px;
  left: 18px;
  background: var(--surface-2);
  border: 1px solid #333348;
  color: var(--text-dim);
  padding: 6px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  z-index: 210;
  transition: all .2s;
}
.lang-toggle-auth:hover { border-color: var(--purple); color: var(--text); }

/* LTR (English) overrides — body[dir] drives direction */
body[dir="ltr"] .lang-toggle-auth { left: auto; right: 18px; }
body[dir="ltr"] .msg-row.user { align-self: flex-start; flex-direction: row; }
body[dir="ltr"] .header { direction: ltr; }
body[dir="ltr"] .msg-bubble { text-align: left; }
body[dir="ltr"] .chat-container { direction: ltr; }
body[dir="ltr"] .input-bar,
body[dir="ltr"] .sidebar,
body[dir="ltr"] .modal { direction: ltr; }
body[dir="ltr"] .auth-card { direction: ltr; }
body[dir="ltr"] #userInput { direction: ltr; text-align: left; }

@media (max-width: 700px) {
  body[dir="ltr"] .sidebar { box-shadow: 4px 0 20px rgba(0,0,0,.4); }
}

/* ===== Prompt suggestions (memory-aware conversation starters) ===== */
.suggestions-box {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  animation: suggestions-in .4s ease both;
}

@keyframes suggestions-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.suggestion-chip {
  background: var(--surface-2);
  border: 1px solid rgba(123, 47, 190, .4);
  color: var(--text-dim);
  padding: 8px 15px;
  border-radius: 20px;
  font-size: .85rem;
  font-family: inherit;
  cursor: pointer;
  transition: all .22s ease;
  animation: chip-pop .35s ease both;
  box-shadow: 0 0 0 rgba(123, 47, 190, 0);
}

.suggestion-chip:nth-child(1) { animation-delay: 0s; }
.suggestion-chip:nth-child(2) { animation-delay: .05s; }
.suggestion-chip:nth-child(3) { animation-delay: .1s; }
.suggestion-chip:nth-child(4) { animation-delay: .15s; }
.suggestion-chip:nth-child(5) { animation-delay: .2s; }

@keyframes chip-pop {
  from { opacity: 0; transform: scale(.92) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.suggestion-chip:hover {
  color: var(--text);
  border-color: var(--purple);
  background: rgba(123, 47, 190, .14);
  box-shadow: 0 0 14px rgba(123, 47, 190, .35);
  transform: translateY(-1px);
}

.suggestion-chip:active { transform: scale(.96); }

/* subtle neon breathing so it reads as "alive", matching the logo bounce */
.suggestions-box.glow .suggestion-chip {
  animation: chip-pop .35s ease both, chip-breathe 3.5s ease-in-out infinite;
}

@keyframes chip-breathe {
  0%, 100% { border-color: rgba(123, 47, 190, .4); }
  50%      { border-color: rgba(123, 47, 190, .75); }
}

/* =====================================================================
   v16 — Interactive extras: themes, mascot, streak, fun & settings,
   choice chips, message reactions. All additive; nothing above changed.
   ===================================================================== */

/* ---- Theme accent recolours every smiley face (logo, avatars, mascot) ---- */
svg circle[fill="#7B2FBE"] { fill: var(--purple); transition: fill .3s ease; }

/* ---- Alternate themes (midnight = default :root, no override needed) ---- */
body[data-theme="sunset"] {
  --purple: #e0724a; --purple-dim: #b8552f; --purple-glow: rgba(224,114,74,.35);
  --bg: #17110f; --surface: #241a16; --surface-2: #2f231d;
  --text: #f2e9e3; --text-dim: #b6a091; --user-bg: #3a251b; --bot-bg: #241a16;
}
body[data-theme="forest"] {
  --purple: #3fa06b; --purple-dim: #2c7d50; --purple-glow: rgba(63,160,107,.35);
  --bg: #0d1310; --surface: #16211b; --surface-2: #1f2d25;
  --text: #e6f0ea; --text-dim: #8fae9c; --user-bg: #1c3327; --bot-bg: #16211b;
}
body[data-theme="mono"] {
  --purple: #8a8fa3; --purple-dim: #6a6f82; --purple-glow: rgba(138,143,163,.30);
  --bg: #0f1013; --surface: #191a20; --surface-2: #23242c;
  --text: #e7e8ee; --text-dim: #9a9ba8; --user-bg: #262832; --bot-bg: #191a20;
}
body { transition: background .3s ease, color .3s ease; }

/* ---- Streak chip in header ---- */
.streak-chip {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface-2); border: 1px solid rgba(255,150,40,.35);
  color: var(--text); padding: 6px 11px; border-radius: 8px;
  cursor: pointer; font-size: .85rem; font-family: inherit; transition: all .2s;
}
.streak-chip:hover { border-color: #ff9a28; box-shadow: 0 0 12px rgba(255,150,40,.3); }
.streak-fire { filter: saturate(1.2); }
.streak-chip.pulse { animation: streak-pop .5s ease; }
@keyframes streak-pop { 0%{transform:scale(1);} 40%{transform:scale(1.25);} 100%{transform:scale(1);} }

/* ---- Floating mascot ---- */
.mascot {
  position: fixed; inset-inline-start: 20px; bottom: 20px;
  width: 58px; height: 58px; border-radius: 50%;
  border: none; padding: 0; cursor: pointer; z-index: 90;
  background: transparent; filter: drop-shadow(0 6px 14px rgba(0,0,0,.4));
  transition: transform .2s ease, filter .2s ease;
  animation: mascot-float 4s ease-in-out infinite;
}
.mascot:hover { transform: scale(1.08) rotate(-3deg); filter: drop-shadow(0 8px 18px var(--purple-glow)); }
.mascot:active { transform: scale(.94); }
.mascot .mascot-face { display: block; width: 100%; height: 100%; }
.mascot .mascot-face svg { width: 100%; height: 100%; display: block; }
@keyframes mascot-float { 0%,100%{ transform: translateY(0); } 50%{ transform: translateY(-5px); } }

/* thinking: quick eager bounce while Chattly is answering */
.mascot.thinking { animation: mascot-think .5s ease-in-out infinite; }
@keyframes mascot-think { 0%,100%{ transform: translateY(0) scale(1);} 50%{ transform: translateY(-8px) scale(1.05);} }

/* happy: a little joyful pop (e.g. after copy) */
.mascot.happy { animation: mascot-happy .6s ease; }
@keyframes mascot-happy { 0%{transform:scale(1);} 30%{transform:scale(1.2) rotate(8deg);} 60%{transform:scale(1.1) rotate(-6deg);} 100%{transform:scale(1);} }

/* sleepy: dim + floating Zzz after a long idle */
.mascot.sleepy { animation: none; opacity: .72; }
.mascot .mascot-zzz {
  position: absolute; top: -6px; inset-inline-end: -4px;
  font-size: .8rem; color: var(--text-dim); opacity: 0; font-style: italic;
}
.mascot.sleepy .mascot-zzz { animation: zzz 2.2s ease-in-out infinite; }
@keyframes zzz { 0%{opacity:0; transform:translateY(0) scale(.8);} 40%{opacity:.9;} 100%{opacity:0; transform:translateY(-14px) scale(1.1);} }

/* blink: eyes close briefly at rest */
.mascot .m-eye { animation: mascot-blink 5s infinite; transform-origin: center; transform-box: fill-box; }
@keyframes mascot-blink { 0%,92%,100%{ transform: scaleY(1);} 96%{ transform: scaleY(.1);} }
.mascot.thinking .m-eye, .mascot.sleepy .m-eye { animation: none; }

@media (max-width: 700px) {
  .mascot { width: 48px; height: 48px; inset-inline-start: 14px; bottom: 84px; }
}

/* ---- Fun corner ---- */
.fun-sub { color: var(--text-dim); font-size: .85rem; margin-bottom: 14px; }
.fun-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fun-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  text-align: start; background: var(--surface-2); border: 1px solid #333348;
  border-radius: 12px; padding: 14px; cursor: pointer; font-family: inherit;
  color: var(--text); transition: all .18s ease;
}
.fun-card:hover { border-color: var(--purple); background: rgba(123,47,190,.12);
  transform: translateY(-2px); box-shadow: 0 6px 16px var(--purple-glow); }
.fun-card:active { transform: scale(.97); }
.fun-card-emoji { font-size: 1.5rem; }
.fun-card-title { font-weight: 600; font-size: .95rem; }
.fun-card-desc { font-size: .78rem; color: var(--text-dim); }

/* vibe picker */
.vibe-picker { margin-top: 16px; border-top: 1px solid #2a2a3a; padding-top: 14px; }
.vibe-prompt { font-size: .9rem; margin-bottom: 10px; color: var(--text); }
.vibe-moods { display: flex; flex-wrap: wrap; gap: 8px; }
.vibe-mood {
  font-size: 1.6rem; line-height: 1; background: var(--surface-2);
  border: 1px solid #333348; border-radius: 12px; width: 52px; height: 52px;
  cursor: pointer; transition: all .16s ease;
}
.vibe-mood:hover { border-color: var(--purple); transform: translateY(-2px) scale(1.06);
  box-shadow: 0 4px 12px var(--purple-glow); }
.vibe-mood:active { transform: scale(.94); }

/* ---- Settings ---- */
.settings-block { margin-bottom: 20px; }
.settings-block:last-child { margin-bottom: 4px; }
.settings-label { font-size: .95rem; margin-bottom: 10px; color: var(--text); }

.settings-streak {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border: 1px solid rgba(255,150,40,.3);
  border-radius: 12px; padding: 14px;
}
.settings-streak-fire { font-size: 1.8rem; }
.settings-streak-count { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.settings-streak-best { font-size: .8rem; color: var(--text-dim); }

.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.theme-swatch {
  display: flex; align-items: center; gap: 9px; background: var(--surface-2);
  border: 1px solid #333348; border-radius: 10px; padding: 9px 11px;
  cursor: pointer; font-family: inherit; color: var(--text-dim); font-size: .85rem;
  transition: all .16s ease;
}
.theme-swatch:hover { color: var(--text); border-color: var(--purple); }
.theme-swatch.active { color: var(--text); border-color: var(--purple);
  background: rgba(123,47,190,.14); box-shadow: 0 0 0 2px var(--purple-glow); }
.theme-swatch .sw { width: 20px; height: 20px; border-radius: 6px; flex-shrink: 0; border: 1px solid rgba(255,255,255,.12); }
.sw-midnight { background: linear-gradient(135deg,#7B2FBE,#0e0e12); }
.sw-sunset   { background: linear-gradient(135deg,#e0724a,#17110f); }
.sw-forest   { background: linear-gradient(135deg,#3fa06b,#0d1310); }
.sw-mono     { background: linear-gradient(135deg,#8a8fa3,#0f1013); }

/* toggle switch */
.settings-switch { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; cursor: pointer; font-size: .9rem; color: var(--text); user-select: none; }
.settings-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { width: 44px; height: 24px; border-radius: 12px; background: var(--surface-2);
  border: 1px solid #333348; position: relative; transition: all .2s ease; flex-shrink: 0; }
.switch-thumb { position: absolute; top: 2px; inset-inline-start: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--text-dim); transition: all .2s ease; }
.settings-switch input:checked + .switch-track { background: rgba(123,47,190,.4); border-color: var(--purple); }
.settings-switch input:checked + .switch-track .switch-thumb { inset-inline-start: 22px; background: var(--purple); }

.face-label { font-size: .82rem; color: var(--text-dim); margin: 14px 0 8px; }
.face-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 8px; }
.face-opt {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  background: var(--surface-2); border: 1px solid #333348; border-radius: 10px;
  padding: 9px 4px; cursor: pointer; font-family: inherit; color: var(--text-dim);
  font-size: .72rem; transition: all .16s ease;
}
.face-opt:hover { border-color: var(--purple); color: var(--text); }
.face-opt.active { border-color: var(--purple); color: var(--text);
  background: rgba(123,47,190,.14); box-shadow: 0 0 0 2px var(--purple-glow); }
.face-preview { width: 30px; height: 30px; display: block; }
.face-preview svg { width: 100%; height: 100%; }

/* ---- Active mode banner (above the input) ---- */
.mode-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(123,47,190,.14); border: 1px solid var(--purple);
  border-radius: 12px; padding: 7px 12px; margin-bottom: 10px;
  animation: suggestions-in .3s ease both;
}
.mode-banner-text { font-size: .85rem; color: var(--text); font-weight: 600; }
.mode-exit-btn {
  background: none; border: 1px solid #333348; color: var(--text-dim);
  border-radius: 8px; padding: 4px 12px; cursor: pointer; font-size: .8rem; font-family: inherit;
  transition: all .16s ease;
}
.mode-exit-btn:hover { border-color: #c44; color: #c44; }

/* ---- Choice chips (story / would-you-rather branches) ---- */
.choice-chips { display: flex; flex-wrap: wrap; gap: 8px;
  align-self: flex-start; margin-block: 4px; margin-inline-start: 46px; max-width: min(88%, 48rem); }
.choice-chip {
  background: var(--surface-2); border: 1px solid rgba(123,47,190,.5);
  color: var(--text); padding: 8px 15px; border-radius: 14px; font-size: .86rem;
  font-family: inherit; cursor: pointer; transition: all .18s ease;
  animation: chip-pop .35s ease both;
}
.choice-chip:hover { border-color: var(--purple); background: rgba(123,47,190,.16);
  box-shadow: 0 0 14px var(--purple-glow); transform: translateY(-1px); }
.choice-chip:active { transform: scale(.96); }

/* ---- Message reactions (sibling row, hugs its message) ---- */
.msg-reactions { display: flex; align-items: center; gap: 5px;
  align-self: flex-start; margin-top: -6px; min-height: 18px; padding-inline-start: 46px; }
body[dir="ltr"] .msg-reactions { align-self: flex-start; }
.react-toggle {
  background: none; border: none; cursor: pointer; font-size: .8rem;
  color: var(--text-dim); opacity: 0; transition: opacity .15s ease; padding: 2px 4px; border-radius: 6px;
}
.msg-row:hover .react-toggle { opacity: .7; }
.react-toggle:hover { opacity: 1; background: var(--surface-2); }
.react-picker {
  display: none; gap: 3px; background: var(--surface-2); border: 1px solid #333348;
  border-radius: 12px; padding: 3px 6px;
}
.react-picker.open { display: inline-flex; animation: chip-pop .2s ease both; }
.react-picker button { background: none; border: none; cursor: pointer; font-size: 1rem;
  padding: 2px; border-radius: 6px; transition: transform .12s ease; }
.react-picker button:hover { transform: scale(1.3); }
.react-badge {
  display: inline-flex; align-items: center; gap: 3px; background: rgba(123,47,190,.14);
  border: 1px solid rgba(123,47,190,.4); border-radius: 12px; padding: 1px 8px;
  font-size: .85rem; cursor: pointer;
}
.react-badge:hover { border-color: var(--purple); }

/* =====================================================================
   V17 — Saga (ספר המסע), proactive outreach, and the crisis card.
   All additive; nothing above is changed. Uses the existing theme vars,
   so it recolours automatically with every theme.
   ===================================================================== */

/* ---- Saga modal content ---- */
.saga-content { display: flex; flex-direction: column; gap: 6px; }
.saga-section-title {
  font-size: .82rem; color: var(--text-dim); font-weight: 700;
  letter-spacing: .3px; margin: 14px 0 8px;
}
.saga-content .saga-section-title:first-child { margin-top: 4px; }

.saga-arcs { display: flex; flex-direction: column; gap: 8px; }
.saga-arc {
  background: var(--surface-2); border: 1px solid rgba(123,47,190,.22);
  border-radius: 12px; padding: 10px 13px;
  animation: fade-slide-in .25s ease both;
}
.saga-arc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: .9rem; }
.saga-arc .arc-from { color: var(--text-dim); }
.saga-arc .arc-to { color: var(--purple); font-weight: 600; }
.saga-arc .arc-arrow { color: var(--text-dim); }
.saga-arc .arc-date { margin-inline-start: auto; font-size: .72rem; color: var(--text-dim); opacity: .8; }
.saga-arc-sum { margin-top: 5px; font-size: .82rem; color: var(--text-dim); line-height: 1.4; }

.saga-insights { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.saga-insights li {
  position: relative; padding: 9px 13px 9px 30px;
  background: var(--surface-2); border-radius: 10px;
  font-size: .87rem; line-height: 1.45; color: var(--text);
  animation: fade-slide-in .25s ease both;
}
body[dir="ltr"] .saga-insights li { padding: 9px 30px 9px 13px; }
.saga-insights li::before {
  content: "💡"; position: absolute; inset-inline-start: 9px; top: 8px; font-size: .82rem;
}

.saga-lang { display: flex; flex-direction: column; gap: 7px; }
.saga-lang-item {
  display: flex; flex-direction: column; gap: 2px;
  background: rgba(123,47,190,.10); border: 1px solid rgba(123,47,190,.28);
  border-radius: 10px; padding: 9px 13px;
  animation: fade-slide-in .25s ease both;
}
.saga-term { color: var(--purple); font-weight: 700; font-size: .88rem; }
.saga-mean { color: var(--text-dim); font-size: .8rem; line-height: 1.4; }

/* ---- Proactive outreach: Chattly opened the conversation itself ---- */
.msg-row.proactive-msg .msg-bubble { position: relative; }
.msg-row.proactive-msg .msg-bubble::before {
  content: attr(data-proactive-label);
  display: block; font-size: .72rem; font-weight: 700; letter-spacing: .2px;
  color: var(--purple); opacity: .95; margin-bottom: 7px;
}
.msg-row.proactive-msg .msg-bubble {
  border: 1px solid rgba(123,47,190,.35);
  box-shadow: 0 0 16px rgba(123,47,190,.14);
}

/* ---- Crisis response: calm, supportive, never alarming ----
   A soft teal accent (not red) so it reads as care, not danger. */
.msg-row.crisis-msg .msg-bubble {
  border-inline-start: 3px solid #4db6a4;
  background: linear-gradient(180deg, rgba(77,182,164,.08), var(--bot-bg));
}
.msg-row.crisis-msg .msg-bubble a { color: #6fd3c1; }
