:root {
  color-scheme: light;
  --paper: #f7f4ed;
  --rail: #eee9df;
  --card: #fbf8f2;
  --ink: #28251f;
  --muted: #686052;
  --line: #dfd7c9;
  --accent: #ac3f2d;
  --accent-dark: #8e3022;
  --accent-wash: #f3e2d8;
  --sans: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --serif: "Songti SC", "Noto Serif CJK SC", SimSun, Georgia, serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-family: var(--sans);
  font-size: 14px;
  background: var(--paper);
  color: var(--ink);
}

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

body {
  margin: 0;
  min-width: 280px;
  min-height: 100vh;
}

button, textarea, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, a, textarea, input, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

::selection { background: #efc9bc; color: #42251e; }

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

.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  display: block;
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.55;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  position: relative;
  z-index: 3;
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 28px 16px 17px;
  background: var(--rail);
  border-right: 1px solid var(--line);
}

.sidebar-top, .brand { display: flex; align-items: center; }
.sidebar-top { justify-content: space-between; padding: 0 9px; }
.brand { gap: 11px; user-select: none; }

.brand-mark, .access-icon {
  display: grid;
  flex: none;
  place-items: center;
}

.brand-mark {
  width: 35px;
  height: 35px;
  color: #fff3e7;
  background: var(--accent);
  border-radius: 9px;
}

.brand-mark .icon { width: 20px; height: 20px; stroke-width: 1.25; }

.brand-name {
  padding-bottom: 2px;
  font: 700 31px/.95 Georgia, serif;
  letter-spacing: -.075em;
}

.brand-name::after {
  content: "";
  display: inline-block;
  width: .16em;
  height: .16em;
  margin-left: .075em;
  border-radius: 50%;
  background: var(--accent);
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-height: 44px;
  margin: 34px 0 0;
  padding: 0 12px;
  border: 1px solid #d5cabc;
  border-radius: 8px;
  background: #f7f2e9;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: background .18s ease, border-color .18s ease;
}

.new-chat > .icon:first-child { color: var(--accent); }
.new-chat .new-chat-arrow { width: 14px; height: 14px; margin-left: auto; color: #746858; }
.new-chat:hover { border-color: #bfae9c; background: #faf6ee; }

.history {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  margin-top: 35px;
}

.section-label {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .115em;
}

.history > .section-label { padding: 0 9px; }
.history-list { margin-top: 12px; padding: 0 0 10px; overflow: auto; }
.history-empty, .history-list > p { margin: 10px 9px; color: var(--muted); font-size: 12px; }
.history-item { display: flex; position: relative; align-items: center; border-radius: 7px; }
.history-item:hover { background: #e8e0d3; }
.history-item:has([aria-current="true"]), .history-item.is-active { background: #e5ddcf; }

.history-open, .history-delete {
  min-height: 39px;
  border: 0;
  background: transparent;
  border-radius: 7px;
}

.history-open {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  padding: 0 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
  font-size: 13px;
}

.history-open > .icon { display: inline-block; vertical-align: middle; margin-right: 6px; }
.history-delete { flex: none; width: 31px; color: var(--muted); opacity: .68; }
.history-delete:hover { color: var(--accent); opacity: 1; }
.history-delete .icon { margin: auto; }

.sidebar-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid #dcd2c3; }
.admin-link { display: block; width: fit-content; margin: 4px 0 0 12px; padding: 7px 0; color: var(--muted); font-size: 12px; text-underline-offset: 4px; }
.admin-link:hover { color: var(--accent-dark); }

.access-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 56px;
  padding: 7px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  transition: background .18s ease;
}

.access-button:hover { background: #e8e0d3; }

.access-icon {
  width: 33px;
  height: 33px;
  border: 1px solid #d7cbbb;
  border-radius: 7px;
  color: var(--accent);
  background: #f6f0e7;
}

.access-icon .icon { width: 16px; height: 16px; }
.access-text { display: grid; min-width: 0; gap: 3px; }
.access-title { font-size: 12px; font-weight: 650; }
#access-label { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.access-arrow { width: 14px; height: 14px; margin-left: auto; color: var(--muted); }

.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex;
  flex: none;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 67px;
  padding: 0 34px;
  border-bottom: 1px solid var(--line);
}

.topbar-title { display: flex; align-items: center; min-width: 0; gap: 11px; font-size: 13px; }
.crumb, .crumb-separator { flex: none; color: var(--muted); }
.crumb-separator { color: #968778; }

#conversation-title {
  overflow: hidden;
  color: var(--ink);
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 13px;
}

.topbar-brand { display: none; }

.teacher-open {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid #ddc5b5;
  border-radius: 7px;
  background: #f8ede3;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.teacher-open:hover { border-color: #c99984; background: var(--accent-wash); }
.teacher-open .icon { width: 16px; height: 16px; }

.icon-button {
  display: grid;
  flex: none;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
}

.icon-button:hover { background: #eee5d7; }
.mobile-only, .sidebar-scrim { display: none; }
.work-area { display: flex; min-height: 0; flex: 1; flex-direction: column; }

.work-area:has(#welcome:not([hidden])) {
  justify-content: center;
  padding-bottom: clamp(24px, 7.5vh, 96px);
}

.feed {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable both-edges;
}

.work-area:has(#welcome:not([hidden])) .feed { flex: 0 1 auto; }
.welcome, .messages, .composer-dock { width: min(100% - 56px, 778px); margin-inline: auto; }
.welcome { padding-top: 24px; padding-bottom: 24px; }

.hero { margin-bottom: clamp(21px, 4vh, 34px); }

.hero h1 {
  margin: 0;
  font: 700 clamp(43px, 4.2vw, 62px)/1.16 var(--serif);
  letter-spacing: -.04em;
}

.hero-description {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

.suggestion-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }

.suggestion {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-content: center;
  align-items: center;
  gap: 9px;
  min-height: 98px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #faf7f0;
  text-align: left;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.suggestion:hover { border-color: #d0b7a4; background: #fcf9f3; transform: translateY(-2px); }
.suggestion:active { transform: translateY(0); }

.suggestion-icon {
  display: grid;
  flex: none;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 7px;
  background: var(--accent-wash);
  color: var(--accent);
}

.suggestion:nth-child(2) .suggestion-icon { background: #ebe5d6; color: #746141; }
.suggestion:nth-child(3) .suggestion-icon { background: #ece4e9; color: #73526a; }
.suggestion:nth-child(4) .suggestion-icon { background: #e6eadc; color: #5c694d; }
.suggestion-icon .icon { width: 17px; height: 17px; }
.suggestion-text { display: grid; grid-column: 1 / -1; min-width: 0; gap: 4px; }
.suggestion-text strong { font-size: 13px; font-weight: 650; }
.suggestion-text small { color: var(--muted); font-size: 11px; line-height: 1.35; }
.suggestion-arrow { grid-column: 2; grid-row: 1; width: 13px; height: 13px; color: #817464; }

.composer-dock { flex: none; padding: 10px 0 12px; }
.work-area:has(#welcome:not([hidden])) .composer-dock { padding-top: 0; }

.composer {
  padding: 9px 11px 10px;
  border: 1px solid #d7cbbb;
  border-radius: 14px;
  background: #fffcf7;
  box-shadow: 0 6px 24px #4e3a2110, 0 2px 4px #4e3a2108;
  transition: border-color .18s ease, box-shadow .18s ease;
}

.composer:focus-within { border-color: #bd9681; box-shadow: 0 6px 24px #4e3a2114, 0 0 0 2px #d6a18c24; }

.composer textarea {
  display: block;
  width: 100%;
  min-height: 54px;
  max-height: min(160px, 24vh);
  padding: 9px 5px 6px;
  resize: none;
  border: 0;
  border-radius: 5px;
  background: transparent;
  outline: none;
  font-size: 15px;
  line-height: 1.6;
  scrollbar-color: #c2b6a6 transparent;
}

.composer textarea::placeholder { color: #746c60; }
.composer textarea:focus-visible { outline: none; }
.composer-toolbar, .composer-controls, .mode-picker, .image-options { display: flex; align-items: center; min-width: 0; }
.composer-toolbar { gap: 8px; }
.composer-controls { gap: 8px; flex: 1; flex-wrap: wrap; }
.mode-picker { gap: 3px; }
.image-options { gap: 5px; }

.mode-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.mode-button:hover { background: #f4eee4; }
.mode-button[aria-pressed="true"] { border-color: #ecd8cb; background: #f6eae1; color: var(--accent-dark); }
.mode-button .icon { width: 16px; height: 16px; }

.image-options select {
  height: 31px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8f4eb;
  color: #594f43;
  font-size: 12px;
}

.send-button {
  display: grid;
  flex: none;
  width: 36px;
  height: 36px;
  margin-left: auto;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff8ed;
  transition: background .18s ease, color .18s ease;
}

.send-button .icon { width: 19px; height: 19px; stroke-width: 1.8; }
.send-button:disabled { background: #e8dbcd; color: #716354; }
.send-button:hover:not(:disabled), .primary-button:hover:not(:disabled) { background: var(--accent-dark); }

.composer-status {
  margin: 8px 3px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.composer-status:empty { display: none; }
.composer-status[data-state="error"], .dialog-error { color: #9d3025; }
.footer-note { margin: 10px 0 0; color: var(--muted); text-align: center; font-size: 11px; line-height: 1.5; }
.quota-note { color: var(--accent-dark); font-weight: 650; }
.access-admin-link { display: inline-block; padding: 6px 0; color: var(--muted); font-size: 12px; text-underline-offset: 4px; }
.access-admin-link:hover { color: var(--accent-dark); }

.messages { display: grid; gap: 24px; padding-top: 35px; padding-bottom: 25px; }
.message { display: grid; gap: 8px; justify-items: start; min-width: 0; }
.message--user { justify-items: end; }
.message-author { color: var(--muted); font-size: 12px; font-weight: 650; }
.message--assistant .message-author { color: var(--accent-dark); }

.message-body {
  max-width: 100%;
  min-width: 0;
  font-size: 15px;
  line-height: 1.85;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-body p { margin: 0 0 1em; }
.message-body p:last-child { margin-bottom: 0; }
.message-body a { color: var(--accent-dark); text-underline-offset: 3px; }

.message-body pre {
  max-width: 100%;
  overflow: auto;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eee7da;
  white-space: pre;
}

.message-body code { font-family: var(--mono); font-size: .93em; }

.message--user .message-body {
  width: fit-content;
  max-width: min(85%, 630px);
  padding: 8px 13px;
  border: 1px solid #e5dbca;
  border-radius: 13px 13px 4px 13px;
  background: #efe7d8;
}

.message-image {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 520px);
  max-height: min(72vh, 640px);
  object-fit: contain;
  border-radius: 9px;
  background: #eee5d7;
}

.message-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.message-actions button, .message-actions a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  color: #635848;
  font-size: 12px;
  text-decoration: none;
}

.message-actions button:hover, .message-actions a:hover { border-color: #c9ac99; color: var(--accent-dark); }
.message-actions button:disabled { opacity: .65; cursor: wait; }
.message-actions small { color: var(--muted); }
.message-loading { color: var(--muted); }
.message-loading::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: .12em;
  animation: working 1.25s ease-in-out infinite alternate;
}

@keyframes working { from { opacity: .32; } to { opacity: 1; } }

.access-dialog, .teacher-dialog {
  max-height: calc(100dvh - 34px);
  padding: 22px;
  border: 1px solid #d2c2af;
  border-radius: 13px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 18px 55px #241b1450;
}

.access-dialog { width: min(410px, 100% - 34px); }
.teacher-dialog { width: min(548px, 100% - 28px); overscroll-behavior: contain; }
.access-dialog::backdrop, .teacher-dialog::backdrop { background: #26211b76; }
.dialog-top { display: flex; justify-content: space-between; align-items: center; }
.access-dialog h2 { margin: 16px 0 11px; font: 700 26px/1.25 var(--serif); }
.access-dialog p { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.access-dialog label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 650; }

.access-dialog input {
  display: block;
  width: 100%;
  height: 42px;
  padding: 0 10px;
  border: 1px solid #d6c9b8;
  border-radius: 7px;
  background: #fffcf7;
}

.access-dialog .dialog-error { margin: 7px 0 0; color: #9d3025; }
.access-dialog .dialog-error[data-state="info"] { color: var(--muted); }
.dialog-error:empty { display: none; }

.primary-button {
  width: 100%;
  min-height: 42px;
  margin-top: 15px;
  padding: 6px 12px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff6e9;
  font-size: 13px;
  font-weight: 650;
}

.primary-button:disabled { opacity: .65; }

.teacher-dialog .dialog-top { gap: 12px; margin-bottom: 16px; }
.teacher-dialog h2 { margin: 0; font: 700 26px/1.25 var(--serif); }
.teacher-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 13px; }
.teacher-field { display: grid; align-content: start; min-width: 0; gap: 6px; }
.teacher-field--wide { grid-column: 1 / -1; }
.teacher-field label, label.teacher-field { font-size: 13px; font-weight: 650; }

.teacher-field :is(input, select, textarea) {
  width: 100%;
  min-width: 0;
  min-height: 41px;
  padding: 8px 10px;
  border: 1px solid #d6c9b8;
  border-radius: 7px;
  background: #fffcf7;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
}

.teacher-field textarea { min-height: 76px; resize: vertical; }
.teacher-field :is(input, textarea)::placeholder { color: #756b5f; }
.teacher-field :is(input, select, textarea)[aria-invalid="true"] { border-color: var(--accent); }
.teacher-help, .teacher-draft-note, .teacher-error { margin: 10px 0 0; font-size: 12px; line-height: 1.55; }
.teacher-help, .teacher-draft-note { color: var(--muted); }
.teacher-help:empty { display: none; }
.teacher-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.teacher-actions .primary-button, .secondary-button { width: auto; min-height: 42px; margin: 0; padding: 6px 15px; }

.secondary-button {
  border: 1px solid #d6c9b8;
  border-radius: 7px;
  background: #fcf8f0;
  font-size: 13px;
  font-weight: 600;
}

.secondary-button:hover { background: #eee5d7; }

@media (max-width: 1024px) {
  .shell { grid-template-columns: 218px minmax(0, 1fr); }
  .topbar { padding-inline: 24px; }
}

@media (max-width: 900px) {
  .suggestion-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 86vw);
    visibility: hidden;
    transform: translateX(-100%);
    transition: visibility .22s, transform .22s ease;
  }
  .sidebar[data-open="true"] { visibility: visible; transform: translateX(0); }
  .sidebar-scrim {
    display: block;
    position: fixed;
    z-index: 2;
    inset: 0;
    padding: 0;
    border: 0;
    background: #26211b76;
  }
  .mobile-only { display: grid; }
  .topbar { min-height: 57px; padding-inline: 10px 15px; gap: 8px; }
  .topbar-title { gap: 8px; }
  .crumb, .crumb-separator { display: none; }
  .topbar-brand { display: block; color: var(--ink); font: 700 21px/1 Georgia, serif; letter-spacing: -.065em; }
  .teacher-open { min-height: 42px; }
  .feed { scrollbar-gutter: auto; }
  .welcome, .messages, .composer-dock { width: min(100% - 36px, 560px); }
  .hero h1 { font-size: clamp(35px, 7vw, 49px); }
  .hero-description { margin-top: 9px; font-size: 13px; }
  .messages { gap: 19px; padding-top: 23px; }
  .composer-dock { padding-bottom: max(9px, env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
  .work-area:has(#welcome:not([hidden])) { padding-bottom: 0; justify-content: start; }
  .work-area:has(#welcome:not([hidden])) .feed { flex: 1; }
  .welcome { padding-top: clamp(18px, 5vh, 42px); padding-bottom: 17px; }
  .suggestion-grid { gap: 7px; }
  .suggestion { gap: 6px; min-height: 82px; padding: 8px 9px; }
  .suggestion-icon { width: 28px; height: 28px; }
  .suggestion-text { gap: 3px; }
  .work-area:has(#welcome:not([hidden])) .composer-dock { padding-top: 9px; }
  .composer { padding: 8px; }
  .composer-controls { gap: 5px; }
  .mode-button { padding-inline: 5px; }
  .mode-button .icon { width: 14px; height: 14px; }
  .teacher-dialog { padding: 16px; }
  .teacher-dialog .dialog-top { margin-bottom: 9px; }
  .teacher-fields { gap: 8px; margin-top: 9px; }
  .teacher-field { gap: 4px; }
  .teacher-field :is(input, select, textarea) { font-size: 16px; }
  .teacher-field textarea { height: 69px; min-height: 60px; }
  .teacher-actions .primary-button, .secondary-button { min-height: 44px; }
}

@media (max-width: 350px) {
  .topbar-actions { gap: 7px; }
  .topbar-brand { font-size: 18px; }
  .welcome, .messages, .composer-dock { width: calc(100% - 24px); }
  .composer-toolbar { gap: 4px; }
  .composer-controls, .image-options { gap: 3px; }
  .teacher-fields { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 480px) and (max-height: 680px) {
  .welcome { padding-top: 23px; }
}

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