:root {
  --ink: #202529;
  --muted: #687279;
  --line: #d9e0e3;
  --surface: #ffffff;
  --canvas: #f3f7f6;
  --primary: #086a73;
  --primary-hover: #07565d;
  --accent: #1769aa;
  --success: #1e7a4f;
  --warning: #b75c00;
  --danger: #b3262e;
  --focus: #ffbf47;
  --shadow: 0 8px 24px rgba(24, 43, 47, 0.08);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; background: var(--canvas); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.topbar {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px max(20px, calc((100vw - 1180px) / 2));
  background: #17383c;
  color: #fff;
  border-bottom: 4px solid #2ca58d;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; background: #fff; color: #17383c; border-radius: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 18px; font-size: 14px; }
.topbar-actions a, .link-button { color: #fff; }
.topbar-actions form { margin: 0; }
.link-button { padding: 0; border: 0; background: none; cursor: pointer; }
.page-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 36px 0 64px; }

.message-stack { width: min(1180px, calc(100% - 32px)); margin: 18px auto 0; }
.message { padding: 12px 16px; border: 1px solid var(--line); border-left-width: 5px; background: #fff; border-radius: 4px; }
.message.success { border-left-color: var(--success); }
.message.error { border-left-color: var(--danger); }

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: 30px; line-height: 1.25; }
h2 { font-size: 20px; line-height: 1.4; }
.eyebrow { display: block; margin-bottom: 7px; color: var(--primary); font-size: 13px; font-weight: 700; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-heading h1 { margin: 0; }
.lead { max-width: 720px; color: #49555b; font-size: 17px; line-height: 1.75; }
.muted { color: var(--muted); }
.back-link { display: inline-block; margin-bottom: 24px; }

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 17px;
  border: 1px solid #aeb9bd;
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
.button:hover { text-decoration: none; border-color: #7b898f; }
.button.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-hover); }
.button.warning { border-color: var(--warning); background: var(--warning); color: #fff; }
.button.danger { border-color: var(--danger); background: #fff; color: var(--danger); }
.button.large { min-height: 50px; font-size: 16px; }
.button.full { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .55; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

.mode-badge, .status-chip, .status-mark {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 25px;
  padding: 3px 9px;
  border: 1px solid #9dabb0;
  border-radius: 4px;
  color: #47545a;
  background: #f8fafb;
  font-size: 12px;
  font-weight: 700;
}
.mode-badge.practice { border-color: #6db79a; background: #edf8f2; color: #17613e; }
.mode-badge.exam { border-color: #77a9d2; background: #edf5fb; color: #15598e; }
.status-chip.success { border-color: #6db79a; color: #17613e; background: #edf8f2; }

.activity-list { display: grid; gap: 12px; }
.activity-row {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(300px, .9fr) auto;
  align-items: center;
  gap: 24px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}
.activity-main h2 { margin: 9px 0 5px; }
.activity-main p { margin: 0; color: var(--muted); font-size: 14px; }
.activity-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 0; }
.activity-meta div { min-width: 0; }
.activity-meta dt { margin-bottom: 4px; color: var(--muted); font-size: 12px; }
.activity-meta dd { margin: 0; font-weight: 700; }
.empty-state { padding: 72px 24px; border: 1px dashed #b9c5c9; text-align: center; background: #fff; }
.empty-state p { color: var(--muted); }

.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 48px; align-items: start; }
.detail-copy h1 { margin: 12px 0; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin: 28px 0 0; border: 1px solid var(--line); background: var(--line); }
.detail-grid div { min-height: 92px; padding: 17px; background: #fff; }
.detail-grid dt { margin-bottom: 7px; color: var(--muted); font-size: 13px; }
.detail-grid dd { margin: 0; line-height: 1.6; font-weight: 700; }
.action-panel { padding: 22px; border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: var(--shadow); }
.action-panel p { margin: 16px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.history-section { margin-top: 44px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: #edf3f3; color: #405056; font-size: 12px; }
tr:last-child td { border-bottom: 0; }
.table-sub { color: var(--muted); font-size: 12px; }
.table-actions { display: flex; gap: 12px; }

.attempt-shell { width: min(1240px, calc(100% - 30px)); padding-top: 24px; }
.attempt-header { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 18px; }
.attempt-header h1 { margin: 7px 0 0; font-size: 20px; }
.timer-box { min-width: 130px; padding: 9px 14px; border: 1px solid #8eb8bc; border-radius: 5px; background: #fff; text-align: right; }
.timer-box span { display: block; color: var(--muted); font-size: 12px; }
.timer-box strong { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.network-banner { margin-bottom: 12px; padding: 9px 13px; background: #fff1df; border: 1px solid #e7a453; color: #794100; border-radius: 4px; }
.attempt-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 18px; align-items: start; }
.question-stage { min-height: 540px; padding: 30px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.question-status { display: flex; justify-content: space-between; margin-bottom: 22px; color: var(--muted); font-size: 13px; }
.question-stage h2 { min-height: 56px; margin-bottom: 24px; font-size: 20px; line-height: 1.75; }
.question-image { display: block; max-width: 100%; max-height: 360px; margin: 0 auto 24px; object-fit: contain; }
.question-image[hidden] { display: none; }
.option-list { display: grid; gap: 10px; }
.option {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  padding: 14px;
  border: 1px solid #cbd5d8;
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
  line-height: 1.6;
}
.option:hover { border-color: #6c979c; background: #f4faf9; }
.option.selected { border-color: var(--primary); background: #eaf6f4; box-shadow: inset 4px 0 0 var(--primary); }
.option input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--primary); }
.option-key { display: inline-grid; place-items: center; width: 25px; height: 25px; margin-right: 8px; border: 1px solid #aab8bd; border-radius: 50%; font-size: 12px; font-weight: 700; }
.question-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 30px; }
.answer-panel { position: sticky; top: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.answer-summary { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; }
.answer-summary span { color: var(--muted); font-size: 13px; }
.number-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-bottom: 18px; }
.number-button { aspect-ratio: 1; border: 1px solid #bcc8cc; border-radius: 4px; background: #fff; cursor: pointer; font-size: 12px; }
.number-button.answered { border-color: var(--success); background: #eaf7f0; color: #17613e; font-weight: 700; }
.number-button.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.save-state { min-height: 34px; margin-bottom: 12px; color: var(--success); font-size: 12px; }
.save-state.saving { color: var(--warning); }
.save-state.error { color: var(--danger); }
.switch-note { margin: 14px 0 0; color: var(--muted); text-align: center; font-size: 12px; }

.result-panel { max-width: 620px; margin: 26px auto; padding: 42px; border: 1px solid var(--line); border-radius: 7px; background: #fff; text-align: center; box-shadow: var(--shadow); }
.result-panel h1 { margin: 15px 0 25px; font-size: 24px; }
.status-mark { margin: 0 auto; border-color: #6db79a; background: #edf8f2; color: #17613e; }
.score-value { display: flex; justify-content: center; align-items: baseline; gap: 6px; }
.score-value strong { font-size: 64px; line-height: 1; color: var(--primary); }
.score-value span { font-size: 20px; }
.result-status { margin: 12px 0; font-size: 18px; font-weight: 700; }
.result-meta { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px 20px; margin-bottom: 24px; color: var(--muted); font-size: 13px; }
.result-panel .muted { margin: 22px 0; line-height: 1.8; }

.login-page .page-shell { display: grid; min-height: calc(100vh - 66px); place-items: center; padding: 40px 0; }
.login-panel { width: min(430px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: var(--shadow); }
.login-heading { margin-bottom: 25px; }
.login-heading h1 { font-size: 25px; }
.stack-form { display: grid; gap: 17px; }
.stack-form label { display: grid; gap: 7px; font-size: 14px; font-weight: 700; }
.stack-form input:not([type="checkbox"]), .stack-form select, .stack-form textarea {
  width: 100%; min-height: 44px; padding: 9px 11px; border: 1px solid #aebbc0; border-radius: 4px; background: #fff;
}
.stack-form input[type="file"] { padding: 8px; }
.stack-form small { color: var(--muted); font-weight: 400; line-height: 1.5; }
.stack-form .errorlist { margin: 0; padding: 0; list-style: none; color: var(--danger); font-size: 12px; font-weight: 400; }
.form-error { padding: 12px; border: 1px solid #df8b90; background: #fff0f1; color: #7d161c; border-radius: 4px; }
.form-error .errorlist { margin: 0; padding-left: 18px; }
.form-page { display: grid; grid-template-columns: minmax(240px, .65fr) minmax(420px, 1fr); gap: 48px; align-items: start; }
.wide-form { padding: 26px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.checkbox-label { grid-template-columns: auto 1fr; align-items: center; }
.checkbox-label input { grid-column: 1; grid-row: 1; width: 18px; height: 18px; }
.checkbox-label small, .checkbox-label .errorlist { grid-column: 1 / -1; }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin-bottom: 22px; border: 1px solid var(--line); background: var(--line); }
.metric-grid div { padding: 18px; background: #fff; }
.metric-grid span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 13px; }
.metric-grid strong { font-size: 28px; }
.admin-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 32px; }
.admin-tools a { min-height: 105px; padding: 17px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); }
.admin-tools a:hover { border-color: #7d9fa3; text-decoration: none; }
.admin-tools strong { display: block; margin-bottom: 9px; }
.admin-tools span { color: var(--muted); font-size: 12px; line-height: 1.6; }
.section-heading { display: flex; align-items: center; justify-content: space-between; }

@media (max-width: 880px) {
  .activity-row { grid-template-columns: 1fr auto; }
  .activity-meta { grid-column: 1; }
  .activity-row > .button { grid-column: 2; grid-row: 1 / span 2; }
  .detail-layout, .form-page { grid-template-columns: 1fr; gap: 24px; }
  .action-panel { box-shadow: none; }
  .attempt-layout { grid-template-columns: 1fr; }
  .answer-panel { position: static; }
  .number-grid { grid-template-columns: repeat(10, 1fr); }
  .metric-grid, .admin-tools { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .topbar { min-height: 56px; padding: 7px 14px; }
  .brand { font-size: 14px; }
  .brand-mark { width: 30px; height: 30px; }
  .user-name, .topbar-actions > a { display: none; }
  .page-shell { width: min(100% - 22px, 1180px); padding: 24px 0 45px; }
  h1 { font-size: 24px; }
  .page-heading { align-items: start; flex-direction: column; }
  .activity-row { grid-template-columns: 1fr; gap: 16px; padding: 18px; }
  .activity-meta { grid-template-columns: repeat(3, 1fr); grid-column: auto; gap: 8px; }
  .activity-row > .button { grid-column: auto; grid-row: auto; width: 100%; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid div { min-height: 0; }
  .attempt-shell { width: min(100% - 14px, 1240px); padding-top: 14px; }
  .attempt-header h1 { max-width: 210px; font-size: 16px; }
  .timer-box { min-width: 110px; padding: 7px 10px; }
  .timer-box strong { font-size: 20px; }
  .question-stage { min-height: 0; padding: 20px 15px; }
  .question-stage h2 { min-height: 0; font-size: 18px; line-height: 1.7; }
  .option { padding: 12px 10px; }
  .number-grid { grid-template-columns: repeat(10, 1fr); gap: 5px; }
  .number-button { min-height: 28px; aspect-ratio: auto; }
  .result-panel, .login-panel { padding: 26px 18px; }
  .result-panel { margin-top: 8px; }
  .score-value strong { font-size: 52px; }
  .metric-grid, .admin-tools { grid-template-columns: 1fr 1fr; }
  .admin-tools a { min-height: 90px; padding: 13px; }
  .form-page { gap: 12px; }
  .wide-form { padding: 18px; }
}
