/* Quiz site styles */
:root {
  --accent: #2563eb;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c2230;
  --muted: #687083;
  --line: #e2e5eb;
  --good: #16a34a;
  --good-bg: #e8f7ee;
  --mid: #d97706;
  --mid-bg: #fdf3e2;
  --bad: #dc2626;
  --bad-bg: #fdecec;
  --pend: #7c3aed;
  --pend-bg: #f1ebfe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: .2em 0 .4em; }
h2 { font-size: 1.15rem; margin: 1.2em 0 .6em; }
h3 { font-size: 1rem; margin: .8em 0 .4em; }
code { background: #eef0f4; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.tiny { font-size: .75rem; }
.warn-text { color: var(--mid); font-weight: 600; }
.ok-text { color: var(--good); }
.spacer { flex: 1; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* layout */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.brand img { height: 32px; width: auto; }
.nav { display: flex; gap: 4px 16px; align-items: center; margin-left: auto; flex-wrap: wrap; }
.nav a, .linklike { color: var(--muted); text-decoration: none; font: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.nav a:hover, .linklike:hover { color: var(--accent); }
.wrap { max-width: 860px; margin: 0 auto; padding: 24px 16px 64px; }
.wrap.wide { max-width: 1200px; }
.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.narrow-card { max-width: 560px; }
.center-page .wrap { padding-top: 8vh; }
.inline { display: inline; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin-bottom: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 .span2 { grid-column: 1 / -1; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.empty { text-align: center; color: var(--muted); }
.card h2:first-child { margin-top: 0; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  text-decoration: none; cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover { border-color: #c7ccd6; background: #fafbfc; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-go { border-color: var(--good); color: var(--good); }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-small { padding: 5px 10px; font-size: .875rem; }
.btn-big { padding: 12px 22px; font-size: 1.05rem; }
.icon-btn { border: 1px solid transparent; background: none; color: var(--muted); border-radius: 6px; width: 30px; height: 30px; cursor: pointer; font-size: 15px; }
.icon-btn:hover { background: #eef0f4; color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-bg); color: var(--bad); }

/* forms */
.form label, label.block { display: block; margin-bottom: 14px; font-weight: 500; font-size: .92rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], input[type=datetime-local], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 11px;
  border: 1px solid #cdd2db; border-radius: 8px; background: #fff; color: var(--text);
  font: inherit; font-weight: 400;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { resize: vertical; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
input[type=color] { display: block; margin-top: 4px; width: 64px; height: 36px; padding: 2px; border: 1px solid #cdd2db; border-radius: 8px; }
.form label.check, label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin-bottom: 8px; }
label.check input { width: auto; margin: 0; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 4px; margin: 0 0 8px; }
legend { font-weight: 600; padding: 0 6px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { margin: 0; min-width: 200px; }

/* flash */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash ul { margin: 6px 0 0; padding-left: 20px; }
.flash-ok { background: var(--good-bg); border-color: #b7e4c7; color: #14532d; }
.flash-error { background: var(--bad-bg); border-color: #f5c2c2; color: #7f1d1d; }
.flash-warn { background: var(--mid-bg); border-color: #f3d7a7; color: #78350f; }

/* badges & tags */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #eef0f4; color: var(--muted); vertical-align: middle; text-transform: uppercase; letter-spacing: .02em; }
.badge-open { background: var(--good-bg); color: var(--good); }
.badge-draft { background: #eef0f4; color: var(--muted); }
.badge-closed { background: var(--bad-bg); color: var(--bad); }
.badge-pending { background: var(--pend-bg); color: var(--pend); }
.badge-pass { background: var(--good-bg); color: var(--good); }
.badge-fail { background: var(--bad-bg); color: var(--bad); }
.badge-grade { background: var(--accent); color: #fff; }
.tag { display: inline-block; font-size: .75rem; padding: 1px 8px; border-radius: 99px; background: #eef2ff; color: #3730a3; margin-right: 4px; }

/* quiz list */
.quiz-card { display: flex; gap: 16px; justify-content: space-between; flex-wrap: wrap; }
.quiz-card-main { flex: 1; min-width: 260px; }
.quiz-card-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 2px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.quiz-card-title a { color: var(--text); text-decoration: none; }
.quiz-card-title a:hover { color: var(--accent); }
.quiz-card-actions { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.share-row { display: flex; gap: 8px; margin-top: 10px; max-width: 520px; }
.share-input { margin: 0 !important; font-size: .85rem !important; background: #f8f9fb !important; }
.share-card { display: flex; flex-direction: column; gap: 4px; }
.more { position: relative; }
.more summary { list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.more-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: 12px; width: 280px; display: flex; flex-direction: column; gap: 10px; }
.more-menu a, .more-menu .linklike { color: var(--text); text-align: left; }
.danger-zone { border-top: 1px solid var(--line); padding-top: 10px; }
.danger-zone label { font-weight: 400; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 8px 0 16px; }
.tab { padding: 10px 16px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* builder */
.builder-bar { display: flex; gap: 10px; align-items: center; position: sticky; top: 57px; z-index: 5; background: var(--bg); padding: 8px 0; flex-wrap: wrap; }
.sec { border: 1px dashed #c9ced8; border-radius: 14px; padding: 12px; margin-bottom: 18px; background: rgba(255, 255, 255, .5); }
.sec-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.sec-title { font-weight: 600; font-size: 1.05rem; margin: 0 !important; background: transparent !important; border-color: transparent !important; }
.sec-title:hover, .sec-title:focus { background: #fff !important; border-color: #cdd2db !important; }
.sec-foot { padding: 8px 0 2px; border-radius: 8px; }
.builder-foot { margin-bottom: 40px; }
.qcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); position: relative; }
.qcard.dragging { opacity: .4; }
.qcard.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.qcard.drop-after { box-shadow: 0 3px 0 var(--accent); }
.sec-foot.drop-end { box-shadow: 0 -3px 0 var(--accent); }
.q-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.q-head select { width: auto; margin: 0; padding: 6px 8px; font-size: .875rem; }
.drag { cursor: grab; color: var(--muted); font-size: 18px; padding: 0 4px; user-select: none; }
.q-num { min-width: 32px; }
.pts { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }
.pts input { width: 70px; margin: 0; padding: 6px 8px; }
.prompt { font-size: 1rem; margin-bottom: 10px !important; }
.opts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; align-items: flex-start; }
.opt-row { display: flex; gap: 8px; align-items: center; width: 100%; border-radius: 8px; padding: 2px; }
.opt-row.is-correct .opt-text { border-color: var(--good); background: var(--good-bg); }
.opt-mark { display: flex; align-items: center; gap: 4px; cursor: pointer; font-weight: 600; color: var(--muted); min-width: 44px; }
.opt-mark input { width: 18px; height: 18px; margin: 0; accent-color: var(--good); }
.opt-text { margin: 0 !important; }
.opts.tf .opt-row { width: auto; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); cursor: pointer; }
.opts.tf .opt-row.is-correct { border-color: var(--good); background: var(--good-bg); }
.hint { margin-top: 2px; }
.q-foot { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 10px; }
.q-foot label { font-size: .82rem; color: var(--muted); font-weight: 500; }
.q-foot label:first-child { width: 180px; }
.q-foot .grow, .grow { flex: 1; min-width: 220px; }

/* results */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-v { font-size: 1.6rem; font-weight: 700; }
.stat-l { color: var(--muted); font-size: .85rem; }
.stat.warn .stat-v { color: var(--pend); }
.results-toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.results-toolbar input[type=search] { max-width: 300px; margin: 0; }
.results-toolbar label.check { margin: 0; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good); margin-right: 4px; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.grid-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
.grid { border-collapse: separate; border-spacing: 0; font-size: .85rem; width: max-content; min-width: 100%; }
.grid th, .grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: center; white-space: nowrap; background: var(--surface); }
.grid thead th { background: #f8f9fb; position: sticky; top: 0; font-weight: 600; z-index: 1; }
.grid .sticky { position: sticky; left: 0; text-align: left; z-index: 2; min-width: 170px; border-right: 1px solid var(--line); }
.grid thead .sticky { z-index: 3; }
.grid .qh { cursor: help; min-width: 40px; }
.grid .sec-start { border-left: 2px solid #c9ced8; }
.grid .score { text-align: right; }
.avg-row td { font-weight: 600; font-size: .78rem; background: #fbfbfd; }
.cell { font-weight: 600; }
.c-full { background: var(--good-bg) !important; color: var(--good); }
.c-part { background: var(--mid-bg) !important; color: var(--mid); }
.c-zero { background: var(--bad-bg) !important; color: var(--bad); }
.c-blank { color: #b0b6c2; }
.c-pend { background: var(--pend-bg) !important; color: var(--pend); }
.h-good { color: var(--good); }
.h-mid { color: var(--mid); }
.h-bad { color: var(--bad); }
.legend .cell { display: inline-block; min-width: 22px; text-align: center; border-radius: 4px; margin: 0 2px 0 8px; padding: 0 4px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 40%) 1fr 64px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: .88rem; }
.bar-label { overflow-wrap: anywhere; line-height: 1.3; }
.sec-head > .muted { white-space: nowrap; }
.bar { height: 10px; background: #eef0f4; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: currentColor; }
.bar-v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
table.simple { width: 100%; border-collapse: collapse; }
table.simple th, table.simple td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }

/* score & review */
.score-box { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.score-main { min-width: 180px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.score-pct { font-size: 2.6rem; font-weight: 800; line-height: 1; color: var(--accent); }
.score-pts { color: var(--muted); }
.score-breakdown { flex: 1; min-width: 260px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px 24px; }
.score-breakdown h3 { margin-top: 0; font-size: .85rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
.section-title { margin-top: 28px; padding-bottom: 6px; border-bottom: 2px solid var(--line); }
.review-q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.review-full { border-color: #b7e4c7; }
.review-part { border-color: #f3d7a7; }
.review-zero, .review-blank { border-color: #f5c2c2; }
.review-pend { border-color: #d9c8fb; }
.review-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.review-pts { font-weight: 600; font-size: .9rem; }
.review-full .review-pts { color: var(--good); }
.review-part .review-pts { color: var(--mid); }
.review-zero .review-pts, .review-blank .review-pts { color: var(--bad); }
.review-pend .review-pts { color: var(--pend); }
.review-prompt { margin-bottom: 10px; font-weight: 500; }
.review-opts { list-style: none; padding: 0; margin: 0 0 10px; display: flex; flex-direction: column; gap: 4px; }
.review-opts li { padding: 6px 10px; border-radius: 8px; border: 1px solid transparent; }
.opt-letter { display: inline-block; width: 22px; font-weight: 700; color: var(--muted); }
.opt-correct { background: var(--good-bg); border-color: #b7e4c7 !important; }
.opt-wrong { background: var(--bad-bg); border-color: #f5c2c2 !important; }
.opt-chosen { font-weight: 600; }
.opt-note { float: right; font-size: .75rem; font-weight: 600; color: var(--bad); text-transform: uppercase; margin-left: 8px; }
.opt-note.ok { color: var(--good); }
.opt-correct .opt-note:not(.ok) { color: var(--good); }
.review-text { background: #f8f9fb; border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; white-space: normal; }
.rationale { background: #f3f6ff; border-radius: 8px; padding: 10px 12px; font-size: .92rem; margin-top: 6px; }
.comment { background: var(--pend-bg); border-radius: 8px; padding: 10px 12px; font-size: .92rem; margin-top: 6px; }
.grade-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.grade-form label { font-size: .82rem; color: var(--muted); font-weight: 500; margin: 0; }
.grade-form input[type=number] { width: 110px; }
.mark-q { margin-top: 24px; }

/* import */
.preview-list { padding-left: 22px; }
.preview-list > li { margin-bottom: 12px; }
.preview-list ul { margin: 4px 0 0; padding-left: 18px; }
.help table code { white-space: nowrap; }
.logo-preview { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.logo-preview img { max-height: 48px; }

/* learner */
.learner .wrap { max-width: 780px; }
.quiz-intro h1 { margin-top: 0; }
.facts { padding-left: 18px; color: var(--muted); margin: 0 0 18px; }
.join-form { display: flex; gap: 8px; margin: 16px 0; }
.join-form input { margin: 0; text-transform: uppercase; letter-spacing: .1em; font-size: 1.1rem; text-align: center; }
.take-head h1 { margin-bottom: 2px; }
.progress-wrap { position: sticky; top: 57px; z-index: 10; background: var(--bg); padding: 10px 0; display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.progress { flex: 1; height: 8px; background: #e3e6ec; border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 100%; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform .25s; }
.timer { font-weight: 700; font-variant-numeric: tabular-nums; padding: 2px 10px; border-radius: 99px; background: #fff; border: 1px solid var(--line); white-space: nowrap; }
.timer-low { color: #fff; background: var(--bad); border-color: var(--bad); }
.instructions { font-size: .95rem; }
.question { margin: 0 0 16px; padding: 18px 20px; }
.question.answered { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }
.q-legend { display: flex; justify-content: space-between; width: 100%; padding: 0; font-weight: 400; float: left; margin-bottom: 8px; }
.q-legend + * { clear: both; }
.q-num { font-weight: 700; color: var(--accent); font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; }
.q-pts { color: var(--muted); font-size: .82rem; }
.q-prompt { font-size: 1.05rem; font-weight: 500; margin-bottom: 12px; clear: both; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid #d6dae2; border-radius: 10px; cursor: pointer; background: #fff; transition: border-color .15s, background .15s; }
.choice:hover { border-color: var(--accent); }
.choice input { margin: 3px 0 0; width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.choice:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, #fff); }
.choice-letter { font-weight: 700; color: var(--muted); min-width: 16px; }
.short-answer, .long-answer { font-size: 1rem; }
.submit-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 24px; }
.result-head h1 { margin-bottom: 0; }

@media (max-width: 600px) {
  .wrap { padding: 16px 12px 48px; }
  .card { padding: 16px; }
  .question { padding: 14px; }
  .inline-form { width: 100%; }
  .inline-form input { min-width: 0; flex: 1; }
  .q-foot label:first-child { width: 100%; }
  .more-menu { right: auto; left: 0; width: min(280px, 85vw); }
  .score-pct { font-size: 2.2rem; }
  .nav { margin-left: 0; width: 100%; }
  .builder-bar, .progress-wrap { top: 0; position: static; }
}
@media print {
  .topbar, .grade-form, .actions { display: none; }
  body { background: #fff; }
  .card, .review-q { box-shadow: none; break-inside: avoid; }
}
