:root {
  color-scheme: light;
  --paper: #f4f1e8;
  --sheet: #fffdf7;
  --ink: #211f1b;
  --muted: #716d63;
  --line: #d8d1c2;
  --wash: #ebe5d7;
  --cinnabar: #a33a2b;
  --cinnabar-dark: #7c291f;
  --technical: #263a42;
  font-family: "Songti SC", "STSong", "Noto Serif CJK SC", serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); }
button, textarea, input, summary { font: inherit; }
button, summary { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 30px 24px; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: #ebe6da; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-seal, .assistant-mark { display: grid; place-items: center; flex: 0 0 auto; color: #fff8ea; background: var(--cinnabar); }
.brand-seal { width: 42px; height: 42px; border-radius: 50%; font-size: 1.25rem; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1.02rem; letter-spacing: .03em; }
.brand small { margin-top: 4px; color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: .72rem; }
.new-chat { margin-top: 34px; width: 100%; padding: 11px 14px; border: 1px solid var(--ink); background: transparent; color: var(--ink); text-align: left; font-weight: 700; }
.new-chat::before { content: "+"; margin-right: 10px; color: var(--cinnabar); font-size: 1.15rem; }
.new-chat:hover { background: var(--sheet); }
.history-panel { min-height: 0; margin-top: 22px; display: flex; flex: 1 1 auto; flex-direction: column; border-top: 1px solid var(--line); padding-top: 16px; }
.history-panel h2 { margin: 0 0 9px; color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: .72rem; font-weight: 700; letter-spacing: .08em; }
.history-list { min-height: 0; overflow-y: auto; }
.history-empty { margin: 5px 0; color: var(--muted); font-size: .8rem; line-height: 1.55; }
.history-item { width: 100%; display: block; padding: 9px 10px; border: 0; border-left: 2px solid transparent; background: transparent; color: var(--ink); text-align: left; }
.history-item:hover { background: rgba(255, 253, 247, .65); }
.history-item.active { border-left-color: var(--cinnabar); background: var(--sheet); }
.history-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; }
.history-time { display: block; margin-top: 3px; color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: .68rem; }
.session-note { margin-top: 25px; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; line-height: 1.65; }
.session-note p { margin: 0 0 8px; }
.developer-switch { margin-top: auto; display: flex; align-items: center; gap: 9px; color: var(--technical); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: .82rem; }
.developer-switch input { accent-color: var(--technical); }

.chat-panel { min-width: 0; max-width: 960px; width: 100%; margin: 0 auto; padding: 0 44px 190px; }
.chat-header { padding: 34px 0 23px; border-bottom: 2px solid var(--ink); display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.chat-header h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: .04em; }
.chat-header p { margin: 8px 0 0; color: var(--muted); font-size: .92rem; }
.connection-state { flex: 0 0 auto; padding: 5px 9px; border: 1px solid var(--line); color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: .72rem; }
.conversation { padding: 28px 0; }
.empty-state { max-width: 540px; margin: 14vh auto 0; text-align: center; color: var(--muted); }
.empty-mark { width: 54px; height: 54px; margin: 0 auto 18px; display: grid; place-items: center; border: 1px solid var(--cinnabar); border-radius: 50%; color: var(--cinnabar); font-size: 1.35rem; }
.empty-state h2 { margin: 0 0 10px; color: var(--ink); font-size: 1.25rem; }
.empty-state p { margin: 0; line-height: 1.75; }
.turn { padding: 10px 0 36px; border-bottom: 1px solid var(--line); }
.turn + .turn { padding-top: 34px; }
.user-row { display: flex; justify-content: flex-end; margin-bottom: 27px; }
.user-question { max-width: min(78%, 640px); padding: 13px 16px; background: var(--wash); border-left: 3px solid var(--cinnabar); white-space: pre-wrap; line-height: 1.65; }
.assistant-row { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 15px; }
.assistant-mark { width: 34px; height: 34px; border-radius: 50%; font-size: .9rem; }
.assistant-body { min-width: 0; }
.answer { max-width: 74ch; font-size: 1rem; line-height: 1.82; }
.answer p, .answer ol, .answer ul { margin: 0 0 13px; }
.answer li { margin: 6px 0; }
.answer code { padding: .08em .3em; background: var(--wash); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }
.source-details, .developer-details { margin-top: 20px; border-top: 1px solid var(--line); }
.source-details summary, .developer-details summary { width: fit-content; padding: 12px 0 8px; color: var(--cinnabar-dark); font-weight: 700; font-size: .88rem; }
.source-list { padding: 3px 0 7px; }
.source-item { display: grid; grid-template-columns: minmax(150px, .75fr) minmax(180px, 1.25fr); gap: 18px; padding: 9px 0; border-bottom: 1px dotted var(--line); }
.source-item strong { font-size: .9rem; }
.source-item span { color: var(--muted); font-size: .86rem; }
.developer-details { display: none; border-color: #9eafb4; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.developer-mode .developer-details { display: block; }
.developer-details summary { color: var(--technical); }
.developer-grid { display: grid; grid-template-columns: 145px minmax(0, 1fr); margin: 0; border: 1px solid #bdc9cc; background: #f3f7f7; font-size: .78rem; }
.developer-grid dt, .developer-grid dd { margin: 0; padding: 8px 10px; border-bottom: 1px solid #d6dfe1; }
.developer-grid dt { color: #52676e; font-weight: 700; }
.developer-grid dd { white-space: pre-wrap; overflow-wrap: anywhere; }
.feedback-bar { margin-top: 21px; display: flex; flex-wrap: wrap; align-items: center; gap: 7px; color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: .76rem; }
.feedback-bar button { padding: 5px 9px; border: 1px solid var(--line); background: transparent; color: var(--muted); }
.feedback-bar button:hover, .feedback-bar button.selected { border-color: var(--cinnabar); color: var(--cinnabar-dark); background: #fff9ef; }
.feedback-status { color: var(--cinnabar-dark); }

.composer { position: fixed; right: max(0px, calc((100vw - 248px - 960px) / 2)); bottom: 0; z-index: 3; width: min(calc(100vw - 248px), 960px); padding: 14px 44px 22px; background: linear-gradient(to bottom, rgba(244, 241, 232, 0), var(--paper) 14px); }
.composer textarea { display: block; width: 100%; min-height: 92px; resize: vertical; padding: 14px 15px; border: 1px solid #aaa394; border-bottom: 0; background: var(--sheet); color: var(--ink); line-height: 1.6; }
.composer-bar { min-height: 48px; display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid #aaa394; border-top: 1px solid var(--line); background: var(--sheet); padding: 7px 8px 7px 14px; }
#status { color: var(--muted); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: .75rem; }
.composer-actions { display: flex; align-items: center; gap: 8px; }
.voice-button { min-width: 104px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); background: transparent; color: var(--ink); padding: 8px 11px; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: .82rem; font-weight: 700; }
.voice-button:hover { border-color: var(--cinnabar); color: var(--cinnabar-dark); background: #fff9ef; }
.voice-button.listening { border-color: var(--cinnabar); background: #fff0e9; color: var(--cinnabar-dark); }
.voice-button.transcribing { border-color: var(--line); color: var(--muted); background: var(--wash); }
.voice-button:disabled { cursor: not-allowed; }
.voice-icon { position: relative; width: 11px; height: 16px; border: 2px solid currentColor; border-radius: 7px; }
.voice-icon::before { content: ""; position: absolute; left: 50%; top: 12px; width: 17px; height: 9px; border: 2px solid currentColor; border-top: 0; border-radius: 0 0 10px 10px; transform: translateX(-50%); }
.voice-icon::after { content: ""; position: absolute; left: 50%; top: 20px; width: 2px; height: 4px; background: currentColor; transform: translateX(-50%); }
.voice-button.listening .voice-icon { animation: voice-pulse 1.15s ease-in-out infinite; }
#send-button, .primary-button { border: 0; background: var(--cinnabar); color: white; padding: 9px 20px; font-weight: 700; }
#send-button:hover, .primary-button:hover { background: var(--cinnabar-dark); }

dialog { width: min(520px, calc(100% - 30px)); border: 1px solid var(--ink); background: var(--sheet); color: var(--ink); padding: 24px; }
dialog::backdrop { background: rgba(33, 31, 27, .48); }
dialog h2 { margin: 0 0 8px; }
dialog p { color: var(--muted); line-height: 1.6; }
dialog textarea { width: 100%; padding: 11px; border: 1px solid var(--line); background: white; line-height: 1.55; }
.dialog-actions { margin-top: 16px; display: flex; justify-content: flex-end; gap: 8px; }
.text-button { border: 1px solid var(--line); background: transparent; padding: 9px 15px; }
button:focus-visible, textarea:focus-visible, summary:focus-visible, input:focus-visible { outline: 3px solid rgba(163, 58, 43, .24); outline-offset: 2px; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 18px; border-right: 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 14px; }
  .new-chat { grid-column: 2; grid-row: 1; width: auto; margin: 0; }
  .history-panel { grid-column: 1 / -1; max-height: 132px; margin-top: 0; padding-top: 12px; }
  .session-note { display: none; }
  .developer-switch { grid-column: 1 / -1; margin: 0; }
  .chat-panel { padding: 0 18px 180px; }
  .chat-header { padding-top: 24px; }
  .chat-header p { max-width: 38ch; }
  .connection-state { display: none; }
  .user-question { max-width: 90%; }
  .composer { right: 0; width: 100%; padding: 14px 18px 18px; }
  .composer-bar { align-items: flex-end; }
  #status { max-width: 40%; }
  .voice-button { min-width: 44px; padding-inline: 10px; }
  .voice-button .voice-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .source-item { grid-template-columns: 1fr; gap: 3px; }
  .developer-grid { grid-template-columns: 1fr; }
  .developer-grid dt { padding-bottom: 2px; }
  .developer-grid dd { padding-top: 2px; }
}

@keyframes voice-pulse { 50% { box-shadow: 0 0 0 5px rgba(163, 58, 43, .14); } }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
