:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef6f4;
  --text: #17202a;
  --muted: #5f6f7a;
  --line: #dce5eb;
  --blue: #1f67d2;
  --blue-dark: #164fa3;
  --green: #168466;
  --green-soft: #e6f5ef;
  --amber: #b7791f;
  --amber-soft: #fff7e6;
  --red: #c73e3e;
  --red-soft: #fff0f0;
  --shadow: 0 16px 40px rgba(23, 32, 42, 0.08);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(31, 103, 210, 0.06), transparent 260px),
    var(--bg);
}

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

button {
  border: 0;
}

a {
  color: var(--blue);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(18px, 4vw, 44px);
  border-bottom: 1px solid rgba(220, 229, 235, 0.8);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.brand-with-logo {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.brand-logo {
  display: block;
  height: 44px;
  width: auto;
  max-width: min(220px, 42vw);
  object-fit: contain;
  flex-shrink: 0;
}

/* 顶栏仅 Logo 时略放大 */
.brand-logo-only .brand-logo {
  height: 52px;
  max-width: min(280px, 70vw);
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1.25;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 56px;
}

.student-page {
  width: min(940px, calc(100% - 28px));
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.8fr);
  align-items: start;
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.question-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.78fr);
  gap: 18px;
  align-items: start;
}

.question-bank-head {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 18px 0 4px;
}

.question-bank-head .panel-title {
  margin-bottom: 4px;
}

.question-overview {
  display: grid;
  grid-template-columns: repeat(3, minmax(88px, 1fr));
  gap: 10px;
}

.mini-stat {
  min-width: 88px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
}

.mini-stat b {
  display: block;
  font-size: 22px;
  line-height: 1.1;
}

.mini-stat span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.question-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.question-bank-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 15px;
  box-shadow: 0 10px 28px rgba(23, 32, 42, 0.05);
}

.question-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.question-bank-card .rich-preview {
  max-height: 280px;
  overflow: auto;
}

.question-bank-card .message {
  margin: 0;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed #b8c8d4;
  border-radius: 8px;
  background: #fbfdff;
  color: var(--muted);
  font-size: 20px;
  font-weight: 800;
}

.modal-dialog {
  width: min(1180px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.modal-dialog::backdrop {
  background: rgba(17, 30, 43, 0.42);
  backdrop-filter: blur(4px);
}

.modal-shell {
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  padding: 18px;
  box-shadow: 0 24px 80px rgba(17, 30, 43, 0.25);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.modal-head .panel-title {
  margin: 0;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.panel.tight {
  padding: 16px;
}

.panel-title {
  margin: 0 0 14px;
  font-size: 18px;
  line-height: 1.35;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.form-row {
  display: grid;
  gap: 7px;
}

.form-row label {
  color: #283744;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

code {
  border-radius: 5px;
  background: #edf3f7;
  padding: 1px 5px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 103, 210, 0.14);
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 8px;
  padding: 9px 14px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font-weight: 750;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.button:hover {
  background: var(--blue-dark);
  box-shadow: 0 8px 18px rgba(31, 103, 210, 0.22);
}

.button:active {
  transform: translateY(1px);
}

.button.secondary {
  background: #eaf0f7;
  color: #22313d;
}

.button.secondary:hover {
  background: #dfe8f2;
  box-shadow: none;
}

.button.success {
  background: var(--green);
}

.button.danger {
  background: var(--red);
}

.button.ghost {
  background: transparent;
  color: var(--blue);
  padding-inline: 8px;
}

.button.ghost:hover {
  background: rgba(31, 103, 210, 0.08);
  box-shadow: none;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
}

.message {
  border-radius: 8px;
  padding: 12px 14px;
  margin: 12px 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.message.error {
  border-color: rgba(199, 62, 62, 0.3);
  background: var(--red-soft);
  color: #822b2b;
}

.message.ok {
  border-color: rgba(22, 132, 102, 0.28);
  background: var(--green-soft);
  color: #0d6049;
}

.message.warn {
  border-color: rgba(183, 121, 31, 0.3);
  background: var(--amber-soft);
  color: #765016;
}

.editor-shell {
  display: grid;
  gap: 12px;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
}

.option-editor {
  display: grid;
  gap: 10px;
}

.doc-editor {
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 18px;
  line-height: 1.75;
  outline: none;
  overflow: auto;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.doc-editor:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 103, 210, 0.14);
}

.doc-editor:empty::before {
  content: attr(data-placeholder);
  color: #8a9aa6;
}

.doc-editor p,
.doc-editor div {
  margin: 0 0 10px;
}

.doc-media {
  position: relative;
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.doc-media:has(img) {
  display: inline-block;
  max-width: 100%;
}

.doc-media img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  background: transparent;
}

.doc-media video {
  display: block;
  width: 100%;
  height: auto;
  background: #0e1720;
}

.doc-media-remove {
  position: absolute;
  right: 10px;
  top: 10px;
  min-height: 30px;
  border-radius: 8px;
  padding: 4px 10px;
  background: rgba(21, 36, 51, 0.82);
  color: #fff;
  cursor: pointer;
  font-weight: 750;
}

.rich-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  padding: 14px;
}

.rich-preview.compact {
  margin-top: 12px;
  box-shadow: none;
}

.preview-title {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.rich-text,
.question-stem {
  line-height: 1.75;
  white-space: normal;
}

.rich-text + .rich-text,
.rich-text + .rich-media,
.rich-media + .rich-text,
.rich-media + .rich-media {
  margin-top: 12px;
}

.rich-media {
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.rich-media:has(img) {
  display: inline-block;
  max-width: 100%;
}

.rich-media:first-child {
  margin-top: 0;
}

.rich-media img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  background: transparent;
}

.rich-media video {
  display: block;
  width: 100%;
  height: auto;
  background: #0e1720;
}

.option-builder {
  display: grid;
  gap: 10px;
}

.simple-option {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.simple-option.is-correct {
  border-color: rgba(22, 132, 102, 0.42);
  background: #f4fbf8;
}

.simple-option-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.simple-option-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.simple-option-actions .button {
  min-height: 28px;
  padding: 4px 7px;
  font-size: 12px;
}

.answer-badge {
  display: none;
  border-radius: 999px;
  background: var(--green-soft);
  color: #0d6049;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
}

.simple-option.is-correct .answer-badge {
  display: inline-flex;
}

.simple-option textarea {
  min-height: 64px;
}

.correct-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #334653;
  font-size: 13px;
  font-weight: 750;
}

.correct-picker input {
  width: 17px;
  height: 17px;
}

.option-line {
  margin: 5px 0;
  line-height: 1.6;
}

.preview-panel {
  position: sticky;
  top: 86px;
}

.exam-preview {
  display: grid;
  gap: 12px;
}

.preview-question-card {
  box-shadow: none;
}

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

.stat {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #f7fafc);
  border-radius: 8px;
  padding: 14px;
}

.stat b {
  display: block;
  font-size: 24px;
  margin-bottom: 4px;
}

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

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}

.tab {
  min-width: max-content;
  background: transparent;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  padding: 11px 12px;
  cursor: pointer;
  font-weight: 750;
}

.tab.active {
  color: var(--blue);
  border-color: var(--blue);
}

.section {
  display: none;
}

.section.active {
  display: grid;
  gap: 18px;
}

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

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

.item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.item-title {
  margin: 0 0 5px;
  font-weight: 800;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #eef3f7;
  color: #334653;
  font-size: 12px;
  font-weight: 700;
}

.tag.green {
  background: var(--green-soft);
  color: #0d6049;
}

.tag.blue {
  background: #e8f0ff;
  color: var(--blue-dark);
}

.tag.red {
  background: var(--red-soft);
  color: #822b2b;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  background: #fff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: #f4f8fb;
  color: #354756;
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.login-box {
  width: min(440px, calc(100% - 28px));
  margin: 9vh auto 0;
}

.home-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.home-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-left: auto;
}

.admin-entry {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  padding: 6px 2px;
}

.admin-entry:hover {
  color: var(--blue);
}

.home-main {
  display: grid;
  place-items: center;
  min-height: 62vh;
  padding: 48px 18px;
}

.home-hero {
  display: grid;
  justify-items: center;
  gap: 28px;
  text-align: center;
}

.home-hero h1 {
  margin: 0;
  color: #122131;
  font-size: clamp(22px, 4.2vw, 40px);
  line-height: 1.35;
  letter-spacing: 0;
  max-width: 22em;
}

.home-actions {
  justify-content: center;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(18px, 4vw, 44px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.78);
}

.center {
  text-align: center;
}

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

.time-cell {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  padding: 14px 8px;
  text-align: center;
}

.time-cell b {
  display: block;
  font-size: clamp(24px, 8vw, 44px);
  line-height: 1;
}

.time-cell span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.exam-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 102px;
  z-index: 8;
  background: rgba(246, 248, 251, 0.92);
  backdrop-filter: blur(12px);
  padding: 10px 0;
}

/* 考生端顶栏仅 Logo，粘性工具条上移 */
.student-page .exam-toolbar {
  top: 84px;
}

.timer-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  background: #152433;
  color: #fff;
  padding: 8px 12px;
  font-weight: 800;
}

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

.question-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.question-stem {
  white-space: pre-wrap;
  line-height: 1.7;
}

.media-preview {
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.media-preview:has(img) {
  display: inline-block;
  max-width: 100%;
}

.media-preview img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  background: transparent;
}

.media-preview video {
  display: block;
  width: 100%;
  height: auto;
  background: #000;
}

.options {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.option {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  cursor: pointer;
}

.option input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
}

.option:has(input:checked) {
  border-color: rgba(31, 103, 210, 0.45);
  background: #f0f6ff;
}

.progress-line {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #e4ebf0;
  overflow: hidden;
}

.progress-line span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .grid.two,
  .grid.three,
  .stats,
  .question-workbench {
    grid-template-columns: 1fr;
  }

  .preview-panel {
    position: static;
  }

  .question-bank-head {
    grid-template-columns: 1fr;
  }

  .question-overview {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .exam-toolbar {
    top: 96px;
    align-items: flex-start;
    flex-direction: column;
  }

  .student-page .exam-toolbar {
    top: 78px;
  }
}

@media (max-width: 560px) {
  .page {
    width: min(100% - 20px, 1180px);
    margin-top: 16px;
  }

  .panel {
    padding: 16px;
  }

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

  .brand-logo {
    height: 36px;
    max-width: min(160px, 38vw);
  }

  .brand-logo-only .brand-logo {
    height: 44px;
    max-width: min(260px, 72vw);
  }

  .topbar {
    padding: 14px 12px;
  }

  .home-nav {
    width: auto;
    flex-shrink: 0;
    justify-content: flex-end;
  }

  .home-nav .button {
    flex: 0 1 auto;
  }

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

  .actions {
    align-items: stretch;
  }

  .actions .button {
    flex: 1 1 auto;
  }

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

  .question-head,
  .item-header,
  .question-card-head {
    flex-direction: column;
  }

  .question-card-grid {
    grid-template-columns: 1fr;
  }

  .modal-dialog {
    width: min(100vw - 16px, 1180px);
  }

  .modal-shell {
    padding: 12px;
  }
}
