/* ==========================================================================
   Theme
   ========================================================================== */
:root {
  --bg-top: hsla(220, 40%, 6%, 1);
  --bg-bottom: hsla(220, 35%, 3%, 1);
  --text: #f1f5f9;
  --muted: rgba(255, 255, 255, .6);
  --accent: hsla(220, 70%, 65%, 1);
  --accent-hover: hsla(220, 70%, 75%, 1);
  --text-bright: #fff;                       /* text on solid buttons, editor caret */
  --text-faint: rgba(255, 255, 255, .35);    /* footer */
  --text-shadow: 0 2px 6px hsla(0, 0%, 0%, .4);

  --status-up: hsla(145, 65%, 50%, 1);
  --status-down: hsla(0, 78%, 62%, 1);
  --status-unknown: rgba(255, 255, 255, .4);
  --status-up-glow: 0 0 8px hsla(145, 65%, 50%, .6);
  --status-down-glow: 0 0 8px hsla(0, 78%, 62%, .6);
  --status-down-border: hsla(0, 78%, 62%, .35);

  --glass-bg: linear-gradient(180deg, hsla(220, 40%, 6%, .65) 0%, hsla(220, 40%, 6%, .4) 60%, hsla(220, 40%, 6%, .55) 100%);
  --glass-border: hsla(0, 0%, 100%, .08);
  --glass-highlight: inset 0 1px 0 hsla(0, 0%, 100%, .06);
  --glass-shadow: 0 10px 40px hsla(0, 0%, 0%, .45);
  --lift-shadow: 0 18px 50px hsla(0, 0%, 0%, .55);   /* a card being dragged */
  --bg-glow: hsla(220, 55%, 14%, .5);
  --glass-blur: blur(20px) saturate(120%);

  --pill-bg: hsla(220, 25%, 15%, .42);
  --pill-bg-hover: hsla(220, 25%, 25%, .58);

  --btn: hsla(220, 70%, 35%, 1);
  --btn-hover: hsla(220, 70%, 45%, 1);
  --btn-border: hsla(220, 55%, 25%, 1);
  --btn-shadow: inset 0 1px 0 hsla(0, 0%, 100%, .12), 0 4px 12px hsla(0, 0%, 0%, .25);
  --btn-shadow-hover: inset 0 1px 0 hsla(0, 0%, 100%, .18), 0 6px 16px hsla(220, 70%, 45%, .4);
  --ghost-shadow-hover: inset 0 1px 0 hsla(0, 0%, 100%, .18), 0 6px 16px hsla(0, 0%, 0%, .32);
  --tab-shadow: inset 0 1px 0 hsla(0, 0%, 100%, .12), 0 2px 8px hsla(0, 0%, 0%, .25);

  /* Destructive actions (delete, remove, replace everything) */
  --danger: hsla(0, 70%, 40%, 1);
  --danger-hover: hsla(0, 70%, 48%, 1);
  --danger-border: hsla(0, 60%, 30%, 1);
  --danger-shadow-hover: 0 6px 16px hsla(0, 78%, 50%, .35);

  /* Solid surfaces that sit above the glass */
  --surface-menu: hsla(220, 40%, 10%, 1);       /* <select> dropdown */
  --surface-dialog: hsla(220, 40%, 8%, .97);
  --surface-sidebar: hsla(220, 40%, 6%, .9);    /* File Studio file tree */
  --surface-code: hsla(220, 40%, 5%, .9);       /* File Studio editor */
  --surface-preview: #fff;                      /* page previews render on white, like a browser */
  --backdrop: hsla(220, 40%, 3%, .7);           /* behind dialogs */
  --backdrop-strong: hsla(220, 40%, 4%, .94);   /* behind the QR code */
  --drop-border: hsla(0, 0%, 100%, .18);        /* dashed file drop zone */
  --flash-bg: hsla(220, 55%, 14%, .65);
  --flash-border: hsla(220, 70%, 65%, .35);

  /* Printed QR codes: plain black text on white paper */
  --print-bg: #fff;
  --print-text: #000;
  --print-muted: #444;

  /* Quiz certificates: printed on white paper; the PDF (certificates.py) uses the same colours */
  --cert-paper: #fff;
  --cert-ink: #1a2233;
  --cert-muted: #5b6473;
  --cert-rule: #d0d5de;
  --cert-accent: #1b4498;
  --cert-gold: #b08d3c;
  --cert-shadow: 0 20px 60px hsla(0, 0%, 0%, .5);

  --swatch-rainbow: #f44, #fd4, #4d6, #4cf, #46f, #c4f, #f44;   /* "pick any colour" swatch */

  /* Syntax highlighting in File Studio */
  --code-comment: #6b7a90;
  --code-punctuation: #9fb0c8;
  --code-tag: #7db2ff;
  --code-attr: #7fd6c2;
  --code-string: #f3b07a;
  --code-number: #d6a1ff;
  --code-operator: #c9d4e6;
  --code-regex: #f08fa0;

  --mono: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ==========================================================================
   Base
   ========================================================================== */
* { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  min-height: 100%;
  background: var(--bg-bottom);
  overscroll-behavior-y: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  padding: 2rem;
  font-family: system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 50% 20%, var(--bg-glow) 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
  background-attachment: fixed;
  overscroll-behavior-y: none;
  animation: fadeIn .6s ease-out;
}

main { width: 100%; max-width: 44rem; margin: 0 auto; flex: 1; }
main.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-width: none;
  text-align: center;
}
main.center > * { width: 100%; max-width: 30rem; }

h1, h2, h3 { margin: .3em 0 .5em; text-shadow: var(--text-shadow); }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }

a { color: var(--accent); word-break: break-all; transition: color .2s; }
a:hover { color: var(--accent-hover); }
small { color: var(--muted); }

/* ==========================================================================
   Forms
   ========================================================================== */
label { display: block; color: var(--muted); font-size: .9rem; }

input[type=text],
input[type=email],
input[type=number],
input[type=datetime-local],
select,
textarea {
  width: 100%;
  margin: .3rem 0 1rem;
  padding: .7rem 1.1rem;
  border: 1px solid var(--glass-border);
  border-radius: 9999px;
  background: var(--pill-bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s, background-color .2s;
}
input[type=text]:focus,
input[type=email]:focus,
input[type=number]:focus,
input[type=datetime-local]:focus,
select:focus,
textarea:focus { border-color: var(--accent); background: var(--pill-bg-hover); }
input[type=datetime-local] { color-scheme: dark; font-family: inherit; }   /* dark calendar picker */
textarea { display: block; border-radius: 16px; font-family: inherit; line-height: 1.5; resize: vertical; }
button.sm, .btn.sm,
button.ghost.sm, .btn.ghost.sm { padding: .35rem .8rem; font-size: .85rem; }   /* beats the ghost size below */
button.icon.sm { padding: .3rem; }
select option { background: var(--surface-menu); color: var(--text); }

input[type=file] { max-width: 100%; margin: .3rem 0 1rem; color: var(--muted); }
input[type=file]::file-selector-button {
  margin-right: .75rem;
  padding: .5rem 1rem;
  border: 1px solid var(--glass-border);
  border-radius: 9999px;
  background: var(--pill-bg);
  color: var(--text);
  cursor: pointer;
}

/* File drop zone: a label wrapping an invisible full-size file input */
.drop {
  display: block;
  position: relative;
  margin: .3rem 0 1rem;
  padding: 1.75rem;
  border: 2px dashed var(--drop-border);
  border-radius: 20px;
  background: var(--pill-bg);
  color: var(--muted);
  text-align: center;
  transition: border-color .2s, background-color .2s;
}
.drop:hover { border-color: var(--accent); background: var(--pill-bg-hover); }
.drop input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }

.chk { display: flex; gap: .6rem; align-items: center; padding: .4rem 0; color: var(--text); font-size: 1rem; }
.chk input { width: auto; margin: 0; }

.inline { display: flex; gap: .5rem; }
.inline input { margin: 0; }

/* Link preview under a link-name field, and the live "available / taken" hint */
.url { margin: -.4rem 0 1rem; font-size: .85rem; color: var(--muted); word-break: break-all; }
.hint { min-height: 1.1em; margin: -.5rem 0 1rem; font-size: .85rem; }
.hint.ok { color: var(--status-up); }
.hint.bad { color: var(--status-down); }

/* ==========================================================================
   Buttons
   ========================================================================== */
button,
.btn {
  display: inline-block;
  padding: .7rem 1.5rem;
  border: 1px solid var(--btn-border);
  border-radius: 9999px;
  background: var(--btn);
  color: var(--text-bright);
  font-size: .95rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--btn-shadow);
  transition: background-color .2s, transform .2s, box-shadow .2s;
}
button:hover,
.btn:hover {
  background: var(--btn-hover);
  color: var(--text-bright);
  transform: translateY(-2px);
  box-shadow: var(--btn-shadow-hover);
}
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button svg, .btn svg { vertical-align: -3px; }

button.ghost,
.btn.ghost {
  padding: .55rem 1.1rem;
  border-color: var(--glass-border);
  background: var(--pill-bg);
  color: var(--text);
  font-size: .9rem;
  backdrop-filter: blur(10px) saturate(120%);
}
button.ghost:hover,
.btn.ghost:hover {
  background: var(--pill-bg-hover);
  box-shadow: var(--ghost-shadow-hover);
}

button.red { background: var(--danger); border-color: var(--danger-border); }
button.red:hover { background: var(--danger-hover); box-shadow: var(--danger-shadow-hover); }

button.icon,
.btn.icon { display: inline-flex; align-items: center; justify-content: center; padding: .6rem; line-height: 0; }
.btn.back svg { margin-right: .4rem; }

/* ==========================================================================
   Layout pieces
   ========================================================================== */
.nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
  padding: .65rem 1.4rem;
  border: 1px solid var(--glass-border);
  border-radius: 9999px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-highlight), var(--glass-shadow);
}
.nav a { color: var(--muted); text-decoration: none; transition: color .2s; }
.nav a:hover { color: var(--text); }

.tabs {
  display: flex;
  gap: .3rem;
  margin: 0 0 1rem;
  padding: .3rem;
  border: 1px solid var(--glass-border);
  border-radius: 9999px;
  background: var(--pill-bg);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: 1 0 auto;
  padding: .55rem 1.1rem;
  border-radius: 9999px;
  color: var(--muted);
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .2s, color .2s;
}
.tabs a:hover { color: var(--text); background: var(--pill-bg-hover); }
.tabs a.on {
  background: var(--btn);
  color: var(--text-bright);
  box-shadow: var(--tab-shadow);
}
.tabs .ct { margin-left: .4rem; font-size: .8em; opacity: .7; }

.card {
  margin: 1rem 0;
  padding: 1.5rem;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--glass-highlight), var(--glass-shadow);
}

.flash {
  margin: .75rem 0;
  padding: .75rem 1.1rem;
  border: 1px solid var(--flash-border);
  border-radius: 14px;
  background: var(--flash-bg);
  word-break: break-all;
  animation: fadeIn .4s ease-out;
}

/* Page heading with an action button on the right */
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; margin: .25rem 0 .9rem; }
.head h2 { margin: 0; }
.head button, .head .btn, .empty button { display: inline-flex; align-items: center; gap: .45rem; }
.btn .ct { font-size: .8em; opacity: .7; }

/* "Disable automatically" row under the published / disabled status */
.schedule { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--glass-border); }
.schedule label { margin-bottom: .3rem; }
.schedule .inline { flex-wrap: wrap; }
.schedule input[type=datetime-local] { flex: 1 1 13rem; width: auto; }

.split { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; }
.split h3 { margin: 0 0 .2rem; }

.acts { display: flex; flex-wrap: wrap; gap: .4rem; }
.acts form { margin: 0; }

.footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .35rem .75rem;
  margin-top: auto;
  padding: 1rem;
  color: var(--text-faint);
  font-size: .75rem;
  text-align: center;
}
.footer .sep { opacity: .4; }
.footer a { color: inherit; text-decoration: underline; }
.footer a:hover { color: var(--accent-hover); }

/* ==========================================================================
   Lists of pages / projects / users
   ========================================================================== */
.row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  padding: .8rem 0;
  border-top: 1px solid var(--glass-border);
}
.row:first-of-type { border-top: 0; }
.row.off .rmain > b,
.row.off .rmain > a { opacity: .5; }
.rmain { flex: 1 1 14rem; min-width: 0; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .6rem; margin-top: .35rem; }
.empty { color: var(--muted); text-align: center; }
.empty p { margin: .2rem 0 1rem; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .12rem .6rem;
  border: 1px solid var(--glass-border);
  border-radius: 9999px;
  background: var(--pill-bg);
  color: var(--text);
  font-size: .78rem;
  text-decoration: none;
  word-break: normal;
}
.pill svg { width: 13px; height: 13px; opacity: .8; }
a.pill:hover { background: var(--pill-bg-hover); color: var(--text); }
.pill.off { border-color: var(--status-down-border); }
.pill .dot { width: 7px; height: 7px; margin: 0; }

/* Status dot: green = published / active, red = disabled */
.dot {
  display: inline-block;
  flex-shrink: 0;
  width: 9px;
  height: 9px;
  margin-right: .5rem;
  border-radius: 50%;
  background: var(--status-unknown);
}
.dot.up { background: var(--status-up); box-shadow: var(--status-up-glow); animation: pulse 2.5s infinite; }
.dot.down { background: var(--status-down); box-shadow: var(--status-down-glow); }

/* ==========================================================================
   File list on the page screen
   ========================================================================== */
.ftree { margin-top: .75rem; }
.frow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .6rem;
  padding: .5rem 0 .5rem calc(var(--d, 0) * 1.1rem);
  border-top: 1px solid var(--glass-border);
}
.frow:first-child { border-top: 0; }
.frow svg { flex: 0 0 16px; }
.frow .fn { flex: 1 1 8rem; min-width: 0; word-break: break-all; }
.frow.dir { color: var(--muted); }
.frow small { white-space: nowrap; }
.frow .acts { flex: 0 0 auto; flex-wrap: nowrap; gap: .3rem; }
.frow .acts form { display: inline; }

/* Zip contents preview shown before uploading */
.ztree {
  max-height: 14rem;
  margin: 0 0 1rem;
  padding: .6rem .8rem;
  border: 1px solid var(--glass-border);
  border-radius: 14px;
  background: var(--pill-bg);
  font-size: .85rem;
  overflow: auto;
}
.zt-sum { margin-bottom: .4rem; color: var(--muted); }
.zt-row { padding: .08rem 0; word-break: break-all; }
.zt-dir { color: var(--muted); }
.zt-warn { margin-top: .5rem; color: var(--status-down); }

/* ==========================================================================
   Dialogs
   ========================================================================== */
dialog.dlg {
  width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  background: var(--surface-dialog);
  color: var(--text);
  box-shadow: var(--glass-shadow);
  overflow: auto;
}
dialog.dlg::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.dbody { padding: 1.5rem; }
.dh { display: flex; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
.dh h3 { margin: 0; }

/* The confirmation dialog that replaces the browser's confirm() */
dialog.dlg.confirm { width: min(26rem, calc(100vw - 2rem)); }
.confirm p { margin: .25rem 0 0; line-height: 1.5; color: var(--muted); word-break: break-word; }
.dfoot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* ==========================================================================
   QR code overlay
   ========================================================================== */
#qro {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--backdrop-strong);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: fadeIn .25s ease-out;
}
.qrbox { display: flex; flex-direction: column; align-items: center; gap: .5rem; max-width: 100%; text-align: center; }
.qrbox h2 { margin: 0 0 .5rem; font-size: 1.6rem; }
.qrbox .url { margin: .25rem 0 1rem; }
.qrbox .qr-colours { margin-top: .75rem; }
#qrc {
  width: min(78vmin, 30rem);
  height: auto;
  aspect-ratio: 1;
  border-radius: 16px;
  image-rendering: pixelated;
  box-shadow: var(--glass-shadow);
}
.qrx { position: absolute !important; top: 1rem; right: 1rem; }

/* ==========================================================================
   Page screen extras: broken links, access, storage
   ========================================================================== */
h3.sub { margin: 1.25rem 0 .25rem; font-size: 1rem; color: var(--muted); }
code { padding: .05rem .35rem; border-radius: 6px; background: var(--pill-bg); font: .85em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }

/* Broken-link warning inside the "Page contents" card */
.warn {
  margin: 1rem 0 .25rem;
  padding: .8rem 1rem;
  border: 1px solid var(--status-down-border);
  border-radius: 14px;
  background: var(--pill-bg);
}
.warn b { display: block; color: var(--status-down); }
.warn ul { margin: .5rem 0 .25rem; padding-left: 1.2rem; font-size: .88rem; line-height: 1.6; }

/* "Who can open it": the code field only matters when "access code" is picked */
.access-code { margin: .5rem 0 .75rem 1.6rem; }
#access:not(:has(input[value=code]:checked)) .access-code,
#access:not(:has(input[value=users]:checked, input[value=signed_in]:checked, input[value=invited]:checked)) .signed-in-only,
#access:not(:has(input[value=invited]:checked)) .invite-only { display: none; }
.invite-only { display: block; margin: .2rem 0 .6rem 1.6rem; }

/* Tables (form results) */
.table-wrap { padding: .5rem; overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.data th, table.data td { padding: .5rem .7rem; border-bottom: 1px solid var(--glass-border); text-align: left; vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
.nowrap { white-space: nowrap; }

/* Results: the list of responses, and the viewer that shows one response's answers */
table.responses tbody tr { cursor: pointer; transition: background-color .15s; }
table.responses tbody tr:hover, table.responses tbody tr.viewing { background: var(--pill-bg); }
table.responses td { vertical-align: middle; }
.cert-yes { color: var(--status-up); }
.cert-yes svg { vertical-align: -3px; }
.row-acts { display: flex; justify-content: flex-end; align-items: center; gap: .4rem; }
.row-acts form { margin: 0; }
dialog.dlg.response-viewer { width: min(40rem, calc(100vw - 2rem)); }
.response-viewer .dh { align-items: flex-start; }
.response-viewer .dh small { display: block; margin-top: .2rem; }
.rv-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem;
  margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--glass-border); }
.rv-score { margin: 0; font-size: 1.1rem; }
.rv-score b { font-size: 1.8rem; }
.rv-answers { margin: 0; }
.rv-answers dt { margin-top: 1rem; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.rv-answers dt:first-child { margin-top: 0; }
.rv-answers dd { margin: .25rem 0 0; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.rv-answers dd.right .rv-mark { color: var(--status-up); }
.rv-answers dd.wrong .rv-mark { color: var(--status-down); }
.rv-none { color: var(--text-faint); font-style: italic; }
.rv-nav { justify-content: space-between; position: sticky; bottom: 0; margin: 1.25rem -1.5rem -1.5rem;
  padding: .9rem 1.5rem; border-top: 1px solid var(--glass-border); background: var(--surface-dialog); }

/* Label-over-value facts (visitor details) */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .8rem 1.2rem; margin: .5rem 0 1rem; }
.facts small { display: block; margin-bottom: .15rem; }

/* Privacy policy / terms */
main.policy-page { max-width: 46rem; }
.policy h2 { margin: 1.4rem 0 .4rem; font-size: 1.15rem; }
.policy p, .policy li { color: var(--muted); line-height: 1.6; }
.policy ul { padding-left: 1.2rem; }
.policy-edit { margin-top: 1.2rem; }
.policy-edit textarea { font: var(--mono); }
.fine-print { margin: 1rem 0 0; }

/* Storage meter on the admin screen */
.meter { height: 6px; max-width: 18rem; margin-top: .4rem; border-radius: 9999px; background: var(--pill-bg); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 9999px; background: var(--accent); }
.meter.full span { background: var(--status-down); }

/* ==========================================================================
   Forms: shared header, builder, results
   ========================================================================== */
.tabs.sub { margin: .75rem 0 1rem; }
.form-status { margin: -.4rem 0 .25rem; }
.url-inline { word-break: break-all; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; margin-top: .75rem; }

/* Builder */
.builder-head .fb-title { margin: 0 0 .6rem; font-size: 1.3rem; font-weight: 600; }
.builder-head textarea { margin: 0; }
.builder-head .hint { display: block; margin: .5rem 0 0; color: var(--muted); }
.qcard { display: flex; flex-direction: column; gap: .7rem; padding: 1.1rem 1.2rem; }
.qcard input[type=text], .qcard select { margin: 0; }
.qtop { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.qtop .qlabel { flex: 1 1 14rem; font-weight: 600; }
.qtop .qkind { flex: 0 1 12rem; width: auto; }
.qcard .qhelp { font-size: .9rem; }
.qopts, .qpreview { display: flex; flex-direction: column; gap: .45rem; }

/* Drag handle and the card being dragged */
.grip {
  flex: 0 0 auto;
  padding: .35rem .2rem;
  border: 0;
  background: none;
  box-shadow: none;
  color: var(--muted);
  line-height: 0;
  cursor: grab;
  touch-action: none;   /* let the pointer drag instead of scrolling the page */
}
.grip:hover { background: none; color: var(--text); transform: none; box-shadow: none; }
.grip:focus-visible { outline: 2px solid var(--accent); border-radius: 6px; }
.qcard.dragging {
  position: relative;
  z-index: 5;
  border-color: var(--accent);
  background: var(--surface-dialog);   /* solid while lifted, so the card underneath doesn't show through */
  box-shadow: var(--glass-highlight), var(--lift-shadow);
  cursor: grabbing;
  user-select: none;
}
.qcard.dragging .grip { cursor: grabbing; }

/* Images in the builder */
.qimage { display: flex; flex-direction: column; align-items: flex-start; gap: .5rem; }
.qimage img { max-width: 100%; max-height: 16rem; border-radius: 12px; border: 1px solid var(--glass-border); }
.qpreview { flex-direction: row; flex-wrap: wrap; align-items: center; }
.qpreview input { flex: 1 1 14rem; }
.qpreview .qscale { width: auto; }
.qopt { display: flex; align-items: center; gap: .45rem; }
.qopt input { flex: 1; padding-top: .45rem; padding-bottom: .45rem; font-size: .95rem; }
.qmark { width: 1.4rem; color: var(--muted); text-align: center; }
.qopts > button { align-self: flex-start; display: inline-flex; align-items: center; gap: .35rem; }
button.is-correct { border-color: var(--status-up); color: var(--status-up); }
.qfoot { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding-top: .7rem; border-top: 1px solid var(--glass-border); }
.qfoot .chk { padding: 0; font-size: .9rem; }
.qpoints { display: flex; align-items: center; gap: .4rem; color: var(--muted); font-size: .9rem; }
.qpoints input { width: 5rem; margin: 0; padding: .35rem .7rem; }
.qtools { margin-left: auto; }
.fb-add button { display: inline-flex; align-items: center; gap: .45rem; }
/* Sections in the builder */
.qcard-section { border-top: 3px solid var(--accent); }
.qsection-no { color: var(--accent); font-size: .85rem; font-weight: 600; white-space: nowrap; }
.qafter { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; color: var(--muted); font-size: .9rem; }
.qcard select.qgoto { width: auto; max-width: 100%; padding-top: .35rem; padding-bottom: .35rem; font-size: .85rem; }
.qopt .qgoto { flex: 0 1 13rem; }
.warn-text { display: block; margin-top: -.6rem; color: var(--status-down); }

/* Page views */
.stats.views-stats { justify-content: flex-start; gap: 2.5rem; margin: .6rem 0 .9rem; text-align: left; }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 3.5rem; padding-bottom: 1px; border-bottom: 1px solid var(--glass-border); }
.spark span { flex: 1; min-height: 1px; border-radius: 3px 3px 0 0; background: var(--accent); }
#views .hint { display: block; margin-top: .6rem; color: var(--muted); }

/* Results */
.stats { display: flex; flex-wrap: wrap; justify-content: space-around; gap: 1rem; text-align: center; }
.stats b { display: block; font-size: 1.8rem; }
.bars { display: flex; flex-direction: column; gap: .45rem; margin-top: .8rem; }
.bar-row { display: grid; grid-template-columns: minmax(6rem, 14rem) 1fr auto; align-items: center; gap: .75rem; font-size: .9rem; }
.bar-label { overflow-wrap: anywhere; }
.bar { height: .7rem; border-radius: 9999px; background: var(--pill-bg); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 9999px; background: var(--accent); }
.bar-row.correct .bar span { background: var(--status-up); }
.bar-row.correct .bar-label::after { content: " ✓"; color: var(--status-up); }
.bar-count { white-space: nowrap; }
ul.answers { margin: .7rem 0 .3rem; padding-left: 1.2rem; line-height: 1.6; overflow-wrap: anywhere; }

/* The form people fill in */
main.form-page { max-width: 40rem; }
.fp-head h1 { margin-top: 0; }
.fp-desc { margin: 0 0 .5rem; color: var(--muted); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.req { color: var(--status-down); }
fieldset.fq { min-width: 0; }
.fq legend { float: left; width: 100%; margin-bottom: .5rem; padding: 0; font-weight: 600; font-size: 1.05rem; line-height: 1.4; }
.fq legend + * { clear: both; }
.fq-help { display: block; margin: -.25rem 0 .6rem; }
.fq input[type=text], .fq textarea, .fq select { margin: .2rem 0 0; }
.fq.has-error { border-color: var(--status-down-border); }
.fq-error { margin-top: .5rem; color: var(--status-down); font-size: .9rem; }
.scale { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .2rem; }
.scale label { position: relative; }
.scale input { position: absolute; opacity: 0; }
.scale span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.6rem;
  height: 2.6rem;
  border: 1px solid var(--glass-border);
  border-radius: 9999px;
  background: var(--pill-bg);
  color: var(--text);
  cursor: pointer;
}
.scale input:checked + span { background: var(--btn); border-color: var(--btn-border); color: var(--text-bright); }
.scale input:focus-visible + span { outline: 2px solid var(--accent); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.fq-img { display: block; max-width: 100%; max-height: 22rem; margin: 0 0 .8rem; border-radius: 12px; }
figure.fimg { margin: 1rem 0; padding: .8rem; text-align: center; }
figure.fimg img { display: block; max-width: 100%; max-height: 32rem; margin: 0 auto; border-radius: 12px; }
figure.fimg figcaption { margin-top: .6rem; color: var(--muted); font-size: .9rem; }
.fp-submit { justify-content: flex-end; text-align: right; }
.fp-section-head { border-top: 3px solid var(--accent); }
.fp-section-head h2 { margin: 0 0 .3rem; }
.score { margin: 0; font-size: 1.4rem; }
.score b { font-size: 2.6rem; }
.score + small { display: block; margin-bottom: 1rem; }
.cert-earned h2 { margin-top: 0; }
.cert-earned .acts { justify-content: center; margin: .6rem 0 .8rem; }

@media (max-width: 480px) {
  .two-col { grid-template-columns: 1fr; }
  table.responses .nowrap { white-space: normal; }
  table.responses .col-cert { display: none; }   /* the viewer has the certificate */
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-row .bar { grid-column: 1 / -1; grid-row: 2; }
}

/* ==========================================================================
   QR background colour picker (overlay and print-all page)
   ========================================================================== */
.qr-colours { display: flex; flex-wrap: wrap; justify-content: center; gap: .45rem; }
.swatch {
  position: relative;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 2px solid var(--glass-border);
  border-radius: 9999px;
  background: var(--swatch);
  box-shadow: none;
  cursor: pointer;
  overflow: hidden;
}
.swatch:hover { background: var(--swatch); transform: translateY(-2px); box-shadow: var(--ghost-shadow-hover); }
.swatch[aria-pressed=true] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.swatch.custom { background: conic-gradient(var(--swatch-rainbow)); }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.qr-note { display: block; max-width: 24rem; margin-top: .4rem; }
.qr-sheet-colours { margin-top: 1rem; text-align: center; }

/* ==========================================================================
   Print-all page: a preview grid on screen, one large code per sheet when printed
   ========================================================================== */
.qrsheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.qrcard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  padding: 1.1rem;
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  background: var(--glass-bg);
  box-shadow: var(--glass-highlight), var(--glass-shadow);
  text-align: center;
  word-break: break-word;
}
.qrcard small { word-break: break-all; }
.qrimg { width: 100%; max-width: 11rem; height: auto; border-radius: 14px; image-rendering: pixelated; }

/* ==========================================================================
   Quiz certificates: settings, the certificate (a sheet of A4 landscape), checking one
   ========================================================================== */
.cert-settings { margin-top: 1rem; padding-top: .8rem; border-top: 1px solid var(--glass-border); }
.cert-options { margin: .5rem 0 0 1.6rem; }
#certificate:not(:has(input[name=certificate]:checked)) .cert-options { display: none; }
.cert-options .two-col { row-gap: .9rem; }
.cert-options .two-col + label { margin-top: .9rem; }
.cert-warn { display: block; color: var(--status-down); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

main.cert-page { max-width: 64rem; }
.cert-page .cert-sheet + .cert-sheet { margin-top: 2rem; }   /* several on one page: print all */
.cert-count { margin: -.4rem 0 1rem; text-align: center; }
.cert-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin-bottom: 1.2rem; }

/* Sizes are in cqw (hundredths of the sheet's width), so the whole sheet scales like paper.
   They match the PDF, which is 842 points wide: 1pt = 0.119cqw. */
.cert-sheet {
  container-type: inline-size;
  box-sizing: border-box;
  aspect-ratio: 297 / 210;
  padding: 2.14%;   /* 18pt; a percentage of the width, like cqw */
  border-radius: 4px;
  background: var(--cert-paper);
  color: var(--cert-ink);
  box-shadow: var(--cert-shadow);
  font-family: "Times New Roman", Times, serif;
  text-align: center;
}
.cert-frame {
  position: relative;
  box-sizing: border-box;
  height: 100%;
  padding: 6.5cqw 6cqw 0;
  border: .36cqw solid var(--cert-accent);
}
.cert-frame::before {
  content: "";
  position: absolute;
  inset: .83cqw;
  border: max(1px, .1cqw) solid var(--cert-gold);
  pointer-events: none;
}
.cert-frame > p { overflow-wrap: anywhere; }
.cert-heading {
  margin: 0;
  color: var(--cert-accent);
  font-size: 4cqw;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-shadow: none;
}
.cert-rule { width: 14cqw; margin: 1.3cqw auto 3.9cqw; border-top: max(1px, .14cqw) solid var(--cert-gold); }
.cert-intro { margin: 0; color: var(--cert-muted); font-size: 1.9cqw; font-style: italic; }
.cert-name {
  width: 50cqw;
  margin: 2cqw auto 3cqw;
  padding-bottom: .9cqw;
  border-bottom: max(1px, .08cqw) solid var(--cert-rule);
  font-size: 4.75cqw;
  font-weight: 700;
  line-height: 1.15;
}
.cert-quiz { margin: 2cqw 0 0; color: var(--cert-accent); font: 700 2.6cqw/1.25 Arial, Helvetica, sans-serif; }
.cert-line { margin: .9cqw 0 0; color: var(--cert-muted); font: 1.54cqw/1.3 Arial, Helvetica, sans-serif; }
.cert-score { margin: 1.2cqw 0 0; font: 1.54cqw/1.3 Arial, Helvetica, sans-serif; }
.cert-foot {
  position: absolute;
  right: 5.9cqw;
  bottom: 2.4cqw;
  left: 5.9cqw;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  font-family: Arial, Helvetica, sans-serif;
}
.cert-date { width: 21.4cqw; margin-bottom: 1.5cqw; }
.cert-date b { display: block; padding-bottom: .5cqw; border-bottom: max(1px, .08cqw) solid var(--cert-rule); font-size: 1.54cqw; }
.cert-date span { display: block; margin-top: .4cqw; color: var(--cert-muted); font-size: 1.07cqw; }
.cert-verify {
  display: flex;
  align-items: center;
  gap: .6cqw;
  width: 30.9cqw;   /* 260pt, like the PDF */
  box-sizing: border-box;
  padding: .3cqw;
  border: max(1px, .1cqw) solid var(--cert-rule);
  background: var(--cert-paper);
  text-align: left;
}
.cert-qr { flex: none; width: 10.7cqw; height: auto; fill: var(--cert-ink); shape-rendering: crispEdges; }
.cert-qr .cert-qr-bg { fill: var(--cert-paper); }
.cert-verify b { display: block; font-size: 1.07cqw; }
.cert-verify .cert-code { display: block; margin: .5cqw 0; color: var(--cert-accent); font-size: 1.66cqw; }
.cert-code { font-family: ui-monospace, Consolas, "Courier New", monospace; font-weight: 700; letter-spacing: .03em; }
.cert-verify > div { min-width: 0; }
.cert-url { display: block; overflow: hidden; color: var(--cert-muted); font-size: .8cqw; white-space: nowrap; text-overflow: ellipsis; }

.cert-check { text-align: left; }
.cert-check-mark { margin: 0; color: var(--status-up); font-size: 2.6rem; line-height: 1; text-align: center; }
.cert-check > p { line-height: 1.5; }
.cert-facts { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; margin: 1rem 0; }
.cert-facts dt { color: var(--muted); }
.cert-facts dd { margin: 0; overflow-wrap: anywhere; }
.cert-check form { margin-top: .8rem; }

@page certificate { size: A4 landscape; margin: 0; }

@media print {
  @page { size: A4 portrait; margin: 15mm; }
  html, body { background: var(--print-bg); color: var(--print-text); }
  body { padding: 0; animation: none; }
  main { max-width: none; }
  .nav, .tabs, .flash, .footer, .no-print { display: none !important; }

  /* A certificate fills one sheet of A4 landscape, edge to edge */
  main.cert-page { max-width: none; }
  .cert-sheet {
    page: certificate;
    width: 297mm;
    height: 210mm;
    aspect-ratio: auto;
    border-radius: 0;
    box-shadow: none;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .cert-page .cert-sheet + .cert-sheet { margin-top: 0; }
  .cert-sheet:not(:last-of-type) { break-after: page; }
  canvas { print-color-adjust: exact; -webkit-print-color-adjust: exact; }   /* keep the chosen background */

  /* Print all: each code fills its own sheet */
  .qrsheet { display: block; margin: 0; }
  .qrcard {
    justify-content: center;
    gap: 6mm;
    height: 265mm;   /* A4 height minus the page margins */
    padding: 0;
    border: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    break-after: page;
  }
  .qrcard:last-child { break-after: auto; }
  .qrcard b { color: var(--print-text); font-size: 26pt; text-shadow: none; }
  .qrcard small { color: var(--print-muted); font-size: 12pt; }
  .qrimg { width: 150mm; max-width: 100%; border-radius: 0; }

  /* Print from the QR overlay: only that code, on one sheet */
  body.print-qr > *:not(#qro) { display: none !important; }
  body.print-qr { overflow: visible !important; }   /* the open overlay sets overflow: hidden */
  body.print-qr #qro {
    position: static;
    min-height: 265mm;
    padding: 0;
    background: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    animation: none;
  }
  body.print-qr #qro .qrx,
  body.print-qr #qro .acts,
  body.print-qr #qro .qr-colours,
  body.print-qr #qro .qr-note { display: none !important; }
  body.print-qr #qrt { color: var(--print-text); font-size: 26pt; text-shadow: none; }
  body.print-qr #qrc { width: 150mm; border-radius: 0; box-shadow: none; }
  body.print-qr #qrl { color: var(--print-muted); font-size: 12pt; }
}

/* ==========================================================================
   File Studio: file tree | code editor | live preview
   ========================================================================== */
dialog.dlg.studio { width: min(1500px, 98vw); height: min(94vh, 960px); max-height: none; overflow: hidden; }
dialog.dlg.studio[open] { display: flex; flex-direction: column; }

.sthead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  padding: .6rem .8rem;
  border-bottom: 1px solid var(--glass-border);
}
.sthead .hint { flex: 1 1 6rem; min-height: 0; margin: 0; }
.stn { max-width: 40%; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }

/* Pane switcher, only shown on narrow screens */
.sttabs { display: none; gap: .4rem; padding: .5rem .8rem; border-bottom: 1px solid var(--glass-border); }
.sttabs .on { background: var(--btn); color: var(--text-bright); }

.stbody { flex: 1; min-height: 0; display: grid; grid-template-columns: 15rem 1fr 1fr; }
.stpane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stpane + .stpane { border-left: 1px solid var(--glass-border); }

#stt { background: var(--surface-sidebar); overflow: hidden; }
.sthd {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .4rem .6rem;
  border-bottom: 1px solid var(--glass-border);
  color: var(--muted);
  font-size: .85rem;
}
#sttree { flex: 1; padding: .3rem 0; font-size: .88rem; overflow: auto; }

#sted {
  flex: 1;
  padding: .9rem 1rem;
  background: var(--surface-code);
  color: var(--text);
  caret-color: var(--text-bright);
  font: var(--mono);
  white-space: pre;
  tab-size: 2;
  outline: none;
  overflow: auto;
}
#stnote {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  color: var(--muted);
  text-align: center;
}
#stp { flex: 1; width: 100%; border: 0; background: var(--surface-preview); }

/* Tree rows */
.tn { display: flex; align-items: center; padding-left: calc(.35rem + var(--d, 0) * .9rem); }
.tn .tl {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .4rem;
  min-width: 0;
  padding: .28rem .35rem;
  border: 0;
  border-radius: 8px;
  background: none;
  box-shadow: none;
  color: var(--text);
  font-size: inherit;
  font-weight: 400;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.tn .tl:hover { background: var(--pill-bg-hover); color: var(--text); transform: none; box-shadow: none; }
.tn.on .tl { background: var(--btn); color: var(--text-bright); }
.tn.dir .tl { color: var(--muted); }
.tn svg { flex: 0 0 14px; }
.tn .sp { display: inline-block; flex: 0 0 14px; width: 14px; }
.tn .chev { transition: transform .15s; }
.tn.open .chev { transform: rotate(90deg); }

/* Rename / delete buttons appear on hover (always on touch screens) */
.tn .ta { display: none; gap: .1rem; padding-right: .3rem; }
.tn:hover .ta,
.tn:focus-within .ta,
.tn.on .ta { display: flex; }
@media (hover: none) { .tn .ta { display: flex; } }
.ta button { padding: .25rem; border: 0; border-radius: 6px; background: none; box-shadow: none; color: var(--muted); line-height: 0; }
.ta button:hover { background: var(--pill-bg-hover); color: var(--text); transform: none; box-shadow: none; }
input.tinput { width: calc(100% - .8rem); margin: .15rem .4rem; padding: .3rem .7rem; font-size: .85rem; }

/* Syntax highlighting (Prism token classes) */
#sted .token.comment, #sted .token.prolog, #sted .token.doctype, #sted .token.cdata { color: var(--code-comment); }
#sted .token.punctuation { color: var(--code-punctuation); }
#sted .token.tag, #sted .token.keyword, #sted .token.selector, #sted .token.important { color: var(--code-tag); }
#sted .token.attr-name, #sted .token.property, #sted .token.function, #sted .token.class-name { color: var(--code-attr); }
#sted .token.string, #sted .token.attr-value, #sted .token.char { color: var(--code-string); }
#sted .token.number, #sted .token.boolean, #sted .token.constant { color: var(--code-number); }
#sted .token.operator, #sted .token.entity, #sted .token.url { color: var(--code-operator); }
#sted .token.atrule, #sted .token.regex { color: var(--code-regex); }

/* Narrow screens: one pane at a time, picked with the tab bar */
@media (max-width: 800px) {
  .stbody { grid-template-columns: 1fr; }
  .stpane { display: none; }
  .stpane + .stpane { border-left: 0; }
  .sttabs { display: flex; }
  .stn { flex: 1 0 100%; max-width: 100%; }
  .stbody.p-files #stt,
  .stbody.p-code #stl,
  .stbody.p-prev #str2 { display: flex; }
}

/* ==========================================================================
   Animations and small screens
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: .85; }
  50% { transform: scale(1.06); opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 480px) {
  body { padding: 1rem; }
  .card { padding: 1.1rem; }
  .footer { flex-direction: column; gap: .3rem; }
  .footer .sep { display: none; }
}
