/* QuickBee — Create Quiz page. Page-specific layout; shared look comes from theme.css.
   Token fallbacks use :where() (zero specificity) so theme.css always wins when present. */

:where(html) {
  --bg: #fbf8f2; --surface: #fff; --surface-2: #f4efe5; --border: #e7dece;
  --text: #1d1913; --text-muted: #6e6455; --primary: #f5a000; --primary-ink: #1d1400;
  --primary-soft: #fff1cc; --accent: #e2522f; --danger: #d93a3f; --success: #24a148; --warning: #e88a00;
  --radius: 12px; --radius-lg: 20px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.07);
  --shadow-lg: 0 20px 50px -12px rgba(0,0,0,.3);
  --font-display: system-ui, sans-serif; --font-body: system-ui, sans-serif; --font-mono: ui-monospace, monospace;
  --stage-bg: #0f0d0a; --stage-text: #fff8ec; --stage-accent: #ffc23d;
}
@media (prefers-color-scheme: dark) {
  :where(html) {
    --bg: #12100c; --surface: #1c1813; --surface-2: #252019; --border: #3a3226;
    --text: #f6efe2; --text-muted: #ab9f8b; --primary: #ffb81f; --primary-soft: #3a2c0c;
  }
}

/* --------------------------------------------------------------- frame */
.cq-body {
  margin: 0; height: 100vh; height: 100dvh; overflow: hidden;
  display: grid; grid-template-rows: auto auto auto minmax(0, 1fr);
  background: var(--bg); color: var(--text); font-family: var(--font-body);
}
.cq-topbar {
  display: flex; align-items: center; gap: 12px; height: auto; min-height: 60px; padding: 8px clamp(10px, 2vw, 20px);
  border-bottom: 1px solid var(--border); background: var(--surface); position: relative; z-index: 40;
}
.cq-brand { display: inline-flex; align-items: center; flex: none; text-decoration: none; }
.topbar .cq-brand img.cq-logo { height: 30px; width: auto; display: block; }
.topbar .cq-brand img.cq-logo-mark { display: none; }
.cq-title-wrap { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.cq-title-input {
  flex: 1; min-width: 0; max-width: 560px; font: 800 1.15rem/1.2 var(--font-display); color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 10px; padding: .4em .55em;
  letter-spacing: -0.01em;
}
.cq-title-input:hover { border-color: var(--border); }
.cq-title-input:focus { outline: none; border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 30%, transparent); }
.cq-save-state {
  flex: none; font-size: .78rem; font-weight: 700; color: var(--text-muted); white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.cq-save-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.cq-save-state.saved::before { background: var(--success); }
.cq-save-state.dirty::before, .cq-save-state.draft::before { background: var(--warning); }
.cq-save-state.saving::before { background: var(--primary); animation: cq-blink 1s infinite; }
.cq-save-state.error { color: var(--danger); }
.cq-save-state.error::before { background: var(--danger); }
@keyframes cq-blink { 50% { opacity: .3; } }
.cq-top-actions { display: flex; align-items: center; gap: 6px; flex: none; }
#saveBtn { min-width: 84px; }

/* "More" dropdown */
.cq-menu { position: relative; }
.cq-menu > summary { list-style: none; cursor: pointer; }
.cq-menu > summary::-webkit-details-marker { display: none; }
.cq-menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 220px; padding: 6px;
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.cq-menu-list button {
  text-align: left; padding: .6em .75em; border: 0; background: none; border-radius: 8px; cursor: pointer;
  font: 600 .9rem/1.2 var(--font-body); color: var(--text);
}
.cq-menu-list button:hover, .cq-menu-list button:focus-visible { background: var(--surface-2); outline: none; }
.cq-menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* Validation issues banner */
.cq-issues { background: color-mix(in srgb, var(--danger) 10%, var(--surface)); border-bottom: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); }
.cq-issues[hidden] { display: none; }
.cq-issues-inner { display: flex; align-items: flex-start; gap: 12px; padding: 8px clamp(10px, 2vw, 20px); flex-wrap: wrap; }
.cq-issues-inner strong { color: var(--danger); padding-top: 4px; font-size: .9rem; }
.cq-issues-inner ul { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; margin: 0; padding: 0; flex: 1; }
.cq-issues-inner [data-issues-close] { margin-left: auto; }
.cq-issue-link {
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--border)); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: .3em .8em; font: 600 .8rem/1.2 var(--font-body); cursor: pointer;
}
.cq-issue-link:hover { border-color: var(--danger); }

.cq-mobile-nav { display: none; }

/* --------------------------------------------------------------- 3 panes */
.cq-main {
  display: grid; grid-template-columns: 264px minmax(0, 1fr) 400px; min-height: 0;
  transition: grid-template-columns .2s;
}
.cq-main.aux-wide { grid-template-columns: 220px minmax(0, 1fr) minmax(400px, 52%); }
.cq-pane { min-height: 0; overflow: auto; }
.cq-list-pane { border-right: 1px solid var(--border); background: var(--surface-2); display: flex; flex-direction: column; padding: 0 10px 16px; }
.cq-editor-pane { padding: 18px clamp(12px, 2.4vw, 32px) 48px; }
.cq-aux-pane { border-left: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; overflow: hidden; }
.cq-aux-tabs { flex: none; padding: 0 8px; align-items: center; }
.cq-aux-tabs .tab { font-size: .84rem; padding: .85em .7em; }
.cq-widen { margin-left: auto; flex: none; }
.cq-aux-body { flex: 1; overflow: auto; min-height: 0; }
.cq-panel { padding: 4px 16px 40px; }
.cq-panel[hidden] { display: none; }

.cq-pane-head {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 2px 10px; background: var(--surface-2);
}
.cq-pane-head h2 { margin: 0; font: 800 .8rem/1 var(--font-body); letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
.cq-count { font-weight: 600; }

/* --------------------------------------------------------------- thumbs */
.cq-qlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cq-list-empty { padding: 16px 4px; font-size: .88rem; }
.cq-thumb {
  position: relative; display: grid; grid-template-columns: 22px 1fr; gap: 6px; align-items: start;
  cursor: pointer; border-radius: 12px; outline: none;
}
.cq-thumb-num { font: 800 .8rem/1 var(--font-mono); color: var(--text-muted); text-align: right; padding-top: 10px; }
.cq-thumb-card {
  min-width: 0; padding: 8px 10px; border-radius: 10px; background: var(--surface);
  border: 2px solid var(--border); transition: border-color .12s, box-shadow .12s, transform .12s;
}
.cq-thumb:hover .cq-thumb-card { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); }
.cq-thumb.selected .cq-thumb-card { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
.cq-thumb.selected .cq-thumb-num { color: var(--primary); }
.cq-thumb:focus-visible .cq-thumb-card { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 45%, transparent); }
.cq-thumb.dragging { opacity: .45; }
.cq-thumb.drop-before::before, .cq-thumb.drop-after::after {
  content: ""; position: absolute; left: 26px; right: 0; height: 3px; border-radius: 3px; background: var(--primary);
}
.cq-thumb.drop-before::before { top: -6px; }
.cq-thumb.drop-after::after { bottom: -6px; }
.cq-thumb-top { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.cq-thumb-topic { font: 800 .68rem/1.2 var(--font-body); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cq-thumb-topic em { font-style: normal; opacity: .6; }
.cq-thumb-warn { flex: none; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; background: var(--danger); color: #fff; font: 800 .7rem/1 var(--font-body); }
.cq-thumb-text {
  margin: 4px 0 6px; font-size: .82rem; line-height: 1.35; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word;
}
.cq-thumb-text .katex { font-size: 1em; }
.cq-thumb-text .katex-display { margin: 0; display: inline; }
.cq-thumb-meta { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.cq-thumb-tags { display: flex; gap: 3px; flex-wrap: nowrap; min-width: 0; overflow: hidden; max-height: 1.5em; }
.cq-chip-xs { font-size: .62rem !important; padding: .12em .45em !important; gap: 3px !important; }
.cq-chip-xs::before { width: 5px !important; height: 5px !important; }
.cq-thumb-props { flex: none; font: 600 .72rem/1 var(--font-mono); color: var(--text-muted); white-space: nowrap; }
.cq-thumb-props b { color: var(--text); }
.cq-thumb-actions {
  position: absolute; top: 4px; right: 4px; display: flex; gap: 2px; opacity: 0; transition: opacity .12s;
  background: var(--surface); border-radius: 8px; padding: 1px;
}
.cq-thumb:hover .cq-thumb-actions, .cq-thumb:focus-within .cq-thumb-actions, .cq-thumb.selected .cq-thumb-actions { opacity: 1; }
@media (hover: none) { .cq-thumb-actions { opacity: 1; } }
.cq-add-slot {
  margin-top: 10px; margin-left: 28px; padding: 12px; border: 2px dashed var(--border); border-radius: 10px;
  background: none; color: var(--text-muted); font: 700 .85rem/1 var(--font-body); cursor: pointer;
}
.cq-add-slot:hover { border-color: var(--primary); color: var(--text); }

.cq-icon-btn {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; border: 0;
  background: none; color: var(--text-muted); cursor: pointer; font-size: .85rem; line-height: 1; padding: 0;
}
.cq-icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.cq-icon-btn.danger:hover { color: var(--danger); }
.cq-icon-btn:disabled { opacity: .3; cursor: default; }
.cq-icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.cq-icon-btn[hidden] { display: none; }

/* --------------------------------------------------------------- editor */
.cq-loading { padding: 40px; text-align: center; }
.cq-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 auto 12px; max-width: 980px; }
.cq-editor-head h2 { margin: 0; font: 800 1.1rem/1.2 var(--font-display); }
.cq-row-gap { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.cq-center { justify-content: center; }
.cq-danger-text { color: var(--danger) !important; }

.cq-stage-wrap { max-width: 980px; margin: 0 auto 16px; }
.cq-stage {
  container-type: inline-size;
  aspect-ratio: 16 / 9; width: 100%; max-height: 52vh; border-radius: var(--radius-lg); overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--stage-accent, #ffc23d) 10%, transparent), transparent 60%),
    var(--stage-bg, #0f0d0a);
  color: var(--stage-text, #fff8ec);
  box-shadow: var(--shadow-lg), inset 0 0 0 1px rgba(255,255,255,.06);
}
.cq-stage-inner { height: 100%; display: flex; flex-direction: column; padding: 3.2cqw 4cqw; gap: 1.6cqw; box-sizing: border-box; }
.cq-stage-head { display: flex; justify-content: space-between; align-items: center; gap: 2cqw; }
.cq-stage-left { display: flex; align-items: baseline; gap: 2cqw; min-width: 0; }
.cq-stage-num { font: 800 clamp(12px, 2.4cqw, 40px)/1 var(--font-mono); color: var(--stage-accent, #ffc23d); }
.cq-stage-num small { opacity: .55; font-size: .7em; }
.cq-stage-topic {
  font: 800 clamp(10px, 2.1cqw, 34px)/1.1 var(--font-body); text-transform: uppercase; letter-spacing: .12em; opacity: .8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cq-stage-badges { display: flex; gap: 1cqw; flex: none; }
.cq-stage-badge {
  font: 800 clamp(11px, 2.1cqw, 34px)/1 var(--font-mono); padding: .5em .8em; border-radius: 999px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.14); white-space: nowrap;
}
.cq-stage-points { background: var(--stage-accent, #ffc23d); color: #1d1400; border-color: transparent; }
.cq-stage-timer.waiting { border-style: dashed; }
.cq-stage-timer.muted-badge { opacity: .5; }
.cq-stage-tags { display: flex; gap: .8cqw; flex-wrap: wrap; }
.cq-stage-tag {
  font: 700 clamp(9px, 1.5cqw, 24px)/1 var(--font-body); padding: .4em .8em; border-radius: 999px;
  color: color-mix(in srgb, var(--chip) 60%, #fff); background: color-mix(in srgb, var(--chip) 22%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip) 45%, transparent);
}
.cq-stage-question {
  flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column;
  font: 700 clamp(14px, 4cqw, 44px)/1.3 var(--font-display); letter-spacing: -0.01em; text-wrap: balance; word-break: break-word;
}
.cq-stage-question .katex-display { margin: .3em 0; }
.cq-stage-qtext { margin: auto 0; }
.cq-stage-question.len-m { font-size: clamp(13px, 3.2cqw, 36px); }
.cq-stage-question.len-l { font-size: clamp(12px, 2.6cqw, 30px); }
.cq-stage-question.len-xl { font-size: clamp(11px, 2.1cqw, 24px); }
.cq-stage-placeholder { opacity: .35; font-style: italic; font-weight: 500; }
.cq-stage-answer {
  border-radius: 1.4cqw; padding: 1.4cqw 2cqw; border: 1px dashed rgba(255,255,255,.18);
  font: 600 clamp(10px, 1.7cqw, 26px)/1.3 var(--font-body); color: rgba(255,248,236,.55); text-align: center;
}
.cq-stage-answer.shown {
  border: 0; text-align: left; color: var(--stage-text, #fff8ec);
  background: color-mix(in srgb, var(--stage-accent, #ffc23d) 16%, transparent);
  box-shadow: inset 4px 0 0 var(--stage-accent, #ffc23d);
  display: flex; align-items: baseline; gap: 2cqw;
}
.cq-stage-answer-label { font: 800 clamp(9px, 1.4cqw, 22px)/1 var(--font-body); text-transform: uppercase; letter-spacing: .14em; color: var(--stage-accent, #ffc23d); flex: none; }
.cq-stage-answer-text { font: 800 clamp(13px, 3cqw, 34px)/1.25 var(--font-display); }
.cq-stage-hint { font: 600 clamp(9px, 1.4cqw, 22px)/1 var(--font-body); text-align: center; opacity: .55; }
.cq-stage-hint b { color: var(--stage-accent, #ffc23d); }

.cq-stage-bar { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.cq-resolved { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; justify-content: flex-end; }
.cq-res {
  font: 600 .74rem/1 var(--font-body); padding: .45em .7em; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.cq-res-k { color: var(--text-muted); font-weight: 700; margin-right: 2px; }
.cq-res-rule { border-color: color-mix(in srgb, var(--primary) 55%, var(--border)); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }
.cq-res-ov { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }

.cq-form { max-width: 980px; margin: 0 auto; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.cq-form-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.cq-topic-field { flex: 1 1 220px; }
.cq-tag-pickers { display: flex; gap: 14px; flex-wrap: wrap; flex: 2 1 320px; margin-bottom: 14px; }
.cq-tagpick { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cq-tagpick-label { font-size: .82rem; font-weight: 700; color: var(--text); }
.cq-seg { flex-wrap: wrap; max-width: 100%; }
.cq-seg button { position: relative; }
.cq-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--chip, var(--text-muted)); display: inline-block; opacity: .55; }
.cq-seg button[aria-checked="true"] .cq-dot { opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--chip) 25%, transparent); }
.cq-seg button[aria-checked="true"] { box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 0 0 1.5px var(--chip) !important; }

.cq-latex-bar {
  display: flex; flex-wrap: wrap; gap: 3px; padding: 4px; border: 1px solid var(--border); border-bottom: 0;
  border-radius: 10px 10px 0 0; background: var(--surface-2); margin-bottom: -6px;
}
.cq-latex-btn, .cq-latex-greek {
  min-width: 30px; height: 28px; padding: 0 7px; border: 1px solid transparent; border-radius: 6px; background: none;
  color: var(--text); font: 600 .82rem/1 var(--font-mono); cursor: pointer;
}
.cq-latex-btn:hover, .cq-latex-greek:hover { background: var(--surface); border-color: var(--border); }
.cq-latex-greek { font-family: var(--font-body); }
.cq-latex-bar + .cq-math-input { border-top-left-radius: 0; border-top-right-radius: 0; }
.cq-math-input { font-family: var(--font-mono); font-size: .92rem; line-height: 1.5; resize: vertical; min-height: 3em; width: 100%; box-sizing: border-box; }

/* Overrides */
.cq-overrides { margin-top: 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.cq-overrides > summary {
  cursor: pointer; list-style: none; padding: 12px 14px; font-weight: 800; font-size: .9rem; display: flex; align-items: center; gap: 8px;
}
.cq-overrides > summary::-webkit-details-marker { display: none; }
.cq-overrides > summary::before { content: "▸"; transition: transform .15s; color: var(--text-muted); }
.cq-overrides[open] > summary::before { transform: rotate(90deg); }
.cq-overrides > .field-help { margin: -4px 14px 10px; }
.cq-ov-count.on { font-size: .72rem; padding: .2em .6em; border-radius: 999px; background: var(--accent); color: #fff; }
.cq-ov-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; padding: 0 14px 14px; }
.cq-ov-row { display: flex; flex-direction: column; gap: 5px; padding: 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.cq-ov-row > label { font-size: .8rem; font-weight: 700; }
.cq-ov-row.on { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.cq-ov-src { font-size: .74rem; color: var(--text-muted); line-height: 1.35; }
.cq-ov-row.on .cq-ov-src b { color: var(--accent); }
.cq-ctl-line { display: flex; gap: 6px; align-items: center; }
.cq-ctl-line > .input { flex: 1; min-width: 0; }
.cq-num { max-width: 100%; }

/* Empty editor */
.cq-empty { max-width: 560px; margin: 6vh auto; padding: 32px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.cq-empty-art { width: min(220px, 60%); height: auto; margin: 0 auto 8px; display: block; }
.cq-empty h2 { font: 800 1.4rem/1.2 var(--font-display); margin: 4px 0 8px; }
.cq-empty-line { font-size: .86rem; padding: 4px 0; list-style: none; }

/* --------------------------------------------------------------- aux sections */
.cq-section { padding: 14px 0; border-bottom: 1px solid var(--border); }
.cq-section:last-child { border-bottom: 0; }
.cq-section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.cq-section-head h3 { margin: 0; font: 800 1rem/1.2 var(--font-display); }
.cq-section > .field-help { margin: 0 0 12px; }
.cq-warn-line { color: var(--warning) !important; font-weight: 600; }
.cq-defaults-grid { display: grid; grid-template-columns: 1fr; gap: 2px; }
.cq-main.aux-wide .cq-defaults-grid { grid-template-columns: 1fr 1fr; column-gap: 16px; }
.cq-field-row { margin-bottom: 10px; }
.cq-range input[type="range"] { flex: 1; accent-color: var(--primary); }
.cq-range output { font: 700 .82rem/1 var(--font-mono); min-width: 3.2em; text-align: right; color: var(--text-muted); }
.cq-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0; }
.cq-toggle-label { font-weight: 700; font-size: .9rem; }

/* Modes */
.cq-cats { display: flex; flex-direction: column; gap: 10px; }
.cq-cat { padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); box-shadow: none; }
.cq-cat-head { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.cq-cat-name { font-weight: 800 !important; flex: 1; min-width: 0; }
.cq-opts { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.cq-opt { display: flex; align-items: center; gap: 6px; }
.cq-opt .input { flex: 1; min-width: 0; min-height: 32px; padding: .3em .6em; font-size: .88rem; }
.cq-color { width: 32px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: 8px; background: none; cursor: pointer; flex: none; }
.cq-color::-webkit-color-swatch-wrapper { padding: 3px; }
.cq-color::-webkit-color-swatch { border: 0; border-radius: 5px; }
.cq-color::-moz-color-swatch { border: 0; border-radius: 5px; }
.cq-opt-used { font: 600 .72rem/1 var(--font-mono); min-width: 2.6em; text-align: right; }

/* Rules */
.cq-cascade-help { font-size: .8rem; color: var(--text-muted); line-height: 1.45; margin-bottom: 12px; }
.cq-cascade-help p { margin: 0 0 6px; }
.cq-cascade-steps { margin: 0; padding-left: 1.3em; }
.cq-cascade-steps b { color: var(--text); }
.cq-rules { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.cq-rule {
  position: relative; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
}
.cq-rule.dragging { opacity: .5; }
.cq-rule.drop-before { box-shadow: 0 -3px 0 var(--primary); }
.cq-rule.drop-after { box-shadow: 0 3px 0 var(--primary); }
.cq-rule.flash { animation: cq-flash 1.2s ease-out; }
@keyframes cq-flash { 0%, 30% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 55%, transparent); } }
.cq-rule-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; min-width: 0; }
.cq-drag { cursor: grab; color: var(--text-muted); font-size: 1rem; padding: 0 2px; user-select: none; }
.cq-rule-idx { font: 800 .74rem/1 var(--font-mono); color: var(--text-muted); }
.cq-rule-title { font-weight: 800; font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.cq-spec { font-size: .6rem; letter-spacing: 1px; color: var(--primary); flex: none; }
.cq-rule-count { font: 600 .72rem/1 var(--font-mono); flex: none; }
.cq-rule-actions { display: flex; flex: none; }
.cq-rule-when, .cq-rule-then { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cq-rule-then { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border); align-items: flex-start; }
.cq-kw { font: 800 .7rem/1 var(--font-body); text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); min-width: 40px; padding-top: 2px; }
.cq-rule-then .cq-kw { padding-top: 10px; }
.cq-when-item { display: inline-flex; align-items: center; gap: 4px; padding: 2px 2px 2px 8px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.cq-when-item.set { border-color: color-mix(in srgb, var(--primary) 60%, var(--border)); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }
.cq-when-cat { font-size: .72rem; font-weight: 700; color: var(--text-muted); }
.cq-when-item select { border: 0 !important; background-color: transparent !important; box-shadow: none !important; min-height: 28px !important; padding-top: 2px !important; padding-bottom: 2px !important; font-weight: 700; width: auto; }
.cq-plus { font-weight: 800; color: var(--text-muted); }
.cq-sets { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 200px; }
.cq-noset { font-size: .82rem; padding-top: 8px; }
.cq-set-row { display: grid; grid-template-columns: minmax(80px, auto) 1fr auto; gap: 6px; align-items: center; }
.cq-set-label { font-size: .8rem; font-weight: 700; }
.cq-set-ctl { display: flex; gap: 4px; align-items: center; min-width: 0; }
.cq-set-ctl > .input { flex: 1; min-width: 0; min-height: 32px; padding-top: .3em; padding-bottom: .3em; font-size: .88rem; }
.cq-add-set { width: auto; margin-left: 46px; margin-top: 2px; color: var(--text-muted); font-weight: 700; }
.cq-sets + .cq-add-set { margin-left: auto; }

/* Matrix */
.cq-matrix-pick { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; font-size: .8rem; font-weight: 700; color: var(--text-muted); }
.cq-matrix-pick label { display: inline-flex; align-items: center; gap: 6px; }
.cq-matrix-pick select { width: auto; }
.cq-matrix-wrap { overflow-x: auto; }
.cq-matrix { border-collapse: separate; border-spacing: 4px; width: 100%; font-size: .78rem; }
.cq-matrix th, .cq-matrix td { border-radius: 10px; text-align: center; vertical-align: middle; }
.cq-mcorner { font-size: .7rem; color: var(--text-muted); font-weight: 800; padding: 6px; cursor: pointer; border: 1px dashed var(--border); }
.cq-mhead { padding: 6px 4px; cursor: pointer; border: 1px dashed transparent; }
.cq-mhead:hover, .cq-mcorner:hover { border-color: var(--primary); }
.cq-mhead.has-rule, .cq-mcorner.has-rule { border-style: solid; border-color: color-mix(in srgb, var(--primary) 50%, var(--border)); }
.cq-mcell {
  position: relative; padding: 8px 6px; cursor: pointer; min-width: 84px;
  background: var(--surface-2); border: 1px solid var(--border); transition: border-color .12s, transform .12s;
  display: table-cell;
}
.cq-mcell > span { display: block; }
.cq-mcell:hover, .cq-mcell:focus-visible { border-color: var(--primary); outline: none; transform: translateY(-1px); }
.cq-mcell.has-rule { background: color-mix(in srgb, var(--primary) 12%, var(--surface)); border-color: color-mix(in srgb, var(--primary) 55%, var(--border)); }
.cq-mcell.has-rule::before, .cq-legend-dot { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); display: inline-block; }
.cq-mcell.has-rule::before { position: absolute; top: 6px; left: 6px; }
.cq-m-pts { font: 800 1rem/1.1 var(--font-display); }
.cq-m-timer { font: 600 .74rem/1.3 var(--font-mono); color: var(--text); }
.cq-m-start { font-size: .66rem; color: var(--text-muted); }
.cq-m-count { position: absolute !important; top: 4px; right: 6px; font: 700 .62rem/1 var(--font-mono); color: var(--text-muted); }
.cq-matrix-legend { margin-top: 8px; display: block; }

/* Schedule & share */
.cq-open-mode { margin-bottom: 12px; }
.cq-schedule-at[hidden] { display: none; }
.cq-picks { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 8px; }
.cq-picks .btn { border: 1px solid var(--border); }
.cq-open-summary { margin: 8px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--primary-soft); font-weight: 700; font-size: .88rem; }
.cq-share-mini { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.cq-code-sm { font-size: 2rem !important; align-self: flex-start; }
.cq-share-rows { display: flex; flex-direction: column; gap: 6px; }
.cq-link-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px;
  padding: 6px 6px 6px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.cq-link-label { font-size: .74rem; font-weight: 800; color: var(--text-muted); white-space: nowrap; }
.cq-link-row code { font: 500 .78rem/1.3 var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: all; }
.cq-link-secret { border-color: color-mix(in srgb, var(--warning) 55%, var(--border)); }
.cq-share-empty p { margin: 0 0 10px; font-size: .9rem; color: var(--text-muted); }

/* Modal content */
.cq-modal { width: min(520px, 100%); }
.cq-modal-wide { width: min(640px, 100%); }
.cq-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.cq-modal-head h2 { margin: 0; font: 800 1.25rem/1.2 var(--font-display); }
.cq-modal-body p { line-height: 1.5; }
.cq-modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.cq-modal-backdrop.closing { opacity: 0; transition: opacity .15s; }
.cq-share { display: flex; flex-direction: column; gap: 10px; text-align: center; }
.cq-share .cq-link-row { text-align: left; }
.cq-share-lead { margin: 0; font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; }
.cq-code-big { align-self: center; font-size: clamp(2.4rem, 9vw, 4rem) !important; }
.cq-share-open { margin: 4px 0; font-weight: 700; }
.cq-draft-card { display: flex; justify-content: space-between; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.cq-shortcuts { width: 100%; border-collapse: collapse; }
.cq-shortcuts td { padding: 8px 4px; border-bottom: 1px solid var(--border); font-size: .9rem; }
.cq-shortcuts td:first-child { white-space: nowrap; width: 1%; padding-right: 16px; }

/* Toast fallback when theme.css hasn't styled it */
:where(#toast-root) { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
:where(.toast) { padding: .7em 1.1em; border-radius: 12px; background: #221d16; color: #fff8ec; box-shadow: var(--shadow-lg); }

/* --------------------------------------------------------------- responsive */
@media (max-width: 1280px) {
  .cq-main { grid-template-columns: 230px minmax(0, 1fr) 360px; }
}
@media (max-width: 1100px) {
  /* Tablet: questions list stays; editor and settings share the main column via the tab bar */
  .cq-main, .cq-main.aux-wide { grid-template-columns: 210px minmax(0, 1fr); }
  .cq-mobile-nav { display: flex; padding: 0 12px; background: var(--surface); }
  .cq-mobile-nav [data-view="list"] { display: none; }
  .cq-main > .cq-aux-pane { display: none; border-left: 0; }
  .cq-main[data-view="aux"] > .cq-editor-pane { display: none; }
  .cq-main[data-view="aux"] > .cq-aux-pane { display: flex; grid-column: 2; grid-row: 1; }
  .cq-widen { display: none; }
  .cq-main .cq-defaults-grid { grid-template-columns: 1fr 1fr; column-gap: 16px; }
}
@media (max-width: 900px) {
  .cq-body { height: auto; min-height: 100dvh; overflow: auto; grid-template-rows: auto auto auto 1fr; }
  .cq-topbar { position: relative; flex-wrap: wrap; }
  .topbar .cq-brand img.cq-logo-full { display: none !important; }
  .topbar .cq-brand img.cq-logo-mark { display: block; }
  .cq-hide-sm { display: none; }
  .cq-title-wrap { order: 3; flex-basis: 100%; flex-wrap: wrap; gap: 4px 10px; }
  .cq-top-actions { margin-left: auto; }
  .cq-mobile-nav { position: sticky; top: 0; z-index: 35; padding: 0; }
  .cq-mobile-nav [data-view] { display: inline-flex !important; flex: 1; justify-content: center; }
  .cq-main .cq-defaults-grid { grid-template-columns: 1fr; }
  .cq-main, .cq-main.aux-wide { display: block; }
  .cq-pane { overflow: visible; }
  .cq-main > .cq-pane { display: none; }
  .cq-main[data-view="list"] > .cq-list-pane,
  .cq-main[data-view="editor"] > .cq-editor-pane,
  .cq-main[data-view="aux"] > .cq-aux-pane { display: flex; }
  .cq-main[data-view="editor"] > .cq-editor-pane { display: block; }
  .cq-aux-pane { border: 0; overflow: visible; }
  .cq-aux-body { overflow: visible; }
  .cq-list-pane { border: 0; padding: 0 12px 20px; }
  .cq-editor-pane { padding: 14px 12px 40px; }
  .cq-panel { padding: 4px 14px 40px; }
  .cq-stage { max-height: none; }
  .cq-stage-question { font-size: clamp(13px, 4.6cqw, 30px); }
  .cq-resolved { justify-content: flex-start; }
  .cq-form { padding: 14px; }
  .cq-thumb-actions { opacity: 1; }
  .cq-set-row { grid-template-columns: 1fr auto; }
  .cq-set-label { grid-column: 1 / -1; }
  .cq-add-set { margin-left: 0; }
}

.cq-stage-answer-alt { font: 600 clamp(9px, 1.5cqw, 20px)/1.3 var(--font-body); opacity: .7; margin-top: .4cqw; }
