:root {
  --bg: #f6f2ea;
  --ink: #1f2a30;
  --muted: #66757f;
  --line: #dacfbf;
  --panel: rgba(255, 252, 246, 0.94);
  --accent: #1f6b52;
  --accent-strong: #164b3a;
  --accent-soft: #deebe3;
  --warn-soft: #f4e4cf;
  --warn-text: #9e6a2f;
  --danger: #b44235;
  --shadow: 0 18px 42px rgba(31, 42, 48, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(circle at top, rgba(255, 247, 232, 0.9), rgba(255, 247, 232, 0) 30%),
    linear-gradient(180deg, #efe3d0 0%, #f4efe5 42%, #edf3ed 100%);
  color: var(--ink);
  min-height: 100vh;
}

button,
textarea,
input {
  font: inherit;
}

.page-shell {
  min-height: 100vh;
  padding: 20px 14px 28px;
}

.login-screen,
.portal-screen {
  width: min(100%, 980px);
  margin: 0 auto;
}

.hero-card,
.student-header,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.hero-card {
  max-width: 520px;
  margin: 8vh auto 0;
  padding: 28px 22px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-card h1,
.student-header h2 {
  margin: 0;
}

.hero-copy,
.student-meta,
.muted-note,
.onboarding-box p {
  color: var(--muted);
  line-height: 1.6;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

.field input,
.composer textarea,
.guided-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px;
  background: white;
  color: var(--ink);
}

.primary-btn,
.option-btn,
.subject-chip,
.guided-choice,
.guided-submit,
.subject-choice-submit,
.subject-choice-clear {
  border: none;
  border-radius: 999px;
  cursor: pointer;
}

.primary-btn {
  background: var(--accent);
  color: white;
  padding: 12px 18px;
  font-weight: 700;
}

.ghost-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  padding: 10px 14px;
  cursor: pointer;
}

.error-text {
  margin: 14px 0 0;
  color: #b44235;
  font-size: 0.9rem;
}

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

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--warn-soft);
  color: var(--warn-text);
  font-size: 0.82rem;
  font-weight: 700;
}

.status-pill.done {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tabs {
  display: flex;
  gap: 10px;
  margin: 14px 0;
}

.tab-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.panels {
  display: grid;
}

.panel {
  display: none;
  padding: 16px;
}

.panel.active {
  display: block;
}

.onboarding-box {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: linear-gradient(180deg, #fdf7ef, #fbf4ea);
  padding: 18px;
  margin-bottom: 14px;
}

.onboarding-box h4 {
  margin: 0 0 10px;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.option-btn,
.subject-chip,
.guided-choice {
  background: white;
  border: 1px solid var(--line);
  text-align: left;
  padding: 12px 14px;
  color: var(--ink);
}

.subject-chip.selected,
.guided-choice.selected {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.subject-choice-actions,
.guided-form {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.subject-choice-submit {
  background: var(--accent);
  color: white;
  padding: 11px 14px;
}

.subject-choice-clear {
  background: #d9cab1;
  color: var(--ink);
  padding: 11px 14px;
}

.guided-submit {
  background: var(--accent);
  color: white;
  padding: 11px 14px;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 220px;
  max-height: 46vh;
  overflow-y: auto;
  margin-bottom: 14px;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 88%;
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.bubble {
  border-radius: 20px;
  padding: 12px 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 6px;
}

.message.assistant .bubble {
  background: #f1ebe0;
  color: var(--ink);
  border-bottom-left-radius: 6px;
}

.message.pending .bubble {
  color: var(--muted);
}

.message-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
}

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(31, 107, 82, 0.25);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

.message-time {
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0 6px;
}

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

.composer-tools {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--accent-strong);
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

.tool-btn.disabled {
  cursor: not-allowed;
  opacity: 0.55;
  pointer-events: none;
}

.composer textarea {
  min-height: 58px;
  resize: vertical;
}

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  max-width: min(420px, 100%);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--ink);
  padding: 7px 10px 7px 12px;
  font-size: 0.86rem;
}

.attachment-chip.pending {
  color: var(--muted);
}

.attachment-chip.uploading {
  color: var(--muted);
}

.attachment-chip.error {
  border-color: rgba(180, 66, 53, 0.28);
  background: #fff7f5;
  color: var(--danger);
}

.attachment-body {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.attachment-line {
  display: flex;
  min-width: 0;
  gap: 8px;
  align-items: center;
}

.attachment-name {
  overflow: hidden;
  max-width: min(220px, 54vw);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-status {
  overflow: hidden;
  max-width: 180px;
  color: currentColor;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-progress {
  display: block;
  width: 100%;
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--accent-soft);
}

.attachment-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.18s ease;
}

.attachment-remove {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  cursor: pointer;
  line-height: 1;
}

.markdown-body {
  word-break: break-word;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 0.35em 0 0.55em;
  line-height: 1.35;
}

.markdown-body h1 {
  font-size: 1.08rem;
}

.markdown-body h2 {
  font-size: 1rem;
}

.markdown-body h3 {
  font-size: 0.94rem;
}

.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  font-size: 0.9rem;
}

.markdown-body p {
  margin: 0.6em 0;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.55em 0;
  padding-left: 1.2em;
}

.markdown-body li + li {
  margin-top: 0.28em;
}

.markdown-table-wrap {
  max-width: 100%;
  margin: 0.75em 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.markdown-body table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  font-size: 0.92em;
}

.markdown-body th,
.markdown-body td {
  padding: 0.55em 0.65em;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: rgba(27, 110, 86, 0.08);
  font-weight: 700;
}

.markdown-body strong {
  font-weight: 700;
}

.markdown-body code {
  padding: 0.08em 0.35em;
  border-radius: 8px;
  background: rgba(23, 32, 36, 0.08);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

.markdown-body a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0.8em 0;
}

.empty {
  color: var(--muted);
  padding: 18px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  background: #1e2a25;
  color: white;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  white-space: pre-wrap;
  z-index: 20;
}

button:disabled,
textarea:disabled,
input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 640px) {
  .student-header {
    flex-direction: column;
  }

  .option-grid {
    grid-template-columns: 1fr;
  }

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

  .composer-tools {
    order: 2;
  }
}
