:root {
  --color-bg: #f5f5f7;
  --color-surface: #ffffff;
  --color-surface-alt: #fafafb;
  --color-text: #1d1d1f;
  --color-muted: #6b6b70;
  --color-accent: #c43e1c;
  --color-accent-text: #ffffff;
  --color-border: #e2e2e6;
  --color-success: #1e7f4f;
  --color-success-bg: #e6f4ec;
  --color-error: #b3261e;
  --color-error-bg: #fbe9e7;
  --color-warning: #8a5a00;
  --color-warning-bg: #fff4dc;
  --color-zone: #2563eb;
  --color-zone-correct: #16a34a;
  --radius: 8px;
  --gutter: 16px;
  --max-width: 1100px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #151517;
    --color-surface: #1f1f22;
    --color-surface-alt: #26262a;
    --color-text: #ececef;
    --color-muted: #a0a0a8;
    --color-accent: #ff7a50;
    --color-accent-text: #1a0d08;
    --color-border: #333338;
    --color-success: #6fd39d;
    --color-success-bg: #173226;
    --color-error: #ff8a80;
    --color-error-bg: #3a1a18;
    --color-warning: #ffcc66;
    --color-warning-bg: #3a2e12;
    --color-zone: #60a5fa;
    --color-zone-correct: #4ade80;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a { color: var(--color-accent); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.95em; }
.muted { color: var(--color-muted); }
.hint { color: var(--color-muted); font-size: 0.8rem; margin: 2px 0 8px; }

/* ------------------------------------------------------------------ layout */

.site-header,
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px var(--gutter);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.site-footer {
  border-bottom: 0;
  border-top: 1px solid var(--color-border);
  color: var(--color-muted);
  font-size: 0.875rem;
}
.site-footer p { margin: 0; }

.site-logo { font-weight: 700; text-decoration: none; color: var(--color-text); }

.site-nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 0.95rem; }
.site-nav a { text-decoration: none; }
.nav-user { color: var(--color-muted); }
.inline-form { display: inline; margin: 0; }
.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--color-accent); cursor: pointer; }

.lang-switch a { margin-left: 6px; color: var(--color-muted); }
.lang-switch a[aria-current="true"] { color: var(--color-accent); font-weight: 700; }

.site-main {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 28px var(--gutter);
}
.page-wide .site-main { max-width: 1600px; }

.hero h1 { font-size: clamp(1.75rem, 4vw, 2.75rem); line-height: 1.15; margin: 0 0 16px; }
.hero p { max-width: 60ch; color: var(--color-muted); font-size: 1.125rem; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }

/* ------------------------------------------------------------------ components */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.form-card { max-width: 440px; margin: 0 auto; }
.form-card form { display: flex; flex-direction: column; gap: 14px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; font-weight: 500; }
label.check, .checks label, .role-picker label { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  font: inherit;
  font-weight: 400;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface-alt);
  color: var(--color-text);
  width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

fieldset { border: 1px solid var(--color-border); border-radius: 6px; padding: 10px 12px; margin: 0 0 12px; }
legend { font-size: 0.85rem; font-weight: 600; padding: 0 4px; }
.role-picker { display: flex; gap: 20px; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-row > label { flex: 1 1 120px; }
.form-row > label.grow { flex: 3 1 240px; }
.form-row.checks { margin-top: 12px; align-items: center; }
.form-row.checks > label { flex: 0 0 auto; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--color-accent);
  border-radius: 6px;
  background: var(--color-accent);
  color: var(--color-accent-text);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.button:disabled { opacity: 0.6; cursor: progress; }
.button-small { padding: 5px 10px; font-size: 0.85rem; }
.button-secondary { background: transparent; color: var(--color-accent); }
.button-danger { background: transparent; color: var(--color-error); border-color: var(--color-error); }
.button[aria-pressed="true"] { background: var(--color-accent); color: var(--color-accent-text); }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; background: var(--color-surface); border: 1px solid var(--color-border); }
.flash-success { background: var(--color-success-bg); color: var(--color-success); border-color: transparent; }
.flash-error { background: var(--color-error-bg); color: var(--color-error); border-color: transparent; }
.flash-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: transparent; }

.toast {
  position: fixed; right: 16px; bottom: 16px; z-index: 1000;
  max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 6px;
  background: var(--color-text); color: var(--color-bg);
  box-shadow: var(--shadow);
}
.toast-error { background: var(--color-error); color: #fff; }
.toast-success { background: var(--color-success); color: #fff; }

.badge, .tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
  background: var(--color-surface-alt); color: var(--color-muted); border: 1px solid var(--color-border);
}
.badge-on { background: var(--color-success-bg); color: var(--color-success); border-color: transparent; }
.badge-off { background: var(--color-error-bg); color: var(--color-error); border-color: transparent; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table th, .data-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
.data-table th { font-size: 0.8rem; color: var(--color-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.data-table tr.is-current td { background: var(--color-surface-alt); }
.data-table .actions { display: flex; gap: 6px; justify-content: flex-end; }

.upload-form, .join-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.upload-form input[type="file"] { flex: 1 1 240px; }
.code-input { max-width: 200px; text-transform: uppercase; letter-spacing: 0.2em; font-family: ui-monospace, Consolas, monospace; }

/* ------------------------------------------------------------------ slides */

.slide {
  position: relative;
  width: 100%;
  overflow: hidden;
  container-type: inline-size;
  color: #000;
  line-height: 1.2;
  font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif;
  user-select: none;
}
.el { position: absolute; display: flex; }
.el-text-body { display: flex; flex-direction: column; width: 100%; height: 100%; overflow: hidden; }
.el-text-body p { margin: 0; overflow-wrap: break-word; }
.el-bullet { display: inline-block; width: 2cqw; text-indent: 0; }
.el-image img, .el-video img { width: 100%; height: 100%; object-fit: fill; display: block; pointer-events: none; }
.el-video video, .el-video iframe { width: 100%; height: 100%; border: 0; background: #000; }
.el-audio { align-items: flex-end; }
.el-audio audio { width: 100%; min-width: 200px; }
.el-media-badge {
  position: absolute; inset: 0; margin: auto; width: 6cqw; height: 6cqw; border-radius: 50%;
  display: grid; place-items: center; font-size: 3cqw; color: #fff; background: rgba(0, 0, 0, 0.55);
}
.el-media-link { margin: auto; background: #fff; padding: 0.5cqw 1cqw; border-radius: 0.5cqw; font-size: 1.4cqw; }
.el-table { width: 100%; height: 100%; border-collapse: collapse; table-layout: fixed; }
.el-table td { border: 0.08cqw solid #7f7f7f; padding: 0.4cqw 0.6cqw; vertical-align: top; }
.el-table td p { margin: 0; }
video.is-broken { outline: 3px dashed var(--color-error); }

/* Zones in the editor */
.slide-edit .el { cursor: pointer; }
.slide-edit .el:hover, .slide-edit .el.is-selected { outline: 2px dashed var(--color-accent); outline-offset: 1px; }
.slide-edit .zone {
  position: absolute; z-index: 5000;
  border: 2px solid var(--color-zone);
  background: color-mix(in srgb, var(--color-zone) 14%, transparent);
  cursor: pointer;
}
.slide-edit .zone-correct { border-color: var(--color-zone-correct); background: color-mix(in srgb, var(--color-zone-correct) 18%, transparent); }
.zone-label {
  position: absolute; left: 0; top: 0; opacity: 0.9;
  background: var(--color-zone); color: #fff; font: 600 11px/1.4 system-ui, sans-serif;
  padding: 0 5px; border-radius: 0 0 4px 0; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.zone-correct .zone-label { background: var(--color-zone-correct); }
.slide.is-drawing, .slide.is-drawing .el { cursor: crosshair; }
.draw-rect { position: absolute; z-index: 6000; border: 2px dashed var(--color-accent); background: color-mix(in srgb, var(--color-accent) 12%, transparent); }

/* Zones in the exam */
.slide-exam .zone { position: absolute; z-index: 5000; }
.slide-exam .zone-option, .slide-exam .zone-button-next, .slide-exam .zone-button-prev {
  border: 2px solid transparent; background: transparent; cursor: pointer; padding: 0; border-radius: 4px;
}
.slide-exam .zone-option:hover, .slide-exam .zone-button-next:hover, .slide-exam .zone-button-prev:hover {
  border-color: color-mix(in srgb, var(--color-zone) 60%, transparent);
  background: color-mix(in srgb, var(--color-zone) 8%, transparent);
}
.slide-exam .zone-option[aria-pressed="true"] {
  border: 3px solid var(--color-zone);
  background: color-mix(in srgb, var(--color-zone) 18%, transparent);
}
.slide-exam .zone-option:disabled { cursor: default; }
.slide-exam .zone-answer-input {
  resize: none; border: 2px solid var(--color-zone); border-radius: 4px;
  background: rgba(255, 255, 255, 0.92); color: #000; padding: 0.4cqw 0.8cqw; font-family: inherit;
}

/* ------------------------------------------------------------------ editor */

.editor-head { padding: 16px 20px; }
.publish-row { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--color-border); align-items: center; }
.access-code { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.15em; }

.editor-body { display: grid; grid-template-columns: 170px minmax(0, 1fr) 320px; gap: 16px; align-items: start; }

.slide-list { display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 140px); overflow-y: auto; position: sticky; top: 12px; padding: 2px; }
.slide-thumb {
  flex-shrink: 0;
  display: block; position: relative; text-decoration: none; color: var(--color-text);
  border: 2px solid var(--color-border); border-radius: 6px; overflow: hidden; background: var(--color-surface);
}
.slide-thumb.is-current { border-color: var(--color-accent); }
.slide-thumb .slide { pointer-events: none; }
.slide-thumb-number {
  position: absolute; left: 4px; top: 4px; z-index: 9999;
  background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 11px; padding: 0 6px; border-radius: 4px;
}
.slide-thumb-tags { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px; min-height: 8px; }
.slide-thumb-tags .tag { font-size: 10px; }

.editor-stage { position: relative; min-width: 0; }
.stage-toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.stage-help { font-size: 0.85rem; }
.stage-frame { border: 1px solid var(--color-border); box-shadow: var(--shadow); background: #fff; }

.role-menu {
  position: absolute; z-index: 7000;
  display: flex; flex-direction: column; gap: 6px; min-width: 200px;
  padding: 10px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
}
.role-menu[hidden] { display: none; }
.role-menu-title { margin: 0 0 4px; font-size: 0.8rem; color: var(--color-muted); font-weight: 600; }

.editor-side .card { padding: 16px; }
.slide-form { display: flex; flex-direction: column; gap: 10px; }
.slide-form .form-row > label { flex: 1 1 70px; }
.zone-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--color-border); }
.zone-row:last-child { border-bottom: 0; }
.zone-row > strong { flex: 1 1 100%; font-size: 0.85rem; }
.zone-row input[type="text"] { flex: 1 1 120px; width: auto; }
.zone-row .points { flex-direction: row; align-items: center; gap: 6px; }
.zone-row .points input { width: 80px; }
.zone-row-actions { display: flex; gap: 6px; margin-left: auto; }
.zone-row.is-flash { background: var(--color-warning-bg); }

/* ------------------------------------------------------------------ exam */

.exam { max-width: 1200px; margin: 0 auto; }
.exam-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.exam-head h1 { margin: 0; }
.exam-timer { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; }
.exam-timer[hidden] { display: none; }
.exam-timer-bar { width: 140px; height: 6px; border-radius: 3px; background: var(--color-border); overflow: hidden; }
.exam-timer-bar > span { display: block; height: 100%; background: var(--color-accent); transition: width 0.25s linear; }
.exam-timer.is-low { color: var(--color-error); }
.exam-timer.is-low .exam-timer-bar > span { background: var(--color-error); }
.exam-toolbar { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.exam-toolbar[hidden] { display: none; }
.exam-hint { flex: 1; text-align: center; font-size: 0.9rem; }
.exam-toolbar [data-action="next"] { margin-left: auto; }
.exam-finished { text-align: center; padding: 40px 20px; }
.exam-finished-score { font-size: 1.6rem; font-weight: 700; }

/* ------------------------------------------------------------------ bottom bar inside the slide */

/* Editor: strip the author must keep free */
.slide-reserved {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4999;
  display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(135deg, rgba(196, 62, 28, 0.10) 0 8px, rgba(196, 62, 28, 0.20) 8px 16px);
  border-top: 1px dashed var(--color-accent);
  pointer-events: none;
}
.slide-reserved span { font: 600 clamp(9px, 1.1cqw, 13px)/1 system-ui, sans-serif; color: var(--color-accent); background: rgba(255, 255, 255, 0.85); padding: 2px 6px; border-radius: 3px; }
.slide-thumb .slide-reserved span { display: none; }

/* Exam: time slider + clock + slide counter */
.exam-bar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6000;
  display: flex; align-items: center; gap: 1.5cqw;
  padding: 0 2cqw;
  background: rgba(20, 20, 24, 0.82);
  color: #fff;
  font: 600 1.6cqw/1 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
.exam-bar-time { flex: 1; height: 0.9cqw; min-height: 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.25); overflow: hidden; }
.exam-bar-time.is-untimed { visibility: hidden; }
.exam-bar-fill { display: block; height: 100%; width: 100%; background: #4ade80; transition: width 0.1s linear; }
.exam-bar.is-low .exam-bar-fill { background: #f87171; }
.exam-bar.is-low .exam-bar-clock { color: #fca5a5; }
.exam-bar-clock:empty { display: none; }
.exam-bar-count { white-space: nowrap; }

/* ------------------------------------------------------------------ accounts, groups, subjects */

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--color-border); }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--color-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a[aria-selected="true"] { color: var(--color-accent); border-bottom-color: var(--color-accent); }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1, .page-head h2 { margin: 0; }
.inline-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline-row input[type="text"], .inline-row input[type="tel"], .inline-row select { width: auto; flex: 1 1 200px; }
.inline-label { flex-direction: row; align-items: center; gap: 8px; }
.inline-label input { width: 90px; }
.filters select { flex: 0 1 220px; }
.two-columns { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; }
.two-columns .card { margin-bottom: 0; }
.two-columns + .card { margin-top: 20px; }
.check-list { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 8px; }
.check-list small { display: block; }
.data-table tr.is-disabled td { opacity: 0.5; }
.danger-zone { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--color-border); }

.verify-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.verify-grid .card { margin-bottom: 0; }
.wa-code { font: 700 2.4rem/1.1 ui-monospace, Consolas, monospace; letter-spacing: 0.15em; margin: 8px 0; color: var(--color-accent); }

.subject-row {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 8px 0 8px calc(var(--depth, 0) * 24px);
  border-bottom: 1px solid var(--color-border);
}
.subject-row:last-child { border-bottom: 0; }
.subject-row input[type="text"] { flex: 2 1 160px; width: auto; }
.subject-row select { flex: 1 1 160px; width: auto; }

.test-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.test-card { border: 1px solid var(--color-border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--color-surface-alt); }
.test-card h3 { margin: 0; font-size: 1rem; }
.test-card p { margin: 0; }
.test-card form, .test-card .button, .test-card .badge { margin-top: auto; align-self: flex-start; }

.legal { max-width: 820px; margin: 0 auto; }
.legal h2 { margin-top: 24px; }
.legal-note { margin-top: 24px; font-size: 0.85rem; color: var(--color-muted); }
.footer-note { font-size: 0.75rem; flex-basis: 100%; }

@media print {
  body.print-credentials * { visibility: hidden; }
  body.print-credentials .credentials, body.print-credentials .credentials * { visibility: visible; }
  body.print-credentials .credentials { position: absolute; inset: 0; box-shadow: none; border: 0; }
  body.print-credentials .credentials .flash, body.print-credentials .credentials .inline-row { display: none; }
}

/* ------------------------------------------------------------------ responsive */

@media (max-width: 900px) {
  .two-columns { grid-template-columns: minmax(0, 1fr); }
  .two-columns .card + .card { margin-top: 20px; }
}
@media (max-width: 1100px) {
  .editor-body { grid-template-columns: minmax(0, 1fr); }
  .slide-list { flex-direction: row; max-height: none; position: static; overflow-x: auto; }
  .slide-thumb { flex: 0 0 150px; }
}
@media (max-width: 600px) {
  .card { padding: 14px; }
  .exam-hint { display: none; }
  .data-table .actions { flex-direction: column; align-items: stretch; }
}

/* ------------------------------------------------------------------ demo template */
.demo { margin-top: 32px; }
.demo-contents { margin: 0 0 8px; padding-left: 22px; color: var(--color-muted); }
.demo-contents li { margin-bottom: 4px; }

/* ------------------------------------------------------------------ layout catalog */
.layouts-page { max-width: 1300px; margin: 0 auto; }
.lead { font-size: 1.05rem; color: var(--color-muted); max-width: 80ch; }
.steps { padding-left: 22px; margin: 0 0 16px; }
.steps li { margin-bottom: 6px; }
.layout-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.layout-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.layout-preview { position: relative; aspect-ratio: 16 / 9; background: #fff; border-bottom: 1px solid var(--color-border); container-type: inline-size; font-family: system-ui, sans-serif; }
.lp-question { position: absolute; left: 4%; top: 4%; font-size: 4.2cqw; font-weight: 700; color: #9a9aa2; }
.lp-code { position: absolute; right: 2.5%; top: 3%; font: 600 3cqw/1 ui-monospace, Consolas, monospace; color: #6b6b70; }
.lp-rect { position: absolute; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 3.4cqw; color: #6b6b70; border: 0.45cqw dashed; padding: 1cqw; overflow: hidden; }
.lp-media { background: #e6f1fb; border-color: #4a90d9; }
.lp-answer { background: #fff2e2; border-color: #e8963c; font-weight: 700; }
.lp-reserved { position: absolute; left: 0; right: 0; bottom: 0; background: repeating-linear-gradient(135deg, rgba(196, 62, 28, 0.08) 0 6px, rgba(196, 62, 28, 0.16) 6px 12px); }
.layout-info { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; }
.layout-info h3 { margin: 0; font-size: 1rem; }
.layout-info p { margin: 0; font-size: 0.9rem; }
.layout-info .tag { align-self: flex-start; margin-top: 4px; }
.layout-code code { font-weight: 700; color: var(--color-accent); }
