:root {
  --bg: #eef2f6;
  --paper: #ffffff;
  --paper-soft: #f8fafc;
  --line: #d8dee7;
  --line-strong: #9aa7b8;
  --text: #18202b;
  --muted: #657184;
  --primary: #1769aa;
  --primary-dark: #0f548c;
  --primary-soft: #e8f3ff;
  --accent: #b84b4b;
  --ok: #24734d;
  --warn: #9b6a12;
  --highlight: #fff2a6;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 12px 34px rgba(15, 23, 42, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #e7edf4 0, var(--bg) 240px, #f5f7fa 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid #8bbcf0;
  outline-offset: 2px;
}

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

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

.topbar {
  height: 58px;
  background: #17222e;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 28px;
  border-bottom: 1px solid #0f1720;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  font-weight: 700;
  letter-spacing: 0;
  background: rgba(255, 255, 255, 0.08);
}

.brand-subtitle {
  color: #d8dee6;
  font-size: 14px;
}

.primary-button,
.secondary-button,
.ghost-button,
.ghost-light-button,
.icon-button {
  border: 1px solid transparent;
  min-height: 36px;
  padding: 0 15px;
  border-radius: 6px;
  font-weight: 700;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-light-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.primary-button {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: #b9d7f2;
}

.danger-button {
  color: var(--accent);
  background: #fff5f5;
  border-color: #f0c4c4;
}

.ghost-button {
  color: #fff;
  background: transparent;
  border-color: #66717f;
}

.ghost-light-button {
  color: var(--text);
  background: #fff;
  border-color: var(--line-strong);
}

.icon-button {
  min-width: 36px;
  padding: 0;
  background: #f2f4f6;
  color: var(--text);
  border-color: var(--line);
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.ghost-light-button:active,
.icon-button:active {
  transform: scale(0.97);
}

.toast-region {
  position: fixed;
  z-index: 100;
  top: 70px;
  right: 18px;
  width: min(420px, calc(100vw - 36px));
  display: grid;
  gap: 8px;
  pointer-events: none;
}

.app-toast {
  padding: 12px 14px;
  border: 1px solid #b9c8d8;
  border-radius: 6px;
  background: #fff;
  box-shadow: var(--shadow-md);
  color: var(--text);
  line-height: 1.45;
  animation: toast-in 180ms cubic-bezier(0.23, 1, 0.32, 1);
}

.app-toast-error {
  border-color: #e4b7b7;
  background: #fff8f8;
}

.app-toast-success {
  border-color: #acd7bc;
  background: #f5fff8;
}

.app-toast-warning {
  border-color: #e6cf99;
  background: #fffaf0;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.setup-panel {
  width: min(1180px, calc(100vw - 40px));
  align-self: start;
  justify-self: center;
  margin-top: 32px;
  padding: 0 0 44px;
}

.setup-section {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  padding: 26px 28px;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.setup-section h1 {
  margin: 0 0 8px;
  font-size: 34px;
  letter-spacing: 0;
}

.setup-section p {
  margin: 0;
  max-width: 760px;
  line-height: 1.6;
  color: var(--muted);
}

.setup-dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  margin-top: 22px;
}

.setup-column {
  display: grid;
  gap: 18px;
}

.mode-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.mode-panel-head,
.import-workspace-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.mode-panel-head h2,
.mode-panel-head p,
.import-workspace-head h2,
.import-workspace-head p {
  margin: 0;
}

.mode-panel-head p,
.import-workspace-head p {
  color: var(--muted);
  line-height: 1.5;
  margin-top: 4px;
}

.mode-choice {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.mode-choice label {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 0 16px;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.mode-choice label:has(input:checked) {
  color: var(--primary-dark);
  border-color: #9cc8ec;
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px #cfe5f8;
}

.subject-picker {
  margin-bottom: 14px;
}

.subject-picker label {
  display: grid;
  gap: 7px;
  max-width: 320px;
  font-weight: 700;
}

.subject-picker select,
.field-stack select,
.field-stack input,
.field-stack textarea {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
}

.speaking-bank-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid #c8d7e6;
  background: #f7fbff;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.speaking-bank-panel div {
  display: grid;
  gap: 3px;
}

.speaking-bank-panel span {
  color: var(--muted);
  font-size: 13px;
}

.full-mock-panel {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.full-mock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.full-mock-head div {
  display: grid;
  gap: 3px;
}

.full-mock-head span {
  color: var(--muted);
  font-size: 13px;
}

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

.full-mock-card {
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 118px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 12px;
  font-weight: 700;
}

.full-mock-card > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.full-mock-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.full-mock-grid select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.subject-flow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.subject-flow div {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.subject-flow div:nth-child(1) {
  border-top: 4px solid #d99a20;
}

.subject-flow div:nth-child(2) {
  border-top: 4px solid #27845b;
}

.subject-flow div:nth-child(3) {
  border-top: 4px solid #9a6840;
}

.subject-flow div:nth-child(4) {
  border-top: 4px solid #3e73ad;
}

.subject-flow strong,
.subject-flow span {
  display: block;
}

.subject-flow span,
.mode-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.mode-hint {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-left: 4px solid #9cc8ec;
  background: #f4f9ff;
  border-radius: 6px;
}

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

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

.file-drop {
  min-height: 128px;
  border: 1px dashed #aeb9c8;
  background: var(--paper-soft);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 18px;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.file-drop:hover {
  border-color: var(--primary);
  background: #f3f8fd;
  box-shadow: var(--shadow-sm);
}

.file-drop input {
  margin-top: 8px;
}

.file-title {
  font-weight: 700;
}

.file-hint {
  color: var(--muted);
  font-size: 14px;
}

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

.import-workspace {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.glm-pipeline,
.settings-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.glm-pipeline div,
.settings-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 12px;
}

.glm-pipeline strong,
.glm-pipeline span,
.settings-summary strong,
.settings-summary span {
  display: block;
}

.glm-pipeline span,
.settings-summary span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-top: 4px;
}

.full-material-guide {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.full-material-guide div {
  border: 1px dashed var(--line-strong);
  background: var(--paper-soft);
  border-radius: 8px;
  padding: 12px;
}

.full-material-guide strong,
.full-material-guide span {
  display: block;
}

.full-material-guide span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-top: 4px;
}

.ai-import-panel,
.manual-import-panel,
.ai-settings-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
}

.import-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-weight: 700;
}

.import-details summary small {
  color: var(--muted);
}

.provider-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.provider-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 14px;
}

.provider-card h3 {
  margin: 0 0 10px;
}

.provider-model-row,
.connection-grid,
.model-slot-grid {
  display: grid;
  gap: 10px;
}

.connection-grid {
  grid-template-columns: minmax(280px, 1.3fr) minmax(220px, 0.7fr);
  margin-bottom: 14px;
}

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

.model-settings-card {
  background: #fff;
}

.model-settings-head {
  margin-bottom: 14px;
}

.model-settings-head h3,
.model-settings-head p {
  margin: 0;
}

.model-settings-head p,
.model-slot small {
  color: var(--muted);
  font-weight: 500;
  line-height: 1.4;
}

.model-slot {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  padding: 12px;
}

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

.field-error {
  color: var(--accent);
  font-size: 12px;
  line-height: 1.35;
  font-weight: 600;
}

.settings-dialog {
  width: min(1080px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow-md);
}

.settings-dialog::backdrop {
  background: rgba(16, 24, 32, 0.5);
}

.settings-body {
  padding: 18px;
  max-height: min(76vh, 760px);
  overflow: auto;
}

.ai-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(320px, 1.2fr);
  gap: 14px;
  margin: 14px 0;
}

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

.manual-text-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
  margin: 14px 0;
  padding: 0;
}

.manual-text-details summary {
  cursor: pointer;
  font-weight: 700;
  padding: 12px 14px;
}

.manual-text-details .ai-text-grid {
  padding: 0 14px 14px;
  margin: 0;
}

.pdf-page-image-panel {
  margin: 12px 0 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-soft);
}

.pdf-page-image-panel input {
  max-width: 180px;
}

.field-stack {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

.field-stack input,
.field-stack textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
  font-weight: 400;
}

.field-stack textarea {
  min-height: 118px;
  resize: vertical;
  line-height: 1.45;
}

.ai-file-drop {
  min-height: 92px;
}

.ai-status {
  align-self: center;
  color: var(--muted);
}

.ai-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.ai-progress progress {
  width: min(520px, 100%);
  height: 8px;
  accent-color: var(--primary);
}

.ai-progress[data-state="complete"] {
  color: var(--ok);
}

.ai-progress[data-state="error"] {
  color: var(--accent);
}

.pending-panel {
  margin: 18px 0 12px;
  border: 1px solid #b9d3eb;
  background: #f4f9ff;
  border-radius: 8px;
  padding: 14px;
}

.pending-panel h2 {
  margin: 6px 0 4px;
  font-size: 18px;
}

.pending-panel p {
  margin: 0;
  color: var(--muted);
}

.pending-label {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.library-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

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

.library-head h2,
.library-title {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
}

.library-toggle {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  font-weight: 800;
}

.library-toggle-icon {
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-soft);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  line-height: 1;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.library-toggle:hover .library-toggle-icon {
  background: var(--primary-soft);
  border-color: #b9d7f2;
  color: var(--primary);
}

.library-toggle.is-collapsed .library-toggle-icon {
  transform: rotate(-90deg);
}

.library-head span,
.test-source {
  color: var(--muted);
  font-size: 13px;
}

.library-head > span {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef3f8;
  color: #516071;
  font-weight: 700;
}

.test-list {
  display: grid;
  gap: 12px;
}

.test-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 126px;
  align-items: center;
  gap: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.test-card:hover {
  border-color: #b7c5d5;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

.test-card-main {
  min-width: 0;
}

.test-card h3 {
  margin: 6px 0 4px;
  font-size: 19px;
}

.test-card p {
  margin: 0 0 6px;
  color: var(--muted);
}

.test-type {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.test-type.reading {
  color: #174d33;
  background: #e6f4ec;
}

.test-type.listening {
  color: #6a3c00;
  background: #fff2d8;
}

.test-type.writing {
  color: #6b3f13;
  background: #f7eadc;
}

.test-type.speaking {
  color: #284c7a;
  background: #e6eef8;
}

.test-card-actions {
  display: grid;
  grid-template-columns: 1fr;
  align-content: center;
  gap: 8px;
}

.test-card-actions button {
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  white-space: nowrap;
}

.empty-state {
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  background: var(--paper-soft);
  padding: 18px;
  border-radius: 8px;
}

.history-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.asset-warning {
  display: block;
  margin-top: 6px;
  color: #9a5b00;
  font-size: 13px;
  font-weight: 600;
}

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

.history-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.history-card h3 {
  margin: 5px 0 3px;
  font-size: 16px;
}

.history-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.history-card strong {
  font-size: 18px;
}

.history-card > span {
  min-width: 54px;
  text-align: right;
  color: var(--muted);
}

.history-panel .empty-state {
  margin: 0;
}

.exam {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  height: calc(100vh - 56px);
  min-height: 0;
  overflow: hidden;
}

.exam-header {
  min-height: 72px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
}

.exam-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.mode-toggle label {
  display: inline-flex;
  position: relative;
  cursor: pointer;
}

.mode-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-toggle span {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: #f7f9fb;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.mode-toggle input:checked + span {
  background: var(--primary);
  color: #fff;
}

.exam-header h2 {
  margin: 2px 0 0;
  font-size: 20px;
}

.exam-type {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  font-weight: 700;
}

.timer {
  min-width: 92px;
  text-align: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: #f7f9fb;
  font-size: 22px;
  font-weight: 700;
  border-radius: 4px;
}

.timer.warning {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.part-tabs {
  min-height: 52px;
  display: flex;
  align-items: stretch;
  gap: 0;
  background: #eef1f4;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.part-tab {
  min-width: 150px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #eef1f4;
  color: var(--text);
  padding: 8px 16px;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  text-align: left;
  font-weight: 700;
}

.part-tab small {
  color: var(--muted);
  font-weight: 600;
}

.part-tab.active {
  background: #fff;
  box-shadow: inset 0 -4px 0 var(--primary);
}

.audio-panel {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.audio-status {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
}

.audio-status strong {
  color: var(--text);
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.workbench {
  min-height: 0;
  overflow: hidden;
}

.reading-layout,
.listening-layout {
  height: 100%;
  display: grid;
  min-height: 0;
}

.reading-layout {
  grid-template-columns: minmax(340px, 1fr) minmax(360px, 1fr);
  font-size: 17px;
}

.listening-layout {
  grid-template-columns: minmax(0, 1fr);
}

.passage-pane,
.question-pane,
.section-list {
  overflow: auto;
  min-height: 0;
  padding: 20px;
  background: var(--paper);
}

.passage-pane {
  border-right: 1px solid var(--line);
}

.section-list {
  border-right: 1px solid var(--line);
  background: #f9fafb;
}

.section-tab {
  width: 100%;
  display: block;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 4px;
  padding: 12px;
  margin-bottom: 8px;
  font-weight: 700;
}

.section-tab.active {
  border-color: var(--primary);
  box-shadow: inset 4px 0 0 var(--primary);
}

.passage-title,
.section-title {
  margin: 0 0 14px;
  font-size: 24px;
}

.passage-text {
  font-size: 18px;
  line-height: 1.72;
  white-space: pre-wrap;
}

.writing-layout {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(420px, 1.18fr);
  min-height: 0;
}

.writing-prompt-pane,
.writing-editor-pane,
.speaking-layout {
  overflow: auto;
  min-height: 0;
  padding: 22px;
  background: var(--paper);
}

.writing-prompt-pane {
  border-right: 1px solid var(--line);
}

.task-kicker {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.writing-prompt {
  border: 1px solid var(--line);
  background: #fbfcfd;
  border-radius: 6px;
  padding: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.writing-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.writing-toolbar span,
.word-badge {
  color: var(--muted);
  font-weight: 700;
}

.writing-editor {
  width: 100%;
  min-height: calc(100% - 42px);
  resize: none;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 16px;
  line-height: 1.7;
  font-size: 17px;
}

.speaking-layout {
  display: grid;
  place-items: start center;
}

.speaking-card {
  width: min(900px, 100%);
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 22px;
}

.cue-card,
.speaking-questions {
  border: 1px solid var(--line);
  background: #fbfcfd;
  border-radius: 6px;
  padding: 16px 18px;
  line-height: 1.65;
}

.cue-card h3 {
  margin: 0 0 10px;
}

.speaking-meta,
.speaking-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.speaking-meta span {
  border: 1px solid var(--line);
  background: #f8fafc;
  border-radius: 4px;
  padding: 7px 9px;
  color: var(--muted);
  font-weight: 700;
}

.speaking-actions audio {
  max-width: min(520px, 100%);
}

.muted-note {
  color: var(--muted);
}

.speaking-notes {
  margin-top: 18px;
}

.speaking-notes textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 12px;
  line-height: 1.6;
}

.group {
  border-bottom: 1px solid var(--line);
  padding: 0 0 20px;
  margin-bottom: 20px;
}

.group:last-child {
  border-bottom: 0;
}

.group h3 {
  margin: 0 0 8px;
  font-size: 19px;
}

.instructions {
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 14px;
}

.map-image {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  margin: 10px 0 18px;
}

.question {
  position: relative;
  padding: 14px 42px 14px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin: 12px 0;
  background: #fff;
}

.question.current {
  border-color: var(--primary);
  box-shadow: inset 4px 0 0 var(--primary);
}

.question.answered {
  background: #fbfefc;
}

.question.review {
  border-color: var(--warn);
}

.question-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.question-number {
  min-width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #e9eef4;
  font-weight: 700;
}

.question-content {
  flex: 1;
  min-width: 0;
  line-height: 1.58;
}

.answer-input {
  width: min(340px, 100%);
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 7px 9px;
  margin-top: 10px;
}

.inline-template {
  margin: 10px 0 18px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: #fbfcfd;
  line-height: 2.25;
  font-size: 16px;
}

.inline-line + .inline-line {
  margin-top: 8px;
}

.inline-answer {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px;
  border-radius: 4px;
  vertical-align: middle;
}

.inline-answer.current {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.inline-answer.answered .inline-number {
  background: #dcfce7;
  color: #17663a;
}

.inline-answer.review .inline-number {
  background: #fff4cc;
  color: #8a5a00;
}

.inline-number {
  min-width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #e9eef4;
  font-size: 13px;
  font-weight: 700;
}

.inline-input {
  width: 148px;
  min-height: 30px;
  margin: 0;
  padding: 4px 7px;
}

.inline-review {
  position: static;
  width: 24px;
  height: 24px;
  font-size: 12px;
}

.option-bank {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 6px 14px;
  margin: 12px 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #f8fafc;
  font-size: 14px;
}

.bank-option {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.bank-letter {
  width: 22px;
  flex: 0 0 22px;
  font-weight: 700;
  color: var(--accent);
}

.option-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  border: 1px solid #e3e7ec;
  border-radius: 4px;
  background: #fbfcfd;
}

.option input {
  margin-top: 3px;
}

.review-toggle {
  position: absolute;
  right: 8px;
  top: 8px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  background: #f6f8fa;
  border-radius: 4px;
  color: var(--muted);
}

.review-toggle.active {
  color: #fff;
  background: var(--warn);
  border-color: var(--warn);
}

.question-nav {
  min-height: 58px;
  background: #fff;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  overflow-x: auto;
}

.nav-number {
  flex: 0 0 auto;
  min-width: 38px;
  height: 38px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: 4px;
  font-weight: 700;
}

.nav-number.answered {
  color: #fff;
  background: var(--ok);
  border-color: var(--ok);
}

.nav-number.current {
  outline: 3px solid #b8d8f5;
}

.nav-number.review {
  border-color: var(--warn);
  box-shadow: inset 0 -4px 0 var(--warn);
}

.highlight-popover {
  position: fixed;
  z-index: 20;
  border: 1px solid #8d7b24;
  background: #fff3a6;
  color: #1d1d1d;
  padding: 6px 10px;
  border-radius: 4px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

mark.user-highlight {
  background: var(--highlight);
  padding: 0 1px;
}

.result-dialog {
  width: min(880px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 {
  margin: 0;
}

.result-dialog::backdrop {
  background: rgba(16, 24, 32, 0.5);
}

#resultBody {
  padding: 18px;
  max-height: min(70vh, 680px);
  overflow: auto;
}

.score-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.score-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fbfcfd;
}

.score-label {
  color: var(--muted);
  font-size: 13px;
}

.score-value {
  margin-top: 4px;
  font-size: 24px;
  font-weight: 700;
}

.review-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.review-table th,
.review-table td {
  border: 1px solid var(--line);
  padding: 8px;
  vertical-align: top;
  text-align: left;
}

.review-table th {
  background: #f0f3f7;
}

.correct {
  color: var(--ok);
  font-weight: 700;
}

.wrong {
  color: var(--accent);
  font-weight: 700;
}

.compact-button {
  min-height: 30px;
  padding: 0 9px;
  white-space: nowrap;
}

.ai-feedback {
  border: 1px solid #bed7ef;
  background: #f4f9ff;
  border-radius: 6px;
  padding: 12px;
  color: var(--text);
  line-height: 1.6;
}

.ai-feedback p {
  margin: 6px 0 12px;
}

.ai-feedback section + section {
  margin-top: 10px;
}

.feedback-object {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.feedback-field {
  display: grid;
  gap: 2px;
}

.feedback-field strong {
  color: var(--muted);
  font-size: 0.86rem;
}

.ai-feedback ul {
  margin: 8px 0 0 18px;
  padding: 0;
}

.ai-feedback li + li {
  margin-top: 10px;
}

.productive-review {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 14px;
  margin-bottom: 14px;
}

.productive-review h3 {
  margin: 0 0 8px;
}

.productive-review pre {
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  white-space: pre-wrap;
  line-height: 1.6;
  font: inherit;
}

.result-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 0 0 14px;
}

.result-note {
  color: var(--muted);
  line-height: 1.5;
  margin: -4px 0 14px;
}

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

  .setup-grid,
  .setup-dashboard,
  .ai-grid,
  .ai-text-grid,
  .material-grid,

  .provider-grid,
  .connection-grid,
  .model-slot-grid,
  .glm-pipeline,
  .settings-summary,
  .full-material-guide,
  .full-mock-grid,
  .listening-layout,
  .score-card {
    grid-template-columns: 1fr;
  }

  .setup-section {
    align-items: stretch;
    flex-direction: column;
  }

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

  .mode-panel-head,
  .import-workspace-head {
    flex-direction: column;
  }

  .reading-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 46vh) minmax(260px, 1fr);
  }

  .writing-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 40vh) minmax(300px, 1fr);
  }

  .test-card {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .test-card-actions {
    grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  }

  .history-card {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .history-card > span {
    text-align: left;
  }

  .passage-pane,
  .section-list {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .audio-panel,
  .exam-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .exam-controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .feature-settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .topbar {
    padding: 0 14px;
  }

  .setup-panel {
    width: min(100% - 20px, 1180px);
    margin-top: 16px;
  }

  .setup-section,
  .mode-panel,
  .import-workspace,
  .library-panel,
  .history-panel {
    padding: 16px;
  }

  .setup-section h1 {
    font-size: 28px;
  }

  .subject-flow {
    grid-template-columns: 1fr;
  }

  .setup-actions > button,
  .setup-actions > .file-button {
    width: 100%;
  }

  .audio-controls {
    width: 100%;
    justify-content: space-between;
  }

  .exam-header {
    padding: 10px 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
