:root {
  color-scheme: dark;
  --page-bg: #030914;
  --surface: rgba(15, 24, 38, 0.9);
  --surface-soft: rgba(23, 36, 55, 0.76);
  --border: rgba(142, 167, 199, 0.2);
  --border-strong: rgba(166, 190, 221, 0.36);
  --text: #f7f9fd;
  --muted: rgba(230, 237, 247, 0.66);
  --accent: #a9d1ff;
  --danger: #ffc4c4;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--page-bg);
}

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

.rishai-page {
  width: 100%;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background-image: url("/media/homepage-alpine-lake.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.rishai-page::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 16%, rgba(52, 92, 143, 0.2), transparent 46%),
    linear-gradient(180deg, rgba(2, 9, 20, 0.76), rgba(2, 9, 20, 0.86));
}

.rishai-frame {
  position: relative;
  width: calc(100% - 12px);
  height: calc(100dvh - 12px);
  min-height: 420px;
  margin: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(142, 167, 199, 0.24);
  border-radius: 18px;
  background: rgba(4, 12, 25, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.025), 0 24px 80px rgba(0, 0, 0, 0.24);
}

.rishai-header {
  z-index: 4;
  height: 0;
  min-height: 0;
  padding: 0 clamp(14px, 2vw, 30px);
  opacity: 0;
  transform: translateY(-12px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid transparent;
  transition: height 300ms ease, min-height 300ms ease, padding 300ms ease, opacity 240ms ease, transform 300ms ease, border-color 300ms ease;
}

.rishai-frame.has-conversation .rishai-header {
  height: 64px;
  min-height: 64px;
  padding-top: 8px;
  padding-bottom: 8px;
  opacity: 1;
  transform: none;
  overflow: visible;
  border-color: rgba(255, 255, 255, 0.06);
  background: rgba(3, 10, 21, 0.34);
  backdrop-filter: blur(18px);
}

.rishai-identity {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.rishai-header-actions { display: flex; align-items: center; gap: 8px; }

.quiet-button, .icon-button, .symbol-trigger, .send-button, .answer-control {
  border: 1px solid var(--border);
  background: rgba(10, 18, 31, 0.62);
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease, color 180ms ease;
}

.quiet-button:hover, .icon-button:hover, .symbol-trigger:hover, .answer-control:hover {
  border-color: var(--border-strong);
  background: rgba(33, 49, 72, 0.7);
}

.quiet-button { min-height: 42px; padding: 0 14px; border-radius: 11px; font-size: 14px; font-weight: 650; }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; padding: 0; }
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.rishai-main {
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(173, 196, 225, 0.34) transparent;
  scroll-behavior: smooth;
}

.rishai-welcome {
  width: min(900px, calc(100% - 32px));
  min-height: calc(100% - 8px);
  margin: 0 auto;
  padding: clamp(28px, 8vh, 90px) 0 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 320ms ease, transform 320ms ease, min-height 420ms ease, max-height 420ms ease, padding 420ms ease;
}

.rishai-welcome.is-hidden {
  min-height: 0;
  max-height: 0;
  padding: 0;
  opacity: 0;
  transform: translateY(-20px);
  overflow: hidden;
  pointer-events: none;
}

.rishai-logo {
  width: clamp(88px, 7vw, 108px);
  height: clamp(88px, 7vw, 108px);
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(192, 215, 242, 0.3);
  border-radius: 22px;
  object-fit: cover;
  display: block;
  background: rgba(6, 16, 31, 0.72);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.rishai-logo--small { width: 40px; height: 40px; border-radius: 11px; }

.rishai-welcome h1 {
  margin: 20px 0 10px;
  color: var(--text);
  font-size: clamp(52px, 5vw, 74px);
  line-height: 0.96;
  letter-spacing: -0.055em;
}

.rishai-welcome p { margin: 0; color: rgba(255, 255, 255, 0.75); font-size: clamp(17px, 1.5vw, 22px); line-height: 1.5; }
.grounding-note { margin-top: 12px; color: rgba(225, 235, 247, 0.48); font-size: 13px; line-height: 1.5; }

.rishai-conversation {
  width: min(1500px, calc(100% - 40px));
  margin: 0 auto;
  padding: 22px 0 44px;
  display: grid;
  gap: 22px;
}
.rishai-conversation:empty { display: none; }

.message-row { min-width: 0; }
.user-message {
  width: min(1080px, 88%);
  min-width: min(320px, 88%);
  margin-left: auto;
  padding: 18px 22px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid rgba(124, 157, 201, 0.22);
  border-radius: 18px 18px 5px 18px;
  background: rgba(34, 53, 82, 0.82);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
  color: var(--text);
  font-size: clamp(17px, 1.25vw, 20px);
  line-height: 1.58;
}
.user-message.is-long { width: min(1400px, 96%); }

.assistant-message-row {
  width: 100%;
  min-width: 0;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.assistant-avatar { width: 46px; height: 46px; border-radius: 13px; }
.assistant-avatar > span { font-size: 23px; }

.assistant-message {
  width: 100%;
  min-width: 0;
  padding: clamp(20px, 2vw, 28px);
  overflow-wrap: anywhere;
  border: 1px solid rgba(130, 155, 188, 0.18);
  border-radius: 18px;
  background: rgba(16, 25, 39, 0.86);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.18);
  color: rgba(248, 250, 253, 0.96);
  font-size: clamp(17px, 1.25vw, 20px);
  line-height: 1.66;
}

.assistant-message.is-streaming .assistant-content::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 5px;
  vertical-align: -0.15em;
  border-radius: 2px;
  background: var(--accent);
  animation: cursor-blink 900ms ease-in-out infinite;
}
@keyframes cursor-blink { 50% { opacity: 0.18; } }

.assistant-content > :first-child { margin-top: 0; }
.assistant-content > :last-child { margin-bottom: 0; }
.assistant-content p { margin: 0 0 1em; }
.assistant-content h1, .assistant-content h2, .assistant-content h3 { margin: 1.35em 0 0.55em; color: #fff; line-height: 1.18; letter-spacing: -0.025em; }
.assistant-content h1 { font-size: 1.7em; }
.assistant-content h2 { font-size: 1.42em; }
.assistant-content h3 { font-size: 1.2em; }
.assistant-content ul, .assistant-content ol { padding-left: 1.4em; }
.assistant-content li + li { margin-top: 0.35em; }
.assistant-content a { color: #b9d9ff; text-underline-offset: 3px; }
.assistant-content blockquote { margin: 1.2em 0; padding: 0.2em 1em; border-left: 3px solid rgba(169, 209, 255, 0.54); color: var(--muted); }
.assistant-content code { padding: 0.15em 0.35em; border-radius: 5px; background: rgba(0, 0, 0, 0.3); font-size: 0.88em; }
.assistant-content pre { max-width: 100%; overflow-x: auto; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: rgba(2, 7, 15, 0.6); }
.assistant-content pre code { padding: 0; background: none; }
.assistant-content table { width: 100%; display: block; overflow-x: auto; border-collapse: collapse; }
.assistant-content th, .assistant-content td { padding: 10px 12px; border: 1px solid var(--border); text-align: left; }

.math-display {
  display: block;
  width: 100%;
  margin: 24px auto;
  padding: 10px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  text-align: center;
  font-size: 2em;
  scrollbar-width: thin;
}
.math-display > .katex-display { width: max-content; min-width: 100%; margin: 0; }
.math-inline { white-space: nowrap; }
.math-error { color: var(--danger); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.55em; }

.message-meta { margin: 0 0 10px; display: flex; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 13px; }
.meta-pill { padding: 4px 8px; border: 1px solid rgba(153, 187, 226, 0.14); border-radius: 999px; background: rgba(73, 104, 143, 0.14); }
.search-status { color: #bedcff; }
.source-details { margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, 0.07); font-size: 14px; color: var(--muted); }
.source-details summary { width: fit-content; cursor: pointer; color: rgba(244, 248, 253, 0.84); font-weight: 650; }
.source-details ol { margin-bottom: 0; }
.source-details li + li { margin-top: 7px; }

.answer-controls { display: flex; align-items: center; gap: 6px; margin-top: 16px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.05); }
.answer-control { min-width: 38px; min-height: 36px; padding: 0 10px; display: inline-flex; gap: 6px; align-items: center; justify-content: center; border-radius: 9px; color: var(--muted); font-size: 13px; }
.answer-control svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.answer-control.is-selected { color: #fff; border-color: rgba(169, 209, 255, 0.45); background: rgba(94, 144, 201, 0.2); }

.rishai-composer-shell {
  z-index: 5;
  position: relative;
  width: min(1500px, calc(100% - 40px));
  margin: 0 auto;
  padding: 8px 0 max(10px, env(safe-area-inset-bottom));
}

.rishai-composer-shell::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: -30px;
  right: -30px;
  bottom: 0;
  height: calc(100% + 38px);
  pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(3, 9, 19, 0.86) 38%);
}

.auth-notice { min-height: 20px; margin: 0 4px 7px; color: var(--muted); font-size: 13px; text-align: center; }
.auth-notice:empty { display: none; }
.auth-notice.is-error { color: var(--danger); }
.auth-notice a { color: #c6e0ff; }

.rishai-composer {
  min-height: 84px;
  padding: 14px 14px 10px 17px;
  border: 1px solid rgba(138, 158, 188, 0.24);
  border-radius: 18px;
  background: rgba(17, 25, 39, 0.93);
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.025);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.rishai-composer:focus-within { border-color: rgba(173, 205, 244, 0.44); box-shadow: 0 18px 55px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(123, 174, 231, 0.08); }
.rishai-composer textarea {
  width: 100%;
  min-height: 29px;
  max-height: 210px;
  padding: 0 2px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 17px;
  line-height: 1.5;
}
.rishai-composer textarea::placeholder { color: rgba(223, 232, 243, 0.46); }
.rishai-composer textarea:disabled { cursor: not-allowed; }

.composer-toolbar { min-height: 44px; margin-top: 5px; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.composer-tools { display: flex; align-items: center; gap: 10px; }
.symbol-trigger { width: 44px; height: 44px; padding: 0; border-radius: 12px; font-family: Georgia, "Times New Roman", serif; font-size: 22px; }
.character-count { color: rgba(230, 237, 247, 0.42); font-size: 11px; }
.character-count.is-near-limit { color: #ffd097; }
.send-button { width: 46px; height: 46px; padding: 0; display: grid; place-items: center; border-radius: 14px; border-color: rgba(200, 223, 248, 0.55); background: #edf5ff; color: #07101d; }
.send-button:hover:not(:disabled) { transform: translateY(-2px); background: #fff; }
.send-button:disabled { cursor: not-allowed; opacity: 0.38; }
.send-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stop-icon { display: none; width: 14px; height: 14px; border-radius: 3px; background: currentColor; }
.send-button.is-generating .send-icon { display: none; }
.send-button.is-generating .stop-icon { display: block; }
.send-button.is-generating { opacity: 1; }

.rishai-disclaimer { margin: 7px 0 0; color: rgba(226, 235, 246, 0.46); font-size: 11px; text-align: center; }
.privacy-note { width: fit-content; max-width: 760px; margin: 4px auto 0; color: rgba(226, 235, 246, 0.42); font-size: 10px; text-align: center; }
.privacy-note summary { cursor: pointer; }
.privacy-note p { margin: 6px 0 0; line-height: 1.45; }

.symbol-drawer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% - 3px);
  max-height: min(560px, calc(100dvh - 170px));
  padding: 18px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: rgba(10, 18, 31, 0.985);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.52);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.99);
  transform-origin: bottom;
  transition: opacity 180ms ease, visibility 180ms ease, transform 180ms ease;
}
.symbol-drawer.is-open { opacity: 1; visibility: visible; transform: none; }
.symbol-drawer-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.symbol-drawer-heading strong, .symbol-drawer-heading span { display: block; }
.symbol-drawer-heading strong { font-size: 18px; }
.symbol-drawer-heading span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.symbol-search-label { height: 44px; margin-top: 14px; padding: 0 12px; display: flex; align-items: center; gap: 9px; border: 1px solid var(--border); border-radius: 11px; background: rgba(2, 8, 17, 0.4); }
.symbol-search-label svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.symbol-search-label input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.symbol-groups { margin-top: 15px; display: grid; gap: 18px; }
.symbol-group h2 { margin: 0 0 8px; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; }
.symbol-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 7px; }
.symbol-option { min-height: 52px; padding: 7px 9px; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 1px solid var(--border); border-radius: 10px; background: rgba(29, 43, 63, 0.55); color: var(--text); cursor: pointer; }
.symbol-option:hover, .symbol-option:focus-visible { border-color: var(--border-strong); background: rgba(47, 68, 95, 0.66); }
.symbol-preview { max-width: 100%; overflow: hidden; font-size: 18px; white-space: nowrap; text-overflow: ellipsis; }
.symbol-code { max-width: 100%; overflow: hidden; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.symbol-empty { color: var(--muted); text-align: center; }

.inline-error { color: var(--danger); }

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

:focus-visible { outline: 2px solid #b9d9ff; outline-offset: 3px; }

@media (max-width: 700px) {
  html, body { overflow: hidden; }
  .rishai-frame { width: 100%; height: 100dvh; min-height: 100dvh; margin: 0; border-width: 0; border-radius: 0; }
  .rishai-frame.has-conversation .rishai-header { height: 58px; min-height: 58px; }
  .rishai-identity { font-size: 16px; }
  .quiet-button { min-height: 40px; padding: 0 11px; }
  .icon-button { width: 40px; height: 40px; }
  .rishai-welcome { width: calc(100% - 24px); padding-top: 24px; }
  .grounding-note { max-width: 340px; }
  .rishai-conversation, .rishai-composer-shell { width: calc(100% - 16px); }
  .rishai-conversation { padding-top: 14px; gap: 16px; }
  .user-message, .user-message.is-long { width: 96%; min-width: 0; padding: 15px 16px; font-size: 16px; }
  .assistant-message-row { grid-template-columns: 34px minmax(0, 1fr); gap: 8px; }
  .assistant-avatar { width: 34px; height: 34px; border-radius: 9px; }
  .assistant-avatar > span { font-size: 17px; }
  .assistant-message { padding: 16px; border-radius: 15px; font-size: 16px; line-height: 1.6; }
  .math-display { margin: 18px auto; padding-inline: 4px; font-size: 1.65em; }
  .answer-control span { display: none; }
  .answer-control { padding: 0 8px; }
  .rishai-composer { min-height: 78px; border-radius: 16px; }
  .rishai-composer textarea { font-size: 16px; }
  .privacy-note { display: none; }
  .symbol-drawer { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; max-height: min(76dvh, 640px); padding: 16px 12px max(18px, env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; transform: translateY(100%); }
  .symbol-drawer.is-open { transform: none; }
  .symbol-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-height: 700px) and (min-width: 701px) {
  .rishai-welcome { padding-top: 18px; }
  .rishai-logo { width: 78px; height: 78px; border-radius: 18px; }
  .rishai-welcome h1 { margin-top: 14px; font-size: 48px; }
  .rishai-welcome p { font-size: 17px; }
  .grounding-note { margin-top: 8px; }
}

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