:root {
  --navy: #0b2233;
  --navy-2: #11364d;
  --blue: #197aa8;
  --cyan: #77c7e8;
  --gold: #f5bd3d;
  --orange: #d96832;
  --paper: #f7f4ed;
  --white: #fffefa;
  --line: #d9d5ca;
  --text: #132a3a;
  --muted: #617482;
  --shadow: 0 18px 50px rgba(11, 34, 51, .12);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { height: 100vh; overflow: hidden; color: var(--text); background: #dfe5e8; font-family: "Microsoft YaHei", "Noto Sans SC", sans-serif; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.app-header {
  height: 82px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 clamp(20px, 3.2vw, 56px);
  color: white;
  background: var(--navy);
  border-bottom: 2px solid rgba(119, 199, 232, .28);
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 310px; color: white; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border: 1px solid var(--gold); color: var(--gold); font: 30px Georgia, serif; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 19px; }
.brand small { margin-top: 4px; color: #acd3e5; font-size: 12px; letter-spacing: .12em; }
.header-progress { flex: 1; max-width: 320px; }
.header-progress span { display: block; margin-bottom: 7px; font-size: 12px; color: #d5e9f2; }
.header-progress i { display: block; height: 4px; overflow: hidden; border-radius: 9px; background: rgba(255,255,255,.16); }
.header-progress b { display: block; width: 16.666%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gold), var(--cyan)); transition: width .35s ease; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.notebook-count { font-size: 12px; color: #b7d2df; white-space: nowrap; }
.notebook-count b { color: var(--gold); }
.home-link { color: #d7e7ee; font-size: 13px; text-decoration: none; white-space: nowrap; }
.home-link:hover { color: var(--gold); }

.primary-button, .ghost-button, .context-button {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid var(--navy-2);
  border-radius: 2px;
  transition: transform .18s ease, background .18s ease, color .18s ease;
}
.primary-button { color: white; background: var(--navy-2); }
.primary-button:hover { background: #174b69; transform: translateY(-1px); }
.ghost-button { color: var(--navy-2); background: transparent; }
.app-header .ghost-button { color: #dbe9ef; border-color: rgba(255,255,255,.35); }
.ghost-button:hover { background: rgba(119,199,232,.1); }

.learning-workbench { height: calc(100vh - 82px); display: grid; grid-template-columns: minmax(0, 1.34fr) minmax(390px, .76fr); gap: 1px; background: #bfcbd1; }
.lesson-panel, .ai-panel { min-width: 0; min-height: 0; background: var(--paper); }
.lesson-panel { display: grid; grid-template-rows: auto minmax(0,1fr) auto; }
.panel-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; padding: 24px 30px 18px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.55); }
.eyebrow { margin: 0 0 7px; color: var(--orange); font-size: 11px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.panel-heading h1 { margin: 0; font-family: "Songti SC", SimSun, serif; font-size: clamp(23px, 2vw, 34px); font-weight: 500; }
.step-tabs { display: flex; gap: 7px; }
.step-tab { width: 36px; height: 36px; border: 1px solid #b8c2c7; border-radius: 50%; background: white; color: var(--muted); font-size: 13px; }
.step-tab.active { color: white; border-color: var(--orange); background: var(--orange); box-shadow: 0 0 0 4px rgba(217,104,50,.12); }
.step-tab.done:not(.active) { color: var(--navy); border-color: var(--cyan); background: #eaf6fa; }

.lesson-scroll { overflow-y: auto; overscroll-behavior: contain; scrollbar-color: #a8b8bf transparent; padding: 26px clamp(22px, 3vw, 46px) 42px; }
.step-figure { position: relative; margin: 0 0 24px; padding: 16px; background: #0d1e29; box-shadow: var(--shadow); }
.step-figure img { display: block; width: 100%; max-height: 420px; object-fit: contain; background: #fff; }
.figure-label { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; color: white; }
.figure-label span { color: var(--gold); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.figure-label small { color: #a9c7d5; }
.step-figure figcaption { margin-top: 10px; color: #9fb8c4; font-size: 12px; }

.reading-card { padding: 26px 28px; border: 1px solid var(--line); background: var(--white); box-shadow: 0 12px 28px rgba(25,50,64,.06); }
.selection-hint { display: flex; justify-content: space-between; gap: 20px; margin: -4px 0 22px; padding-bottom: 13px; border-bottom: 1px solid #e5e1d8; color: var(--blue); font-size: 12px; }
.selection-hint small { color: var(--muted); }
.reading-card h2 { margin: 0 0 12px; font: 500 27px "Songti SC", SimSun, serif; }
.reading-card .lead { margin: 0 0 22px; color: #3f5664; font-size: 17px; line-height: 1.9; }
.selectable { border-radius: 3px; outline: none; transition: background .18s ease, box-shadow .18s ease; }
.selectable:hover, .selectable:focus { background: #eef8fb; box-shadow: 0 0 0 5px #eef8fb; }
.selectable::selection, .selectable *::selection { color: #071b28; background: #ffda78; }
.io-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.io-grid > div { padding: 15px 17px; border-left: 3px solid var(--cyan); background: #eff5f6; }
.io-grid span, .knowledge-block h3 { display: block; margin: 0 0 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.io-grid p, .knowledge-block p { margin: 0; line-height: 1.75; }
.knowledge-block { margin-top: 12px; padding: 17px 18px; border: 1px solid #dce3e5; }
.knowledge-block.accent { border-left: 4px solid var(--blue); background: #eef7fa; }
.knowledge-block.warning { border-left: 4px solid var(--gold); background: #fff8e8; }
.knowledge-block h3 { color: var(--navy-2); font-size: 14px; }

.personal-note { display: block; margin-top: 20px; padding: 20px; color: var(--navy); background: #ebe7dd; }
.personal-note > span { display: block; margin-bottom: 10px; font-weight: 700; }
.personal-note textarea, .chat-form textarea, .student-dialog input, .student-dialog textarea {
  width: 100%; resize: vertical; border: 1px solid #c5ced2; border-radius: 2px; color: var(--text); background: white; padding: 12px 14px; outline: none;
}
.personal-note textarea:focus, .chat-form textarea:focus, .student-dialog input:focus, .student-dialog textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(25,122,168,.12); }
.lesson-navigation { display: flex; align-items: center; justify-content: space-between; padding: 14px 30px; border-top: 1px solid var(--line); background: white; }
.lesson-navigation span { color: var(--muted); font-size: 13px; }

.ai-panel { display: grid; grid-template-rows: auto auto minmax(0,1fr) auto auto; background: #edf1f2; }
.ai-heading { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 20px 22px; color: white; background: var(--navy); }
.ai-avatar { display: grid; place-items: center; width: 46px; height: 46px; border: 1px solid var(--cyan); border-radius: 50%; color: var(--gold); font: 700 15px Georgia, serif; box-shadow: inset 0 0 0 4px rgba(119,199,232,.08); }
.ai-heading h2, .ai-heading p { margin: 0; }
.ai-heading h2 { font-size: 17px; }
.ai-heading p { margin-top: 4px; color: #a8c8d7; font-size: 11px; }
.text-button { padding: 6px; border: 0; color: #b9d1dc; background: none; font-size: 12px; }
.text-button:hover { color: var(--gold); }

.selected-context { margin: 16px 18px 8px; padding: 14px 15px; border: 1px solid #c7d8df; background: white; }
.selected-context > div { display: flex; justify-content: space-between; gap: 12px; }
.selected-context span { font-size: 12px; font-weight: 700; color: var(--blue); }
.selected-context small { color: #8799a2; }
.selected-context blockquote { max-height: 80px; overflow: auto; margin: 10px 0 12px; padding-left: 12px; border-left: 3px solid var(--gold); color: #405965; font-size: 13px; line-height: 1.65; }
.context-button { width: 100%; min-height: 36px; color: var(--navy-2); border-color: #8eb9cb; background: #edf8fb; font-size: 13px; }
.context-button:disabled { cursor: not-allowed; opacity: .45; }

.chat-scroll { overflow-y: auto; overscroll-behavior: contain; padding: 10px 18px 22px; }
.message { max-width: 92%; margin: 10px 0; padding: 13px 15px; border-radius: 3px; box-shadow: 0 5px 14px rgba(14,44,60,.07); }
.message.assistant { margin-right: auto; border-left: 3px solid var(--cyan); background: white; }
.message.user { margin-left: auto; color: white; background: var(--navy-2); }
.message-role { display: block; margin-bottom: 6px; color: var(--blue); font-size: 11px; font-weight: 800; }
.message.user .message-role { color: #a9d9ec; }
.message p { margin: 0; white-space: pre-wrap; font-size: 13px; line-height: 1.75; }
.message-context { margin-bottom: 8px; padding: 8px; color: #59717c; background: #eef3f4; font-size: 11px; }
.note-toggle { display: flex; align-items: center; gap: 7px; margin-top: 10px; color: #59717c; font-size: 11px; }
.typing p::after { content: ""; display: inline-block; width: 5px; height: 5px; margin-left: 5px; border-radius: 50%; background: var(--blue); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.quick-questions { display: flex; gap: 7px; overflow-x: auto; padding: 0 18px 10px; }
.quick-question { flex: 0 0 auto; padding: 8px 11px; border: 1px solid #b8cbd3; border-radius: 18px; color: #365664; background: transparent; font-size: 11px; }
.quick-question:hover { color: white; border-color: var(--blue); background: var(--blue); }
.chat-form { padding: 14px 18px 17px; border-top: 1px solid #cbd5d9; background: white; }
.chat-form > label { display: block; margin-bottom: 7px; color: var(--navy); font-size: 12px; font-weight: 700; }
.chat-form textarea { min-height: 70px; max-height: 150px; }
.chat-form-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 9px; }
.chat-form-footer span { color: #7c8d95; font-size: 10px; }

.student-dialog { width: min(630px, calc(100vw - 30px)); border: 0; padding: 0; color: var(--text); background: var(--paper); box-shadow: 0 30px 90px rgba(0,0,0,.3); }
.student-dialog::backdrop { background: rgba(4,21,31,.72); }
.student-dialog form { padding: 28px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.dialog-heading h2 { margin: 0; font: 500 28px "Songti SC", SimSun, serif; }
.dialog-heading button { border: 0; color: var(--muted); background: none; font-size: 30px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.student-dialog label { display: block; margin-bottom: 14px; color: #3e5663; font-size: 13px; }
.student-dialog input, .student-dialog textarea { display: block; margin-top: 7px; }
.dialog-note { color: var(--muted); font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.pdf-status { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; color: white; background: rgba(4,21,31,.84); }
.pdf-status[hidden] { display: none; }
.pdf-status span { width: 46px; height: 46px; border: 3px solid rgba(255,255,255,.22); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .notebook-count, .home-link { display: none; }
  .brand { min-width: 260px; }
  .learning-workbench { grid-template-columns: minmax(0, 1.12fr) minmax(360px, .88fr); }
  .panel-heading { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 820px) {
  body { height: auto; overflow: auto; }
  .app-header { position: sticky; top: 0; z-index: 10; height: auto; min-height: 68px; padding: 10px 14px; }
  .brand { min-width: 0; flex: 1; }
  .brand-mark { width: 40px; height: 40px; font-size: 25px; }
  .brand strong { font-size: 15px; }
  .brand small, .header-progress, #openStudentInfo { display: none; }
  .header-actions { margin: 0; }
  .header-actions .primary-button { min-height: 38px; padding: 0 11px; font-size: 12px; }
  .learning-workbench { height: auto; display: block; }
  .lesson-panel, .ai-panel { display: block; }
  .lesson-scroll, .chat-scroll { overflow: visible; }
  .panel-heading { padding: 20px 16px 15px; }
  .panel-heading h1 { font-size: 24px; }
  .step-tabs { width: 100%; justify-content: space-between; }
  .lesson-scroll { padding: 16px 14px 26px; }
  .step-figure { padding: 10px; }
  .step-figure img { max-height: none; }
  .reading-card { padding: 20px 17px; }
  .selection-hint { display: block; }
  .selection-hint small { display: block; margin-top: 4px; }
  .io-grid { grid-template-columns: 1fr; }
  .lesson-navigation { position: sticky; bottom: 0; z-index: 5; padding: 10px 14px; box-shadow: 0 -5px 18px rgba(0,0,0,.08); }
  .ai-panel { border-top: 8px solid #d4dde1; }
  .chat-scroll { min-height: 240px; }
  .chat-form { padding-bottom: 28px; }
  .form-grid { grid-template-columns: 1fr; gap: 0; }
}
