/*
  Direction: a modern, quiet chat for long study sessions.
  - Heebo: a Hebrew sans drawn for screens, so long answers stay easy to read.
  - Frank Ruhl Libre on the wordmark only: the one nod to printed seforim.
  - One accent, tekhelet blue, used for the send action, focus and the source tag on the starters.
    Chosen because it belongs to the subject, not because it's a default.
  - User questions sit in tinted bubbles; answers run full width so long sources read like text,
    not like chat confetti.
  - Elevation only on the composer, because it floats over scrolling content.
  Dials: ENERGY 2 / RHYTHM 1 / MOTION 2 (new turns fade in, a typing indicator while waiting).
*/

:root {
  --font: 'Heebo', 'Segoe UI', 'Arial Hebrew', Arial, sans-serif;
  --font-mark: 'Frank Ruhl Libre', 'David', serif;
  --measure: 46rem;
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --ink: #1b1c1f;
  --ink-soft: #5c6068;
  --line: #e3e3df;
  --accent: #1e4b8f;
  --accent-ink: #ffffff;
  --bubble: #e7edf6;
  --bubble-ink: #14243d;
  --error-bg: #fdecea;
  --error-ink: #8f1d1d;
  --shadow: 0 6px 24px rgb(20 24 32 / 0.08), 0 1px 3px rgb(20 24 32 / 0.06);
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #121316;
  --surface: #1b1d21;
  --ink: #ececef;
  --ink-soft: #a5a9b1;
  --line: #2d3036;
  --accent: #8fb5f0;
  --accent-ink: #0e1726;
  --bubble: #1f2b3e;
  --bubble-ink: #e4ecf8;
  --error-bg: #3a1b1b;
  --error-ink: #f6bcbc;
  --shadow: 0 6px 24px rgb(0 0 0 / 0.4), 0 1px 3px rgb(0 0 0 / 0.3);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Keep scrolled-to turns clear of the sticky top bar and composer. */
html {
  scroll-padding-top: 5rem;
  scroll-padding-bottom: 9rem;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button,
label[for] {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem clamp(1rem, 4vw, 2rem);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  min-width: 0;
}

.wordmark {
  margin: 0;
  font-family: var(--font-mark);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
}

.corpora {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.ghost-btn,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  min-width: 44px;
  padding: 0 0.8rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-size: 0.95rem;
  font-weight: 500;
}

.icon-btn {
  padding: 0;
}

.ghost-btn:hover,
.icon-btn:hover {
  background: var(--surface);
  border-color: var(--line);
}

.ghost-btn:active,
.icon-btn:active {
  transform: scale(0.97);
}

:root[data-theme='light'] .icon-sun,
:root[data-theme='dark'] .icon-moon {
  display: none;
}

/* Thread */

.thread {
  flex: 1;
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2rem clamp(1rem, 4vw, 2rem) 1.5rem;
}

.empty {
  padding-top: clamp(1rem, 8vh, 4rem);
}

.empty h2 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  font-weight: 700;
  line-height: 1.25;
}

.empty > p {
  margin: 0 0 1.75rem;
  max-width: 38rem;
  color: var(--ink-soft);
}

.starters {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.starter {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: 100%;
  padding: 0.8rem 1rem;
  text-align: start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  line-height: 1.5;
  transition: border-color 0.15s, transform 0.15s;
}

.starter:hover {
  border-color: var(--accent);
}

.starter:active {
  transform: scale(0.99);
}

.starter-source {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
}

.turn {
  margin: 0 0 1.75rem;
  animation: turn-in 0.25s ease-out;
}

.turn-user {
  display: flex;
  justify-content: flex-start;
}

.turn-user .turn-body {
  max-width: min(85%, 34rem);
  padding: 0.65rem 1rem;
  background: var(--bubble);
  color: var(--bubble-ink);
  border-radius: var(--r-lg);
  border-start-start-radius: var(--r-sm);
  white-space: pre-wrap;
}

.turn-body {
  overflow-wrap: anywhere;
}

.turn-model .turn-body p {
  margin: 0 0 0.85rem;
}

.turn-model .turn-body ul,
.turn-model .turn-body ol {
  margin: 0 0 0.85rem;
  padding-inline-start: 1.4rem;
}

.turn-model .turn-body li {
  margin-bottom: 0.25rem;
}

.turn-model .turn-body > :last-child {
  margin-bottom: 0;
}

.turn-model strong {
  font-weight: 700;
}

/* Links to the passages the bot actually fetched, so every answer can be checked in the source. */
.sources {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.sources-title {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.sources ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.sources a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 0.85rem;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}

.sources a:hover {
  border-color: var(--accent);
  text-decoration: underline;
}

.sources a:active {
  transform: scale(0.98);
}

.answer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.answer-actions .ghost-btn {
  border-color: var(--line);
  background: var(--surface);
}

.answer-actions .ghost-btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.answer-actions .ghost-btn:disabled {
  opacity: 0.5;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink-soft);
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: dot 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.turn-error {
  margin: 0 0 1.75rem;
  padding: 0.85rem 1rem;
  background: var(--error-bg);
  color: var(--error-ink);
  border-radius: var(--r-md);
}

.turn-error p {
  margin: 0 0 0.6rem;
}

.turn-error .ghost-btn {
  border-color: currentColor;
}

@keyframes turn-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@keyframes dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}

/* Composer */

.dock {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 0 clamp(0.75rem, 4vw, 2rem) calc(0.6rem + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0.5rem;
  padding-inline-start: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

.composer:focus-within {
  border-color: var(--accent);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 40vh;
  padding: 0.55rem 0;
  background: transparent;
  border: 0;
  resize: none;
  line-height: 1.6;
}

/* The whole composer shows focus via :focus-within, so the inner outline would double it. */
.composer textarea:focus-visible {
  outline: none;
}

.composer textarea::placeholder {
  color: var(--ink-soft);
}

.send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 50%;
  transition: transform 0.15s, opacity 0.15s;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.06);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.send-btn:disabled {
  opacity: 0.45;
}

.fineprint {
  max-width: var(--measure);
  margin: 0.45rem auto 0;
  font-size: 0.78rem;
  line-height: 1.5;
  text-align: center;
  color: var(--ink-soft);
}

.primary-btn {
  min-height: 44px;
  padding: 0 1.25rem;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: var(--r-sm);
  font-weight: 700;
}

.primary-btn:hover {
  filter: brightness(1.1);
}

.primary-btn:active {
  transform: scale(0.97);
}

/* Access dialog */

.access-dialog {
  width: min(24rem, calc(100vw - 2rem));
  padding: 1.5rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow);
}

.access-dialog::backdrop {
  background: rgb(0 0 0 / 0.5);
}

.access-dialog h2 {
  margin: 0 0 0.4rem;
  font-size: 1.3rem;
}

.access-dialog p {
  margin: 0 0 1rem;
  color: var(--ink-soft);
}

.access-dialog label {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 500;
}

.access-dialog input {
  width: 100%;
  min-height: 44px;
  padding: 0 0.8rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}

.access-dialog input:focus-visible {
  border-color: var(--accent);
}

.access-dialog .access-error {
  margin-top: 0.6rem;
  padding: 0.35rem 0.7rem;
  background: var(--error-bg);
  color: var(--error-ink);
  border-radius: var(--r-sm);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
}

@media (max-width: 34rem) {
  .corpora {
    display: none;
  }

  .ghost-btn span {
    display: none;
  }

  .ghost-btn {
    padding: 0;
  }

  .turn-user .turn-body {
    max-width: 92%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .typing-dots span {
    opacity: 0.7;
  }
}
