:root {
    --ed-bg: #f5f6f8;
    --ed-panel: #ffffff;
    --ed-ink: #1c2127;
    --ed-muted: #5d6874;
    --ed-line: #dde1e6;
    --ed-line-strong: #c3c9d0;
    --ed-soft: #eef1f4;
    --ed-accent: #2f5f98;
    --ed-accent-soft: #e8eff8;
    --ed-ok: #1d7a46;
    --ed-ok-soft: #e6f4ec;
    --ed-warn: #8a5a00;
    --ed-warn-soft: #fff4d6;
    --ed-err: #b42318;
    --ed-err-soft: #fdecea;
    --ed-radius: 8px;
    --ed-font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--ed-font); font-size: 15px; line-height: 1.45; color: var(--ed-ink); background: var(--ed-bg); }
h1, h2, h3, h4 { line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; background: var(--ed-soft); padding: 1px 5px; border-radius: 4px; }

.ed-skip { position: absolute; left: -9999px; }
.ed-skip:focus { left: 12px; top: 8px; z-index: 50; background: #fff; padding: 6px 10px; border-radius: 6px; }

/* Top bar */
.ed-top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: #1f2a37; color: #fff; }
.ed-brand { font-weight: 700; letter-spacing: 0.02em; }
.ed-status { font-size: 0.85rem; color: #b9c3cf; }
.ed-top-actions { margin-left: auto; display: flex; gap: 8px; }
.ed-top .ed-btn { background: transparent; color: #fff; border-color: #4a5868; }
.ed-top .ed-btn:hover { background: #2c3a4a; }

/* Shell */
.ed-shell { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: calc(100vh - 48px); }
.ed-side { border-right: 1px solid var(--ed-line); background: var(--ed-panel); padding: 16px 12px; overflow-y: auto; position: sticky; top: 48px; height: calc(100vh - 48px); }
.ed-main { padding: 24px 28px 64px; outline: none; min-width: 0; }
@media (max-width: 860px) {
    .ed-shell { grid-template-columns: 1fr; }
    .ed-side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--ed-line); }
    .ed-main { padding: 16px; }
}

.ed-side-group + .ed-side-group { margin-top: 20px; }
.ed-side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 6px 6px; }
.ed-side-head h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ed-muted); margin: 0; }
.ed-side-list { list-style: none; margin: 0; padding: 0; }
.ed-side-item { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px; background: none; cursor: pointer; }
.ed-side-item:hover { background: var(--ed-soft); }
.ed-side-item.is-active { background: var(--ed-accent-soft); box-shadow: inset 3px 0 0 var(--ed-accent); }
.ed-side-title { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-side-meta { display: block; font-size: 0.8rem; color: var(--ed-muted); }
.ed-side-empty { color: var(--ed-muted); font-size: 0.875rem; padding: 0 10px; margin: 4px 0; }

/* Buttons */
.ed-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--ed-line-strong); border-radius: 6px; background: var(--ed-panel); cursor: pointer; font-weight: 500; white-space: nowrap; }
.ed-btn:hover:not(:disabled) { background: var(--ed-soft); }
.ed-btn:focus-visible, .ed-input:focus-visible, .rte-area:focus-visible, .ed-side-item:focus-visible, .ed-qitem:focus-visible, .ed-tab:focus-visible, .ed-chip:focus-visible { outline: 3px solid color-mix(in srgb, var(--ed-accent) 45%, transparent); outline-offset: 1px; }
.ed-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ed-btn.is-primary { background: var(--ed-accent); border-color: var(--ed-accent); color: #fff; }
.ed-btn.is-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ed-accent) 85%, #000); }
.ed-btn.is-danger { background: var(--ed-err); border-color: var(--ed-err); color: #fff; }
.ed-btn.is-danger-text { color: var(--ed-err); }
.ed-btn.is-small { padding: 4px 10px; font-size: 0.85rem; }
.ed-btn.is-ghost { border-color: transparent; background: transparent; }
.ed-btn.is-ghost:hover:not(:disabled) { background: var(--ed-soft); }

/* Inputs */
.ed-field { margin: 0 0 14px; min-width: 0; }
.ed-label { display: block; font-weight: 600; font-size: 0.875rem; margin-bottom: 5px; }
.ed-help { color: var(--ed-muted); font-size: 0.82rem; margin: 5px 0 0; }
.ed-input { width: 100%; padding: 7px 10px; border: 1px solid var(--ed-line-strong); border-radius: 6px; background: #fff; min-height: 36px; }
select.ed-input { width: auto; max-width: 100%; }
.ed-num { width: 110px; }
.ed-title-input { font-size: 1.4rem; font-weight: 700; border-color: transparent; background: transparent; padding: 4px 8px; margin-left: -8px; }
.ed-title-input:hover { border-color: var(--ed-line); }
.ed-title-input:focus { background: #fff; border-color: var(--ed-line-strong); }
.ed-toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.ed-toggle input { width: 18px; height: 18px; accent-color: var(--ed-accent); }
.ed-toggle + .ed-help { margin-left: 26px; }
.ed-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ed-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.ed-grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 18px; }
.ed-grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 18px; align-items: start; }
.ed-badge { display: inline-block; font-size: 0.72rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--ed-soft); color: var(--ed-muted); }
.ed-tags { font-size: 0.75rem; color: var(--ed-muted); }
.ed-kicker { margin: 0; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ed-muted); }
.ed-meta { margin: 4px 0 0; color: var(--ed-muted); font-size: 0.85rem; }
.ed-list { margin: 0; padding-left: 1.2em; }
.ed-list li + li { margin-top: 6px; }

/* Rich text */
.rte { border: 1px solid var(--ed-line-strong); border-radius: 6px; background: #fff; }
.rte:focus-within { border-color: var(--ed-accent); }
.rte-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px; border-bottom: 1px solid var(--ed-line); background: #fafbfc; border-radius: 6px 6px 0 0; }
.rte-btn { border: 0; background: none; padding: 3px 8px; border-radius: 4px; font-size: 0.8rem; font-weight: 600; color: var(--ed-muted); cursor: pointer; min-width: 30px; }
.rte-btn:hover { background: var(--ed-soft); color: var(--ed-ink); }
.rte-area { min-height: 72px; padding: 8px 10px; outline: none; overflow-wrap: anywhere; }
.rte-area p { margin: 0 0 0.5em; }
.rte-area p:last-child { margin-bottom: 0; }
.rte-area img { max-width: 100%; max-height: 240px; height: auto; border-radius: 4px; }
.rte-single .rte-area { min-height: 0; padding: 6px 9px; }
.rte-area.is-empty::before { content: attr(data-placeholder); color: #98a1ab; pointer-events: none; position: absolute; }

/* Page head */
.ed-view { max-width: 1180px; }
.ed-pagehead { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 20px; margin-bottom: 18px; }
.ed-pagehead-main { flex: 1 1 360px; min-width: 0; }
.ed-pagehead-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Home */
.ed-home { max-width: 680px; }
.ed-home h1 { font-size: 2rem; margin: 8px 0 8px; outline: none; }
.ed-lede { font-size: 1.05rem; color: var(--ed-muted); }
.ed-steps { padding-left: 1.3em; }
.ed-steps li + li { margin-top: 6px; }
.ed-note { margin-top: 24px; padding: 12px 16px; border-radius: var(--ed-radius); background: var(--ed-panel); border: 1px solid var(--ed-line); color: var(--ed-muted); font-size: 0.9rem; }
.ed-note p { margin: 0; }

/* Bank */
.ed-bank { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 1100px) { .ed-bank { grid-template-columns: 1fr; } }
.ed-qlist-pane { background: var(--ed-panel); border: 1px solid var(--ed-line); border-radius: var(--ed-radius); padding: 12px; position: sticky; top: 64px; max-height: calc(100vh - 88px); display: flex; flex-direction: column; }
@media (max-width: 1100px) { .ed-qlist-pane { position: static; max-height: 360px; } }
.ed-qlist-head h2 { font-size: 0.9rem; margin: 0 0 8px; }
.ed-qlist-items { overflow-y: auto; flex: 1; margin: 0 -4px; padding: 0 4px; }
.ed-qlist { list-style: none; margin: 0; padding: 0; }
.ed-qitem { display: flex; gap: 10px; width: 100%; text-align: left; padding: 8px; border: 0; border-radius: 6px; background: none; cursor: pointer; }
.ed-qitem:hover { background: var(--ed-soft); }
.ed-qitem.is-active { background: var(--ed-accent-soft); box-shadow: inset 3px 0 0 var(--ed-accent); }
.ed-qitem-num { flex: none; width: 22px; color: var(--ed-muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; padding-top: 1px; }
.ed-qitem-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ed-qitem-text { font-size: 0.9rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ed-qitem-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ed-qlist-add { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 10px; border-top: 1px solid var(--ed-line); margin-top: 8px; }

.ed-qedit { background: var(--ed-panel); border: 1px solid var(--ed-line); border-radius: var(--ed-radius); padding: 20px 22px; min-width: 0; }
.ed-qform-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 14px; }
.ed-qform-head h2 { font-size: 1rem; margin: 0; }
.ed-qform-tools { display: flex; flex-wrap: wrap; gap: 4px; }
.ed-empty { text-align: center; padding: 32px 16px; color: var(--ed-muted); }
.ed-empty .ed-actions { justify-content: center; }

.ed-seg { border: 0; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.ed-seg legend { padding: 0; margin-bottom: 5px; }
.ed-seg-opt { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--ed-line-strong); border-radius: 6px; cursor: pointer; }
.ed-seg-opt:has(input:checked) { border-color: var(--ed-accent); background: var(--ed-accent-soft); font-weight: 600; }
.ed-seg-opt input { accent-color: var(--ed-accent); }

.ed-choices { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ed-choice { border: 1px solid var(--ed-line); border-radius: 6px; padding: 8px; background: #fcfcfd; }
.ed-choice.is-correct { border-color: var(--ed-ok); background: var(--ed-ok-soft); }
.ed-choice-main { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; }
@media (max-width: 720px) { .ed-choice-main { grid-template-columns: auto minmax(0, 1fr); } .ed-choice-tools { grid-column: 1 / -1; } }
.ed-choice-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 6px; padding-left: 52px; font-size: 0.85rem; }
.ed-inline-label { display: inline-flex; align-items: center; gap: 6px; color: var(--ed-muted); }
.ed-choice-sub select.ed-input { min-height: 30px; padding: 3px 8px; font-size: 0.85rem; }
.ed-correct { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.ed-correct input { width: 18px; height: 18px; accent-color: var(--ed-ok); }
.ed-letter { font-weight: 700; color: var(--ed-muted); width: 1.1em; }
.ed-choice-text .rte { background: #fff; }
.ed-choice-tools { display: flex; gap: 2px; }
.ed-choice-fb { margin-top: 8px; padding-left: 52px; }
.ed-choice-fb .ed-field { margin: 0; }

.ed-hints:empty { display: none; }
.ed-hints { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.ed-hint { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 8px 12px; border-radius: 6px; background: var(--ed-warn-soft); border-left: 3px solid var(--ed-warn); font-size: 0.875rem; }
.ed-hint p { margin: 0; }

.ed-details { margin: 6px 0 14px; border: 1px solid var(--ed-line); border-radius: 6px; padding: 0 12px; background: #fcfcfd; }
.ed-details > summary { cursor: pointer; padding: 9px 0; font-weight: 600; font-size: 0.9rem; }
.ed-details[open] { padding-bottom: 4px; }
.ed-details[open] > summary { margin-bottom: 8px; }

/* Quiz */
.ed-chip { border: 0; border-radius: 999px; padding: 3px 10px; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.ed-chip.is-ok { background: var(--ed-ok-soft); color: var(--ed-ok); }
.ed-chip.is-warn { background: var(--ed-warn-soft); color: var(--ed-warn); }
.ed-chip.is-error { background: var(--ed-err-soft); color: var(--ed-err); }
.ed-problems { background: var(--ed-panel); border: 1px solid var(--ed-line); border-radius: var(--ed-radius); padding: 10px 16px; margin-bottom: 16px; }
.ed-problems ul { margin: 0; padding-left: 1.2em; }
.ed-problems li { margin: 3px 0; }
.ed-problems .is-error, .ed-error { color: var(--ed-err); }
.ed-problems .is-warn { color: var(--ed-warn); }

.ed-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--ed-line); margin-bottom: 18px; }
.ed-tab { border: 0; background: none; padding: 9px 16px; font-weight: 600; color: var(--ed-muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.ed-tab:hover { color: var(--ed-ink); }
.ed-tab.is-active { color: var(--ed-accent); border-bottom-color: var(--ed-accent); }

.ed-settings, .ed-sections { max-width: 900px; }
.ed-group { background: var(--ed-panel); border: 1px solid var(--ed-line); border-radius: var(--ed-radius); padding: 14px 18px 4px; margin-bottom: 16px; }
.ed-group h3 { margin: 0 0 12px; font-size: 1rem; }

.ed-section-card { background: var(--ed-panel); border: 1px solid var(--ed-line); border-radius: var(--ed-radius); padding: 14px 18px 8px; margin-bottom: 16px; }
.ed-section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ed-subhead { margin: 6px 0 8px; font-size: 0.9rem; }
.ed-draws { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.ed-draw { display: grid; grid-template-columns: minmax(180px, 1.3fr) minmax(220px, 1.4fr) minmax(140px, 1fr) auto; gap: 10px; align-items: end; padding: 10px 12px; border-radius: 6px; background: var(--ed-soft); }
.ed-draw .ed-field { margin: 0; }
.ed-draw .ed-field > select.ed-input { width: 100%; }
.ed-draw .ed-row { flex-wrap: nowrap; }
.ed-draw .ed-row select.ed-input { width: auto; flex: none; }
.ed-avail { margin: 0; white-space: nowrap; }
@media (max-width: 900px) { .ed-draw { grid-template-columns: 1fr; } }
.ed-section-summary { font-weight: 600; color: var(--ed-ink); margin: 6px 0 12px; }

.ed-preview { max-width: 860px; }
.ed-preview-bar { margin-bottom: 12px; }
.ed-preview-frame { background: #fff; border: 1px dashed var(--ed-line-strong); border-radius: var(--ed-radius); padding: 24px; }

/* Dialog, toasts, dropzone */
.ed-dialog { border: 0; border-radius: 10px; padding: 22px 24px 18px; width: min(560px, calc(100vw - 32px)); box-shadow: 0 18px 50px rgba(15, 23, 32, 0.28); }
.ed-dialog::backdrop { background: rgba(20, 28, 38, 0.45); }
.ed-dialog-title { margin: 0 0 10px; font-size: 1.15rem; }
.ed-dialog-actions { display: flex; flex-direction: row-reverse; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.ed-dialog-preview { max-height: 70vh; overflow-y: auto; }
.ed-dialog:has(.ed-dialog-preview) { width: min(820px, calc(100vw - 32px)); }

.ed-toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.ed-toast { background: #1f2a37; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); max-width: 380px; transition: opacity 0.4s; }
.ed-toast.is-error { background: var(--ed-err); }
.ed-toast.is-out { opacity: 0; }

.ed-dropzone { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: rgba(47, 95, 152, 0.18); border: 4px dashed var(--ed-accent); pointer-events: none; }
.ed-dropzone p { background: #fff; padding: 14px 22px; border-radius: 10px; font-weight: 600; }
.ed-dropzone[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Fill in the blanks */
.ed-spacer { flex: 1; }
.ed-blank-tools { margin-bottom: 6px; }
.ed-blank-tools .ed-help { margin: 0; flex: 1 1 260px; }
.ed-blank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ed-blank { border: 1px solid var(--ed-line); border-radius: 6px; padding: 8px 12px 2px; background: #fcfcfd; }
.ed-blank-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.ed-blank-tag { font-weight: 700; font-size: 0.875rem; }
.ed-blank-head select.ed-input { min-height: 30px; padding: 3px 8px; font-size: 0.875rem; }
.ed-blank-body textarea.ed-input { resize: vertical; font-family: inherit; }
.ed-blank-body .ed-num { width: 120px; }

/* Sort the list */
.ed-help-top { margin: 0 0 8px; }
.ed-sort-items { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ed-sort-item { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 8px; align-items: center; border: 1px solid var(--ed-line); border-radius: 6px; padding: 8px; background: #fcfcfd; }
.ed-sort-num { font-weight: 700; color: var(--ed-muted); text-align: center; }

/* Match and categorise */
.ed-pairs, .ed-extras, .ed-groups, .ed-cards { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ed-pair-head { display: grid; grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr) 170px; gap: 8px; font-size: 0.8rem; font-weight: 600; color: var(--ed-muted); margin-bottom: 4px; }
.ed-pair { display: grid; grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: center; border: 1px solid var(--ed-line); border-radius: 6px; padding: 8px; background: #fcfcfd; }
.ed-extra { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.ed-group-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 8px; align-items: center; border: 1px solid var(--ed-line); border-radius: 6px; padding: 8px; background: #fcfcfd; }
.ed-card-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) minmax(150px, 220px) auto; gap: 8px; align-items: center; border: 1px solid var(--ed-line); border-radius: 6px; padding: 8px; background: #fcfcfd; }
.ed-card-row select.ed-input { width: 100%; }
@media (max-width: 760px) {
    .ed-pair, .ed-card-row { grid-template-columns: 28px minmax(0, 1fr); }
    .ed-pair > :nth-child(3), .ed-pair > .ed-choice-tools, .ed-card-row > select, .ed-card-row > .ed-btn { grid-column: 2; }
    .ed-pair-head { display: none; }
}

/* Range slider */
.ed-range-summary { margin: 0 0 16px; padding: 8px 12px; border-radius: 6px; background: var(--ed-soft); color: var(--ed-ink); font-weight: 500; }
