@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Instrument+Serif:ital@0;1&display=swap');

:root {
  color-scheme: dark;
  --canvas: #14181b;
  --rail: #191d20;
  --surface: #22282d;
  --border: #384146;
  --ink: #f1f1e9;
  --soft: #dce1db;
  --muted: #a4afac;
  --accent: #b7e4d4;
  --on-accent: #172724;
  --body: 'DM Sans', system-ui, sans-serif;
  --display: 'Instrument Serif', Georgia, serif;
  --thread: 810px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--rail);
  color: var(--ink);
  font: 16px var(--body);
}

button, input, textarea, select { color: inherit; font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }

:where(button, input, a, pre, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

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

.icon { display: inline-flex; width: 18px; height: 18px; flex: none; }

.icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar {
  z-index: 3;
  display: flex;
  min-height: 0;
  flex-direction: column;
  padding: 16px 12px;
  background: var(--rail);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 5px;
  border: 0;
  background: transparent;
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: -.045em;
  white-space: nowrap;
}

.brand-ai { color: #a8c3b8; }

.brand-icon {
  display: block;
  width: 29px;
  height: 29px;
  flex: none;
  background: url('/icon.png') center/contain no-repeat;
  image-rendering: pixelated;
}

.sidebar-actions {
  display: grid;
  gap: 5px;
}

.new-chat, .side-link, .icon-button {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #1b2224;
  color: var(--soft);
  font-size: .875rem;
  font-weight: 600;
  transition: background-color .16s, color .16s, border-color .16s;
}

.new-chat, .side-link { justify-content: flex-start; text-align: left; }
.new-chat { background: #252c30; color: var(--ink); }
.new-chat .icon { color: var(--accent); }
.side-link { border-color: transparent; background: transparent; color: var(--muted); }
.new-chat:hover, .side-link:hover, .icon-button:hover { border-color: #495855; background: #263032; color: var(--ink); }

.sidebar-toggle {
  width: 34px;
  min-height: 34px;
  flex: none;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.history { min-height: 0; margin-top: 30px; overflow: auto; scrollbar-width: thin; scrollbar-color: #40504d transparent; }
.history h2, .history p { padding-inline: 8px; }
.history h2 { margin: 0 0 8px; color: #bfc9c4; font-size: .875rem; font-weight: 600; }
.history p { margin: 0; color: #939f9c; font-size: .875rem; }
.history ul, .search-results { margin: 0; padding: 0; list-style: none; }

.history li {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  border-radius: 8px;
}

.history li:hover, .history li:has([aria-current]) { background: #232c2d; }
.history li:has(:focus-visible) { z-index: 1; }

.history-main {
  display: flex;
  min-width: 0;
  min-height: 40px;
  flex: 1;
  align-items: center;
  gap: 7px;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--soft);
  text-align: left;
  font-size: .875rem;
}

.history-main .icon { width: 15px; height: 15px; color: #a1aaa7; }
.history-main span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history li:hover .history-main, .history li:focus-within .history-main { padding-right: 37px; }

.history-delete {
  position: absolute;
  right: 3px;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: #232c2d;
  color: var(--muted);
  opacity: 0;
}

.history-delete .icon { width: 15px; height: 15px; }
.history li:hover .history-delete, .history li:focus-within .history-delete { opacity: 1; }
.history-delete:hover { background: #303c3b; color: var(--ink); }

.workspace {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  margin: 7px 7px 7px 0;
  border: 1px solid #333b40;
  border-radius: 15px;
  background:
    radial-gradient(ellipse 610px 370px at 52% 45%, #18383b 0%, #1b2e387d 43%, transparent 100%),
    var(--canvas);
}

.workspace:has(.chatting) { background: var(--canvas); }

.topbar {
  display: flex;
  min-height: 55px;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 23px;
}

.workspace:has(.chatting) .topbar { border-bottom: 1px solid #2c3436; }

.top-left { display: flex; min-width: 0; align-items: center; gap: 9px; }
.top-actions { display: flex; flex: none; align-items: center; gap: 7px; }

.top-title {
  overflow: hidden;
  color: var(--soft);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .875rem;
  font-weight: 600;
}

.mobile-menu, .mobile-new-chat, .mobile-brand, .scrim { display: none; }

.free-label {
  padding: 4px 9px;
  border: 1px solid #3f504e;
  border-radius: 7px;
  background: #1e2b2c;
  color: var(--accent);
  font-size: .8125rem;
  font-weight: 600;
}

.stage { display: flex; min-height: 0; flex: 1; flex-direction: column; overflow: auto; }
.stage:not(.chatting) { justify-content: safe center; }

.welcome {
  display: grid;
  flex: none;
  place-items: center;
  padding: 10px 16px 18px;
  text-align: center;
}

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

.welcome-mark {
  width: 52px;
  height: 52px;
  filter: drop-shadow(0 2px 10px #63b6a34d);
  animation: welcome-in .42s ease-out both;
}

.dock {
  width: min(710px, calc(100% - 44px));
  flex: none;
  margin: 0 auto clamp(36px, 10vh, 104px);
}

.composer {
  padding: 9px 10px;
  border: 1px solid #495b60;
  border-radius: 17px;
  background: var(--surface);
  box-shadow: 0 13px 36px #0f151665, inset 0 1px #f2ffff08;
  transition: border-color .16s, box-shadow .16s;
}

.composer:focus-within { border-color: #73968a; box-shadow: 0 11px 33px #11171866, 0 0 0 2px #86b8a223; }

textarea {
  display: block;
  width: 100%;
  min-height: 50px;
  max-height: 190px;
  padding: 8px 6px;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  line-height: 1.5;
}

textarea::placeholder { color: #aab5b0; }

.composer-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.composer-leading { display: flex; align-items: center; gap: 6px; }
.composer-options { display: flex; min-width: 0; align-items: center; gap: 7px; }

.attachment-button {
  display: grid;
  width: 38px;
  height: 36px;
  flex: none;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
}

.attachment-button:hover:not(:disabled) { border-color: #698f81; background: #2b3a37; }
.attachment-button:disabled { opacity: .6; }

.web-toggle {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: .8125rem;
  white-space: nowrap;
}

.web-toggle .icon { width: 16px; height: 16px; color: var(--accent); }
.web-toggle:hover:not(:disabled) { border-color: #58716e; background: #293b3d; color: var(--ink); }
.web-toggle[aria-pressed="true"] { border-color: #648d82; background: #304743; color: var(--accent); }
.web-toggle:disabled { opacity: .65; }

.image-preview {
  display: flex;
  width: fit-content;
  max-width: 100%;
  align-items: center;
  gap: 9px;
  margin: 2px 2px 5px;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #273333;
  color: var(--soft);
  font-size: .875rem;
}

.image-preview img { width: 39px; height: 39px; border-radius: 6px; object-fit: cover; }
.image-preview span:not(.icon) { max-width: 23ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-preview .attachment-button { width: 31px; height: 31px; border-color: transparent; }
.image-preview .icon { width: 15px; height: 15px; }

.mode-control { position: relative; }

.mode-trigger {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid #3f4b50;
  border-radius: 8px;
  background: #262f33;
  color: #c2cdc7;
  font-size: .875rem;
  white-space: nowrap;
  transition: background-color .16s, border-color .16s;
}

.mode-trigger:hover, .mode-trigger[aria-expanded="true"] {
  border-color: #617b76;
  background: #2c393b;
  color: var(--ink);
}

.mode-trigger .icon { width: 14px; height: 14px; color: #accdc1; }
.mode-chevron { transition: transform .16s; }
.mode-trigger[aria-expanded="true"] .mode-chevron { transform: rotate(180deg); }

.mode-menu {
  position: absolute;
  z-index: 4;
  right: 0;
  bottom: calc(100% + 8px);
  display: grid;
  width: min(248px, calc(100vw - 82px));
  max-height: min(205px, 56dvh);
  gap: 3px;
  overflow-y: auto;
  padding: 5px;
  border: 1px solid #465b5e;
  border-radius: 12px;
  background: #212a2e;
  box-shadow: 0 13px 38px #090f13a6, inset 0 1px #f3ffff0a;
  animation: mode-in .14s ease-out;
}

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

.mode-option {
  display: grid;
  min-height: 48px;
  grid-template-columns: 18px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--soft);
  text-align: left;
}

.mode-option[aria-selected="true"] { border-color: #637f775b; background: #314441; }
.mode-option:hover { background: #37494a; border-color: #819d93; }
.mode-option:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.mode-option strong { display: block; font-size: .875rem; font-weight: 600; }
.mode-option small { display: block; margin-top: 2px; color: #b6c3c0; font-size: .75rem; line-height: 1.25; }
.mode-option .icon { width: 16px; height: 16px; color: var(--accent); }
.mode-option .mode-check { visibility: hidden; }
.mode-option[aria-selected="true"] .mode-check { visibility: visible; }

@media (max-height: 440px) {
  .mode-menu { max-height: min(185px, 45dvh); }
}

.send {
  display: grid;
  width: 39px;
  height: 39px;
  flex: none;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  transition: background-color .16s;
}

.send:hover:not(:disabled) { background: #d0f4e6; }
.send:active:not(:disabled) { background: #a4ccbc; }
.send:disabled { background: #343f43; color: #a8b4b1; }
.send .icon { width: 19px; height: 19px; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  margin-top: 13px;
}

.prompt-chip {
  display: inline-flex;
  min-height: 37px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 5px 11px;
  border: 1px solid #789d9a36;
  border-radius: 999px;
  background: #1b272a66;
  color: #d0d8d4;
  font-size: .875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color .16s, color .16s, border-color .16s;
}

.prompt-chip .icon { width: 15px; height: 15px; color: #a7c9bd; }
.prompt-chip:hover { border-color: #698f81; background: #263a3b; color: var(--ink); }

.stage.chatting { overflow: hidden; }
.chatting .dock { width: min(var(--thread), calc(100% - 48px)); margin: 0 auto; padding: 8px 0 max(17px, env(safe-area-inset-bottom)); }
.chatting .composer { padding: 7px 9px; border-radius: 14px; }
.chatting textarea { min-height: 42px; }

.conversation {
  width: 100%;
  min-height: 0;
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 30px max(24px, calc((100% - var(--thread))/2)) 16px;
  scrollbar-width: thin;
  scrollbar-color: #495653 transparent;
}

.message { margin: 0 0 32px; overflow-wrap: anywhere; }
.message:last-child { margin-bottom: 9px; }

.message.user {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.message-text {
  width: fit-content;
  max-width: min(84%, 625px);
  padding: 11px 16px;
  border: 1px solid #3c4b49;
  border-radius: 15px 15px 5px 15px;
  background: #283433;
  white-space: pre-wrap;
}

.message-figure {
  display: flex;
  justify-content: flex-end;
  max-width: min(84%, 340px);
  margin: 0;
}

.message-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 238px;
  border: 1px solid #3c4b49;
  border-radius: 13px;
  object-fit: contain;
}

.attachment-missing { color: var(--muted); font-size: .875rem; }

.message.assistant { position: relative; padding: 4px 0 8px 46px; }

.message-label {
  display: flex;
  align-items: center;
  margin: 1px 0 14px;
  color: var(--soft);
  font-size: .875rem;
  font-weight: 700;
}

.message-avatar {
  position: absolute;
  top: 0;
  left: 0;
  width: 33px;
  height: 33px;
  border: 1px solid #4b6259;
  border-radius: 10px;
  background-color: #263a34;
  background-size: 76%;
}

.pixel-pulse { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: .875rem; }
.pixel-pulse span { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: pulse .8s ease-in-out infinite alternate; }
.pixel-pulse span:nth-child(2) { animation-delay: .15s; }
.pixel-pulse span:nth-child(3) { margin-right: 4px; animation-delay: .3s; }
@keyframes pulse { to { opacity: .3; } }

.message-body { color: #e1e5dd; line-height: 1.7; }
.message-body > :first-child { margin-top: 0; }
.message-body > :last-child { margin-bottom: 0; }
.message-body p, .message-body ul, .message-body ol { margin: 0 0 14px; }
.message-body :is(ul, ol) { padding-inline-start: 1.55em; }
.message-body li + li { margin-top: 5px; }
.message-body li > :last-child { margin-bottom: 0; }
.message-body li::marker { color: #a7c6ba; }
.message-body strong { color: var(--ink); }
.message-body a { color: var(--accent); text-underline-offset: .2em; }

.message-body :is(h1, h2, h3, h4, h5, h6) {
  margin: 23px 0 9px;
  color: var(--ink);
  font: 700 1rem/1.3 var(--body);
  letter-spacing: -.025em;
}

.message-body :is(h1, h2) { font-size: clamp(1.38rem, 2.1vw, 1.75rem); }
.message-body h3 { font-size: 1.16rem; }
.message-body hr { margin: 23px 0; border: 0; border-top: 1px solid var(--border); }
.message-body blockquote { margin: 0 0 14px; padding: 5px 0 5px 14px; border-left: 2px solid #6c978a; color: #c0ccc5; }
.message-body blockquote > :last-child { margin-bottom: 0; }

.table-scroll, .code-panel {
  margin: 0 0 17px;
  border: 1px solid #374442;
  border-radius: 10px;
  background: #1b2224;
}

.table-scroll { overflow: auto; }
.message-body table { width: 100%; min-width: 360px; border-collapse: collapse; font-size: .925rem; }
.message-body :is(th, td) { padding: 9px 12px; border-bottom: 1px solid #364240; text-align: left; vertical-align: top; }
.message-body th { background: #2a3534; color: #e8f1eb; font-weight: 700; }
.message-body tr:nth-child(even) td { background: #25302e72; }
.message-body tr:last-child td { border-bottom: 0; }
.message-body .align-center { text-align: center; }
.message-body .align-right { text-align: right; }

.code-panel { background: #141a1c; }

.code-header {
  display: flex;
  min-height: 39px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 8px 4px 13px;
  border-bottom: 1px solid #364240;
  border-radius: 9px 9px 0 0;
  background: #232c2d;
  color: #c4d2cb;
  font-size: .8125rem;
  font-weight: 600;
}

.message-body pre { margin: 0; padding: 13px; overflow: auto; white-space: pre; }
.message-body code { color: #c2e4d5; font: .875rem/1.6 ui-monospace, monospace; }
.message-body :not(pre) > code { padding: .1em .33em; border-radius: 4px; background: #293533; overflow-wrap: anywhere; }
.message-actions { display: flex; gap: 5px; margin-top: 12px; }

.web-sources {
  margin: 16px 0 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--soft);
  font-size: .875rem;
}

.source-list { display: grid; gap: 4px; margin: 6px 0 0; padding-inline-start: 1.5em; }
.source-list li::marker { color: var(--muted); }
.source-link { display: inline-flex; flex-wrap: wrap; gap: 2px 8px; padding: 2px 0; color: var(--accent); text-underline-offset: .2em; }
.source-link small { color: var(--muted); font-size: .8125rem; }
.source-link:hover { color: var(--ink); }

.message-actions button, .code-header .copy {
  display: inline-flex;
  min-height: 29px;
  align-items: center;
  gap: 6px;
  padding: 4px 7px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #bbc8c1;
  font-size: .8125rem;
}

.message-actions button:hover, .code-header .copy:hover { background: #354642; color: var(--ink); }
.copy .icon { width: 14px; height: 14px; }
.error { color: #ffc4c9; }

dialog {
  width: min(460px, calc(100vw - 28px));
  padding: 20px;
  border: 1px solid #50615b;
  border-radius: 14px;
  background: #20282b;
  color: var(--ink);
  box-shadow: 0 20px 68px #0a0f116e;
}

dialog::backdrop { background: #0b1113ae; }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.dialog-header h2 { margin: 0; font: 400 2rem/1.05 var(--display); }

.close, .primary, .secondary {
  padding: 7px 12px;
  border: 0;
  border-radius: 8px;
  background: #333e40;
  color: var(--ink);
}

.close { font-size: 1.3125rem; line-height: 1; }
.primary { background: #ecc0bd; color: #391f23; font-weight: 700; }
dialog input { width: 100%; padding: 10px 12px; border: 1px solid #475651; border-radius: 8px; background: #151b1e; }
dialog input::placeholder { color: var(--muted); }
dialog p { color: var(--soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 17px; }
.search-results { max-height: 46vh; overflow: auto; margin-top: 10px; }
.search-results li:not(:has(button)) { padding: 8px 0; color: var(--muted); }
.search-results button { width: 100%; padding: 9px; border: 0; border-radius: 8px; background: transparent; text-align: left; overflow-wrap: anywhere; }
.search-results button:hover { background: #303d3b; }

.toast {
  position: fixed;
  right: 15px;
  bottom: 15px;
  z-index: 5;
  padding: 8px 12px;
  border: 1px solid #50615b;
  border-radius: 9px;
  background: #25332f;
  color: #e0f2e9;
}

@media (max-width: 960px) {
  body { grid-template-columns: 200px minmax(0, 1fr); }
}

@media (min-width: 701px) {
  body.sidebar-compact { grid-template-columns: 62px minmax(0, 1fr); }
  .sidebar-compact .sidebar { align-items: center; padding-inline: 9px; }
  .sidebar-compact .sidebar-head { flex-direction: column; gap: 8px; margin-bottom: 13px; }
  .sidebar-compact :is(.sidebar-label, .history) { display: none; }
  .sidebar-compact .sidebar-actions button { width: 40px; justify-content: center; padding-inline: 0; }
}

@media (max-width: 700px) {
  body { display: block; }
  .workspace { height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .topbar { min-height: 55px; padding: 0 13px; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(260px, 85vw); transform: translateX(-100%); visibility: hidden; }
  .sidebar.open { transform: none; visibility: visible; }
  .sidebar-toggle { display: none; }
  .mobile-menu, .mobile-new-chat { display: flex; min-width: 37px; min-height: 38px; padding: 6px; border-color: transparent; background: transparent; }
  .mobile-new-chat { color: var(--accent); }
  .mobile-brand { display: block; white-space: nowrap; font-size: 1rem; font-weight: 700; letter-spacing: -.03em; }
  .top-left:has(.top-title:not(:empty)) .mobile-brand { display: none; }
  .scrim { position: fixed; z-index: 2; inset: 0; display: block; width: 100%; border: 0; background: #070f11b0; }
  .welcome-mark { width: 44px; height: 44px; }
  .dock { width: calc(100% - 26px); margin-bottom: clamp(35px, 9vh, 86px); }
  .composer { border-radius: 15px; }
  .conversation { padding: 18px 14px 9px; }
  .chatting .dock { width: calc(100% - 24px); }
  .message { margin-bottom: 23px; }
  .message.assistant { padding: 2px 0 6px; }
  .message-label { min-height: 29px; padding-inline-start: 38px; }
  .message-avatar { width: 29px; height: 29px; }
}

@media (max-width: 455px) {
  .suggestions { display: grid; grid-template-columns: repeat(2, max-content); }
  .prompt-chip { min-height: 41px; }
}

@media (max-width: 380px) {
  .web-toggle { width: 36px; justify-content: center; padding: 0; }
  .web-toggle-label { display: none; }
}

@media (hover: none) {
  .history .history-main { padding-right: 37px; }
  .history .history-delete { opacity: 1; }
}

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