:root {
  --ink: #1f2a2e;
  --muted: #627176;
  --green: #1f7a5a;
  --mint: #e8f4ee;
  --paper: #fbfbf7;
  --blue: #2868d8;
  --gold: #a87518;
  --line: #dfe7e1;
  --white: #ffffff;
  --danger: #9c3d2f;
  --shadow: 0 18px 45px rgba(31, 42, 46, 0.08);
  --radius: 8px;
  color-scheme: light;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(232, 244, 238, 0.72), rgba(251, 251, 247, 0) 28%),
    var(--paper);
  color: var(--ink);
}

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

button,
.file-button,
.upload-box {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
textarea:focus-visible,
.file-button:focus-within,
.upload-box:focus-within {
  outline: 3px solid rgba(40, 104, 216, 0.24);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) minmax(280px, 360px);
  gap: 0;
}

.curriculum-panel,
.insight-panel {
  min-height: 100vh;
  max-height: 100vh;
  overflow: auto;
  scrollbar-width: thin;
}

.curriculum-panel {
  background: rgba(255, 255, 255, 0.78);
  border-right: 1px solid var(--line);
  padding: 22px 18px;
}

.insight-panel {
  background: rgba(255, 255, 255, 0.7);
  border-left: 1px solid var(--line);
  padding: 20px;
}

.lesson-workspace {
  min-width: 0;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: 24px;
}

.panel-head,
.lesson-topbar,
.card-head,
.tool-row,
.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-actions {
  display: flex;
  gap: 8px;
}

.panel-head h1,
.lesson-topbar h2,
.card-head h3 {
  margin: 0;
}

.panel-head h1 {
  font-size: 22px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  cursor: pointer;
}

.settings-dialog {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  background: transparent;
  overflow: auto;
}

.settings-dialog::backdrop {
  background: rgba(31, 42, 46, 0.36);
}

.settings-panel {
  display: grid;
  gap: 16px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.settings-head,
.settings-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-head h2 {
  margin: 0;
  font-size: 22px;
}

.setting-note {
  padding: 12px 14px;
  border-left: 4px solid var(--blue);
  border-radius: var(--radius);
  background: #eef4ff;
  color: var(--muted);
  line-height: 1.55;
}

.provider-fields {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  padding: 9px 11px;
}

.settings-status {
  min-height: 22px;
  color: var(--green);
  font-size: 13px;
}

.settings-status.is-error {
  color: var(--danger);
}

.settings-actions {
  align-items: stretch;
}

.settings-actions button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  padding: 0 14px;
}

#save-ai-config {
  border-color: var(--green);
  background: var(--green);
  color: var(--white);
}

.mobile-toggle {
  display: none;
}

.curriculum-summary {
  margin: 20px 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--mint);
}

.curriculum-summary span,
.curriculum-summary strong {
  display: block;
}

.curriculum-summary span {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.curriculum-summary strong {
  font-size: 14px;
  line-height: 1.35;
}

.module-list {
  display: grid;
  gap: 16px;
}

.module-block {
  display: grid;
  gap: 8px;
}

.module-title {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.lesson-list {
  position: relative;
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0 0 0 16px;
  list-style: none;
}

.lesson-list::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 13px;
  bottom: 13px;
  width: 2px;
  background: var(--line);
}

.lesson-item {
  position: relative;
}

.lesson-button {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.lesson-button:hover {
  background: rgba(232, 244, 238, 0.8);
}

.lesson-button.is-selected {
  border-color: rgba(31, 122, 90, 0.34);
  background: var(--white);
  box-shadow: 0 10px 22px rgba(31, 122, 90, 0.1);
}

.trace-dot {
  z-index: 1;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.lesson-button.is-started .trace-dot {
  border-color: var(--blue);
  color: var(--blue);
}

.lesson-button.is-strong .trace-dot {
  border-color: var(--green);
  background: var(--green);
  color: var(--white);
}

.lesson-button.is-weak .trace-dot {
  border-color: var(--gold);
  background: #fff8e6;
  color: var(--gold);
}

.lesson-name {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.lesson-name strong,
.lesson-name small,
.lesson-summary,
.message-bubble,
.knowledge-card p,
.weak-pill {
  overflow-wrap: anywhere;
}

.lesson-name strong {
  font-size: 13px;
  line-height: 1.35;
}

.lesson-name small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.lesson-score {
  min-width: 38px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.lesson-topbar {
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.lesson-topbar h2 {
  max-width: 920px;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.18;
}

.lesson-summary {
  max-width: 920px;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.lesson-stats {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(2, 92px);
  gap: 10px;
}

.lesson-stats div {
  min-height: 74px;
  display: grid;
  place-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}

.lesson-stats span {
  color: var(--blue);
  font-size: 22px;
  font-weight: 900;
}

.lesson-stats small {
  color: var(--muted);
}

.mode-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(74px, 1fr));
  gap: 8px;
  padding: 16px 0;
}

.mode-tab,
#send-button,
.tool-row button,
.file-button,
.secondary-action {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.mode-tab.is-active {
  border-color: var(--green);
  background: var(--green);
  color: var(--white);
}

.conversation-card {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(260px, 1fr) auto auto auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.conversation-feed {
  min-height: 260px;
  overflow: auto;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  max-width: min(760px, 94%);
  display: grid;
  gap: 7px;
}

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

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

.message.is-user .message-meta {
  text-align: right;
}

.message-bubble {
  padding: 14px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  white-space: pre-wrap;
}

.message.is-ai .message-bubble {
  border-left: 4px solid var(--green);
  background: var(--mint);
}

.message.is-user .message-bubble {
  background: #eef4ff;
  border-right: 4px solid var(--blue);
}

.next-question {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(31, 122, 90, 0.18);
  color: var(--ink);
  font-weight: 800;
}

.detected-gap {
  margin-top: 8px;
  color: var(--gold);
  font-size: 13px;
}

.quick-starters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 18px 16px;
}

.starter-chip {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid rgba(40, 104, 216, 0.24);
  border-radius: 999px;
  background: #f5f8ff;
  color: var(--blue);
  padding: 6px 12px;
  cursor: pointer;
}

.answer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 12px;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.answer-box textarea {
  width: 100%;
  min-height: 82px;
  max-height: 180px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  background: var(--white);
  color: var(--ink);
  line-height: 1.55;
}

#send-button {
  height: 82px;
  align-self: start;
  border-color: var(--blue);
  background: var(--blue);
  color: var(--white);
}

#send-button:disabled,
.mode-tab:disabled,
button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.status-line {
  min-height: 22px;
  margin: 0;
  padding: 0 18px 12px;
  color: var(--muted);
  font-size: 13px;
}

.status-line.is-error {
  color: var(--danger);
}

.side-card {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--white);
}

.card-head h3 {
  font-size: 16px;
}

.card-head strong {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mastery-card {
  justify-items: stretch;
}

.progress-ring {
  width: 132px;
  height: 132px;
  justify-self: center;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle closest-side, var(--white) 72%, transparent 73%),
    conic-gradient(var(--green) var(--progress), #dfe7e1 0);
}

.progress-ring span {
  color: var(--green);
  font-size: 28px;
  font-weight: 900;
}

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

.weak-list,
.knowledge-list {
  display: grid;
  gap: 10px;
}

.weak-pill {
  padding: 10px 12px;
  border-left: 4px solid var(--gold);
  border-radius: var(--radius);
  background: #fff8e6;
  color: #5b4318;
  line-height: 1.45;
}

.knowledge-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}

.knowledge-card strong {
  color: var(--ink);
}

.knowledge-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.knowledge-card small {
  color: var(--green);
  line-height: 1.45;
}

.tool-row {
  align-items: stretch;
}

.tool-row button,
.file-button,
.secondary-action {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 0 12px;
}

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

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

.upload-box {
  min-height: 76px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(31, 122, 90, 0.46);
  border-radius: var(--radius);
  background: var(--mint);
  color: var(--green);
  font-weight: 800;
  cursor: pointer;
}

.secondary-action {
  width: 100%;
}

.danger-action {
  border-color: rgba(156, 61, 47, 0.3);
  color: var(--danger);
}

.empty-state {
  color: var(--muted);
  line-height: 1.6;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(240px, 290px) minmax(0, 1fr);
  }

  .insight-panel {
    grid-column: 1 / -1;
    min-height: auto;
    max-height: none;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .side-card {
    margin-bottom: 0;
  }
}

@media (max-width: 820px) {
  body {
    background: var(--paper);
  }

  .app-shell {
    display: block;
  }

  .curriculum-panel,
  .insight-panel {
    min-height: auto;
    max-height: none;
  }

  .curriculum-panel {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .mobile-toggle {
    display: block;
  }

  .module-list {
    display: none;
    max-height: 62vh;
    overflow: auto;
  }

  .app-shell.is-map-open .module-list {
    display: grid;
  }

  .curriculum-summary {
    margin: 12px 0 0;
  }

  .app-shell.is-map-open .curriculum-summary {
    margin-bottom: 14px;
  }

  .lesson-workspace {
    min-height: calc(100vh - 104px);
    padding: 16px;
  }

  .lesson-topbar {
    display: grid;
  }

  .lesson-topbar h2 {
    font-size: 24px;
  }

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

  .mode-strip {
    grid-template-columns: repeat(5, minmax(58px, 1fr));
    gap: 6px;
    overflow-x: auto;
  }

  .mode-tab {
    min-width: 58px;
    padding: 0 6px;
  }

  .conversation-card {
    grid-template-rows: minmax(320px, 1fr) auto auto auto;
  }

  .conversation-feed {
    padding: 16px;
  }

  .answer-box {
    grid-template-columns: 1fr;
  }

  #send-button {
    width: 100%;
    height: 46px;
  }

  .insight-panel {
    display: grid;
    grid-template-columns: 1fr;
    padding: 16px;
  }

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

@media (prefers-reduced-motion: no-preference) {
  .lesson-button,
  .mode-tab,
  #send-button,
  .starter-chip,
  .side-card {
    transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  }

  .lesson-button:hover,
  .starter-chip:hover,
  .side-card:hover {
    transform: translateY(-1px);
  }
}
