/* ========================================
   Scholar's Study — Design System
   Deep ink + warm paper + amber accent
   ======================================== */

:root {
  --ink: #1a2332;
  --ink-soft: #2d3b4f;
  --ink-muted: #5a6b80;
  --paper: #faf8f5;
  --paper-warm: #f5f0e8;
  --paper-card: #fefdfb;
  --line: #e6e0d6;
  --line-strong: #d4cdc0;
  --amber: #d4892a;
  --amber-soft: #fdf3e4;
  --amber-deep: #b06814;
  --green: #3b8c5b;
  --green-soft: #edf7f0;
  --red: #c5554a;
  --red-soft: #fdf3f1;
  --blue-faded: #dcf0fa;
  --sky: #3788b8;
  --white: #ffffff;
  --shadow-xs: 0 1px 3px rgba(26,35,50,0.04);
  --shadow-sm: 0 2px 8px rgba(26,35,50,0.06);
  --shadow-md: 0 6px 20px rgba(26,35,50,0.08);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, sans-serif;
  --font-serif: "Noto Serif SC", "STSong", "Songti SC", "SimSun", serif;
}

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

html { background: var(--paper); }

body {
  font-family: var(--font);
  background:
    linear-gradient(180deg, #fefcf8 0%, var(--paper) 30%, #f7f3ec 100%);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { border: none; cursor: pointer; background: none; }
a { color: inherit; text-decoration: none; }

.hidden { display: none !important; }

/* ---- Typography ---- */

h1, h2, h3, h4 {
  font-weight: 700;
  line-height: 1.25;
  color: var(--ink);
}

/* ---- Auth ---- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(212,137,42,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(26,35,50,0.04) 0%, transparent 50%),
    var(--paper);
}

.auth-box {
  width: min(400px, 100%);
  padding: 40px 36px;
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(26,35,50,0.04);
}

.auth-box h1 {
  font-family: var(--font-serif);
  font-size: 28px;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.auth-box > p {
  text-align: center;
  color: var(--ink-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--paper-warm);
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.auth-tab {
  padding: 10px;
  border-radius: 7px;
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  color: var(--ink-muted);
  transition: background .15s, color .15s, box-shadow .15s;
}

.auth-tab.active {
  background: var(--white);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}

.auth-form { display: none; }
.auth-form.active { display: block; }

.form-group { margin: 16px 0; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-card);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
  border-color: var(--line-strong);
  background: var(--white);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
  background: var(--white);
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.7;
}

.auth-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 10px;
  display: none;
}

.auth-switch {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-muted);
}

.auth-switch button {
  color: var(--amber);
  font-weight: 700;
  padding: 2px 6px;
}

.auth-form select {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-card);
  color: var(--ink);
  font-size: 14px;
}

.forgot-question {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  color: var(--amber-deep);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.5;
}

.security-box {
  width: min(92vw, 380px);
  padding: 24px;
  border-radius: var(--radius);
  background: var(--paper-card);
  box-shadow: var(--shadow-md);
  max-height: 86vh;
  overflow-y: auto;
}

.security-box h3 {
  margin: 0 0 4px;
  font-size: 17px;
}

.security-box .auth-error {
  margin-top: 10px;
}

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  transition: transform .12s, box-shadow .12s, background .12s, opacity .12s;
  letter-spacing: 0.2px;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.btn-primary {
  background: var(--amber);
  color: #fff;
  box-shadow: 0 4px 14px rgba(212,137,42,0.24);
}
.btn-primary:hover { background: var(--amber-deep); box-shadow: 0 6px 18px rgba(212,137,42,0.30); }

.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.92; }

.btn-warning { background: #e8a550; color: #fff; }
.btn-warning:hover { opacity: 0.92; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.92; }

.btn-muted {
  background: var(--paper-warm);
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn-muted:hover { background: var(--white); border-color: var(--line-strong); }

.btn-small { padding: 5px 12px; font-size: 12px; border-radius: 5px; }
.btn-block { width: 100%; }

/* ---- App Shell ---- */

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ---- Sidebar ---- */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 32px 20px 24px;
  background: rgba(255,255,255,0.70);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.side-brand {
  text-align: center;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--ink);
  color: var(--amber);
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 900;
  letter-spacing: -1px;
}

.side-brand h1 {
  font-family: var(--font-serif);
  font-size: 15px;
  letter-spacing: 1px;
}

.side-brand p {
  font-size: 11px;
  color: var(--ink-muted);
  margin-top: 4px;
}

/* Sidebar nav */

.side-nav.tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 12px;
  flex: 1;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-muted);
  text-align: left;
  transition: background .15s, color .15s;
  width: 100%;
}

.tab-btn:hover { background: var(--paper-warm); color: var(--ink-soft); }

.tab-btn.active {
  background: var(--ink);
  color: var(--paper);
}

.nav-icon {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 900;
  flex-shrink: 0;
  background: rgba(90,107,128,0.10);
  color: inherit;
}

.tab-btn.active .nav-icon { background: rgba(255,255,255,0.15); }

.muted-nav { opacity: 0.45; pointer-events: none; }
.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
}

/* Sidebar footer */

.streak-card {
  margin-top: auto;
  padding: 16px;
  border-radius: var(--radius-lg);
  text-align: center;
  background: var(--paper-warm);
}

.medal-icon {
  width: 36px;
  height: 36px;
  margin: 0 auto 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f7d774, var(--amber));
  box-shadow: 0 4px 12px rgba(212,137,42,0.20);
}

.streak-card strong { display: block; font-size: 13px; }
.streak-card span { display: block; font-size: 11px; color: var(--ink-muted); margin-top: 4px; }

.side-profile {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding-top: 16px;
  text-align: center;
}

.avatar {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-size: 20px;
  font-weight: 700;
}

.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.role-badge.student { background: var(--green-soft); color: var(--green); }
.role-badge.teacher { background: var(--amber-soft); color: var(--amber-deep); }

.side-profile p { font-size: 12px; color: var(--ink-muted); }
.side-profile .btn { margin-top: 4px; }

.mobile-session-bar { display: none; }

/* ---- Main Stage ---- */

.main-stage {
  padding: 40px 44px 48px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 32px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.topbar h1 {
  font-family: var(--font-serif);
  font-size: 32px;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.topbar p { color: var(--ink-muted); font-size: 15px; }

.date-chip {
  padding: 10px 18px;
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 700;
  box-shadow: var(--shadow-xs);
  white-space: nowrap;
}

/* ---- Tab Content ---- */

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ---- Panel ---- */

.panel {
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: 28px 32px;
  box-shadow: var(--shadow-sm), 0 0 0 1px rgba(26,35,50,0.03);
  margin-bottom: 24px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1.5px solid var(--line);
}

.section-head h2 {
  font-family: var(--font-serif);
  font-size: 20px;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.section-head p { color: var(--ink-muted); font-size: 13px; }

/* ---- Subject Filter ---- */

.subject-filter {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.subject-chip {
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-muted);
  background: var(--paper-warm);
  border: 1px solid transparent;
  transition: background .15s, color .15s, border-color .15s;
}

.subject-chip:hover { color: var(--ink-soft); background: var(--white); border-color: var(--line-strong); }

.subject-chip.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* ---- Grid Cards (courseware / homework / history) ---- */

.cw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.cw-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--paper-card);
  border: 1px solid var(--line);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.cw-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); transform: translateY(-1px); }

.cw-card h3 { font-size: 15px; margin-bottom: 2px; }

.meta { color: var(--ink-muted); font-size: 12px; }

/* ---- Homework Grid ---- */

.hw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.homework-records {
  min-width: 0;
}

.homework-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.homework-filter-bar select {
  min-height: 36px;
  min-width: 136px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper-card);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.hw-subject-filter {
  margin-bottom: 0;
}

.hw-student-group {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.hw-student-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--paper-card);
  border: 1px solid var(--line);
}

.hw-student-head strong {
  display: block;
  font-size: 15px;
  color: var(--ink);
}

.hw-student-head span {
  display: block;
  margin-top: 2px;
  color: var(--ink-muted);
  font-size: 12px;
}

.hw-student-head em {
  flex-shrink: 0;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber-deep);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.hw-student-head em.done {
  background: var(--green-soft);
  color: var(--green);
}

.hw-ai-summary {
  margin-top: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--paper-card);
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-soft);
}

.hw-ai-summary:empty { display: none; }

.hw-ai-summary::before {
  content: "AI 总结";
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 800;
  color: var(--amber-deep);
  letter-spacing: 0.05em;
}

.hw-ai-summary h2 { font-size: 15px; color: var(--ink); margin: 12px 0 6px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.hw-ai-summary h2:first-child { margin-top: 0; }
.hw-ai-summary p { margin: 4px 0; }
.hw-ai-summary ul, .hw-ai-summary ol { margin: 4px 0; padding-left: 20px; }
.hw-ai-summary li { margin: 0; }
.hw-ai-summary li + li { margin-top: 2px; }
.hw-ai-summary strong { color: var(--amber-deep); }
.hw-ai-summary mjx-container[jax="CHTML"] { line-height: 1; vertical-align: -0.08em; }

/* ---- 批改面板：状态胶囊 + 评语视图/编辑切换 ---- */

.hw-grade-panel {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.hw-status-pills {
  display: flex;
  gap: 6px;
}

.hw-status-pills .pill {
  flex: 1;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-card);
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}

.hw-status-pills .pill:hover {
  border-color: var(--amber);
  color: var(--ink);
}

.hw-status-pills .pill.active {
  color: #fff;
  box-shadow: 0 2px 8px rgba(26,35,50,0.14);
}

.hw-status-pills .pill.active.done { background: var(--green); border-color: var(--green); }
.hw-status-pills .pill.active.reviewing { background: var(--amber-deep); border-color: var(--amber-deep); }
.hw-status-pills .pill.active.pending { background: var(--red); border-color: var(--red); }

.hw-comment-area { min-height: 34px; }

.hw-comment-empty {
  padding: 10px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink-muted);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

.hw-comment-empty:hover {
  border-color: var(--amber);
  color: var(--amber-deep);
}

.hw-comment-view {
  position: relative;
  padding: 10px 12px 12px;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  border: 1px solid #f0dcbb;
  cursor: pointer;
  transition: border-color .15s;
}

.hw-comment-view:hover { border-color: var(--amber); }

.hw-comment-view p {
  margin: 6px 0 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink);
  white-space: pre-wrap;
}

.hw-comment-label span {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--amber);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.hw-comment-hint {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 11px;
  color: var(--ink-muted);
  opacity: 0;
  transition: opacity .15s;
}

.hw-comment-view:hover .hw-comment-hint { opacity: 1; }

.hw-comment-view.student {
  background: var(--green-soft);
  border-color: #cde7d4;
  cursor: default;
}

.hw-comment-view.student .hw-comment-label span { background: var(--green); }
.hw-comment-view.student .hw-comment-hint { display: none; }

.hw-comment-edit textarea {
  width: 100%;
  min-height: 62px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-card);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
}

.hw-comment-edit textarea:focus { outline: none; border-color: var(--amber); }

.hw-comment-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.hw-card {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--paper-card);
  border: 1px solid var(--line);
  transition: border-color .15s, box-shadow .15s;
}

.hw-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }

.hw-image-grid {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.hw-image-grid.single {
  grid-template-columns: 1fr;
}

.hw-image-grid.multi {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.hw-image-thumb {
  position: relative;
  width: 100%;
  height: 112px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--paper-warm);
  cursor: pointer;
}

.hw-image-grid.single .hw-image-thumb {
  height: 150px;
}

.hw-image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .15s;
}

.hw-image-thumb:hover img {
  transform: scale(1.02);
}

.hw-card h3 { font-size: 14px; margin-bottom: 4px; }

.status-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.status-tag.pending { background: var(--amber-soft); color: var(--amber-deep); }
.status-tag.reviewing { background: var(--blue-faded); color: var(--sky); }
.status-tag.done { background: var(--green-soft); color: var(--green); }

/* ---- Upload Layout ---- */

.upload-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 24px;
  align-items: start;
}

.upload-zone {
  min-height: 160px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper-warm);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.upload-zone:hover { border-color: var(--amber); background: var(--amber-soft); }

.upload-zone strong { display: block; font-size: 15px; margin-bottom: 4px; }
.upload-zone span { color: var(--ink-muted); font-size: 13px; }

.submitter-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper-card);
  color: var(--ink-muted);
  font-size: 13px;
  font-weight: 700;
}

.submitter-chip strong {
  color: var(--ink);
  font-size: 14px;
}

.preview-img {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--paper-warm);
}

.hw-preview-list {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
  gap: 8px;
}

.hw-preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--paper-warm);
}

.hw-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hw-preview-item span,
.hw-image-thumb span {
  position: absolute;
  right: 6px;
  bottom: 6px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(26, 35, 50, 0.82);
  color: var(--white);
  font-size: 12px;
  font-weight: 800;
}

.hw-preview-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: rgba(211, 67, 67, 0.92);
  color: var(--white);
  font-size: 17px;
  line-height: 1;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(26, 35, 50, 0.18);
}

.hw-preview-remove:hover {
  background: var(--red);
}

/* ---- Q&A Layout ---- */

.qa-layout {
  display: grid;
  grid-template-columns: minmax(300px, 340px) 1fr;
  gap: 24px;
  align-items: start;
}

/* ---- Answer Panel ---- */

.answer-panel {
  min-height: 460px;
  max-height: calc(100vh - 180px);
  overflow: auto;
  border-radius: var(--radius-lg);
  background: var(--paper-card);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.answer-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(254,253,251,0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.answer-toolbar strong {
  font-family: var(--font-serif);
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.answer-toolbar strong::before {
  content: "";
  display: block;
  width: 6px;
  height: 16px;
  border-radius: 999px;
  background: var(--amber);
}

.model-chip {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--paper-warm);
  color: var(--ink-muted);
  font-size: 11px;
  font-weight: 700;
}

.answer-content {
  flex: 1;
  padding: 18px;
  line-height: 1.75;
  color: var(--ink-soft);
  font-size: 14px;
}

.answer-content h2 {
  font-size: 16px;
  color: var(--ink);
  margin: 16px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.answer-content h2:first-child { margin-top: 0; }

.answer-content h3 { font-size: 14px; color: var(--ink); margin: 12px 0 4px; }

.answer-content p { margin: 4px 0; }

.answer-content ul, .answer-content ol { margin: 4px 0; padding-left: 20px; }
.answer-content li { margin: 0; }
.answer-content li + li { margin-top: 2px; }

.answer-content strong { color: var(--amber-deep); }

.answer-content mjx-container[jax="CHTML"] { line-height: 1; vertical-align: -0.08em; }

/* Thinking status */
.thinking-status {
  display: block;
  padding: 12px 14px;
  margin: 4px 0;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  border: 1px solid rgba(212,137,42,0.15);
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.6;
}

.thinking-status strong { display: block; color: var(--amber-deep); margin-bottom: 4px; }

/* Fractions */
.frac {
  display: inline-grid;
  grid-template-rows: auto auto;
  align-items: center;
  justify-items: center;
  vertical-align: middle;
  margin: 0 2px;
  line-height: 1.05;
  font-size: 0.95em;
}

.frac .num {
  border-bottom: 1px solid currentColor;
  padding: 0 4px 1px;
  min-width: 1.2em;
  text-align: center;
}

.frac .den {
  padding: 1px 4px 0;
  min-width: 1.2em;
  text-align: center;
}

/* ---- Followup ---- */

.followup-box {
  margin: 0 18px 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.followup-box textarea {
  width: 100%;
  min-height: 64px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--white);
  resize: vertical;
  outline: none;
  font-size: 13px;
  line-height: 1.6;
  transition: border-color .15s, box-shadow .15s;
}

.followup-box textarea:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-soft);
}

.followup-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  color: var(--ink-muted);
  font-size: 12px;
}

.followup-entry {
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--paper-card);
  border-left: 3px solid var(--amber);
}

.followup-question {
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.qa-image-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.qa-image-strip .hw-image-thumb {
  height: 96px;
}

/* ---- History ---- */

.history-list { display: grid; gap: 8px; }

.history-row {
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--paper-card);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}

.history-row:hover {
  border-color: var(--amber);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.history-row h4 { font-size: 14px; margin-bottom: 4px; }
.history-row p { font-size: 12px; color: var(--ink-muted); line-height: 1.5; }

.history-date-select {
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-warm);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
  outline: none;
}

.history-date-select:focus { border-color: var(--amber); }

/* ---- Learning Report ---- */

.report-head { align-items: center; }

.report-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.report-controls select {
  height: 38px;
  min-width: 128px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--paper-warm);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  padding: 0 12px;
}

.report-body { display: grid; gap: 18px; }

.report-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--ink), #24364f);
  color: var(--paper);
}

.report-kicker {
  display: inline-block;
  margin-bottom: 8px;
  color: rgba(255,255,255,0.68);
  font-size: 12px;
  font-weight: 800;
}

.report-hero h3 {
  font-family: var(--font-serif);
  font-size: 22px;
  margin-bottom: 6px;
  color: var(--paper);
}

.report-hero p {
  color: rgba(255,255,255,0.72);
  line-height: 1.6;
}

.report-cache-note {
  margin-top: 4px;
  color: rgba(255,255,255,0.58) !important;
  font-size: 12px;
}

.report-score {
  width: 112px;
  height: 112px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  background: rgba(255,255,255,0.12);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
  flex-shrink: 0;
}

.report-score strong { font-size: 34px; line-height: 1; }

.report-score span {
  margin-top: 6px;
  color: rgba(255,255,255,0.72);
  font-size: 12px;
  font-weight: 800;
}

.report-metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.report-metrics div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper-card);
}

.report-metrics span,
.report-metrics em {
  display: block;
  color: var(--ink-muted);
  font-size: 12px;
  font-style: normal;
}

.report-metrics strong {
  display: inline-block;
  margin: 8px 4px 3px 0;
  color: var(--ink);
  font-size: 26px;
}

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

.report-ai-card {
  padding: 20px;
  border: 1px solid rgba(212,137,42,0.28);
  border-radius: 16px;
  background: linear-gradient(180deg, #fffaf2 0%, var(--paper-card) 100%);
  box-shadow: var(--shadow-xs);
}

.report-ai-content {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.72;
}

.report-ai-content h2 {
  margin: 14px 0 6px;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 17px;
}

.report-ai-content h2:first-child {
  margin-top: 0;
}

.report-ai-content p {
  margin: 6px 0;
}

.report-ai-content ul,
.report-ai-content ol {
  margin: 6px 0;
  padding-left: 20px;
}

.report-ai-content li {
  margin: 3px 0;
}

.report-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper-card);
  box-shadow: var(--shadow-xs);
}

.report-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.report-card-head h3 {
  font-family: var(--font-serif);
  font-size: 17px;
}

.report-card-head span {
  color: var(--ink-muted);
  font-size: 12px;
  text-align: right;
}

.topic-list,
.status-bars,
.course-mini,
.risk-list {
  display: grid;
  gap: 10px;
}

.topic-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--paper-warm);
  color: var(--ink-soft);
  font-weight: 800;
}

.topic-list b { color: var(--amber-deep); }

.risk-list button {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  text-align: left;
}

.risk-list button:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-xs);
}

.risk-list strong,
.risk-list span,
.risk-list em {
  display: block;
}

.risk-list strong {
  color: var(--amber-deep);
  font-size: 12px;
  margin-bottom: 5px;
}

.risk-list span {
  color: var(--ink);
  font-weight: 800;
  margin-bottom: 4px;
}

.risk-list em {
  color: var(--ink-muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.5;
}

.status-bars > div > div {
  display: flex;
  justify-content: space-between;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 6px;
}

.status-bars i {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: var(--paper-warm);
  overflow: hidden;
}

.status-bars em {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.course-mini { margin-top: 14px; }

.course-mini div {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--paper-warm);
  color: var(--ink-muted);
  font-size: 12px;
}

.course-mini b { color: var(--ink-soft); }

.suggestion-list {
  display: grid;
  gap: 10px;
  padding-left: 18px;
  color: var(--ink-soft);
  line-height: 1.65;
}

.empty-msg.compact { padding: 18px 8px; }

/* ---- Courseware Upload ---- */

.cw-upload {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.cw-upload h3 { font-size: 15px; margin-bottom: 12px; }

.cw-file-field { min-width: min(100%, 300px); }

.file-picker-btn {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--paper-warm);
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 13px;
  transition: border-color .15s, background .15s;
}

.file-picker-btn:hover { border-color: var(--amber); background: var(--amber-soft); }

.file-picked-name {
  display: inline-block;
  margin-left: 10px;
  color: var(--ink-muted);
  font-size: 13px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* ---- Dashboard / Home ---- */

.hero-card {
  padding: 36px 40px;
  border-radius: var(--radius-xl);
  background: var(--ink);
  color: var(--paper);
  margin-bottom: 28px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: center;
}

.hero-card h2 {
  font-family: var(--font-serif);
  font-size: 26px;
  color: var(--paper);
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.hero-card p { color: rgba(250,248,245,0.65); font-size: 15px; }

.hero-illustration {
  width: 200px;
  height: 120px;
  position: relative;
  opacity: 0.6;
}

.desk {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 14px;
  height: 8px;
  border-radius: 999px;
  background: rgba(250,248,245,0.3);
}

.student-head {
  position: absolute;
  right: 88px;
  top: 10px;
  width: 44px;
  height: 50px;
  border-radius: 42% 42% 46% 46%;
  background: rgba(250,248,245,0.25);
  box-shadow: inset 0 10px 0 rgba(250,248,245,0.5);
}

.student-body {
  position: absolute;
  right: 60px;
  top: 58px;
  width: 100px;
  height: 52px;
  border-radius: 36px 36px 12px 12px;
  background: rgba(250,248,245,0.15);
}

.laptop {
  position: absolute;
  right: 128px;
  bottom: 22px;
  width: 94px;
  height: 56px;
  border-radius: 8px;
  background: rgba(250,248,245,0.2);
}

.plant {
  position: absolute;
  bottom: 20px;
  width: 30px;
  height: 40px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(180deg, rgba(212,137,42,0.4) 0 40%, rgba(250,248,245,0.1) 40%);
}
.plant.left { left: 24px; }
.plant.right { right: 14px; }

/* Dashboard cards */

.dashboard-card {
  margin-bottom: 24px;
  padding: 28px 32px;
  border-radius: var(--radius-xl);
  background: var(--white);
  box-shadow: var(--shadow-sm), 0 0 0 1px rgba(26,35,50,0.03);
  transition: transform .15s, box-shadow .15s;
}

.home-jump-card { cursor: pointer; }

.home-jump-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(26,35,50,0.05);
}

.dash-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.dash-head > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.step-dot {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 700;
}
.step-dot.green { background: var(--green); }
.step-dot.purple { background: #7c5ce0; }

.dash-head h2 { font-family: var(--font-serif); font-size: 18px; }

.ghost-link {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--paper-warm);
  color: var(--ink-soft);
}
.ghost-link.green { color: var(--green); }
.ghost-link.purple { color: #7c5ce0; }

.dash-body {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 28px;
  align-items: center;
}

.book-cover {
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  text-align: center;
  background: linear-gradient(145deg, var(--ink-soft), var(--ink));
  color: var(--paper);
}

.book-cover strong { display: block; font-size: 30px; }
.book-cover span { font-size: 10px; letter-spacing: 2px; opacity: 0.6; }

.chemistry-cover {
  background:
    url("/frontend/assets/chemistry-course.png") center / contain no-repeat,
    linear-gradient(145deg, rgba(249,246,240,0.95), rgba(245,240,232,0.95));
}
.chemistry-cover strong,
.chemistry-cover span { display: none; }

.clipboard-illus {
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  background:
    url("/frontend/assets/homework-submit.png") center / contain no-repeat,
    linear-gradient(145deg, #f8f6f1, #f2eee5);
}

.robot-illus {
  width: 200px;
  aspect-ratio: 1;
  border-radius: var(--radius);
  background:
    url("/frontend/assets/ai-robot.svg") center / contain no-repeat,
    linear-gradient(145deg, #f5f1ea, #ede7d8);
}

.ai-home-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 28px;
  align-items: center;
}

.dash-copy h3 { font-family: var(--font-serif); font-size: 20px; margin-bottom: 10px; }

.dash-copy p { color: var(--ink-muted); line-height: 1.7; }

.dash-copy em {
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber-deep);
  font-size: 12px;
  font-style: normal;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  margin: 14px 0 18px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--paper-warm);
  overflow: hidden;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.task-list { display: grid; gap: 8px; }

.task-list div,
.note-box {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--paper-warm);
  font-size: 13px;
  color: var(--ink-muted);
  display: flex;
  justify-content: space-between;
}

.note-box { margin-top: 16px; line-height: 1.7; display: block; }

.prompt-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 16px;
}

.prompt-pills span {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--paper-warm);
  color: var(--ink-soft);
  font-size: 13px;
}

.ask-strip {
  width: 100%;
  padding: 12px 20px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--white);
  color: var(--ink-muted);
  text-align: left;
  font-size: 14px;
  transition: border-color .15s;
}

.ask-strip:hover { border-color: var(--line-strong); }

/* ---- Empty state ---- */

.empty-msg {
  text-align: center;
  padding: 40px 16px;
  color: var(--ink-muted);
  font-size: 14px;
}

/* ---- Modal ---- */

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(26,35,50,0.88);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal.open { display: flex; }

.modal img {
  max-width: 94vw;
  max-height: 88vh;
  border-radius: var(--radius);
}

.modal .close-btn {
  position: absolute;
  top: 18px;
  right: 26px;
  color: var(--paper);
  font-size: 34px;
  background: none;
}

/* ---- 图集查看器（微信相册式） ---- */

.gallery-modal {
  flex-direction: column;
  padding: 0;
  background: rgba(8, 12, 18, 0.96);
}

.gallery-head {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 0 8px;
}

#galleryCount {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.gallery-close {
  top: 12px;
  right: 18px;
}

.gallery-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#galleryImg {
  max-width: 96vw;
  max-height: 76vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 6px 30px rgba(0,0,0,0.5);
}

.gallery-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 3px;
}

.gallery-arrow:hover { background: rgba(255,255,255,0.28); }

.gallery-prev { left: 14px; }
.gallery-next { right: 14px; }

.gallery-thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 16px 20px;
  max-width: 100%;
  -webkit-overflow-scrolling: touch;
}

.gallery-thumbs img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0.7;
  transition: border-color .15s, opacity .15s;
}

.gallery-thumbs img.active {
  border-color: var(--amber, #f0b429);
  opacity: 1;
}

@media (max-width: 600px) {
  .gallery-arrow {
    width: 38px;
    height: 38px;
    font-size: 24px;
  }
  .gallery-thumbs img {
    width: 48px;
    height: 48px;
  }
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1100;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(26,35,50,0.18);
}

.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }

/* ============================================
   Responsive — Phone only (< 768px)
   Desktop & iPad (≥768px) keep full sidebar layout
   ============================================ */

@media (max-width: 767px) {
  /* Sidebar → fixed bottom nav */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    z-index: 90;
    height: auto;
    padding: 6px 8px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-bottom: 0;
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(14px);
    box-shadow: 0 -4px 20px rgba(26,35,50,0.06);
  }

  .side-nav.tabs {
    flex-direction: row;
    gap: 2px;
    margin: 0;
    flex: 1;
    justify-content: space-around;
  }

  .side-nav .tab-btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
    padding: 8px 4px 6px;
    font-size: 11px;
    gap: 3px;
    flex-direction: column;
    align-items: center;
    border-radius: var(--radius-sm);
    min-height: 52px;
  }

  .side-nav .tab-btn .nav-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font-size: 11px;
  }

  .mobile-session-bar {
    display: none;
  }

  .mobile-session-bar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 89;
    padding: 8px 14px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,0.94);
    backdrop-filter: blur(12px);
    font-size: 13px;
    font-weight: 700;
    justify-content: space-between;
    align-items: center;
  }

  .mobile-session-bar button {
    padding: 5px 14px;
    border-radius: 999px;
    background: var(--red-soft);
    color: var(--red);
    font-size: 12px;
    font-weight: 700;
  }

  /* Main area */
  .main-stage {
    padding: 16px 12px 100px; /* bottom padding for fixed nav */
  }

  .panel {
    padding: 16px 14px;
    border-radius: var(--radius-lg);
    margin-bottom: 16px;
  }

  /* Topbar */
  .topbar {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 18px;
  }
  .topbar h1 { font-size: 22px; }
  .topbar p { font-size: 13px; }
  .date-chip { font-size: 12px; padding: 8px 14px; align-self: flex-start; }
  .topbar-actions {
    align-self: flex-start;
    width: 100%;
    justify-content: space-between;
  }

  /* Hero */
  .hero-card {
    padding: 22px 20px;
    grid-template-columns: 1fr;
    border-radius: var(--radius-lg);
    margin-bottom: 18px;
  }
  .hero-card h2 { font-size: 20px; }
  .hero-card p { font-size: 13px; }
  .hero-illustration { display: none; }

  /* Dashboard — single column */
  .dash-body,
  .ai-home-row {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .dashboard-card {
    padding: 18px 16px;
    margin-bottom: 16px;
    border-radius: var(--radius-lg);
  }

  .dash-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
  }

  .dash-head h2 { font-size: 16px; }

  .dash-copy h3 {
    font-size: 16px;
    margin-bottom: 6px;
  }

  .book-cover, .clipboard-illus {
    aspect-ratio: 16/9;
    min-height: 140px;
  }
  .book-cover strong { font-size: 22px; }
  .robot-illus { width: 100%; min-height: 140px; aspect-ratio: 16/9; }

  .prompt-pills span { font-size: 12px; padding: 6px 12px; }
  .ask-strip { font-size: 13px; padding: 12px 16px; }

  /* Upload */
  .upload-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .upload-zone {
    min-height: 140px;
    padding: 20px;
  }

  .upload-zone strong { font-size: 14px; }

  .preview-img { max-height: 200px; }

  /* QA */
  .qa-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .answer-panel {
    max-height: none;
    min-height: 360px;
    border-radius: var(--radius);
  }

  .answer-toolbar {
    padding: 12px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .answer-toolbar strong { font-size: 14px; }

  .answer-content {
    padding: 14px;
    font-size: 13px;
    line-height: 1.7;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .answer-content h2 { font-size: 15px; }

  .followup-box {
    margin: 0 12px 14px;
  }

  .followup-entry {
    margin-top: 12px;
    padding: 12px;
  }

  /* Grid — single column */
  .cw-grid { grid-template-columns: 1fr; gap: 8px; }
  .hw-grid { grid-template-columns: 1fr; gap: 10px; }
  .cw-card { padding: 14px; }
  .hw-card { padding: 12px; }
  .hw-image-grid.single .hw-image-thumb { height: 180px; }
  .hw-image-thumb { height: 120px; }
  .hw-card h3 { font-size: 14px; }

  .history-list { gap: 6px; }
  .history-row {
    padding: 14px;
    border-radius: var(--radius);
  }
  .history-row h4 { font-size: 13px; }

  /* Section head */
  .section-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 12px;
  }
  .section-head h2 { font-size: 17px; }

  .subject-filter { gap: 4px; }
  .subject-chip { padding: 5px 12px; font-size: 12px; }
  .homework-filter-bar {
    align-items: stretch;
    gap: 8px;
  }
  .homework-filter-bar select {
    width: 100%;
  }
  .hw-student-head {
    align-items: flex-start;
    flex-direction: column;
  }

  /* Buttons — bigger touch targets */
  .btn {
    min-height: 44px;
    padding: 10px 18px;
    font-size: 14px;
  }
  .btn-small {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 12px;
  }

  /* Form */
  .form-group { margin: 12px 0; }
  .form-group input,
  .form-group select,
  .form-group textarea {
    padding: 12px 14px;
    font-size: 15px; /* prevent iOS zoom */
  }
  .form-group textarea { min-height: 72px; }

  /* Courseware upload */
  .cw-upload { margin-top: 14px; padding-top: 14px; }
  .cw-file-field { min-width: 100%; }
  .file-picked-name { max-width: 140px; font-size: 12px; }

  /* Auth */
  .auth-shell { padding: 16px; }
  .auth-box {
    padding: 28px 20px;
    border-radius: var(--radius-lg);
  }
  .auth-box h1 { font-size: 24px; }
  .auth-box > p { font-size: 13px; margin-bottom: 22px; }

  .auth-tab {
    padding: 12px;
    font-size: 14px;
  }

  /* Modal */
  .modal { padding: 12px; }
  .modal .close-btn { top: 10px; right: 14px; font-size: 28px; }

  /* Toast — bottom to avoid covering content */
  .toast {
    top: auto;
    bottom: 100px;
    right: 12px;
    left: 12px;
    text-align: center;
    padding: 14px 18px;
    font-size: 14px;
  }

  /* Scroll smooth for answer panel */
  .answer-panel { -webkit-overflow-scrolling: touch; }

  /* Followup actions stack */
  .followup-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .followup-actions button { width: 100%; }
}

/* Final responsive layout overrides */
@media (max-width: 1199px) {
  .app-shell {
    display: block;
    min-height: 100vh;
    width: 100%;
  }

  .main-stage {
    width: 100%;
    min-width: 0;
  }

  .side-brand,
  .streak-card,
  .side-profile,
  .muted-nav {
    display: none !important;
  }

  .sidebar {
    width: 100%;
    height: auto;
    min-height: 0;
  }

  .tab-content {
    width: 100%;
    min-width: 0;
  }

  .dashboard-card,
  .panel,
  .hero-card {
    width: 100%;
    min-width: 0;
  }
}

@media (min-width: 768px) and (max-width: 1199px) {
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 80;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px 28px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,0.94);
    box-shadow: 0 8px 24px rgba(26,35,50,0.06);
  }

  .side-nav.tabs {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    margin: 0;
    flex: none;
  }

  .side-nav .tab-btn {
    justify-content: center;
    min-height: 60px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.68);
    text-align: center;
  }

  .side-nav .tab-btn.active {
    border-color: transparent;
    background: var(--ink);
  }

  .mobile-session-bar {
    position: static;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--white);
    font-size: 14px;
    font-weight: 800;
  }

  .mobile-session-bar button {
    padding: 7px 16px;
    border-radius: 999px;
    background: var(--red-soft);
    color: var(--red);
    font-weight: 800;
  }

  .main-stage {
    padding: 28px 32px 44px;
  }

  .dash-body {
    grid-template-columns: minmax(180px, 240px) 1fr;
  }

  .ai-home-row {
    grid-template-columns: minmax(180px, 220px) 1fr;
  }

  .qa-layout,
  .upload-layout {
    grid-template-columns: 1fr;
  }

  .report-metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .answer-panel {
    max-height: none;
  }
}

@media (max-width: 767px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 90;
    display: block;
    height: auto;
    padding: 7px 8px max(7px, env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,0.97);
  }

  .side-nav.tabs {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    margin: 0;
  }

  .side-nav .tab-btn {
    min-width: 0;
    min-height: 54px;
    padding: 7px 2px 6px;
    gap: 3px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    font-size: 11px;
    line-height: 1.15;
    text-align: center;
    white-space: normal;
  }

  .side-nav .tab-btn .nav-icon {
    width: 24px;
    height: 24px;
    border-radius: 7px;
  }

  .mobile-session-bar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 89;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(12px);
    font-size: 13px;
    font-weight: 800;
  }

  .mobile-session-bar button {
    min-height: 30px;
    padding: 4px 13px;
    border-radius: 999px;
    background: var(--red-soft);
    color: var(--red);
    font-weight: 800;
  }

  .main-stage {
    width: 100%;
    padding: 60px 12px 92px;
  }

  .topbar,
  .hero-card,
  .dashboard-card,
  .panel {
    max-width: 100%;
  }

  .dash-head {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .dash-head > div {
    min-width: 0;
  }

  .dash-head h2 {
    overflow-wrap: anywhere;
  }

  .ghost-link {
    flex-shrink: 0;
  }

  .book-cover,
  .clipboard-illus,
  .robot-illus {
    width: 100%;
    max-width: 100%;
  }

  .history-date-select {
    width: 100%;
    min-width: 0;
  }

  .report-head {
    align-items: stretch;
  }

  .report-controls {
    width: 100%;
    justify-content: stretch;
  }

  .report-controls select,
  .report-controls .btn {
    flex: 1 1 100%;
  }

  .report-hero {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .report-score {
    width: 92px;
    height: 92px;
  }

  .report-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .report-card-head {
    flex-direction: column;
  }

  .report-card-head span {
    text-align: left;
  }

  .course-mini div {
    grid-template-columns: 1fr;
  }
}
