:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687386;
  --line: #dde2ea;
  --primary: #176b54;
  --primary-dark: #0f513f;
  --primary-soft: #e7f3ef;
  --danger: #c43f4f;
  --danger-soft: #fff0f2;
  --success: #16835f;
  --shadow: 0 12px 36px rgba(28, 39, 56, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 20px;
  background: #132a25;
  color: #fff;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 28px;
}

.brand-mark {
  width: 42px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  background: #f2c14e;
  color: #24362f;
  font-size: 22px;
  font-weight: 800;
  border-radius: 8px;
}

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

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

.brand span {
  margin-top: 3px;
  color: #a8bbb5;
  font-size: 12px;
}

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

.nav-item {
  height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #c9d6d2;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: #25463e;
  color: #fff;
}

.nav-icon {
  font-weight: 800;
  color: #79b8a5;
}

.nav-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #3d5b53;
  display: grid;
  place-items: center;
  font-size: 12px;
}

.sidebar-summary {
  margin-top: auto;
  padding: 16px;
  background: #1c3932;
  border-radius: 8px;
}

.summary-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: #adc0ba;
}

.summary-label strong {
  color: #fff;
}

.progress-track,
.distribution-track {
  overflow: hidden;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

.progress-track {
  height: 6px;
  margin-top: 10px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: #f2c14e;
  transition: width 180ms ease;
}

.main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 34px 36px 56px;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 26px;
  line-height: 1.3;
}

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

.phone-button {
  height: 40px;
  padding: 0 15px;
  border: 1px solid var(--primary);
  border-radius: 7px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
}

.jump-control {
  height: 40px;
  padding-left: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  display: flex;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.jump-control input {
  width: 64px;
  height: 30px;
  margin-left: 6px;
  border: 0;
  outline: none;
  color: var(--text);
  text-align: center;
}

.jump-control button {
  align-self: stretch;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--primary);
  font-weight: 700;
}

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--muted);
  font-size: 20px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric {
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  font-size: 20px;
}

.metric b {
  color: var(--primary);
}

.question-card,
.distribution-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.question-card {
  padding: 30px;
}

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

.question-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 13px;
}

.type-pill {
  padding: 5px 9px;
  border-radius: 5px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
}

.question-card h2 {
  margin-bottom: 24px;
  font-size: 21px;
  line-height: 1.65;
}

.options {
  display: grid;
  gap: 12px;
}

.option {
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-align: left;
  line-height: 1.5;
}

.option:hover:not(:disabled) {
  border-color: #7cae9f;
  background: #f8fbfa;
}

.option.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.option.correct {
  border-color: var(--success);
  background: #ebf8f2;
}

.option.incorrect {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.option-key {
  width: 30px;
  height: 30px;
  border: 1px solid #cfd6df;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
}

.option.selected .option-key {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.answer-result {
  margin-top: 20px;
  padding: 15px 16px;
  border-left: 4px solid var(--success);
  border-radius: 4px;
  background: #eef8f4;
}

.answer-result.error {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}

.answer-result strong,
.answer-result span {
  display: block;
}

.answer-result span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

.question-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr;
  gap: 12px;
  margin-top: 26px;
}

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

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

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

.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.secondary-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.keyboard-hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.section-toolbar {
  margin-bottom: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.section-toolbar h2 {
  margin-bottom: 5px;
}

.section-toolbar p {
  margin-bottom: 0;
  color: var(--muted);
}

.wrong-list {
  display: grid;
  gap: 10px;
}

.wrong-item {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
}

.wrong-index {
  color: var(--danger);
  font-weight: 800;
}

.wrong-item h3 {
  margin: 0 0 5px;
  font-size: 15px;
  line-height: 1.5;
}

.wrong-item p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.wrong-item button {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 700;
}

.empty-state {
  padding: 72px 20px;
  border: 1px dashed #cbd3dd;
  border-radius: 8px;
  display: grid;
  place-items: center;
  gap: 8px;
  background: #fff;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
  font-size: 18px;
}

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

.stat-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stat-card.accent {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
}

.stat-card.accent span,
.stat-card.accent p {
  color: #cfe3dd;
}

.stat-card strong {
  display: block;
  margin: 10px 0 7px;
  font-size: 31px;
}

.stat-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
}

.distribution-card {
  padding: 26px;
}

.distribution-list {
  display: grid;
  gap: 22px;
}

.distribution-item > div:first-child {
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}

.distribution-track {
  height: 9px;
  background: #e7ebf0;
}

.distribution-track i {
  display: block;
  height: 100%;
  background: var(--primary);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 320px;
  padding: 12px 16px;
  border-radius: 7px;
  background: #172033;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  padding: 20px;
  background: rgba(14, 24, 31, 0.55);
  display: grid;
  place-items: center;
}

.phone-modal {
  position: relative;
  width: min(420px, 100%);
  padding: 30px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.phone-modal h2 {
  margin-bottom: 18px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 26px;
}

.qr-code {
  width: 220px;
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.qr-code img,
.qr-code canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.phone-url-row {
  margin-top: 18px;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.phone-url-row code {
  min-width: 0;
  flex: 1;
  padding: 11px 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.phone-url-row button {
  padding: 0 15px;
  border: 0;
  border-left: 1px solid var(--line);
  background: #f6f8fa;
  color: var(--primary);
  font-weight: 700;
}

.phone-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    padding: 16px;
  }

  .brand {
    padding-bottom: 14px;
  }

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

  .nav-item {
    grid-template-columns: 20px 1fr auto;
    padding: 0 10px;
  }

  .sidebar-summary {
    display: none;
  }

  .main {
    padding: 24px 18px 40px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

@media (max-width: 560px) {
  html,
  body {
    height: 100%;
  }

  body.practice-mode {
    overflow: hidden;
  }

  body.practice-mode .app-shell {
    height: 100dvh;
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  body.practice-mode .main {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.practice-mode #practiceView {
    min-height: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .sidebar {
    padding: 10px 12px 8px;
  }

  .brand {
    gap: 9px;
    padding: 0 4px 8px;
  }

  .brand-mark {
    width: 34px;
    border-radius: 6px;
    font-size: 18px;
  }

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

  .brand span {
    margin-top: 1px;
    font-size: 10px;
  }

  .nav-list {
    gap: 6px;
  }

  .nav-icon,
  .nav-badge {
    display: none;
  }

  .nav-item {
    height: 36px;
    display: block;
    text-align: center;
    font-size: 12px;
  }

  .main {
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  }

  .topbar {
    margin-bottom: 8px;
  }

  .topbar > div:first-child {
    display: none;
  }

  .topbar-actions {
    width: 100%;
    gap: 6px;
  }

  .phone-button {
    display: none;
  }

  .jump-control {
    width: auto;
    height: 34px;
    min-width: 0;
    flex: 1;
    padding-left: 10px;
    font-size: 12px;
  }

  .jump-control input {
    flex: 1;
    width: 44px;
    height: 28px;
  }

  .icon-button {
    width: 36px;
    height: 34px;
    font-size: 18px;
  }

  .metric-row {
    flex: 0 0 auto;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 8px;
  }

  .metric {
    min-width: 0;
    padding: 8px 7px;
    border-radius: 6px;
  }

  .metric span {
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 10px;
  }

  .metric strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
  }

  .question-card {
    min-height: 0;
    flex: 1;
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 7px;
    box-shadow: 0 6px 20px rgba(28, 39, 56, 0.07);
  }

  .question-scroll {
    min-height: 0;
    flex: 1;
    padding: 14px 13px 12px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: auto;
  }

  .question-meta {
    margin-bottom: 10px;
    font-size: 11px;
  }

  .type-pill {
    padding: 4px 7px;
  }

  .question-card h2 {
    margin-bottom: 14px;
    font-size: 17px;
    line-height: 1.52;
    letter-spacing: 0;
  }

  .options {
    gap: 8px;
  }

  .option {
    min-height: 48px;
    padding: 9px 11px;
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 9px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1.4;
  }

  .option-key {
    width: 27px;
    height: 27px;
    font-size: 12px;
  }

  .answer-result {
    margin-top: 12px;
    padding: 10px 11px;
  }

  .answer-result span {
    margin-top: 3px;
    font-size: 12px;
  }

  .question-actions {
    z-index: 2;
    flex: 0 0 auto;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 0;
    padding: 9px 10px max(9px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: #fff;
    box-shadow: 0 -7px 18px rgba(28, 39, 56, 0.06);
  }

  .primary-button,
  .secondary-button {
    min-height: 42px;
    padding: 0 10px;
  }

  #submitButton {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .keyboard-hint {
    display: none;
  }

  .wrong-item {
    grid-template-columns: 1fr;
  }

  .phone-modal {
    padding: 24px 18px 20px;
  }

  .qr-code {
    width: min(210px, 66vw);
  }
}
