:root {
  color-scheme: light;
  --card-width: 880px;
  --ink: #111;
  --muted: #cfcfcf;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: #fff url("./assets/heartbug-logo.jpg") center / cover fixed no-repeat;
  font-family: Arial, Helvetica, sans-serif;
}

.page-shell {
  min-height: calc(100vh - 64px);
  padding: 32px 20px 72px;
}

.quiz-card {
  width: min(100%, var(--card-width));
  margin: 0 auto;
  padding: 18px 54px 42px;
  background: rgba(255, 255, 255, .97);
  border: 1px solid #d5d5d5;
  box-shadow: 0 2px 4px rgba(0,0,0,.18);
}

h1 {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 700;
}

.brand {
  display: block;
  width: 100%;
  max-height: 165px;
  margin-bottom: 24px;
  object-fit: contain;
}

.brand-header { border-bottom: 1px solid #ececec; margin-bottom: 28px; }
.brand-header .brand { max-height: 130px; }
.entry-view { max-width: 470px; min-height: 400px; margin: 0 auto; padding: 48px 0; }
.eyebrow { margin: 0 0 8px; color: #b30000; font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.entry-view h2, .admin-heading h2, .result-heading h2 { margin: 0 0 10px; font-size: 28px; }
.supporting { margin: 0 0 28px; color: #666; line-height: 1.55; }
.stack-form { display: grid; gap: 10px; }
.stack-form label, .share-panel label { font-size: 13px; font-weight: 700; }
input { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #c9c9c9; border-radius: 3px; font: inherit; }
input:focus { outline: 2px solid #111; outline-offset: 2px; }
.stack-form .button { margin-top: 8px; }
.error { min-height: 20px; margin: 0; color: #a40000; font-size: 13px; }
.quiet-link { display: inline-block; margin-top: 30px; color: #555; font-size: 13px; }
.quiz-meta { display: flex; justify-content: space-between; padding-bottom: 12px; color: #555; font-size: 13px; font-weight: 700; }
.save-status { min-height: 18px; margin: 5px 0 0; color: #777; font-size: 12px; text-align: right; }

.ecg-frame {
  position: relative;
  min-height: 280px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #fff;
}

#ecg-image {
  display: block;
  width: 100%;
  max-height: 390px;
  object-fit: contain;
}

.image-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #777;
  background: #fafafa;
}

.image-loader[hidden] { display: none; }

textarea {
  width: 100%;
  min-height: 76px;
  margin-top: 24px;
  padding: 14px;
  resize: vertical;
  border: 1px solid #d8d8d8;
  border-radius: 0;
  background: #fff;
  color: #222;
  font: 14px/1.45 Arial, Helvetica, sans-serif;
}

textarea:focus {
  outline: 2px solid #111;
  outline-offset: 2px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 18px;
}

.button {
  min-width: 116px;
  padding: 13px 24px;
  border: 1px solid #000;
  border-radius: 3px;
  background: #050505;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.button:hover { background: #2a2a2a; }
.button:focus-visible { outline: 3px solid #c8c8c8; outline-offset: 2px; }
.button-secondary { background: #fff; color: #111; }
.button-secondary:hover { background: #f2f2f2; }
.button[hidden] { display: none; }

.pagination { margin-top: 26px; }

.page-numbers {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
}

.page-number {
  min-width: 27px;
  height: 27px;
  padding: 0 7px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #222;
  font-weight: 600;
  cursor: pointer;
}

.page-number:hover { background: #eee; }
.page-number[aria-current="page"] { background: #e5e5e5; }
.ellipsis { padding: 0 7px; }

.result-view {
  min-height: 360px;
  padding: 12px 0;
}

.result-heading, .admin-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.result-times { display: grid; gap: 5px; color: #666; font-size: 12px; text-align: right; }
.share-panel { margin-bottom: 28px; padding: 18px; background: #f5f5f5; border: 1px solid #ddd; }
.share-row { display: flex; gap: 8px; margin-top: 8px; }
.share-panel p { margin: 8px 0 0; color: #666; font-size: 12px; }
.button-small { min-width: auto; padding: 10px 16px; font-size: 13px; }
.result-list { display: grid; gap: 22px; }
.result-item { padding: 18px; border: 1px solid #ddd; background: #fff; }
.result-item h3 { margin: 0 0 12px; }
.result-item img { display: block; width: 100%; max-height: 330px; object-fit: contain; }
.answer-block { margin-top: 12px; padding: 14px; border-left: 4px solid #bbb; background: #f7f7f7; }
.answer-block p { margin: 6px 0 0; line-height: 1.5; white-space: pre-wrap; }
.model-answer { border-left-color: #b40000; background: #fff5f5; }
.admin-view { padding: 10px 0 26px; }
.admin-grid { display: grid; grid-template-columns: minmax(250px, .8fr) minmax(440px, 1.5fr); gap: 20px; }
.admin-panel { padding: 18px; border: 1px solid #ddd; background: #fff; }
.admin-panel h3 { margin-top: 0; }
.code-form { display: grid; gap: 8px; margin-bottom: 18px; }
.code-list { display: grid; gap: 8px; }
.code-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px; background: #f5f5f5; }
.status-toggle { padding: 6px 10px; border: 1px solid #aaa; border-radius: 999px; background: #eee; cursor: pointer; }
.status-toggle.active { border-color: #23702d; background: #e8f7ea; color: #17561f; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 8px; border-bottom: 1px solid #e5e5e5; text-align: left; vertical-align: top; }
th { color: #666; font-size: 11px; text-transform: uppercase; }
.text-button { border: 0; padding: 0; background: none; color: #9a0000; font: inherit; font-weight: 700; cursor: pointer; }

footer {
  min-height: 64px;
  padding: 22px;
  background: rgba(255,255,255,.94);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

footer a { color: inherit; }

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

@media (max-width: 680px) {
  .page-shell { padding: 12px 8px 44px; }
  .quiz-card { padding: 16px 16px 30px; }
  .brand { margin-bottom: 12px; }
  .ecg-frame { min-height: 190px; }
  .actions { justify-content: stretch; }
  .button { flex: 1; }
  .page-numbers { flex-wrap: wrap; }
  .result-heading, .admin-heading { display: grid; }
  .result-times { text-align: left; }
  .share-row { display: grid; }
  .admin-grid { grid-template-columns: 1fr; }
}

/* ---------- template composer ---------- */
.composition-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.composition-actions .save-status { margin: 0; }
.template-panel { margin-top: 8px; border: 1px solid #d6d6d6; border-radius: 8px; background: #fff; display: flex; flex-direction: column; }
.template-panel input[type="search"] { margin: 8px; padding: 8px 10px; border: 1px solid #d6d6d6; border-radius: 6px; }
.template-groups { overflow-y: auto; max-height: 320px; padding: 0 8px 8px; }
.template-group { border-bottom: 1px solid #ececec; }
.template-group:last-child { border-bottom: 0; }
.template-group summary { padding: 8px 4px; cursor: pointer; font-weight: 600; font-size: 14px; }
.template-item { display: flex; justify-content: space-between; gap: 12px; width: 100%; text-align: left; padding: 7px 8px; border: 0; background: transparent; border-radius: 6px; cursor: pointer; font-size: 13px; }
.template-item:hover { background: #f2f6ff; }
.template-en { color: #111; }
.template-zh { color: #6b6b6b; white-space: nowrap; }
.template-empty { color: #666; font-size: 13px; padding: 8px 4px; }
.param-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; padding: 8px; border: 1px dashed #b9c6e2; border-radius: 8px; }
.param-form label { display: flex; }
.param-form input { width: 150px; padding: 6px 8px; border: 1px solid #d6d6d6; border-radius: 6px; }
.model-zh { color: #444; margin-top: 4px; }
.model-original { color: #8a8a8a; font-size: 12px; margin-top: 4px; }

/* ---------- template browser: 3 columns (ported from review-platform CommentTemplateBrowser) ---------- */
.template-panel[hidden] { display: none; }
.param-form[hidden] { display: none; }
.template-panel { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.template-panel input[type="search"] { padding: 8px 10px; border: 1px solid #d6d6d6; border-radius: 6px; }
/* cols: explicit height + always-on scroll (Firefox resolves fr rows of auto-height
   containers by content; explicit heights are deterministic across engines) */
.template-browser { display: grid; grid-template-columns: minmax(132px, 170px) minmax(0, 1fr) minmax(116px, 152px); gap: 8px; min-height: 0; }
.template-browser-col { height: min(42vh, 430px); min-height: 0; overflow-y: scroll; border: 1px solid rgba(216, 222, 232, 0.9); border-radius: 6px; background: rgba(255, 255, 255, 0.7); }
.template-category-label { position: sticky; top: 0; z-index: 1; margin: 0; padding: 5px 8px 4px; font-size: 10.5px; letter-spacing: 0.04em; text-transform: uppercase; color: #6b7280; background: rgba(255, 255, 255, 0.88); border-bottom: 1px solid rgba(216, 222, 232, 0.6); }
.template-conjunction-col .template-category-label { color: #7c3aed; }
.template-group-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; column-gap: 6px; row-gap: 1px; width: 100%; padding: 5px 8px; border: 0; border-bottom: 1px solid rgba(216, 222, 232, 0.6); background: transparent; text-align: left; cursor: pointer; }
.template-group-head:hover { background: rgba(59, 130, 246, 0.1); }
.template-group-head[aria-current='true'] { background: rgba(59, 130, 246, 0.16); box-shadow: inset 2px 0 0 #2563eb; }
.template-group-head .group-name { grid-area: 1 / 1; font-size: 12.5px; font-weight: 600; color: #111; }
.template-group-head .group-count { grid-area: 1 / 2; font-size: 11px; color: #6b7280; background: rgba(216, 222, 232, 0.55); border-radius: 8px; padding: 0 6px; }
.template-group-head .group-alt { grid-area: 2 / 1 / 3 / 3; font-size: 11.5px; color: #6b7280; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-option-list { list-style: none; margin: 0; padding: 0 0 2px; }
.template-option { display: flex; justify-content: space-between; gap: 10px; width: 100%; padding: 7px 8px; border: 0; border-bottom: 1px solid rgba(216, 222, 232, 0.45); background: transparent; text-align: left; cursor: pointer; }
.template-option:hover { background: rgba(59, 130, 246, 0.12); }
.template-option .opt-en { font-size: 12.5px; color: #111; }
.template-option .opt-zh { font-size: 11.5px; color: #6b7280; text-align: right; }
.template-option.conjunction .opt-en { color: #7c3aed; font-style: italic; }
.template-empty { color: #666; font-size: 13px; padding: 8px; }

/* ---------- ECG lightbox & answers visibility ---------- */
.ecg-frame img { cursor: zoom-in; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.82); display: flex; align-items: center; justify-content: center; z-index: 50; cursor: zoom-out; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 96vw; max-height: 94vh; border-radius: 6px; }
.answers-hidden p { color: #444; }
