:root {
  --canvas: #eef2f4;
  --paper: #fffefa;
  --ink: #17212b;
  --ink-soft: #5d6975;
  --line: #ccd5db;
  --line-strong: #9eabb4;
  --brand: #12665c;
  --brand-deep: #0c4c45;
  --brand-soft: #dcebe7;
  --wrong: #b42318;
  --wrong-soft: #f7e4e1;
  --correct: #20744d;
  --correct-soft: #e1efe7;
  --focus: #b75c14;
  --shadow: 0 12px 32px rgba(23, 33, 43, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--canvas);
  color: var(--ink);
  font-family: "Microsoft YaHei UI", "PingFang SC", sans-serif;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.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;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  padding: 12px clamp(16px, 4vw, 48px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: rgba(238, 242, 244, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  color: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--brand);
  font-family: "STKaiti", "KaiTi", serif;
  font-size: 24px;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
}

.brand small {
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: 12px;
}

.nav {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  background: var(--paper);
}

.nav-item {
  min-width: 66px;
  padding: 8px 12px;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  font-weight: 700;
}

.nav-item.is-active {
  color: white;
  background: var(--brand);
}

.shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 48px) 64px;
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr) 240px;
  gap: 24px;
  align-items: start;
}

.progress-rail,
.context-panel {
  position: sticky;
  top: 100px;
}

body:not([data-view="practice"]) .progress-rail,
body:not([data-view="practice"]) .context-panel {
  display: none;
}

.rail-head {
  display: flex;
  justify-content: space-between;
  color: var(--ink-soft);
  font-size: 13px;
}

.rail-head strong {
  color: var(--ink);
}

.paper-grid {
  list-style: none;
  margin: 14px 0 20px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.paper-grid li {
  margin: 0;
}

.paper-number {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  border-radius: 0;
}

.paper-number[data-state="current"] {
  color: white;
  border-color: var(--brand);
  background: var(--brand);
}

.paper-number[data-state="correct"] {
  color: var(--correct);
  border-color: var(--correct);
  background: var(--correct-soft);
}

.paper-number[data-state="wrong"] {
  color: var(--wrong);
  border-color: var(--wrong);
  background: var(--wrong-soft);
}

.paper-number:hover {
  border-color: var(--brand);
}

.question-paper {
  min-height: 620px;
  padding: clamp(24px, 5vw, 64px);
  background:
    linear-gradient(var(--paper), var(--paper)) padding-box,
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 31px,
      rgba(18, 102, 92, 0.045) 32px
    ) border-box;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.question-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--ink-soft);
  font-size: 13px;
}

.question-timer {
  margin-left: 12px;
  color: var(--brand-deep);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.question-paper h1 {
  margin: 24px 0 20px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.3;
}

.stem {
  min-height: 160px;
  color: #111820;
  font-family: "Songti SC", "SimSun", serif;
  font-size: clamp(19px, 2vw, 22px);
  line-height: 1.95;
  white-space: pre-wrap;
}

.choices {
  display: grid;
  gap: 10px;
  margin: 28px 0 0;
  padding: 0;
  border: 0;
}

.choice {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 12px;
  align-items: center;
  color: var(--ink);
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  border-radius: 0;
}

.choice:hover:not(:disabled) {
  border-color: var(--brand);
}

.choice.is-selected {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.choice.is-correct {
  border-color: var(--correct);
  background: var(--correct-soft);
}

.choice.is-wrong {
  border-color: var(--wrong);
  background: var(--wrong-soft);
}

.choice:disabled {
  cursor: default;
}

.choice-label {
  font-weight: 800;
}

.feedback {
  margin-top: 20px;
  padding: 14px 16px;
  border-left: 4px solid;
}

.feedback.correct {
  color: var(--correct);
  background: var(--correct-soft);
  border-color: var(--correct);
}

.feedback.wrong {
  color: var(--wrong);
  background: var(--wrong-soft);
  border-color: var(--wrong);
}

.explanation-panel {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.explanation-content {
  white-space: pre-wrap;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 17px;
  line-height: 1.85;
}

.paper-actions {
  margin-top: 28px;
  display: flex;
  gap: 12px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 9px 18px;
  border-radius: 0;
  font-weight: 700;
}

.primary-button {
  color: white;
  background: var(--brand);
  border: 1px solid var(--brand);
}

.primary-button:hover:not(:disabled) {
  background: var(--brand-deep);
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.secondary-button {
  color: var(--brand-deep);
  background: transparent;
  border: 1px solid var(--line-strong);
}

.context-panel {
  display: grid;
  gap: 28px;
  padding-left: 24px;
  border-left: 1px solid var(--line);
}

.context-panel section {
  min-height: 112px;
}

.context-panel p {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.6;
}

.eyebrow {
  margin: 0;
  color: var(--brand-deep) !important;
  font-size: 12px !important;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.metric {
  display: block;
  margin-top: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 40px;
  line-height: 1;
}

.state-panel {
  min-height: 420px;
  padding: 48px;
  display: grid;
  align-content: center;
  justify-items: start;
  background: var(--paper);
  border: 1px solid var(--line);
}

.state-panel h2 {
  margin-top: 0;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 28px;
}

.state-panel p {
  color: var(--ink-soft);
}

.session-summary {
  width: 100%;
  margin: 10px 0 24px;
}

.summary-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-metrics div {
  padding: 14px;
  background: #f4f7f8;
  border-top: 3px solid var(--brand);
}

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

.summary-metrics span {
  color: var(--ink-soft);
  font-size: 13px;
}

.summary-metrics strong {
  margin-top: 6px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
}

.wrong-summary {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 14px;
  background: var(--wrong-soft);
  border-left: 4px solid var(--wrong);
}

.wrong-summary span {
  font-size: 14px;
}

.skeleton {
  width: 100%;
  height: 20px;
  margin-bottom: 18px;
  background: #e2e8eb;
  animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-title {
  width: 44%;
  height: 36px;
}

.skeleton.short {
  width: 70%;
}

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

.full-view {
  grid-column: 1 / -1;
}

.view-heading {
  margin-bottom: 24px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
}

.view-heading h1 {
  margin: 6px 0 0;
  font-family: "Songti SC", "SimSun", serif;
  font-size: clamp(28px, 4vw, 42px);
}

.stack {
  display: grid;
  gap: 16px;
}

.mistake-item,
.panel {
  padding: 24px;
  background: var(--paper);
  border: 1px solid var(--line);
}

.mistake-item h2,
.panel h2 {
  margin: 0 0 12px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 20px;
}

.mistake-item p {
  line-height: 1.8;
}

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

.mistake-options span {
  padding: 8px 10px;
  background: #f4f7f8;
}

.mistake-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.mistake-footer select {
  min-height: 40px;
  padding: 6px 32px 6px 10px;
  background: white;
  border: 1px solid var(--line-strong);
}

.note-editor {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.mistake-explanation-tools {
  margin-top: 16px;
}

.mistake-explanation {
  margin-top: 16px;
  padding: 18px;
  background: #f4f7f8;
  border-left: 4px solid var(--brand);
}

.mistake-explanation-content {
  white-space: pre-wrap;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 16px;
  line-height: 1.85;
}

.note-editor label {
  font-weight: 800;
}

.note-editor textarea {
  width: 100%;
  min-height: 112px;
  padding: 12px;
  resize: vertical;
  color: var(--ink);
  background: #fbfcfc;
  border: 1px solid var(--line-strong);
  font-family: "Microsoft YaHei UI", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.7;
}

.note-editor textarea:focus {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.note-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.note-actions span {
  color: var(--ink-soft);
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.analysis-panel {
  margin-bottom: 16px;
}

.time-panel {
  margin-bottom: 16px;
}

.time-stats,
.vocab-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.time-metric,
.vocab-stats > div {
  padding: 14px;
  background: #f4f7f8;
  border-top: 3px solid var(--brand);
}

.time-metric span,
.vocab-stats span {
  display: block;
  color: var(--ink-soft);
  font-size: 13px;
}

.time-metric strong,
.vocab-stats strong {
  display: block;
  margin-top: 6px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
}

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

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  background: var(--paper);
}

.segment {
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  font-weight: 700;
}

.segment:last-child {
  border-right: 0;
}

.segment.is-active {
  color: white;
  background: var(--brand);
}

.vocab-controls select {
  min-height: 40px;
  max-width: 290px;
  padding: 8px 32px 8px 10px;
  background: white;
  border: 1px solid var(--line-strong);
}

.vocab-stats {
  margin-bottom: 16px;
}

.vocab-card {
  max-width: 920px;
  min-height: 420px;
  padding: clamp(24px, 5vw, 56px);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.vocab-card h2 {
  margin: 18px 0 28px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1.45;
}

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

.vocab-option {
  min-height: 56px;
  padding: 12px 16px;
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  font-size: 17px;
}

.vocab-option:hover:not(:disabled) {
  border-color: var(--brand);
}

.vocab-option.is-correct {
  color: var(--correct);
  background: var(--correct-soft);
  border-color: var(--correct);
}

.vocab-option.is-wrong {
  color: var(--wrong);
  background: var(--wrong-soft);
  border-color: var(--wrong);
}

.vocab-answer {
  margin-top: 22px;
  padding: 18px;
  background: #f4f7f8;
  border-left: 4px solid var(--brand);
}

.vocab-answer h3 {
  margin: 0 0 10px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 24px;
}

.vocab-answer p,
.vocab-answer li {
  line-height: 1.8;
}

.vocab-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.analysis-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.analysis-heading h2 {
  margin-bottom: 4px;
}

.analysis-heading p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

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

.analysis-controls select {
  min-height: 42px;
  padding: 8px 34px 8px 10px;
  background: white;
  border: 1px solid var(--line-strong);
}

.analysis-result {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.analysis-metrics {
  display: flex;
  gap: 18px;
  align-items: baseline;
  margin-bottom: 18px;
  color: var(--brand-deep);
}

.analysis-metrics span {
  font-weight: 800;
}

.analysis-copy {
  white-space: pre-wrap;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 17px;
  line-height: 1.85;
}

.analysis-usage,
.analysis-loading {
  margin-top: 20px;
  color: var(--ink-soft);
  font-size: 13px;
}

.generated-panel {
  margin-bottom: 16px;
}

.generated-summary {
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 14px;
}

.generated-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.generated-item {
  padding: 18px;
  background: #fbfcfc;
  border: 1px solid var(--line);
}

.generated-item h3 {
  margin: 12px 0;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 18px;
  line-height: 1.7;
}

.generated-item details {
  margin-top: 12px;
}

.generated-item summary {
  cursor: pointer;
  color: var(--brand-deep);
  font-weight: 700;
}

.generated-explanation {
  margin-top: 10px;
  white-space: pre-wrap;
  font-family: "Songti SC", "SimSun", serif;
  line-height: 1.8;
}

.generated-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.approved-label {
  color: var(--correct);
  font-weight: 800;
}

.bar-row {
  display: grid;
  grid-template-columns: 112px 1fr 32px;
  gap: 12px;
  align-items: center;
  margin: 12px 0;
  font-size: 14px;
}

.bar-track {
  height: 10px;
  background: #e1e8eb;
}

.bar-fill {
  height: 100%;
  background: var(--brand);
}

.set-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.set-row:last-child {
  border-bottom: 0;
}

.set-row small {
  display: block;
  margin-top: 3px;
  color: var(--ink-soft);
}

.recent-panel {
  margin-top: 16px;
}

.recent-list {
  display: grid;
}

.recent-row {
  display: grid;
  grid-template-columns: 150px 1fr 100px;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.recent-row:last-child {
  border-bottom: 0;
}

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

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

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 12px 16px;
  color: white;
  background: var(--ink);
  box-shadow: var(--shadow);
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--canvas);
}

.auth-panel {
  width: min(440px, 100%);
  padding: clamp(24px, 6vw, 40px);
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
}

.auth-brand strong,
.auth-brand small {
  display: block;
}

.auth-brand small {
  margin-top: 3px;
  color: var(--ink-soft);
}

.auth-panel h1 {
  margin: 8px 0 24px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 32px;
}

.auth-form {
  display: grid;
  gap: 16px;
}

.auth-hint {
  margin: -10px 0 22px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.7;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
}

.auth-form input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line-strong);
  border-radius: 0;
}

.link-button {
  margin-top: 16px;
  padding: 4px 0;
  color: var(--brand-deep);
  background: transparent;
  border: 0;
  text-decoration: underline;
}

.auth-error {
  margin: 18px 0 0;
  padding: 10px 12px;
  color: var(--wrong);
  background: var(--wrong-soft);
}

.account-button {
  min-height: 38px;
  padding: 7px 12px;
  color: var(--brand-deep);
  background: var(--paper);
  border: 1px solid var(--line);
  font-weight: 700;
}

.settings-info {
  margin-top: 16px;
  color: var(--ink-soft);
  line-height: 1.8;
}

.invite-code {
  display: block;
  margin: 10px 0;
  padding: 12px;
  color: var(--ink);
  background: #f4f7f8;
  border: 1px solid var(--line);
  font-family: Consolas, monospace;
  font-size: 18px;
  word-break: break-all;
}

@media (max-width: 1024px) {
  .shell {
    grid-template-columns: 148px minmax(0, 1fr);
  }

  .context-panel {
    position: static;
    grid-column: 1 / -1;
    padding: 20px 0 0;
    grid-template-columns: repeat(3, 1fr);
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}

@media (max-width: 760px) {
  body {
    padding-bottom: 72px;
  }

  .topbar {
    min-height: 62px;
    padding: 10px 16px;
    align-items: center;
    flex-direction: row;
  }

  .account-button {
    margin-left: auto;
  }

  .nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: 100%;
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 2px;
    border: 0;
    border-top: 1px solid var(--line);
    background: rgba(255, 254, 250, 0.98);
    backdrop-filter: blur(12px);
  }

  .nav-item {
    min-width: 0;
    min-height: 50px;
    padding: 7px 3px;
    font-size: 12px;
  }

  .shell {
    grid-template-columns: 1fr;
    padding-top: 16px;
  }

  .progress-rail {
    position: static;
  }

  .paper-grid {
    grid-template-columns: repeat(10, 1fr);
  }

  .vocab-controls,
  .vocab-controls .segmented {
    width: 100%;
  }

  .vocab-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

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

  .vocab-controls select {
    max-width: none;
    width: 100%;
  }

  .vocab-options {
    grid-template-columns: 1fr;
  }

  .time-stats,
  .vocab-stats {
    grid-template-columns: 1fr 1fr;
  }

  .question-paper {
    min-height: 0;
  }

  .context-panel {
    grid-template-columns: 1fr;
  }

  .context-panel section {
    min-height: 0;
  }

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

  .summary-metrics {
    grid-template-columns: 1fr 1fr;
  }

  .analysis-heading,
  .analysis-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .generated-actions {
    flex-direction: column;
  }

  .mistake-options {
    grid-template-columns: 1fr;
  }

  .mistake-footer,
  .view-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .recent-row {
    grid-template-columns: 1fr;
  }
}

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