:root {
  color-scheme: light;
  --paper: #f7f0e6;
  --paper-deep: #eadfce;
  --ink: #231b18;
  --muted: #76685e;
  --line: rgba(61, 47, 39, 0.16);
  --line-strong: rgba(61, 47, 39, 0.25);
  --accent: #8f2f27;
  --accent-dark: #5d1f1a;
  --accent-soft: rgba(143, 47, 39, 0.1);
  --white: rgba(255, 252, 246, 0.88);
  --rail: rgba(247, 240, 230, 0.98);
  --rail-tint: rgba(143, 47, 39, 0.035);
  --shadow: 18px 0 46px rgba(61, 47, 39, 0.12);
  --ease-panel: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background:
    linear-gradient(120deg, rgba(143, 47, 39, 0.08), transparent 42%),
    repeating-linear-gradient(
      90deg,
      rgba(61, 47, 39, 0.035) 0,
      rgba(61, 47, 39, 0.035) 1px,
      transparent 1px,
      transparent 92px
    ),
    var(--paper);
  color: var(--ink);
  font-family:
    "Noto Serif SC", "Songti SC", "STSong", "Source Han Serif SC", ui-serif,
    "Iowan Old Style", "Source Serif Pro", Georgia, "Times New Roman", serif;
  letter-spacing: 0;
}

button,
textarea,
input {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(228px, 280px) minmax(0, 1fr);
  height: 100dvh;
  min-height: 0;
  background: transparent;
  transition: grid-template-columns 320ms var(--ease-panel);
  will-change: grid-template-columns;
}

.shell.is-history-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.history-hotspot {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 7;
  width: 12px;
  background: transparent;
}

.history-backdrop {
  position: fixed;
  inset: 0;
  z-index: 6;
  background: rgba(35, 27, 24, 0.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 240ms ease;
}

.history-pane {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border-right: 1px solid rgba(61, 47, 39, 0.1);
  background:
    linear-gradient(90deg, var(--rail-tint), transparent 42%),
    linear-gradient(180deg, rgba(255, 252, 246, 0.52), transparent 36%),
    var(--rail);
  backdrop-filter: blur(10px);
  padding: 16px 12px;
  transition:
    transform 340ms var(--ease-panel),
    opacity 220ms ease,
    padding 320ms var(--ease-panel),
    background-color 320ms var(--ease-panel);
  will-change: transform;
}

.shell.is-history-collapsed .history-pane {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 8;
  width: 280px;
  padding: 14px 10px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-104%);
  box-shadow: var(--shadow);
}

.shell.is-history-collapsed.is-history-peeking .history-pane,
.shell.is-history-collapsed.is-history-open .history-pane {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.history-pane__top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 2px 12px;
  border-bottom: 1px solid rgba(61, 47, 39, 0.1);
  transition:
    grid-template-columns 320ms var(--ease-panel),
    gap 320ms var(--ease-panel),
    border-color 240ms ease,
    padding-bottom 320ms var(--ease-panel);
}

.shell.is-history-collapsed .history-pane__top {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0;
  padding-bottom: 0;
  border-bottom-color: transparent;
}

.shell.is-history-collapsed.is-history-peeking .history-pane__top,
.shell.is-history-collapsed.is-history-open .history-pane__top {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom-color: var(--line);
}

.history-title {
  margin: 0;
  color: var(--ink);
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  transition:
    opacity 180ms ease,
    transform 320ms var(--ease-panel);
}

.ghost-button,
.composer button {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.new-chat-sidebar {
  min-height: 32px;
  border: 1px solid rgba(61, 47, 39, 0.12);
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.46);
  color: var(--ink);
  cursor: pointer;
  padding: 0 11px;
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  white-space: nowrap;
  transition:
    opacity 180ms ease,
    transform 320ms var(--ease-panel);
}

.new-chat-sidebar:hover {
  background: rgba(255, 252, 246, 0.74);
  border-color: rgba(143, 47, 39, 0.22);
  color: var(--accent-dark);
}

.shell.is-history-collapsed:not(.is-history-peeking):not(.is-history-open) .history-title,
.shell.is-history-collapsed:not(.is-history-peeking):not(.is-history-open) #new-chat-sidebar {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-8px);
}

.history-list {
  min-height: 0;
  overflow-y: auto;
  padding: 10px 2px 0;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  opacity: 1;
  transform: translateX(0);
  transition:
    opacity 180ms ease 80ms,
    transform 320ms var(--ease-panel);
}

.shell.is-history-collapsed:not(.is-history-peeking):not(.is-history-open) .history-list {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-10px);
  transition:
    opacity 120ms ease,
    transform 220ms ease;
}

.history-empty {
  margin: 8px 0;
  color: var(--muted);
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

.history-item {
  width: 100%;
  min-height: 36px;
  display: block;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 9px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

.history-item:hover,
.history-item[aria-current="true"] {
  background: rgba(143, 47, 39, 0.075);
  color: var(--ink);
}

.chat {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  width: min(1180px, calc(100vw - 96px));
  height: 100dvh;
  min-height: 0;
  justify-self: center;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  padding: 22px clamp(28px, 4vw, 56px) 16px;
}

.chat::before {
  content: "";
  position: absolute;
  inset: 92px 36px 94px;
  pointer-events: none;
  border-top: 1px solid rgba(61, 47, 39, 0.045);
  border-bottom: 1px solid rgba(61, 47, 39, 0.045);
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0,
      transparent 78px,
      rgba(61, 47, 39, 0.04) 79px,
      transparent 80px
    );
  opacity: 0.38;
  animation: ambient-field 16s var(--ease-panel) infinite alternate;
}

@keyframes ambient-field {
  from {
    opacity: 0.24;
    transform: translateY(0);
  }

  to {
    opacity: 0.42;
    transform: translateY(8px);
  }
}

.chat__header,
.messages,
.status,
.composer {
  position: relative;
  z-index: 1;
}

.chat__header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-weight: 500;
}

h1 {
  font-size: 34px;
  line-height: 1.05;
}

.ghost-button {
  min-height: 36px;
  padding: 0 12px;
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  transition:
    background-color 180ms ease,
    border-color 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.ghost-button:hover,
.ghost-button[aria-expanded="true"] {
  background: rgba(255, 252, 246, 0.48);
  border-color: rgba(143, 47, 39, 0.22);
  color: var(--accent-dark);
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 8px 2px 18px 0;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.empty {
  max-width: 470px;
  margin: 10vh 0 0;
  color: var(--muted);
  font-size: 24px;
  line-height: 1.36;
  text-wrap: pretty;
}

.message {
  display: grid;
  margin: 0 0 14px;
}

.message__body {
  max-width: min(720px, 92%);
  white-space: pre-wrap;
  line-height: 1.68;
  font-size: 16px;
  text-wrap: pretty;
}

.message--user {
  justify-items: end;
}

.message--user .message__body {
  max-width: min(560px, 88%);
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.58;
}

.message--assistant .message__body {
  border-top: 1px solid var(--line);
  padding-top: 13px;
}

.message--assistant .message__body > * {
  margin: 0 0 10px;
}

.message--assistant .message__body > *:last-child {
  margin-bottom: 0;
}

.message--assistant h3,
.message--assistant h4,
.message--assistant h5 {
  font-size: 1em;
  line-height: 1.5;
  font-weight: 600;
}

.message--assistant ul,
.message--assistant ol {
  padding-left: 1.25em;
}

.message--assistant li + li {
  margin-top: 4px;
}

.message--assistant blockquote {
  border-left: 2px solid rgba(143, 47, 39, 0.28);
  color: var(--muted);
  padding-left: 12px;
}

.message--assistant code {
  border: 1px solid rgba(61, 47, 39, 0.12);
  border-radius: 5px;
  background: rgba(255, 252, 246, 0.6);
  padding: 0 4px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9em;
}

.message--assistant pre {
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid rgba(61, 47, 39, 0.14);
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.56);
  padding: 12px;
}

.message--assistant pre code {
  display: block;
  border: 0;
  background: transparent;
  padding: 0;
  line-height: 1.55;
}

.message--assistant a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.message__meta {
  margin-top: 5px;
  color: var(--muted);
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
}

.message__audio {
  max-width: min(720px, 92%);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
}

.message__audio-status {
  opacity: 0.8;
}

.message__audio[data-audio-status="loading"] .message__audio-status::after {
  content: "";
  display: inline-block;
  width: 1.4em;
  animation: thinking-dots 1.1s steps(4, end) infinite;
}

.audio-action {
  min-height: 28px;
  border: 1px solid rgba(61, 47, 39, 0.14);
  border-radius: 999px;
  background: rgba(255, 252, 246, 0.5);
  color: var(--accent-dark);
  cursor: pointer;
  padding: 0 10px;
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
}

.audio-action:hover {
  background: rgba(143, 47, 39, 0.08);
  border-color: rgba(143, 47, 39, 0.24);
}

.message--user .message__meta {
  max-width: min(560px, 88%);
  text-align: right;
}

.message.is-queued .message__body {
  opacity: 0.68;
}

.message.is-thinking .message__body {
  color: var(--muted);
  min-width: 7em;
}

.message.is-thinking .message__body::after {
  content: "";
  display: inline-block;
  width: 1.4em;
  animation: thinking-dots 1.1s steps(4, end) infinite;
}

@keyframes thinking-dots {
  0% {
    content: "";
  }

  25% {
    content: ".";
  }

  50% {
    content: "..";
  }

  75%,
  100% {
    content: "...";
  }
}

.status {
  min-height: 20px;
  margin: 0 0 8px;
  color: var(--muted);
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 12px;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: end;
  padding: 10px 0 max(0px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.command-menu {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 3;
  width: min(250px, 100%);
  border: 1px solid rgba(61, 47, 39, 0.12);
  border-radius: 8px;
  background: rgba(255, 252, 246, 0.94);
  box-shadow: 0 14px 34px rgba(61, 47, 39, 0.12);
  padding: 5px;
  backdrop-filter: blur(12px);
}

.command-menu[hidden] {
  display: none;
}

.command-item {
  width: 100%;
  min-height: 38px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: 6px;
  background: rgba(143, 47, 39, 0.075);
  color: var(--ink);
  cursor: pointer;
  padding: 7px 9px;
  text-align: left;
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.command-item span {
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 600;
}

.command-item small {
  color: var(--muted);
  font-size: 12px;
}

.command-item:hover,
.command-item:focus-visible {
  background: rgba(143, 47, 39, 0.11);
  outline: none;
}

.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  outline: none;
}

.composer textarea {
  min-height: 44px;
  max-height: 150px;
  resize: none;
  padding: 11px 12px;
  line-height: 1.45;
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

.composer button {
  min-width: 68px;
  min-height: 44px;
  padding: 0 14px;
  font-family:
    "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC",
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

.mode-toggle {
  grid-column: 1 / -1;
  justify-self: start;
  display: inline-flex;
  gap: 2px;
  border: 1px solid rgba(61, 47, 39, 0.12);
  border-radius: 999px;
  background: rgba(255, 252, 246, 0.48);
  padding: 2px;
}

.mode-toggle button {
  min-width: auto;
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  font-size: 12px;
  transition:
    background-color 180ms ease,
    color 180ms ease,
    transform 180ms ease;
}

.mode-toggle button:hover {
  color: var(--ink);
}

.mode-toggle button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

#send-button {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

#stop-button {
  color: var(--accent-dark);
  border-color: var(--accent-dark);
}

@media (max-width: 760px) {
  .shell,
  .shell.is-history-collapsed {
    grid-template-columns: 0 minmax(0, 1fr);
  }

  .history-hotspot {
    display: none;
  }

  .shell.is-history-open .history-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .history-pane {
    z-index: 8;
    padding: 14px 10px;
  }

  .shell.is-history-collapsed .history-pane {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(288px, 84vw);
    transform: translateX(-104%);
  }

  .shell.is-history-collapsed.is-history-peeking .history-pane,
  .shell.is-history-collapsed.is-history-open .history-pane {
    transform: translateX(0);
  }

  .shell:not(.is-history-collapsed) .history-pane {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(288px, 84vw);
    box-shadow: var(--shadow);
    transform: translateX(0);
  }

  .chat {
    width: 100%;
    padding: 14px 12px 12px;
  }

  .chat__header {
    align-items: center;
    padding-bottom: 12px;
  }

  h1 {
    font-size: 24px;
  }

  .empty {
    margin-top: 8vh;
    font-size: 20px;
  }

  .message__body {
    font-size: 15px;
  }

  .message--user .message__body {
    font-size: 13px;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 58px;
  }

  #stop-button {
    grid-column: 2;
  }

  .composer button {
    min-width: 58px;
    padding: 0 10px;
  }

  .mode-toggle button {
    min-width: auto;
    min-height: 28px;
    padding: 0 9px;
  }
}
