:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f5;
  --text: #172026;
  --muted: #61717c;
  --line: #d8e0e4;
  --primary: #0b6f85;
  --primary-strong: #07566a;
  --primary-soft: #e4f4f7;
  --accent: #b36b14;
  --success: #2f7d46;
  --danger: #b33b35;
  --danger-soft: #fdebea;
  --shadow: 0 16px 40px rgba(22, 36, 44, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  line-height: 1.55;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(16px, 4vw, 48px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

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

h1 {
  margin: 0;
  font-size: clamp(23px, 2.6vw, 34px);
  line-height: 1.2;
  letter-spacing: 0;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.header-stats span {
  min-width: 86px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

.header-stats strong {
  margin-right: 3px;
  color: var(--text);
}

.header-side {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 14px;
}

.admin-link {
  color: var(--primary);
  font-weight: 800;
  text-decoration: none;
}

.workspace {
  width: min(1500px, 100%);
  margin: 0 auto;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(260px, 310px) minmax(0, 1fr);
  gap: 20px;
  padding: 20px clamp(16px, 4vw, 48px) 28px;
}

.side-panel,
.content-panel {
  min-width: 0;
}

.side-panel {
  position: sticky;
  top: 20px;
  align-self: start;
  max-height: calc(100vh - 40px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.mode-tabs,
.mobile-mode-tabs,
.segmented {
  display: grid;
  gap: 6px;
}

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

.mode-tab,
.segment {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

.mode-tab.active,
.segment.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.panel-section {
  display: grid;
  gap: 8px;
}

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

.jump-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}

.segmented {
  grid-template-columns: repeat(2, 1fr);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.segment {
  min-height: 34px;
  border-color: transparent;
  background: transparent;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--line);
}

.dot.current {
  background: var(--primary);
}

.dot.done {
  background: var(--success);
}

.dot.wrong {
  background: var(--danger);
}

.number-section {
  min-height: 0;
}

.number-grid {
  min-height: 120px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 6px;
  padding: 2px;
}

.number-grid.collapsed {
  display: none;
}

.number-button {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.number-button.done {
  border-color: rgba(47, 125, 70, 0.45);
  background: #eef8f1;
  color: var(--success);
}

.number-button.wrong {
  border-color: rgba(179, 59, 53, 0.5);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 800;
}

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

.content-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
}

.mobile-toolbar {
  display: none;
}

.question-card {
  min-height: 430px;
  padding: clamp(18px, 3vw, 34px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.question-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.type-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 800;
}

.question-index,
.mode-label {
  color: var(--muted);
  font-size: 14px;
}

.question-index {
  margin-left: 8px;
}

#questionTitle {
  margin: 0 0 22px;
  font-size: clamp(20px, 2.2vw, 28px);
  line-height: 1.45;
  letter-spacing: 0;
}

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

.option-button {
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  text-align: left;
}

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

.option-button.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px var(--primary);
}

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

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

.option-key {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--primary-strong);
  font-weight: 800;
}

.option-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

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

.result-box,
.explanation {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.result-box.correct {
  border-color: rgba(47, 125, 70, 0.45);
  background: #eef8f1;
  color: var(--success);
}

.result-box.incorrect {
  border-color: rgba(179, 59, 53, 0.45);
  background: var(--danger-soft);
  color: var(--danger);
}

.explanation h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.explanation p {
  margin: 8px 0 0;
}

.actions-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

button.primary,
button.secondary,
button.ghost {
  min-height: 42px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 800;
}

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

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

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

button.ghost {
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
}

button.small {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

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

.hidden {
  display: none !important;
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.drawer-backdrop {
  display: none;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.auth-shell {
  width: min(420px, 100%);
}

.auth-card,
.admin-panel {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-form,
.admin-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.form-error,
.form-message {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.form-error,
.form-message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.admin-shell {
  width: min(1200px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 18px;
  padding: 20px clamp(16px, 4vw, 48px) 28px;
}

.admin-panel h2 {
  margin: 0;
  font-size: 20px;
}

.admin-form {
  grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
  align-items: end;
}

.user-table-wrap {
  overflow: auto;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.user-table th,
.user-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.user-table th {
  color: var(--muted);
  font-size: 13px;
}

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

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: minmax(220px, 260px) minmax(0, 1fr);
    gap: 14px;
    padding-inline: 14px;
  }

  .side-panel {
    padding: 12px;
  }

  .header-stats span {
    min-width: 74px;
  }
}

@media (max-width: 760px) {
  html.drawer-open,
  body.drawer-open {
    overflow: hidden;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
    padding-block: 9px;
  }

  .header-stats {
    width: 100%;
    gap: 7px;
    justify-content: stretch;
  }

  .header-side {
    width: 100%;
    justify-items: stretch;
  }

  .user-bar {
    justify-content: flex-start;
  }

  .header-stats span {
    flex: 1 1 90px;
    padding: 5px 7px;
  }

  .workspace {
    display: block;
    padding: 4px 8px 8px;
  }

  .side-panel {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: min(88vw, 340px);
    height: 100dvh;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    border-radius: 0;
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .side-panel .number-section {
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .side-panel .number-grid {
    flex: 1;
    min-height: 0;
    max-height: none;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .side-panel.open {
    transform: translateX(0);
  }

  .drawer-backdrop.open {
    display: block;
    position: fixed;
    z-index: 15;
    inset: 0;
    background: rgba(9, 18, 23, 0.4);
  }

  .content-panel {
    display: grid;
    gap: 4px;
  }

  .mobile-toolbar {
    display: flex;
    align-items: center;
    gap: 5px;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 3px 0;
    background: var(--bg);
  }

  .mobile-mode-tabs {
    flex: 1;
    grid-template-columns: repeat(3, 1fr);
  }

  .mode-tab {
    min-height: 34px;
  }

  .mode-tabs {
    display: none;
  }

  .question-card {
    min-height: 0;
    padding: 10px 12px;
  }

  .question-topline {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
  }

  .type-pill {
    min-height: 26px;
    padding: 3px 9px;
  }

  .question-index,
  .mode-label {
    font-size: 13px;
  }

  #questionTitle {
    margin-bottom: 10px;
    line-height: 1.34;
  }

  .options {
    gap: 8px;
  }

  .option-button {
    min-height: 46px;
    gap: 8px;
    padding: 8px 11px;
  }

  .result-box,
  .explanation {
    margin-top: 12px;
    padding: 10px 12px;
  }

  .explanation h3 {
    margin-bottom: 5px;
    font-size: 15px;
  }

  .explanation p {
    margin-top: 5px;
  }

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

  .actions-bar {
    position: sticky;
    bottom: 0;
    z-index: 8;
    justify-content: stretch;
    gap: 8px;
    padding: 8px;
  }

  .actions-bar button {
    flex: 1 1 112px;
    min-height: 38px;
    padding: 7px 10px;
  }

  .admin-shell {
    gap: 10px;
    padding: 8px;
  }

  .admin-panel {
    padding: 14px;
  }

  .admin-panel h2 {
    font-size: 18px;
  }

  .admin-form {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 12px;
  }

  .user-table-wrap {
    overflow: visible;
  }

  .user-table {
    display: block;
    min-width: 0;
  }

  .user-table thead {
    display: none;
  }

  .user-table tbody {
    display: grid;
    gap: 10px;
  }

  .user-table tr {
    display: grid;
    gap: 6px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
  }

  .user-table td {
    display: grid;
    grid-template-columns: 74px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 0;
    border-bottom: 0;
    font-size: 14px;
  }

  .user-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  .table-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .table-actions::before {
    align-self: center;
  }

  .table-actions button {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .app-header {
    padding: 8px 10px;
  }

  .eyebrow {
    margin-bottom: 1px;
    font-size: 12px;
  }

  h1 {
    font-size: 21px;
  }

  .header-stats span {
    min-width: 0;
    padding-block: 4px;
    font-size: 13px;
  }

  .question-card {
    padding: 9px 11px;
  }

  #questionTitle {
    margin-bottom: 9px;
    font-size: 19px;
  }

  .option-button {
    grid-template-columns: 34px minmax(0, 1fr);
    min-height: 44px;
    padding: 7px 9px;
  }

  .option-key {
    width: 28px;
    height: 28px;
  }

  .actions-bar {
    padding: 7px;
  }
}
