:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #18202b;
  --muted: #5f6b7a;
  --accent: #147d72;
  --accent-text: #ffffff;
  --ok: #1a7f4b;
  --ok-bg: #e5f5ec;
  --warn: #9a6200;
  --warn-bg: #fdf3dc;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --err: #6b4f00;
  --err-bg: #efece4;
  --run: #1d5fbf;
  --run-bg: #e3edfb;
  --frame-bg: #ffffff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0d1626;
  --surface: #111c2e;
  --surface-2: #17243a;
  --border: #26354d;
  --text: #e7edf6;
  --muted: #95a3b8;
  --accent: #2fb3a3;
  --accent-text: #06231f;
  --ok: #4cc98a;
  --ok-bg: #12301f;
  --warn: #f0b84a;
  --warn-bg: #33270d;
  --bad: #ff7b6e;
  --bad-bg: #3a1714;
  --err: #c9b98b;
  --err-bg: #2a2619;
  --run: #7fb0ff;
  --run-bg: #16294a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* 组件样式会设置 display，hidden 属性必须始终生效。 */
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

:root[data-embedded="true"] body { background: var(--surface); }

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

.page { max-width: 1280px; margin: 0 auto; padding: 24px 16px 48px; }

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 24px;
  margin-bottom: 16px;
}

h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: 0.01em; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }

.subtitle { margin: 4px 0 0; color: var(--muted); }

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.v-normal, .g-pass { color: var(--ok); background: var(--ok-bg); }
.v-warning, .g-warn { color: var(--warn); background: var(--warn-bg); }
.v-suspect, .g-fail { color: var(--bad); background: var(--bad-bg); }
.v-error { color: var(--err); background: var(--err-bg); }
.v-running { color: var(--run); background: var(--run-bg); }
.v-none { color: var(--muted); background: var(--surface-2); }

.notice {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn);
  font-weight: 500;
}
.notice.info { background: var(--run-bg); color: var(--run); }

.questions {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.questions > summary { padding: 10px 14px; cursor: pointer; font-weight: 600; }
.questions-body { padding: 0 14px 14px; }
.question-item { margin: 10px 0 0; }
.question-item h3 { color: var(--text); margin-bottom: 4px; }
.question-item p { margin: 0; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.rules { margin: 14px 0 0; color: var(--muted); }

.groups { display: grid; gap: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-meta { margin: 2px 0 0; color: var(--muted); font-size: 12px; word-break: break-all; }

.history { display: flex; flex-wrap: wrap; gap: 3px; margin: 12px 0 4px; }
.history button {
  width: 14px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  cursor: pointer;
  background: var(--surface-2);
}
.history button.v-normal { background: var(--ok); }
.history button.v-warning { background: var(--warn); }
.history button.v-suspect { background: var(--bad); }
.history button.v-error { background: var(--err); opacity: 0.55; }
.history button.v-running { background: var(--run); }
.history button[aria-pressed="true"] { outline: 2px solid var(--text); outline-offset: 1px; }
.history button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.run-line { margin: 6px 0 12px; color: var(--muted); font-size: 12px; }
.run-line button { margin-left: 8px; border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 12px; }

/* 题目数量由后台题库决定，按可用宽度自动排列；渲染类题目更宽，标准答案题较窄。 */
.answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; align-items: start; }

.answer {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.answer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.answer-value {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.15;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}
.answer-value.long { font-size: 13px; font-weight: 400; line-height: 1.5; white-space: pre-wrap; max-height: 180px; overflow: auto; }
.answer-expect { color: var(--muted); font-size: 12px; margin: 0; }

/* 后台题目编辑 */
.question-form textarea {
  width: 100%;
  min-height: 140px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font: 13px/1.5 inherit;
  resize: vertical;
}
.question-form .wide { grid-column: 1 / -1; }
.question-form h3 { margin: 16px 0 12px; color: var(--text); font-size: 14px; }
.field.check-field { display: flex; align-items: center; gap: 6px; min-height: 32px; align-self: end; }
.field.check-field input { width: auto; min-height: 0; margin: 0; }
.field.check-field span { color: var(--text); font-size: 13px; }
.question-prompt { color: var(--muted); font-size: 12px; max-width: 520px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.frame-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  overflow: hidden;
  background: var(--frame-bg);
  border: 1px solid var(--border);
}
.frame-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.frame-actions { display: flex; gap: 12px; font-size: 12px; }
.frame-actions a { color: var(--accent); }

.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  text-align: center;
  padding: 12px;
  font-size: 13px;
}
.placeholder.error { background: var(--err-bg); color: var(--err); word-break: break-word; }

.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 12px; }
.checks li { display: flex; gap: 6px; align-items: baseline; }
.checks .mark { flex: none; width: 16px; text-align: center; font-weight: 700; }
.checks .g-pass, .checks .g-warn, .checks .g-fail { background: none; }
.checks .detail { color: var(--muted); word-break: break-word; }

.stats { color: var(--muted); font-size: 12px; margin: 0; }

.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

@media (max-width: 960px) {
  .answers { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

@media (max-width: 640px) {
  .page { padding: 16px 16px 32px; }
  .answers { grid-template-columns: 1fr; }
  .card { padding: 12px; }
}

/* 管理后台 */
.admin .page { max-width: 1360px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.stat-row { display: flex; flex-wrap: wrap; gap: 12px 32px; }
.stat { min-width: 140px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 18px; font-weight: 600; word-break: break-word; }
.stat .value.small { font-size: 14px; font-weight: 500; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  font-size: 13px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.field { display: grid; gap: 4px; }
.field span { color: var(--muted); font-size: 12px; }
.field input, .field select, .table input, .table select {
  width: 100%;
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.form-actions { display: flex; gap: 8px; margin-top: 12px; align-items: center; flex-wrap: wrap; }
.form-msg { color: var(--muted); font-size: 12px; }
.form-msg.error { color: var(--bad); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 880px; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
.table td.actions { white-space: nowrap; }
.table td.actions .btn { margin-right: 4px; }
.table input[type="checkbox"] { width: auto; min-height: 0; }
.col-sort { width: 72px; }
.col-tokens { width: 110px; }
.col-protocol { width: 120px; }

.add-row { display: grid; grid-template-columns: minmax(220px, 2fr) minmax(200px, 2fr) 120px auto; gap: 8px; align-items: end; margin-top: 12px; }

.login {
  max-width: 360px;
  margin: 10vh auto 0;
}
.login h1 { margin-bottom: 16px; }
.login .field { margin-bottom: 12px; }

.round-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.round-list li { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.round-list .note { color: var(--muted); }

.detail-grid { display: grid; gap: 12px; }
.run-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.run-list button { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); padding: 4px 8px; cursor: pointer; font-size: 12px; }
.run-list button[aria-pressed="true"] { border-color: var(--accent); }
.raw-output {
  margin: 0;
  padding: 10px;
  max-height: 420px;
  overflow: auto;
  border-radius: 6px;
  background: var(--surface-2);
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 760px) {
  .add-row { grid-template-columns: 1fr; }
}
