:root {
  color-scheme: light;
  --paper: #f4f1e9;
  --paper-deep: #e9e4d8;
  --panel: #fbfaf6;
  --ink: #1c2622;
  --muted: #69726d;
  --line: rgba(31, 54, 46, 0.13);
  --green: #1f4b3f;
  --green-soft: #e5ede8;
  --amber: #d6923a;
  --user: #e9e2d4;
  --danger: #a54635;
  --shadow: 0 24px 70px rgba(45, 54, 46, 0.09);
  --sans: "Avenir Next", "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  --serif: "Iowan Old Style", "Songti SC", "STSong", "Noto Serif SC", serif;
}

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

html,
body {
  height: 100%;
}

html {
  overflow: hidden;
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 92% 5%, rgba(221, 178, 94, 0.15), transparent 22rem),
    radial-gradient(circle at 5% 95%, rgba(31, 75, 63, 0.08), transparent 26rem),
    var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button,
textarea {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
}

button,
a,
textarea {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid rgba(31, 75, 63, 0.3);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

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

.skip-link {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100;
  padding: 0.7rem 1rem;
  color: white;
  background: var(--green);
  border-radius: 8px;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.shell {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  width: min(1480px, calc(100% - 36px));
  height: calc(100dvh - 36px);
  min-height: 0;
  margin: 18px auto;
  overflow: hidden;
  background: rgba(251, 250, 246, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 26px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 24px 18px 20px;
  background:
    linear-gradient(150deg, rgba(255, 255, 255, 0.36), transparent 45%),
    var(--paper-deep);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px;
  color: inherit;
  text-decoration: none;
}

.brand__mark {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  color: #fffaf0;
  background: var(--green);
  border-radius: 13px 13px 13px 4px;
  box-shadow: 0 8px 20px rgba(31, 75, 63, 0.18);
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 700;
  place-items: center;
  transform: rotate(-3deg);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-family: var(--serif);
  font-size: 1.14rem;
  letter-spacing: -0.02em;
}

.brand small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.69rem;
  letter-spacing: 0.03em;
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin: 26px 0 22px;
  padding: 12px 14px;
  color: #fff;
  background: var(--green);
  border: 0;
  border-radius: 11px;
  box-shadow: 0 8px 22px rgba(31, 75, 63, 0.15);
  font-weight: 650;
  transition:
    transform 160ms ease,
    background 160ms ease;
}

.new-chat:hover {
  background: #173d33;
  transform: translateY(-1px);
}

.new-chat span {
  font-size: 1.15rem;
  font-weight: 400;
}

.history {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.history__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 9px;
  color: var(--muted);
}

.history__head h2 {
  margin: 0;
  font-size: 0.69rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.history__head span {
  display: grid;
  min-width: 21px;
  height: 21px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 99px;
  font-size: 0.67rem;
  place-items: center;
}

.history__list {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 3px;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.history__empty {
  margin: 4px 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 10px 11px;
  overflow: hidden;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  transition:
    background 150ms ease,
    border-color 150ms ease;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.55);
}

.history-item.is-active {
  background: rgba(255, 255, 255, 0.76);
  border-color: rgba(31, 75, 63, 0.09);
  box-shadow: 0 4px 16px rgba(49, 55, 49, 0.04);
}

.history-item span {
  overflow: hidden;
  font-size: 0.85rem;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item small {
  color: var(--muted);
  font-size: 0.68rem;
}

.sidebar__foot {
  margin-top: auto;
  padding-top: 22px;
}

.memory-card {
  display: flex;
  gap: 9px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid rgba(31, 75, 63, 0.08);
  border-radius: 11px;
}

.memory-card__dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  margin-top: 6px;
  background: var(--amber);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(214, 146, 58, 0.12);
}

.memory-card strong {
  font-size: 0.75rem;
}

.memory-card p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.69rem;
  line-height: 1.55;
}

.text-button {
  width: 100%;
  margin-top: 10px;
  padding: 7px;
  color: var(--muted);
  background: none;
  border: 0;
  font-size: 0.72rem;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
}

.text-button:hover {
  color: var(--danger);
  text-decoration-color: currentColor;
}

.chat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(31, 54, 46, 0.025) 1px, transparent 1px) 0 0 / 100% 42px,
    rgba(251, 250, 246, 0.9);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 21px 30px 18px;
  border-bottom: 1px solid var(--line);
}

.model-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.model-title__status {
  width: 9px;
  height: 9px;
  background: #4c9a74;
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(76, 154, 116, 0.12);
}

.model-title__row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.model-title h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.3rem;
  letter-spacing: -0.025em;
}

.model-title p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
}

.model-pill {
  max-width: 190px;
  padding: 3px 8px;
  overflow: hidden;
  color: var(--green);
  background: var(--green-soft);
  border-radius: 99px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.64rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.expiry {
  text-align: right;
}

.expiry span,
.expiry strong {
  display: block;
}

.expiry span {
  color: var(--muted);
  font-size: 0.63rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.expiry strong {
  margin-top: 1px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.74rem;
  font-weight: 600;
}

.messages {
  min-height: 0;
  padding: 34px clamp(22px, 7vw, 110px) 28px;
  overflow-y: auto;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  scrollbar-color: rgba(31, 75, 63, 0.24) transparent;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.messages::-webkit-scrollbar {
  width: 8px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(31, 75, 63, 0.2);
  border: 2px solid transparent;
  border-radius: 99px;
  background-clip: padding-box;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.empty-state {
  width: min(670px, 100%);
  margin: clamp(2rem, 10vh, 7rem) auto 0;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 18px;
  color: var(--green);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.13em;
}

.eyebrow::before {
  width: 28px;
  height: 1px;
  content: "";
  background: currentColor;
}

.empty-state h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(2.5rem, 5.2vw, 4.65rem);
  font-weight: 500;
  letter-spacing: -0.055em;
  line-height: 1.04;
}

.empty-state__copy {
  max-width: 520px;
  margin: 22px 0 30px;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.8;
}

.prompts {
  display: grid;
  gap: 8px;
  width: min(520px, 100%);
}

.prompts button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  color: #37413c;
  text-align: left;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 0.79rem;
  transition:
    border-color 150ms ease,
    transform 150ms ease,
    background 150ms ease;
}

.prompts button:hover {
  background: #fff;
  border-color: rgba(31, 75, 63, 0.28);
  transform: translateX(3px);
}

.prompts button span {
  color: var(--amber);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.64rem;
}

.message-list {
  width: min(800px, 100%);
  margin: 0 auto;
}

.message {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 17px;
  margin-bottom: 26px;
  animation: message-in 240ms ease both;
}

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

.message__meta {
  padding-top: 12px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.message__meta time {
  display: block;
  margin-top: 2px;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.57rem;
  font-weight: 400;
}

.message__bubble {
  padding: 13px 17px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px 15px 15px 15px;
  box-shadow: 0 5px 18px rgba(46, 53, 47, 0.035);
}

.message__bubble p {
  margin: 0;
  color: #303b36;
  font-size: 0.92rem;
  line-height: 1.78;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message--user {
  grid-template-columns: minmax(0, 1fr) 76px;
}

.message--user .message__meta {
  grid-column: 2;
  grid-row: 1;
  text-align: right;
}

.message--user .message__bubble {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  max-width: min(620px, 90%);
  background: var(--user);
  border-color: transparent;
  border-radius: 15px 5px 15px 15px;
}

.message.is-streaming .message__bubble p::after {
  display: inline-block;
  width: 5px;
  height: 1em;
  margin-left: 3px;
  vertical-align: -0.12em;
  content: "";
  background: var(--green);
  border-radius: 2px;
  animation: blink 850ms steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.message.has-error .message__bubble {
  color: var(--danger);
  background: #fff8f5;
  border-color: rgba(165, 70, 53, 0.2);
}

.message.has-error .message__bubble p {
  color: var(--danger);
}

.composer {
  width: min(840px, calc(100% - 52px));
  margin: 0 auto;
  padding: 12px 15px 9px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(31, 75, 63, 0.17);
  border-radius: 16px;
  box-shadow:
    0 16px 44px rgba(41, 50, 42, 0.08),
    0 0 0 5px rgba(255, 255, 255, 0.32);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.composer:focus-within {
  border-color: rgba(31, 75, 63, 0.4);
  box-shadow:
    0 16px 44px rgba(41, 50, 42, 0.08),
    0 0 0 5px rgba(31, 75, 63, 0.05);
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 25px;
  max-height: 168px;
  padding: 2px 3px 6px;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  resize: none;
  font-size: 0.92rem;
  line-height: 1.6;
}

.composer textarea::placeholder {
  color: #9a9f9c;
}

.composer__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 29px;
}

.composer__foot > span:first-child {
  color: #9a9f9c;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.61rem;
}

.composer__actions {
  display: flex;
  align-items: center;
  gap: 11px;
}

.sending-label {
  display: none;
  color: var(--muted);
  font-size: 0.68rem;
}

.sending-label.is-visible {
  display: inline;
}

.send {
  display: grid;
  width: 30px;
  height: 30px;
  padding: 0;
  color: white;
  background: var(--green);
  border: 0;
  border-radius: 9px;
  place-items: center;
  transition:
    background 150ms ease,
    transform 150ms ease;
}

.send:hover:not(:disabled) {
  background: #173d33;
  transform: translateY(-1px);
}

.send:disabled {
  background: #8b9992;
}

.send svg {
  width: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.notice {
  min-height: 30px;
  margin: 0;
  padding: 4px 28px 7px;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
  opacity: 0;
  transform: translateY(-3px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.notice.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.notice[data-type="error"] {
  color: var(--danger);
}

@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    width: 100%;
    height: 100dvh;
    min-height: 0;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .sidebar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px 16px;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding: 0;
  }

  .brand__mark {
    width: 35px;
    height: 35px;
    border-radius: 10px 10px 10px 3px;
    font-size: 1.05rem;
  }

  .brand small {
    display: none;
  }

  .new-chat {
    grid-column: 2;
    grid-row: 1;
    width: auto;
    margin: 0;
    padding: 8px 12px;
    font-size: 0.78rem;
  }

  .history {
    grid-column: 1 / -1;
    flex: initial;
  }

  .history__head {
    display: none;
  }

  .history__list {
    flex-direction: row;
    flex: initial;
    max-height: none;
    padding-bottom: 2px;
    overflow-x: auto;
  }

  .history-item {
    flex: 0 0 auto;
    width: auto;
    max-width: 210px;
    padding: 7px 10px;
    border-color: rgba(31, 75, 63, 0.08);
  }

  .history-item small {
    display: none;
  }

  .history__empty {
    margin: 0;
    padding: 6px 0;
  }

  .sidebar__foot {
    display: none;
  }

  .chat {
    min-height: 0;
  }

  .topbar {
    padding: 14px 18px;
  }

  .model-title h1 {
    font-size: 1.12rem;
  }

  .model-title p {
    display: none;
  }

  .messages {
    padding: 25px 18px 20px;
  }

  .empty-state {
    margin-top: 5vh;
  }

  .empty-state h2 {
    font-size: clamp(2.45rem, 13vw, 4rem);
  }

  .composer {
    width: calc(100% - 24px);
    margin-bottom: 5px;
  }

  .notice {
    padding-inline: 16px;
  }
}

@media (max-width: 560px) {
  .model-pill {
    display: none;
  }

  .expiry span {
    display: none;
  }

  .prompts {
    gap: 6px;
  }

  .message {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .message__meta,
  .message--user .message__meta {
    grid-column: 1;
    grid-row: 1;
    padding-top: 0;
    text-align: left;
  }

  .message--user .message__meta {
    text-align: right;
  }

  .message__bubble,
  .message--user .message__bubble {
    grid-column: 1;
    grid-row: 2;
    max-width: 100%;
  }
}

@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;
  }
}
