:root {
  color-scheme: dark;
  --canvas: #0b0f14;
  --surface: #11171f;
  --surface-raised: #161e28;
  --surface-soft: #1b2531;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.15);
  --text: #edf4f7;
  --muted: #8c9ba8;
  --quiet: #657480;
  --accent: #79e2a7;
  --accent-strong: #43c981;
  --accent-ink: #092116;
  --danger: #ff8e8e;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--canvas); color: var(--text); }

body { min-height: 100dvh; overflow: hidden; }

button, input, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

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

.loading-view {
  width: min(420px, calc(100% - 40px));
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.loading-view strong { display: block; font-size: 15px; }
.loading-view p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 900;
  letter-spacing: -0.05em;
}

.loading-spinner {
  width: 18px;
  height: 18px;
  margin-left: auto;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.auth-view {
  display: grid;
  grid-template-columns: minmax(380px, 0.92fr) minmax(460px, 1.08fr);
  min-height: 100dvh;
}

.auth-visual {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  padding: clamp(42px, 6vw, 88px);
  background:
    radial-gradient(circle at 23% 18%, rgba(121, 226, 167, 0.22), transparent 30%),
    linear-gradient(145deg, #15251f 0%, #10181c 48%, #0c1117 100%);
  border-right: 1px solid var(--line);
}

.auth-visual::before {
  content: "";
  position: absolute;
  width: 340px;
  height: 340px;
  left: 14%;
  top: 17%;
  border-radius: 46% 54% 64% 36%;
  background: linear-gradient(145deg, rgba(121, 226, 167, 0.35), rgba(121, 226, 167, 0.02));
  filter: blur(1px);
  transform: rotate(-14deg);
}

.visual-orbit {
  position: absolute;
  border: 1px solid rgba(121, 226, 167, 0.22);
  border-radius: 50%;
}

.orbit-one { width: 420px; height: 210px; top: 22%; left: 6%; transform: rotate(30deg); }
.orbit-two { width: 260px; height: 460px; top: 7%; left: 21%; transform: rotate(57deg); }

.visual-copy { position: relative; z-index: 1; max-width: 560px; }
.visual-kicker, .eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
.visual-copy h2 { max-width: 520px; margin: 18px 0; font-size: clamp(38px, 5vw, 66px); line-height: 0.98; letter-spacing: -0.055em; }
.visual-copy p { max-width: 520px; margin: 0; color: #b2c0c5; font-size: 17px; line-height: 1.7; }

.auth-panel { display: grid; place-items: center; padding: 36px; background: var(--canvas); }
.auth-card { width: min(420px, 100%); }
.auth-brand, .brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.auth-brand strong, .brand strong { display: block; font-size: 14px; letter-spacing: -0.01em; }
.auth-brand small, .brand small { display: block; margin-top: 1px; color: var(--muted); font-size: 11px; }
.auth-heading { margin: 64px 0 30px; }
.auth-heading .eyebrow { margin: 0 0 12px; }
.auth-heading h1 { margin: 0; font-size: 38px; letter-spacing: -0.045em; }
.auth-heading p:last-child { margin: 10px 0 0; color: var(--muted); line-height: 1.55; }

.auth-tabs { display: flex; gap: 6px; margin-bottom: 22px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.tab-button { flex: 1; padding: 9px 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.tab-button.is-active { background: var(--surface-soft); color: var(--text); box-shadow: 0 1px 8px rgba(0, 0, 0, 0.2); }

.auth-form { display: grid; gap: 16px; }
.auth-form label { display: grid; gap: 8px; color: #c7d1d6; font-size: 12px; font-weight: 650; }
.auth-form input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.auth-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(121, 226, 167, 0.12); }

.primary-button {
  min-height: 48px;
  margin-top: 4px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  cursor: pointer;
}
.primary-button:hover { background: #8de9b5; }
.primary-button:disabled { opacity: 0.55; cursor: wait; }
.text-button { justify-self: center; padding: 5px; border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer; }
.text-button:hover { color: var(--accent); }
.form-message { min-height: 20px; margin: 16px 0 0; color: var(--danger); font-size: 13px; line-height: 1.5; text-align: center; }

.app-shell { display: grid; grid-template-columns: 294px minmax(0, 1fr); width: 100%; height: 100dvh; }
.sidebar { display: flex; flex-direction: column; min-width: 0; padding: 24px 16px 16px; border-right: 1px solid var(--line); background: #0d1218; }
.brand { padding: 0 8px; }
.sidebar-section { margin-top: 46px; }
.section-label { display: flex; align-items: center; justify-content: space-between; padding: 0 10px 10px; color: var(--quiet); font-size: 10px; font-weight: 750; letter-spacing: 0.12em; text-transform: uppercase; }
.live-pill { padding: 3px 7px; border: 1px solid rgba(121, 226, 167, 0.23); border-radius: 999px; color: var(--accent); font-size: 8px; }
.conversation { display: flex; align-items: center; width: 100%; gap: 12px; padding: 12px; border: 1px solid transparent; border-radius: 13px; background: transparent; text-align: left; cursor: pointer; }
.conversation.is-active { border-color: var(--line); background: var(--surface); }
.conversation-copy { min-width: 0; flex: 1; }
.conversation-copy strong, .conversation-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-copy strong { font-size: 13px; }
.conversation-copy small { margin-top: 3px; color: var(--muted); font-size: 11px; }

.avatar { display: grid; width: 40px; height: 40px; flex: 0 0 auto; place-items: center; border-radius: 13px; background: var(--surface-soft); color: #c6d2d8; font-size: 13px; font-weight: 850; }
.rika-avatar { background: linear-gradient(145deg, var(--accent), #43bfa0); color: var(--accent-ink); }
.online-dot { display: inline-block; width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--accent-strong); box-shadow: 0 0 0 3px rgba(67, 201, 129, 0.08); }
.sidebar-footer { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line); }
.account-block { display: flex; align-items: center; min-width: 0; flex: 1; gap: 10px; }
.account-block > span:last-child { min-width: 0; }
.account-block strong, .account-block small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-block strong { font-size: 12px; }
.account-block small { margin-top: 3px; color: var(--quiet); font-size: 9px; }
.icon-button { display: grid; width: 34px; height: 34px; place-items: center; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-button:hover { background: var(--surface-soft); color: var(--text); }
.icon-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.chat-panel { display: grid; min-width: 0; min-height: 0; grid-template-rows: 74px minmax(0, 1fr) auto; background: var(--canvas); }
.chat-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 clamp(18px, 3vw, 42px); border-bottom: 1px solid var(--line); background: rgba(11, 15, 20, 0.82); backdrop-filter: blur(18px); }
.chat-identity { display: flex; align-items: center; gap: 12px; }
.chat-identity strong, .chat-identity small { display: block; }
.chat-identity strong { font-size: 14px; }
.chat-identity small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.chat-identity small .online-dot { width: 5px; height: 5px; margin-right: 4px; vertical-align: 1px; }
.header-meta { display: flex; align-items: center; gap: 14px; }
.stop-task-button { display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 0 11px; border: 1px solid rgba(255, 142, 142, 0.24); border-radius: 9px; background: rgba(255, 142, 142, 0.08); color: #ffb0b0; font-size: 10px; font-weight: 750; cursor: pointer; }
.stop-task-button:hover { background: rgba(255, 142, 142, 0.14); }
.stop-task-button:disabled { opacity: 0.55; cursor: wait; }
.stop-task-button span { width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.connection-status { color: var(--muted); font-size: 10px; }
.connection-status.is-online { color: var(--accent); }
.release { padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; color: var(--quiet); font: 9px ui-monospace, SFMono-Regular, Menlo, monospace; }

.message-region { min-height: 0; overflow-y: auto; scroll-behavior: smooth; scrollbar-color: var(--surface-soft) transparent; }
.welcome-state { width: min(560px, calc(100% - 40px)); margin: clamp(70px, 14vh, 150px) auto 50px; text-align: center; }
.welcome-mark { display: grid; width: 62px; height: 62px; margin: 0 auto 24px; place-items: center; border-radius: 20px; background: linear-gradient(145deg, var(--accent), #43bfa0); color: var(--accent-ink); font-size: 22px; font-weight: 900; box-shadow: 0 16px 46px rgba(67, 201, 129, 0.14); }
.welcome-state .eyebrow { margin: 0 0 12px; }
.welcome-state h1 { margin: 0; font-size: clamp(31px, 5vw, 48px); letter-spacing: -0.05em; }
.welcome-state > p:last-child { max-width: 510px; margin: 16px auto 0; color: var(--muted); line-height: 1.7; }
.message-list { width: min(900px, calc(100% - 40px)); margin: 0 auto; padding: 38px 0 48px; list-style: none; }
.message { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 13px; margin-bottom: 30px; }
.message.is-user { grid-template-columns: minmax(0, 1fr) 38px; }
.message.is-user .message-avatar { grid-column: 2; }
.message.is-user .message-content { grid-column: 1; grid-row: 1; justify-self: end; align-items: flex-end; }
.message-avatar { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 12px; background: linear-gradient(145deg, var(--accent), #43bfa0); color: var(--accent-ink); font-size: 12px; font-weight: 900; }
.message.is-user .message-avatar { background: var(--surface-soft); color: #c8d5db; }
.message.is-system .message-avatar { background: rgba(255, 142, 142, 0.12); color: var(--danger); }
.message-content { display: flex; min-width: 0; flex-direction: column; align-items: flex-start; }
.message-meta { display: flex; align-items: center; gap: 8px; margin: 0 2px 7px; color: var(--quiet); font-size: 9px; }
.message-meta strong { color: #bfcbd1; font-size: 10px; }
.message-bubble { max-width: min(720px, 100%); padding: 13px 16px; border: 1px solid var(--line); border-radius: 5px 16px 16px; background: var(--surface); color: #dce5e9; font-size: 14px; line-height: 1.68; overflow-wrap: anywhere; white-space: pre-wrap; }
.message.is-user .message-bubble { border-color: transparent; border-radius: 16px 5px 16px 16px; background: var(--accent); color: var(--accent-ink); }
.message.is-system .message-bubble { border-color: rgba(255, 142, 142, 0.2); color: #ffc2c2; background: rgba(255, 142, 142, 0.06); }
.message-bubble strong { color: #f5fafb; font-weight: 800; }
.message-bubble code { padding: 0.16em 0.38em; border: 1px solid var(--line); border-radius: 5px; background: #0a0e13; color: #a9edc5; font: 0.9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.message-bubble pre { max-width: 100%; margin: 12px 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: #090d12; white-space: pre; }
.message-bubble pre code { display: block; min-width: max-content; padding: 14px; border: 0; background: transparent; color: #d9e5e9; line-height: 1.55; }
.message-bubble a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.message-status { color: var(--quiet); }
.message-status[data-status="processing"] { color: #e6c777; }
.message-status[data-status="failed"] { color: var(--danger); }
.message-status[data-status="interrupted"] { color: var(--danger); }
.retry-button { margin-top: 8px; padding: 6px 9px; border: 1px solid var(--line-strong); border-radius: 8px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 700; cursor: pointer; }
.retry-button:hover { border-color: rgba(121, 226, 167, 0.45); color: var(--accent); }
.retry-button:disabled { opacity: 0.55; cursor: wait; }

.composer-wrap { padding: 10px clamp(18px, 4vw, 48px) max(14px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--canvas) 75%, transparent); }
.composer { display: flex; align-items: flex-end; width: min(900px, 100%); margin: 0 auto; gap: 10px; padding: 9px 9px 9px 17px; border: 1px solid var(--line-strong); border-radius: 17px; background: var(--surface); box-shadow: 0 16px 50px rgba(0, 0, 0, 0.22); transition: border-color 0.15s, box-shadow 0.15s; }
.composer:focus-within { border-color: rgba(121, 226, 167, 0.55); box-shadow: 0 0 0 3px rgba(121, 226, 167, 0.08), 0 16px 50px rgba(0, 0, 0, 0.22); }
.composer textarea { width: 100%; max-height: 180px; min-height: 30px; resize: none; padding: 5px 0; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.5; }
.composer textarea::placeholder { color: var(--quiet); }
.send-button { display: grid; width: 38px; height: 38px; flex: 0 0 auto; place-items: center; border: 0; border-radius: 11px; background: var(--accent); color: var(--accent-ink); cursor: pointer; }
.send-button:hover { background: #8de9b5; }
.send-button:disabled { opacity: 0.45; cursor: wait; }
.send-button svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.composer-wrap > p { margin: 8px auto 0; color: var(--quiet); font-size: 9px; text-align: center; }

@media (max-width: 800px) {
  .auth-view { display: block; overflow-y: auto; }
  .auth-visual { display: none; }
  .auth-panel { min-height: 100dvh; padding: 30px 22px; }
  .auth-heading { margin-top: 48px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .chat-header { padding-inline: 16px; }
  .chat-header .avatar { width: 36px; height: 36px; }
  .connection-status, .release { display: none; }
  .message-list { width: calc(100% - 24px); padding-top: 28px; }
  .message { grid-template-columns: 31px minmax(0, 1fr); gap: 9px; margin-bottom: 24px; }
  .message.is-user { grid-template-columns: minmax(0, 1fr) 31px; }
  .message-avatar { width: 30px; height: 30px; border-radius: 10px; font-size: 10px; }
  .message-bubble { padding: 11px 13px; font-size: 13px; }
  .composer-wrap { padding-inline: 12px; }
  .composer-wrap > p { display: none; }
}

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