:root {
  --parchment: #f5f4ed;
  --ivory: #faf9f5;
  --white: #ffffff;
  --warm-sand: #e8e6dc;
  --terracotta: #c96442;
  --coral: #d97757;
  --near-black: #141413;
  --charcoal: #4d4c48;
  --olive-gray: #5e5d59;
  --stone-gray: #87867f;
  --dark-warm: #3d3d3a;
  --warm-silver: #b0aea5;
  --border-cream: #f0eee6;
  --border-warm: #e8e6dc;
  --ring-warm: #d1cfc5;
  --focus-blue: #3898ec;
  --success: #5a7a52;
  --danger: #b53333;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-whisper: rgba(0, 0, 0, 0.05) 0 4px 24px;
  --shadow-ring: 0 0 0 1px var(--ring-warm);
  --font-serif: Georgia, "Songti SC", "Noto Serif SC", serif;
  --font-sans: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--parchment);
  color: var(--near-black);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
}

body {
  min-height: 100dvh;
  position: relative;
}

.page-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(245, 244, 237, 0.78) 0%, rgba(245, 244, 237, 0.88) 100%),
    url("assets/gaokao-bg.png") center center / cover no-repeat fixed;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 16px;
  padding: 20px 16px;
}

.history-panel {
  background: rgba(250, 249, 245, 0.92);
  border: 1px solid var(--border-cream);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-whisper);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: calc(100dvh - 40px);
  position: sticky;
  top: 20px;
  align-self: start;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border-cream);
}

.history-head h2 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 500;
}

.btn-compact {
  padding: 7px 12px;
  font-size: 13px;
}

.session-list {
  list-style: none;
  margin: 0;
  padding: 10px;
  overflow-y: auto;
  flex: 1;
}

.session-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 6px;
  cursor: pointer;
  color: inherit;
}

.session-item:hover {
  background: rgba(232, 230, 220, 0.55);
}

.session-item.active {
  background: var(--white);
  border-color: rgba(201, 100, 66, 0.35);
  box-shadow: var(--shadow-ring);
}

.session-title {
  display: block;
  font-size: 14px;
  color: var(--near-black);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--stone-gray);
}

.session-empty {
  padding: 20px 12px;
  text-align: center;
  color: var(--stone-gray);
  font-size: 13px;
}

.app {
  min-width: 0;
  min-height: calc(100dvh - 40px);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.hero-header {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border-cream);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-whisper);
  background: rgba(250, 249, 245, 0.9);
  backdrop-filter: blur(8px);
}

.hero-content {
  position: relative;
  z-index: 1;
  padding: 22px 24px;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.header-copy {
  min-width: 0;
  flex: 1;
}

h1 {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: clamp(24px, 4vw, 32px);
  font-weight: 500;
  line-height: 1.2;
  color: var(--near-black);
}

.subtitle {
  margin: 0;
  color: var(--olive-gray);
  font-size: 15px;
  line-height: 1.65;
}

.toolbar {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
  align-items: center;
}

.toolbar button {
  height: 38px;
  white-space: nowrap;
}

select,
input,
textarea {
  font: inherit;
  color: var(--near-black);
}

select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-cream);
  background: var(--white);
  box-shadow: var(--shadow-ring);
}

select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--focus-blue);
  box-shadow: 0 0 0 2px rgba(56, 152, 236, 0.2);
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sand {
  background: var(--warm-sand);
  color: var(--charcoal);
  padding: 9px 14px;
  box-shadow: 0 0 0 1px var(--ring-warm);
}

.btn-sand:hover:not(:disabled) {
  background: #dedcd2;
}

.btn-brand {
  background: var(--terracotta);
  color: var(--ivory);
  padding: 10px 16px;
  font-weight: 500;
  border-radius: var(--radius-md);
  box-shadow: 0 0 0 1px var(--terracotta);
}

.btn-brand:hover:not(:disabled) {
  background: #b85a3a;
}

.btn-ghost {
  background: var(--white);
  color: var(--charcoal);
  padding: 9px 14px;
  border: 1px solid var(--border-cream);
}

.btn-test {
  background: var(--white);
  color: var(--terracotta);
  padding: 9px 12px;
  border: 1px solid rgba(201, 100, 66, 0.35);
  white-space: nowrap;
}

.current-model-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--stone-gray);
  margin-top: 12px;
}

.meta-text {
  flex: 1;
  min-width: 180px;
  word-break: break-all;
}

.region-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warm-sand);
  color: var(--charcoal);
}

.region-tag.international {
  background: rgba(56, 152, 236, 0.1);
  color: #2b6cb0;
}

.test-pill {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-cream);
}

.test-pill.ok {
  color: var(--success);
  border-color: rgba(90, 122, 82, 0.35);
  background: rgba(90, 122, 82, 0.08);
}

.test-pill.fail {
  color: var(--danger);
  border-color: rgba(181, 51, 51, 0.35);
  background: rgba(181, 51, 51, 0.06);
}

.test-pill.pending {
  color: var(--stone-gray);
}

.chat-panel {
  background: rgba(250, 249, 245, 0.92);
  border: 1px solid var(--border-cream);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 52dvh;
  box-shadow: var(--shadow-whisper);
  backdrop-filter: blur(8px);
}

.messages {
  overflow-y: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fadeIn 0.25s ease;
}

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

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 500;
  flex-shrink: 0;
  font-family: var(--font-serif);
}

.message.user .avatar {
  background: var(--warm-sand);
  color: var(--charcoal);
}

.message.assistant .avatar {
  background: var(--terracotta);
  color: var(--ivory);
}

.bubble {
  max-width: min(720px, 100%);
  padding: 14px 16px;
  border-radius: 14px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--white);
  border: 1px solid var(--border-cream);
}

.message.assistant .bubble {
  background: var(--white);
  border: 1px solid var(--border-cream);
  box-shadow: var(--shadow-ring);
}

.bubble-rich {
  white-space: normal;
  line-height: 1.72;
  font-size: 15px;
  color: var(--charcoal);
}

.bubble-rich p {
  margin: 0 0 12px;
}

.bubble-rich p:last-child {
  margin-bottom: 0;
}

.bubble-rich .msg-section {
  margin: 18px 0 8px;
  font-weight: 600;
  font-size: 14px;
  color: var(--near-black);
  letter-spacing: 0.01em;
}

.bubble-rich .msg-section-lg {
  font-size: 15px;
}

.bubble-rich .msg-section:first-child {
  margin-top: 0;
}

.bubble-rich ul,
.bubble-rich ol {
  margin: 4px 0 12px;
  padding-left: 1.35em;
}

.bubble-rich li {
  margin-bottom: 8px;
}

.bubble-rich li:last-child {
  margin-bottom: 0;
}

.bubble-rich strong {
  font-weight: 600;
  color: var(--near-black);
}

.bubble-rich code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  background: rgba(20, 20, 19, 0.06);
  padding: 2px 6px;
  border-radius: 5px;
}

.bubble-rich .msg-quote {
  margin: 0 0 12px;
  padding-left: 12px;
  border-left: 3px solid var(--warm-sand);
  color: var(--olive-gray);
}

.bubble-stream {
  min-height: 48px;
}

.answer-body:empty {
  display: none;
}

.thinking-block {
  margin-bottom: 12px;
  border: 1px solid var(--border-cream);
  border-radius: 10px;
  background: rgba(232, 230, 220, 0.35);
  overflow: hidden;
}

.thinking-block.active {
  border-color: rgba(201, 100, 66, 0.25);
  background: rgba(201, 100, 66, 0.06);
}

.thinking-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: transparent;
  color: var(--olive-gray);
  font-size: 13px;
  text-align: left;
}

.thinking-label {
  font-weight: 600;
  color: var(--charcoal);
}

.thinking-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--terracotta);
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.9);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.thinking-chevron {
  margin-left: auto;
  transition: transform 0.2s ease;
}

.thinking-block.collapsed .thinking-chevron {
  transform: rotate(-90deg);
}

.thinking-block.collapsed .thinking-body {
  display: none;
}

.thinking-body {
  padding: 0 12px 12px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--olive-gray);
  min-height: 0;
}

.thinking-trace {
  white-space: pre-wrap;
}

.thinking-trace:empty {
  display: none;
}

.message.system .bubble {
  background: rgba(201, 100, 66, 0.06);
  border: 1px dashed rgba(201, 100, 66, 0.25);
  color: var(--olive-gray);
  font-size: 14px;
}

.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  min-height: 24px;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--stone-gray);
  animation: bounce 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.examples {
  padding: 0 22px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.example-chip {
  background: var(--white);
  color: var(--olive-gray);
  border: 1px solid var(--border-cream);
  padding: 8px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-ring);
}

.example-chip:hover:not(:disabled) {
  color: var(--near-black);
  border-color: rgba(201, 100, 66, 0.35);
}

.history-backdrop {
  display: none;
}

.composer {
  border-top: 1px solid var(--border-cream);
  padding: 16px;
  background: rgba(245, 244, 237, 0.72);
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

textarea {
  width: 100%;
  min-height: 52px;
  max-height: 160px;
  resize: vertical;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-cream);
  background: var(--white);
  padding: 12px 14px;
  line-height: 1.5;
}

.hint {
  margin-top: 8px;
  font-size: 12px;
  color: var(--stone-gray);
}

.hint a {
  color: var(--terracotta);
  text-decoration: none;
}

.hint a:hover {
  text-decoration: underline;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 19, 0.35);
  display: none;
  place-items: center;
  padding: 16px;
  z-index: 20;
}

.modal-backdrop.open {
  display: grid;
}

.modal {
  width: min(720px, 100%);
  max-height: 90dvh;
  overflow: auto;
  background: var(--ivory);
  border: 1px solid var(--border-cream);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-whisper);
}

.modal-wide {
  width: min(640px, 100%);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--warm-sand);
  color: var(--charcoal);
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px var(--ring-warm);
}

.modal-close:hover {
  background: #dedcd2;
}

.modal h2 {
  margin: 0 0 4px;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
}

.modal-desc {
  margin: 0;
  color: var(--olive-gray);
  font-size: 14px;
}

.modal-section {
  margin-bottom: 4px;
}

.section-title {
  margin: 0 0 12px;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 500;
  color: var(--charcoal);
}

.current-panel {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
  align-items: end;
}

.field-action label {
  visibility: hidden;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.modal-divider {
  height: 1px;
  background: var(--border-cream);
  margin: 20px 0;
}

.skill-body {
  color: var(--olive-gray);
  font-size: 15px;
  line-height: 1.7;
}

.skill-body p {
  margin: 0 0 14px;
}

.skill-list {
  margin: 0 0 16px;
  padding-left: 20px;
}

.skill-list li {
  margin-bottom: 8px;
}

.skill-list strong {
  color: var(--near-black);
  font-weight: 500;
}

.profile-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.profile-card {
  background: var(--white);
  border: 1px solid var(--border-cream);
  border-radius: var(--radius-md);
  padding: 14px;
}

.profile-card.active {
  border-color: rgba(201, 100, 66, 0.45);
  box-shadow: 0 0 0 1px rgba(201, 100, 66, 0.15);
}

.profile-card-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.profile-card-head h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 500;
}

.profile-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.field {
  margin-bottom: 10px;
}

.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--stone-gray);
}

.field input,
.field select {
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-cream);
  background: var(--ivory);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.modal-actions .right {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--danger);
}

.status-dot.ok {
  background: var(--success);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .history-panel {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(300px, 88vw);
    max-height: none;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }

  .history-panel.open {
    transform: translateX(0);
  }

  .history-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 19, 0.35);
    z-index: 25;
  }

  .history-backdrop.open {
    display: block;
  }

  .btn-icon-mobile {
    display: inline-flex;
  }
}

@media (min-width: 861px) {
  #toggleHistoryBtn {
    display: none;
  }
}

@media (max-width: 640px) {
  .header-top {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    flex-wrap: wrap;
    width: 100%;
  }

  .toolbar button {
    flex: 1;
    min-width: calc(33% - 6px);
  }

  .current-panel {
    grid-template-columns: 1fr;
  }

  .field-action label {
    display: none;
  }

  .composer-row {
    grid-template-columns: 1fr;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}
