:root {
  --navy: #17324d;
  --navy-deep: #10263b;
  --blue: #2878b8;
  --blue-soft: #e9f3fb;
  --paper: #fffefa;
  --canvas: #f2f5f7;
  --ink: #17212b;
  --muted: #687786;
  --line: #dce3e8;
  --green: #16825d;
  --green-soft: #e7f6ef;
  --red: #c44343;
  --red-soft: #fcecec;
  --amber: #b87918;
  --shadow: 0 18px 50px rgba(25, 48, 68, 0.09);
  --radius: 18px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 0%, rgba(40, 120, 184, 0.11), transparent 30rem),
    linear-gradient(180deg, #f7f9fa 0, var(--canvas) 24rem);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  line-height: 1.55;
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 64px;
}

.site-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 130px;
  padding: 22px 28px;
  color: white;
  background: linear-gradient(125deg, var(--navy-deep), var(--navy) 60%, #22577c);
  border-radius: 24px;
  box-shadow: 0 20px 60px rgba(16, 38, 59, 0.2);
}

.site-header > div:nth-child(2) { text-align: center; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-family: Georgia, "Songti SC", serif; font-size: clamp(1.75rem, 4vw, 2.6rem); }
h2 { margin-bottom: 6px; font-size: clamp(1.4rem, 3vw, 1.9rem); }

.eyebrow {
  margin-bottom: 5px;
  color: var(--blue);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .16em;
}

.site-header .eyebrow { color: #9fd2f4; }
.subtitle { margin: 0; color: #cad8e4; font-size: .9rem; }
.back-link { color: #dbe9f2; text-decoration: none; font-size: .9rem; justify-self: start; }
.back-link:hover { color: white; }

.connection-status {
  justify-self: end;
  padding: 6px 11px;
  color: #d5e2eb;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 999px;
  font-size: .78rem;
}
.connection-status.online::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; background: #57d69d; border-radius: 50%; }

.main-nav {
  display: flex;
  width: fit-content;
  margin: 20px auto 28px;
  padding: 5px;
  background: rgba(255, 255, 255, .88);
  border: 1px solid rgba(220, 227, 232, .9);
  border-radius: 13px;
  box-shadow: 0 8px 25px rgba(25, 48, 68, .06);
}

.nav-button {
  min-width: 120px;
  padding: 9px 18px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.nav-button.active { color: white; background: var(--navy); font-weight: 700; }
.view { display: none; }
.view.active { display: block; animation: enter .22s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(5px); } }

.section-heading, .exam-topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
.section-heading h2 { margin: 0; }
.muted, .list-summary { color: var(--muted); }
.list-summary { margin: 17px 2px 12px; font-size: .88rem; }

.filter-card, .history-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 14px;
  align-items: end;
  padding: 18px;
  background: rgba(255, 255, 255, .82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(25, 48, 68, .04);
}
.history-toolbar { display: flex; }

label {
  display: block;
  color: #536270;
  font-size: .82rem;
  font-weight: 700;
}
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 120, 184, .12);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, background .15s;
}
.button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 7px 18px rgba(25, 48, 68, .12); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button.primary { color: white; background: var(--blue); }
.button.ghost { color: var(--navy); background: white; border-color: var(--line); }
.button.danger { color: white; background: var(--red); }
.button.small { min-height: 36px; padding: 7px 13px; font-size: .85rem; }

.paper-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.paper-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 235px;
  padding: 22px;
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 7px 24px rgba(25, 48, 68, .05);
}
.paper-card::after {
  content: "";
  position: absolute;
  top: -30px;
  right: -30px;
  width: 95px;
  height: 95px;
  border: 18px solid var(--blue-soft);
  border-radius: 50%;
}
.paper-card h3 { max-width: calc(100% - 65px); margin: 10px 0 7px; font-size: 1.16rem; }
.paper-card p { color: var(--muted); font-size: .88rem; }
.paper-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: auto; padding: 15px 0; color: #536270; font-size: .82rem; border-top: 1px dashed var(--line); }
.paper-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.recent-score { color: var(--blue); font-size: .84rem; font-weight: 700; }

.tag {
  display: inline-flex;
  width: fit-content;
  padding: 3px 9px;
  color: #285f89;
  background: var(--blue-soft);
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 800;
}
.tag.active-attempt { color: var(--amber); background: #fff5dc; }

.empty-state, .loading-state, .error-state {
  grid-column: 1 / -1;
  padding: 55px 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, .7);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.error-state { color: var(--red); background: var(--red-soft); }

.history-list { display: grid; gap: 10px; margin-top: 15px; }
.history-card {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(90px, .55fr)) auto;
  gap: 16px;
  align-items: center;
  padding: 15px 18px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 13px;
}
.history-card h3 { margin-bottom: 3px; font-size: 1rem; }
.history-card p, .history-cell span { margin: 0; color: var(--muted); font-size: .78rem; }
.history-cell strong { display: block; }
.status { width: fit-content; padding: 3px 8px; border-radius: 999px; font-size: .76rem; font-weight: 800; }
.status.submitted { color: var(--green); background: var(--green-soft); }
.status.expired { color: var(--red); background: var(--red-soft); }
.status.in_progress { color: var(--amber); background: #fff5dc; }

.exam-view { max-width: 1080px; margin: 0 auto; }
.exam-topbar { align-items: center; }
.exam-topbar h2 { margin: 0; }
.timer-block {
  min-width: 150px;
  padding: 10px 15px;
  text-align: center;
  color: white;
  background: var(--navy);
  border-radius: 13px;
}
.timer-block span { display: block; color: #bfcfda; font-size: .7rem; letter-spacing: .08em; }
.timer-block strong { font-variant-numeric: tabular-nums; font-size: 1.55rem; letter-spacing: .04em; }
.timer-block.warning { background: var(--red); animation: pulse 1.5s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px rgba(196, 67, 67, .12); } }
.exam-progress { height: 5px; margin: -7px 0 20px; overflow: hidden; background: #dbe3e8; border-radius: 5px; }
.exam-progress span { display: block; width: 0; height: 100%; background: var(--blue); transition: width .25s; }

.exam-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; align-items: start; }
.question-sidebar {
  position: sticky;
  top: 15px;
  padding: 18px;
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.sidebar-heading { display: flex; justify-content: space-between; margin-bottom: 14px; }
.sidebar-heading span { color: var(--muted); font-size: .85rem; }
.question-nav { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.question-number {
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fa;
  font-size: .82rem;
  cursor: pointer;
}
.question-number.answered { color: var(--green); background: var(--green-soft); border-color: #b8e3d0; font-weight: 800; }
.question-number.current { color: white; background: var(--blue); border-color: var(--blue); }
.legend { display: flex; gap: 13px; margin-top: 15px; color: var(--muted); font-size: .72rem; }
.legend i { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 50%; }
.answered-dot { background: var(--green); }
.current-dot { background: var(--blue); }
.save-status { margin-top: 14px; padding-top: 12px; color: var(--green); border-top: 1px solid var(--line); font-size: .78rem; }
.save-status.saving { color: var(--amber); }
.save-status.error { color: var(--red); }

.question-card {
  min-height: 420px;
  padding: clamp(22px, 4vw, 38px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.question-kicker { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; }
.question-prompt { margin: 24px 0; white-space: pre-wrap; font-family: Georgia, "Songti SC", serif; font-size: clamp(1.1rem, 2vw, 1.3rem); line-height: 1.8; }
.choice-list { display: grid; gap: 11px; }
.choice-option {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition: border .15s, background .15s;
}
.choice-option:hover { border-color: #91bbd9; }
.choice-option.selected { background: var(--blue-soft); border-color: var(--blue); }
.choice-option input { width: auto; margin: 4px 0 0; }
.option-letter { display: inline-grid; place-items: center; width: 25px; height: 25px; flex: 0 0 25px; color: var(--navy); background: #edf1f4; border-radius: 50%; font-size: .78rem; font-weight: 800; }
.text-answer textarea { min-height: 145px; resize: vertical; }
.numeric-answer { display: grid; grid-template-columns: 1fr minmax(115px, .35fr); gap: 10px; }
.answer-hint { margin-top: 9px; color: var(--muted); font-size: .78rem; }
.exam-actions { display: flex; gap: 10px; margin-top: 14px; }
.exam-actions #submit-exam { margin-left: auto; }

.result-header {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}
.result-summary-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 22px;
  align-items: center;
  padding: 22px;
  color: white;
  background: linear-gradient(130deg, var(--navy-deep), #22577c);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.score-ring { display: grid; place-items: center; width: 105px; height: 105px; border: 7px solid rgba(255, 255, 255, .2); border-radius: 50%; }
.score-ring strong { font-size: 1.8rem; }
.result-summary-card h2 { margin: 0 0 5px; }
.result-summary-card p { margin: 0; color: #cbdbe6; }
.result-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 11px; font-size: .82rem; }
.result-items { display: grid; gap: 13px; }
.result-item { padding: 20px; background: white; border: 1px solid var(--line); border-left: 4px solid var(--red); border-radius: 13px; }
.result-item.correct { border-left-color: var(--green); }
.result-item.pending { border-left-color: var(--amber, #d97706); }
.essay-answer { min-height: 180px; }
.result-item-header { display: flex; justify-content: space-between; gap: 15px; }
.result-item-header h3 { margin-bottom: 9px; font-size: 1rem; white-space: pre-wrap; }
.result-points { white-space: nowrap; font-weight: 800; }
.result-answer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.answer-box { padding: 10px 12px; background: #f5f7f8; border-radius: 9px; font-size: .86rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.answer-box strong { display: block; color: var(--muted); font-size: .72rem; }
.explanation { margin: 10px 0 0; padding: 10px 12px; color: #41515f; background: var(--blue-soft); border-radius: 9px; font-size: .86rem; }
.feedback-detail .feedback-body { white-space: pre-wrap; margin-top: 8px; line-height: 1.65; font-size: .88rem; }

.modal {
  width: min(510px, calc(100% - 30px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  box-shadow: 0 30px 90px rgba(16, 38, 59, .3);
}
.modal::backdrop { background: rgba(16, 38, 59, .62); backdrop-filter: blur(3px); }
.modal form { position: relative; padding: 28px; }
.modal-close { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; color: var(--muted); font-size: 1.6rem; cursor: pointer; }
.start-details { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 18px 0; }
.start-details div { padding: 12px 7px; text-align: center; background: #f3f6f8; border-radius: 10px; }
.start-details strong { display: block; }
.start-details span { color: var(--muted); font-size: .74rem; }
.notice { padding: 12px; color: #6d541e; background: #fff6df; border-radius: 10px; font-size: .84rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }

.toast-region { position: fixed; z-index: 50; right: 20px; bottom: 20px; display: grid; gap: 8px; }
.toast { max-width: 340px; padding: 11px 16px; color: white; background: var(--navy); border-radius: 10px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 820px) {
  .site-header { grid-template-columns: 1fr auto; }
  .site-header > div:nth-child(2) { grid-column: 1 / -1; grid-row: 2; margin-top: 14px; }
  .connection-status { grid-column: 2; grid-row: 1; }
  .filter-card { grid-template-columns: 1fr 1fr; }
  .paper-grid { grid-template-columns: 1fr; }
  .history-card { grid-template-columns: 1fr 1fr 1fr; }
  .history-card > div:first-child { grid-column: 1 / -1; }
  .history-card .button { grid-column: 1 / -1; }
  .exam-layout { grid-template-columns: 1fr; }
  .question-sidebar { position: static; }
  .question-nav { grid-template-columns: repeat(10, 1fr); }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 20px, 1180px); padding-top: 10px; }
  .site-header { padding: 18px; border-radius: 17px; }
  .connection-status { font-size: 0; }
  .connection-status::after { content: "状态"; font-size: .75rem; }
  .main-nav { width: 100%; }
  .nav-button { flex: 1; min-width: 0; }
  .filter-card { grid-template-columns: 1fr; }
  .section-heading { align-items: center; }
  .exam-topbar { align-items: flex-start; }
  .timer-block { min-width: 115px; padding: 8px 10px; }
  .timer-block strong { font-size: 1.25rem; }
  .question-nav { grid-template-columns: repeat(8, 1fr); }
  .question-card { min-height: 360px; padding: 20px 16px; }
  .exam-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .exam-actions #submit-exam { grid-column: 1 / -1; margin: 0; }
  .numeric-answer, .result-answer-grid { grid-template-columns: 1fr; }
  .result-header { grid-template-columns: 1fr; }
  .result-summary-card { grid-template-columns: 1fr; text-align: center; }
  .score-ring { margin: auto; }
  .result-meta { justify-content: center; }
  .start-details { grid-template-columns: 1fr; }
}
