:root {
  --paper: #f7f3eb;
  --paper-strong: #fffaf1;
  --ink: #17211d;
  --muted: #65706b;
  --line: #ded6c8;
  --teal: #0b7b75;
  --teal-dark: #075f5a;
  --mint: #dceee7;
  --amber: #d99525;
  --red: #b43b35;
  --blue: #244f8f;
  --shadow: 0 20px 45px rgba(30, 38, 33, 0.12);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  letter-spacing: 0;
  background:
    linear-gradient(90deg, rgba(23, 33, 29, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 33, 29, 0.03) 1px, transparent 1px),
    var(--paper);
  background-size: 22px 22px;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.exam-body {
  display: flex;
  justify-content: center;
}

.phone-frame {
  position: relative;
  width: min(100%, 520px);
  min-height: 100dvh;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

.brand-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 2px 16px;
}

.brand-avatar {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid rgba(11, 123, 117, 0.28);
  border-radius: 8px;
  color: var(--teal-dark);
  background: var(--mint);
  font-weight: 800;
}

.brand-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.brand-copy strong,
.brand-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy strong {
  font-size: 17px;
}

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

.step-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 0 0 14px;
}

.step-item {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 250, 241, 0.72);
  font-size: 13px;
  font-weight: 700;
}

.step-item.is-active {
  color: #fff;
  border-color: var(--teal);
  background: var(--teal);
}

.panel,
.question-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.94);
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.panel-heading {
  display: grid;
  gap: 4px;
  margin-bottom: 18px;
}

.panel-heading h1,
.panel-heading h2,
.exam-top h2,
.admin-topbar h1 {
  margin: 0;
  line-height: 1.18;
  letter-spacing: 0;
}

.panel-heading h1 {
  font-size: clamp(28px, 9vw, 40px);
}

.panel-heading h2,
.exam-top h2 {
  font-size: 24px;
}

.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mode-line {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  color: var(--ink);
  background: #fffdf8;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input {
  min-height: 48px;
  padding: 0 13px;
  font-size: 16px;
}

select {
  min-height: 48px;
  padding: 0 42px 0 13px;
  font-size: 16px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--teal-dark) 50%),
    linear-gradient(135deg, var(--teal-dark) 50%, transparent 50%);
  background-position:
    calc(100% - 21px) 21px,
    calc(100% - 14px) 21px;
  background-size: 7px 7px, 7px 7px;
  background-repeat: no-repeat;
}

select:disabled {
  color: var(--muted);
  background-color: #f0eadf;
}

textarea {
  min-height: 210px;
  padding: 12px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(11, 123, 117, 0.14);
  background: #ffffff;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.primary-button {
  width: 100%;
  color: #fff;
  background: var(--teal);
  box-shadow: 0 10px 22px rgba(11, 123, 117, 0.22);
}

.primary-button:hover {
  background: var(--teal-dark);
  transform: translateY(-1px);
}

.secondary-button {
  width: 100%;
  margin-top: 12px;
  color: var(--teal-dark);
  background: var(--mint);
}

.ghost-button {
  color: var(--teal-dark);
  border: 1px solid var(--line);
  background: var(--paper-strong);
}

.danger-button {
  width: 100%;
  color: #fff;
  background: var(--red);
}

.draw-panel {
  text-align: center;
}

.draw-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 8px;
  color: var(--teal-dark);
  background: var(--mint);
  font-size: 28px;
  font-weight: 900;
}

.draw-machine {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
}

.draw-ticket {
  min-height: 58px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(11, 123, 117, 0.34);
  border-radius: 8px;
  color: var(--teal-dark);
  background: #effaf6;
  font-size: 17px;
  font-weight: 900;
}

.draw-ticket.is-spinning {
  animation: ticketFlip 0.42s ease both;
}

.draw-slot-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.draw-slot {
  min-height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fffdf8;
  font-size: 12px;
  font-weight: 900;
  animation: slotArrive 0.28s ease both;
}

@keyframes ticketFlip {
  0% {
    transform: translateY(12px) scale(0.96);
    opacity: 0;
  }
  55% {
    transform: translateY(-3px) scale(1.01);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes slotArrive {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.metric-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 0 0 18px;
}

.metric-row div {
  min-height: 76px;
  display: grid;
  place-items: center;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.metric-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-row strong {
  font-size: 24px;
}

.exam-panel {
  display: grid;
  gap: 14px;
}

.exam-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px 0;
}

.exam-top > div:first-child {
  min-width: 0;
}

.exam-top h2,
.exam-top p {
  overflow-wrap: anywhere;
}

.progress-pill {
  min-width: 58px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  color: var(--blue);
  background: #e8eef8;
  font-weight: 900;
}

.exam-status {
  display: grid;
  justify-items: end;
  gap: 7px;
  flex: 0 0 auto;
}

.timer-pill {
  min-width: 82px;
  min-height: 34px;
  display: grid;
  grid-template-columns: auto auto;
  place-items: center;
  gap: 6px;
  border-radius: 8px;
  padding: 0 9px;
  color: var(--teal-dark);
  background: var(--mint);
  font-weight: 900;
}

.timer-pill span {
  color: var(--muted);
  font-size: 12px;
}

.timer-pill strong {
  font-variant-numeric: tabular-nums;
}

.timer-pill strong.is-warning {
  color: var(--red);
}

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

.question-card {
  padding: 16px;
  box-shadow: none;
  scroll-margin: 96px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.question-card.needs-answer {
  border-color: var(--red);
  background: #fff8f6;
  box-shadow: 0 0 0 3px rgba(180, 59, 53, 0.15);
  animation: questionPulse 1.2s ease both;
}

@keyframes questionPulse {
  0%,
  100% {
    transform: translateY(0);
  }
  35% {
    transform: translateY(-3px);
  }
}

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

.question-type {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  padding: 0 9px;
  color: var(--teal-dark);
  background: var(--mint);
  font-size: 12px;
  font-weight: 900;
}

.question-score {
  color: var(--amber);
  font-weight: 900;
}

.question-title {
  margin: 0 0 14px;
  line-height: 1.55;
  font-size: 16px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

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

.option-button {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffdf8;
  font-size: 15px;
  font-weight: 700;
}

.option-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.option-key {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  background: #f0eadf;
  font-weight: 900;
}

.option-key.is-judge-true {
  color: #fff;
  background: var(--teal);
}

.option-key.is-judge-false {
  color: #fff;
  background: var(--red);
}

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

.option-button:has(input:checked) {
  border-color: var(--teal);
  background: #effaf6;
}

.option-button:has(input:checked) .option-key {
  color: #fff;
  background: var(--teal);
}

.option-button:has(input:checked) .option-key.is-judge-false {
  background: var(--red);
}

.blank-input {
  margin-top: 4px;
}

.sticky-submit {
  position: sticky;
  bottom: calc(12px + env(safe-area-inset-bottom));
  margin-top: 14px;
}

.result-panel {
  text-align: center;
}

.score-ring {
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  border: 8px solid var(--mint);
  border-radius: 50%;
  background: #fffdf8;
}

.score-ring span {
  font-size: 44px;
  font-weight: 900;
  line-height: 1;
}

.score-ring small {
  margin-top: -26px;
  color: var(--muted);
  font-weight: 800;
}

.summary-list {
  display: grid;
  gap: 9px;
  text-align: left;
}

.summary-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.summary-item strong,
.summary-item span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.result-action {
  margin-top: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  width: min(calc(100vw - 28px), 440px);
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: rgba(23, 33, 29, 0.94);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}

.admin-body {
  padding: 24px;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1180px, 100%);
  margin: 0 auto 18px;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.admin-topbar h1 {
  font-size: 32px;
}

.admin-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.admin-login {
  max-width: 420px;
  margin: 80px auto 0;
}

.admin-dashboard {
  display: grid;
  gap: 16px;
}

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

.stat-card {
  min-height: 100px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.94);
}

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

.stat-card strong {
  display: block;
  margin-top: 9px;
  font-size: 26px;
  line-height: 1.1;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.admin-main-column,
.admin-side-column {
  display: grid;
  gap: 16px;
}

.inline-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  background: #fffdf8;
}

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: #f0eadf;
  font-size: 12px;
  font-weight: 900;
}

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

.draw-rule-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.setting-toggle {
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.setting-toggle strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 14px;
}

.setting-toggle span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.switch {
  position: relative;
  width: 54px;
  height: 30px;
  display: block;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
}

.switch > span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d9d1c3;
  transition: background 0.16s ease;
}

.switch > span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fffdf8;
  box-shadow: 0 2px 8px rgba(23, 33, 29, 0.18);
  transition: transform 0.16s ease;
}

.switch input:checked + span {
  background: var(--teal);
}

.switch input:checked + span::after {
  transform: translateX(24px);
}

.avatar-uploader {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.admin-avatar-preview {
  width: 64px;
  height: 64px;
  font-size: 22px;
}

.upload-controls {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.file-picker,
.file-drop {
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.file-picker input,
.file-drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-picker {
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--teal-dark);
  background: var(--mint);
  font-size: 13px;
  font-weight: 900;
}

.compact-button {
  min-height: 38px;
  margin: 0;
}

.template-actions {
  margin-bottom: 10px;
}

.template-actions .ghost-button {
  width: 100%;
}

.file-drop {
  min-height: 72px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(11, 123, 117, 0.45);
  border-radius: 8px;
  color: var(--teal-dark);
  background: #effaf6;
  text-align: center;
}

.file-drop span {
  max-width: 100%;
  padding: 0 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.danger-panel {
  border-color: rgba(180, 59, 53, 0.28);
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 920px) {
  .admin-body {
    padding: 16px;
  }

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

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-side-column {
    grid-row: 1;
  }
}

@media (max-width: 540px) {
  .panel {
    padding: 18px;
  }

  .panel-heading h1 {
    font-size: 30px;
  }

  .phone-frame {
    padding-left: 12px;
    padding-right: 12px;
  }

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

  .top-actions {
    width: 100%;
  }

  .top-actions .ghost-button {
    flex: 1 1 0;
  }

  .stat-grid,
  .draw-rule-grid {
    grid-template-columns: 1fr;
  }
}
