/* Captain Study — the payonline / captain_builders design system: near-black
   ground with accent glows, Manrope, pill nav chips, gradient CTA. Two
   themes: dark (default in the builder dashboard) and light (default on the
   participant platform), switched via <html data-theme="light|dark">. The
   accent color is overridden per brand by JS (--accent / --accent-2). */

:root {
  --background: #0a0a0b;
  --foreground: #ffffff;
  --card: #151517;
  --muted: #1f1f1f;
  --muted-foreground: #9a9aa3;
  --border: #2a2a2e;
  --primary: #ffffff;
  --primary-foreground: #0a0a0b;
  --accent: #e60165;
  --accent-2: #8000db;
  --ring: var(--accent);
  --danger: #ff4d6d;
  --success: #35d073;
  --warn: #ffb020;
  --radius: 0.625rem;
  --doc-fg: rgba(255, 255, 255, 0.88);
  --callout-bg: #232326;
  --code-bg: #1b1b1e;
  --inline-code: #ff6b6b;
  color-scheme: dark;
}
[data-theme="light"] {
  --background: #f7f7f9;
  --foreground: #16161a;
  --card: #ffffff;
  --muted: #ececf0;
  --muted-foreground: #63636e;
  --border: #dcdce2;
  --primary: #16161a;
  --primary-foreground: #ffffff;
  --doc-fg: rgba(22, 22, 26, 0.9);
  --callout-bg: #f1f1f4;
  --code-bg: #f1f1f4;
  --inline-code: #c92a2a;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Manrope, -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--foreground);
  background:
    radial-gradient(55% 38% at 75% -5%, color-mix(in srgb, var(--accent-2) 20%, transparent), transparent 65%),
    radial-gradient(45% 30% at 15% 105%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 60%),
    var(--background);
  background-attachment: fixed;
}
[data-theme="light"] body {
  background:
    radial-gradient(55% 38% at 75% -5%, color-mix(in srgb, var(--accent-2) 7%, transparent), transparent 65%),
    radial-gradient(45% 30% at 15% 105%, color-mix(in srgb, var(--accent) 5%, transparent), transparent 60%),
    var(--background);
}
button { font: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted-foreground); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }

/* ---------- app shell: sidebar + content ---------- */

#app { display: flex; height: 100dvh; }
.sidebar {
  width: 15.5rem; flex: none; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: rgba(10, 10, 11, 0.6);
  padding: 1.1rem 0.8rem; gap: 0.15rem;
}
[data-theme="light"] .sidebar { background: rgba(255, 255, 255, 0.65); }
.brand { display: flex; align-items: center; padding: 0.2rem 0.5rem 1.1rem; min-width: 0; }
.brand-word { font-weight: 800; letter-spacing: -0.03em; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-dot {
  display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 50%; margin-left: 0.25rem; flex: none;
  background: linear-gradient(0deg, var(--accent), var(--accent-2));
}
.nav-items { display: flex; flex-direction: column; gap: 0.3rem; }
a.nav-item, a.card { text-decoration: none; }
.nav-item {
  display: flex; align-items: center; gap: 0.6rem; border: 1px solid transparent; background: transparent;
  color: var(--muted-foreground); padding: 0.5rem 0.9rem; min-height: 2.5rem; border-radius: 999px;
  cursor: pointer; text-align: left; font-size: 0.92rem; width: 100%; font-weight: 600;
}
.nav-item:hover { background: var(--muted); color: var(--foreground); }
.nav-item.active { background: var(--muted); color: var(--foreground); border-color: var(--border); }
.nav-item:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.nav-item .count {
  margin-left: auto; font-size: 0.72rem; font-weight: 800; background: var(--accent); color: #fff;
  border-radius: 999px; padding: 0.05rem 0.45rem; min-width: 1.3rem; text-align: center;
}
.sidebar .spacer { flex: 1; }
.sidebar-user {
  display: flex; align-items: center; gap: 0.55rem; padding: 0.6rem 0.6rem 0.1rem;
  border-top: 1px solid var(--border); margin-top: 0.5rem; cursor: pointer;
}
.sidebar-user:hover .u-name { color: var(--accent); }
.sidebar-user .u-name { font-size: 0.85rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.avatar {
  width: 2rem; height: 2rem; border-radius: 50%; flex: none; background: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 800;
  color: var(--muted-foreground); overflow: hidden; border: 1px solid var(--border);
}
.content { flex: 1; overflow-y: auto; min-width: 0; }
.content-inner { max-width: 64rem; margin: 0 auto; padding: 2rem 1.5rem 3.5rem; }
.content-inner.wide { max-width: 80rem; }
.page-title { margin: 0 0 0.4rem; font-size: 1.7rem; letter-spacing: -0.03em; font-weight: 800; text-wrap: balance; }
.page-desc { margin: 0 0 1.6rem; color: var(--muted-foreground); max-width: 44rem; }
.page-head { display: flex; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .page-title { margin-bottom: 0.2rem; }
.page-head .actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.back-row { margin-bottom: 0.8rem; }
.back-link { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--muted-foreground); text-decoration: none; font-size: 0.88rem; font-weight: 600; }
.back-link:hover { color: var(--accent); }

/* ---------- cards ---------- */

.section { margin-bottom: 2.4rem; }
.section-title { margin: 0 0 0.3rem; font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
.section-desc { margin: 0 0 1rem; font-size: 0.88rem; color: var(--muted-foreground); max-width: 44rem; }
.card-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 1rem; overflow: hidden;
  display: flex; flex-direction: column; text-align: left; padding: 0; cursor: default; color: var(--foreground);
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s; position: relative;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 8px 32px color-mix(in srgb, var(--accent) 12%, transparent); transform: translateY(-2px);
}
.card:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.card-body { padding: 1rem 1.1rem 1.05rem; display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.card-title { font-weight: 800; font-size: 1rem; letter-spacing: -0.01em; display: flex; align-items: center; gap: 0.5rem; }
.card-title .emoji { font-size: 1.3rem; line-height: 1; }
.card-desc { font-size: 0.85rem; color: var(--muted-foreground); line-height: 1.5; }
.card-meta { margin-top: auto; padding-top: 0.5rem; font-size: 0.8rem; color: var(--muted-foreground); display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: center; }
.card-actions { position: absolute; top: 0.6rem; right: 0.6rem; display: flex; gap: 0.2rem; }
.card.dragging { opacity: 0.45; }
.card.drag-over { border-color: var(--accent); }

/* ---------- buttons / inputs ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius);
  border: 1px solid transparent; padding: 0.45rem 1rem; min-height: 2.6rem; min-width: 2.6rem;
  background: transparent; color: var(--foreground); cursor: pointer; gap: 0.45rem; font-weight: 700;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s, filter 0.12s; text-decoration: none;
}
.btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
.btn-primary { background: linear-gradient(0deg, var(--accent) 0%, var(--accent-2) 100%); color: #fff; }
.btn-primary:hover { filter: brightness(1.12); }
.btn-white { background: var(--primary); color: var(--primary-foreground); }
.btn-white:hover { opacity: 0.9; }
.btn-outline { border-color: var(--border); }
.btn-outline:hover { background: var(--muted); }
.btn-ghost:hover { background: var(--muted); }
.btn-sm { min-height: 2.1rem; padding: 0.25rem 0.7rem; font-size: 0.85rem; }
.btn-sm.btn-primary { background: var(--accent); }
.btn-icon { padding: 0.2rem 0.55rem; }
.btn-danger { color: var(--danger); }
.btn:disabled { opacity: 0.4; cursor: default; }
.input, .select, .textarea {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--foreground);
  padding: 0.4rem 0.7rem; min-height: 2.6rem; font: inherit; width: 100%;
}
.textarea { min-height: 5rem; resize: vertical; line-height: 1.5; padding-top: 0.55rem; }
.input::placeholder, .textarea::placeholder { color: var(--muted-foreground); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }
.input-sm { min-height: 2.1rem; padding: 0.2rem 0.55rem; font-size: 0.85rem; }
.badge {
  font-size: 0.7rem; font-weight: 700; padding: 0.14rem 0.55rem; border-radius: 999px; border: 1px solid var(--border);
  color: var(--muted-foreground); white-space: nowrap; background: var(--muted); display: inline-block;
}
.badge.ok { color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.badge.accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.badge.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

/* ---------- login ---------- */

.center-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 40; background: var(--background); }
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 1.1rem; padding: 2.3rem 1.9rem;
  max-width: 25rem; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 1rem; align-items: center;
}
.login-card h1 { margin: 0; font-size: 1.35rem; letter-spacing: -0.02em; font-weight: 800; }
.login-card p { margin: 0; font-size: 0.9rem; color: var(--muted-foreground); }
.spinner { width: 1rem; height: 1rem; border-radius: 50%; flex: none; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.table th {
  text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground);
  font-weight: 700; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); background: var(--muted); white-space: nowrap;
}
.table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; font-variant-numeric: tabular-nums; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--muted); }
.count-link { color: var(--accent); cursor: pointer; font-weight: 700; text-decoration: underline dotted; }

/* ---------- forms ---------- */

.form-card { border: 1px solid var(--border); border-radius: 1rem; background: var(--card); padding: 1.2rem 1.3rem; margin-bottom: 1rem; }
.form-card h2 { margin: 0 0 0.9rem; font-size: 1rem; font-weight: 800; letter-spacing: -0.01em; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.field > label { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground); }
.field .hint { font-size: 0.78rem; color: var(--muted-foreground); line-height: 1.45; }
.field-wide { grid-column: 1 / -1; }
.check-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; cursor: pointer; }
.check-row input[type="checkbox"], .check-row input[type="radio"] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; background: var(--muted); border: 1px solid var(--border); border-radius: 0.45rem; padding: 0.2rem 0.5rem; word-break: break-all; }
.color-swatches { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.swatch { width: 2.2rem; height: 2.2rem; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: var(--foreground); box-shadow: 0 0 0 2px var(--card); }
.swatch:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.toast {
  position: fixed; top: 1.2rem; left: 50%; transform: translateX(-50%); background: var(--primary); color: var(--primary-foreground);
  padding: 0.6rem 1.1rem; border-radius: var(--radius); font-size: 0.9rem; font-weight: 700; z-index: 3000;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }
.empty { color: var(--muted-foreground); font-size: 0.9rem; padding: 1.5rem 0; }

/* ---------- tabs (hash-routed, as in captain_pipelines) ---------- */

.tabs { display: flex; gap: 0.4rem; margin: 0 0 1.1rem; flex-wrap: wrap; }
.tab {
  display: inline-flex; align-items: center; gap: 0.4rem; border: 1px solid transparent; background: transparent;
  color: var(--muted-foreground); padding: 0.35rem 0.9rem; border-radius: 999px; cursor: pointer; font: inherit;
  font-size: 0.88rem; font-weight: 700; text-decoration: none;
}
.tab:hover { background: var(--muted); color: var(--foreground); }
.tab.active { background: var(--muted); color: var(--foreground); border-color: var(--border); }
.tab .icon { width: 1rem; height: 1rem; }

/* ---------- profile ---------- */

.profile-card { display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 1rem; background: var(--card); padding: 1.3rem 1.4rem; max-width: 36rem; margin-bottom: 1rem; }
.profile-card .avatar { width: 4rem; height: 4rem; font-size: 1.4rem; }
.profile-info { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; flex: 1; }
.profile-name { font-size: 1.2rem; font-weight: 800; letter-spacing: -0.01em; }
.profile-meta { font-size: 0.85rem; color: var(--muted-foreground); word-break: break-all; }
.viewas-banner {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%); z-index: 2000; display: flex; align-items: center; gap: 0.8rem;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 0.88rem; padding: 0.5rem 0.7rem 0.5rem 1.1rem; border-radius: 999px;
  box-shadow: 0 8px 32px color-mix(in srgb, var(--accent) 35%, transparent); max-width: min(92vw, 40rem);
}
.viewas-banner span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewas-banner .btn { color: #fff; border-color: rgba(255,255,255,0.5); }

/* ---------- modal ---------- */

.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 1rem; padding: 1.3rem 1.4rem; width: 100%; max-width: 34rem; max-height: 90dvh; overflow: auto; }
.modal h2 { margin: 0 0 0.9rem; font-size: 1.05rem; font-weight: 800; }
.modal.wide { max-width: 52rem; }

/* ---------- notifications ---------- */

.notif { display: flex; gap: 0.8rem; padding: 0.8rem 1rem; border: 1px solid var(--border); border-radius: 0.85rem; background: var(--card); margin-bottom: 0.6rem; text-decoration: none; color: inherit; }
.notif.unread { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.notif .dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--accent); flex: none; margin-top: 0.45rem; }
.notif.read .dot { background: transparent; }
.notif-title { font-weight: 700; font-size: 0.92rem; }
.notif-body { font-size: 0.82rem; color: var(--muted-foreground); margin-top: 0.15rem; }

/* ---------- document (rendered blocks) ---------- */

.doc { font-size: 1rem; line-height: 1.65; color: var(--doc-fg); max-width: 46rem; }
.doc-hero { font-size: 4.2rem; line-height: 1; margin: 0.5rem 0 0.6rem; }
.doc-title { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.03em; margin: 0 0 1rem; color: var(--foreground); line-height: 1.15; }
.doc h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; margin: 1.6rem 0 0.4rem; color: var(--foreground); line-height: 1.25; }
.doc h3 { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.01em; margin: 1.3rem 0 0.35rem; color: var(--foreground); }
.doc h4 { font-size: 1.05rem; font-weight: 800; margin: 1rem 0 0.3rem; color: var(--foreground); }
.doc p { margin: 0.25rem 0; min-height: 1.2em; }
.doc ul, .doc ol { margin: 0.25rem 0; padding-left: 1.6rem; }
.doc li { margin: 0.15rem 0; }
.doc ul ul, .doc ol ul { list-style: circle; }
.doc ul ul ul { list-style: square; }
.doc ol, .doc ol ol, .doc ol ol ol { list-style: decimal; }
.doc a { color: var(--accent); text-decoration: underline; }
.doc code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86em; background: var(--muted); color: var(--inline-code); padding: 0.1em 0.35em; border-radius: 0.35rem; }
.doc pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.85rem 1rem; overflow-x: auto; font-size: 0.86rem; line-height: 1.5; margin: 0.6rem 0; }
.doc pre code { background: none; color: inherit; padding: 0; font-size: inherit; }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
.doc blockquote { margin: 0.5rem 0; padding: 0.3rem 0 0.3rem 1rem; border-left: 3px solid var(--foreground); }
.doc .callout { display: flex; gap: 0.7rem; background: var(--callout-bg); border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.85rem 1rem 0.85rem 0.85rem; margin: 0.6rem 0; }
.doc .callout-emoji { font-size: 1.35rem; line-height: 1.3; flex: none; }
.doc .callout-body { flex: 1; min-width: 0; }
.doc details { margin: 0.25rem 0; }
.doc summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: flex-start; gap: 0.3rem; }
.doc summary::-webkit-details-marker { display: none; }
.doc summary::before { content: ""; display: inline-block; width: 0.45em; height: 0.45em; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); margin: 0.55em 0.35em 0 0.2em; flex: none; transition: transform 0.15s; }
.doc details[open] > summary::before { transform: rotate(45deg); }
.doc .toggle-body { padding-left: 1.4rem; }
.doc figure { margin: 0.8rem 0; }
.doc figure img { max-width: 100%; height: auto; display: block; border-radius: 0.5rem; }
.doc figcaption { font-size: 0.82rem; color: var(--muted-foreground); margin-top: 0.35rem; }
.doc .ratio { position: relative; width: 100%; border-radius: 0.6rem; overflow: hidden; background: var(--muted); }
.doc .ratio iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.doc .child-page {
  display: flex; align-items: center; gap: 0.55rem; padding: 0.45rem 0.55rem; margin: 0.15rem 0; border-radius: 0.5rem;
  color: var(--foreground); text-decoration: none; font-weight: 600;
}
.doc .child-page:hover { background: var(--muted); }
.doc .child-page .emoji { width: 1.4rem; text-align: center; font-size: 1.1rem; }
.doc .child-page .title { text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.doc .child-page .badge { margin-left: 0.3rem; }
.doc .field { margin: 0.9rem 0; gap: 0.4rem; }
.doc .field .q { font-weight: 700; color: var(--foreground); font-size: 0.95rem; }
.doc .field .q .req { color: var(--danger); margin-left: 0.2rem; }
.doc .field .input, .doc .field .textarea { max-width: 100%; }
.doc .empty-line { min-height: 1.4em; }
.doc .file-drop { border: 1px dashed var(--border); border-radius: var(--radius); padding: 0.8rem; font-size: 0.88rem; color: var(--muted-foreground); background: var(--card); display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

/* page navigation on the study side */
.crumbs { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; font-size: 0.85rem; color: var(--muted-foreground); margin-bottom: 0.8rem; }
.crumbs a { color: inherit; text-decoration: none; display: inline-flex; gap: 0.3rem; align-items: center; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { opacity: 0.6; }
.pills { display: flex; gap: 0.3rem; flex-wrap: wrap; margin: 0.4rem 0 1rem; }
.pill {
  width: 2.25rem; height: 2.25rem; border-radius: 0.75rem; display: inline-flex; align-items: center; justify-content: center;
  background: var(--muted); color: var(--foreground); font-weight: 700; font-size: 0.88rem; text-decoration: none; border: 1px solid transparent;
}
.pill:hover { border-color: var(--border); }
.pill.active { background: var(--accent); color: #fff; }
.pill.task { border-radius: 999px; }
.module-list { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }
.task-status { font-size: 0.85rem; padding: 0.6rem 0.9rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--card); margin: 0.8rem 0; }
.iteration { border: 1px solid var(--border); border-radius: 0.85rem; padding: 0.9rem 1rem; margin: 0.8rem 0; background: var(--card); }
.iteration-head { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; font-size: 0.85rem; color: var(--muted-foreground); margin-bottom: 0.5rem; }
.answer { margin: 0.5rem 0; }
.answer .q { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-foreground); font-weight: 800; }
.answer .v { white-space: pre-wrap; word-break: break-word; margin-top: 0.15rem; }
.review-box { border-left: 3px solid var(--accent); padding-left: 0.9rem; margin-top: 0.7rem; }

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

.editor { position: relative; }
.ed-title-row { display: flex; align-items: center; gap: 0.6rem; margin: 0 0 0.6rem; }
.ed-hero { font-size: 3.4rem; line-height: 1; cursor: pointer; border-radius: 0.6rem; padding: 0.1rem 0.3rem; user-select: none; }
.ed-hero:hover { background: var(--muted); }
.ed-hero.empty { font-size: 0.85rem; color: var(--muted-foreground); font-weight: 600; padding: 0.4rem 0.6rem; border: 1px dashed var(--border); }
.ed-title { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; border: 0; background: transparent; color: var(--foreground); width: 100%; outline: none; padding: 0.2rem 0; font-family: inherit; }
.ed-title:empty::before { content: attr(data-placeholder); color: var(--muted-foreground); }
.ed-block { position: relative; display: flex; align-items: flex-start; }
.ed-gutter { width: 3.2rem; flex: none; display: flex; justify-content: flex-end; gap: 0.1rem; padding-right: 0.35rem; margin-left: -3.2rem; opacity: 0; transition: opacity 0.1s; padding-top: 0.2rem; }
.ed-block:hover > .ed-gutter, .ed-block.menu-open > .ed-gutter { opacity: 1; }
.ed-gbtn { width: 1.45rem; height: 1.45rem; border: 0; border-radius: 0.35rem; background: transparent; color: var(--muted-foreground); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.ed-gbtn:hover { background: var(--muted); color: var(--foreground); }
.ed-gbtn.handle { cursor: grab; }
.ed-gbtn .icon { width: 1rem; height: 1rem; }
.ed-main { flex: 1; min-width: 0; }
.ed-text { outline: none; white-space: pre-wrap; word-break: break-word; min-height: 1.4em; }
.ed-text:empty::before, .ed-text.show-ph::before { content: attr(data-placeholder); color: var(--muted-foreground); pointer-events: none; }
.ed-text[data-placeholder=""]::before { content: none; }
.ed-block.h1 .ed-text { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; margin: 1.2rem 0 0.3rem; color: var(--foreground); }
.ed-block.h2 .ed-text { font-size: 1.25rem; font-weight: 800; margin: 1rem 0 0.25rem; color: var(--foreground); }
.ed-block.h3 .ed-text { font-size: 1.05rem; font-weight: 800; margin: 0.8rem 0 0.2rem; color: var(--foreground); }
.ed-block.paragraph .ed-text { padding: 0.15rem 0; }
.ed-li { display: flex; gap: 0.5rem; align-items: flex-start; }
.ed-li .marker { flex: none; width: 1.4rem; text-align: right; padding-top: 0.15rem; user-select: none; color: var(--doc-fg); }
.ed-li .ed-text { flex: 1; padding: 0.15rem 0; }
.ed-block.bulleted > .ed-main > .ed-li .marker::before { content: "•"; font-size: 1.2em; line-height: 1; }
.ed-block.bulleted .ed-block.bulleted > .ed-main > .ed-li .marker::before { content: "◦"; }
.ed-block.bulleted .ed-block.bulleted .ed-block.bulleted > .ed-main > .ed-li .marker::before { content: "▪"; font-size: 0.9em; }
.ed-children { padding-left: 1.6rem; }
.ed-block.toggle > .ed-main > .ed-li .marker { cursor: pointer; }
.ed-block.toggle > .ed-main > .ed-li .marker::before { content: ""; display: inline-block; width: 0.45em; height: 0.45em; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); margin-bottom: 0.15em; transition: transform 0.15s; }
.ed-block.toggle.open > .ed-main > .ed-li .marker::before { transform: rotate(45deg); }
.ed-block.toggle:not(.open) > .ed-main > .ed-children { display: none; }
.ed-block.toggle > .ed-main > .ed-li .ed-text { font-weight: 600; }
.ed-block.quote > .ed-main { border-left: 3px solid var(--foreground); padding-left: 0.9rem; margin: 0.4rem 0; }
.ed-block.callout > .ed-main { display: flex; gap: 0.7rem; background: var(--callout-bg); border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.75rem 0.9rem 0.75rem 0.75rem; margin: 0.5rem 0; }
.ed-callout-emoji { font-size: 1.35rem; line-height: 1.3; cursor: pointer; border-radius: 0.4rem; padding: 0 0.15rem; flex: none; user-select: none; }
.ed-callout-emoji:hover { background: var(--muted); }
.ed-callout-body { flex: 1; min-width: 0; }
.ed-block.divider > .ed-main { padding: 0.6rem 0; }
.ed-block.divider hr { border: 0; border-top: 1px solid var(--border); margin: 0; }
.ed-block.code > .ed-main { margin: 0.4rem 0; }
.ed-block.code .ed-text { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.86rem; background: var(--code-bg); border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.8rem 1rem; line-height: 1.5; }
.ed-block.code .ed-lang { font-size: 0.72rem; color: var(--muted-foreground); margin-bottom: 0.2rem; }
.ed-block.code .ed-lang input { font: inherit; background: transparent; border: 0; color: inherit; outline: none; border-bottom: 1px dashed var(--border); width: 8rem; }
.ed-media { margin: 0.5rem 0; }
.ed-media img { max-width: 100%; height: auto; display: block; border-radius: 0.5rem; }
.ed-media .ratio { position: relative; width: 100%; border-radius: 0.6rem; overflow: hidden; background: var(--muted); }
.ed-media .ratio iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; pointer-events: none; }
.ed-media .ed-caption { font-size: 0.82rem; color: var(--muted-foreground); margin-top: 0.35rem; outline: none; min-height: 1.2em; }
.ed-media .ed-caption:empty::before { content: "Подпись…"; color: var(--muted-foreground); opacity: 0.6; }
.ed-media-tools { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.35rem; opacity: 0; transition: opacity 0.1s; }
.ed-block:hover .ed-media-tools, .ed-block.selected .ed-media-tools { opacity: 1; }
.ed-media.selected img, .ed-media.selected .ratio { outline: 2px solid var(--accent); outline-offset: 2px; }
.ed-placeholder { border: 1px dashed var(--border); border-radius: var(--radius); padding: 0.8rem 1rem; color: var(--muted-foreground); font-size: 0.9rem; display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; cursor: pointer; background: var(--card); }
.ed-placeholder:hover { border-color: var(--accent); }
.ed-block.child_page > .ed-main .child-page { display: flex; align-items: center; gap: 0.55rem; padding: 0.45rem 0.55rem; margin: 0.1rem 0; border-radius: 0.5rem; color: var(--foreground); text-decoration: none; font-weight: 600; cursor: pointer; }
.ed-block.child_page > .ed-main .child-page:hover { background: var(--muted); }
.ed-block.child_page .emoji { width: 1.4rem; text-align: center; font-size: 1.1rem; }
.ed-block.child_page .title { text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
.ed-block.child_page .open-btn { margin-left: auto; }
.ed-field { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); padding: 0.7rem 0.9rem; margin: 0.5rem 0; }
.ed-field .ed-field-kind { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground); font-weight: 800; display: flex; align-items: center; gap: 0.6rem; }
.ed-field .ed-text { font-weight: 700; margin: 0.25rem 0; }
.ed-field .ed-preview { border: 1px dashed var(--border); border-radius: 0.45rem; padding: 0.4rem 0.6rem; font-size: 0.85rem; color: var(--muted-foreground); }
.ed-field .ed-preview.tall { min-height: 3.6rem; }
.ed-block.selected > .ed-main { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; border-radius: 0.4rem; }
.ed-drop-line { position: absolute; height: 3px; background: var(--accent); border-radius: 2px; pointer-events: none; z-index: 5; display: none; }
.ed-drop-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.ed-block.drag-src { opacity: 0.35; }
/* A dragged page hovering over another page block / breadcrumb / tree node. */
.ed-block.child_page.drop-into > .ed-main .child-page,
.crumbs a.drop-target, .tree-node.drop-target { outline: 2px solid var(--accent); outline-offset: 1px; background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 0.5rem; }
.ed-tools { display: flex; gap: 0.2rem; align-items: center; margin: 0 0 0.4rem; }
.ed-tools .ed-gbtn { width: 1.8rem; height: 1.8rem; border: 1px solid var(--border); }
.ed-tools .ed-gbtn:disabled { opacity: 0.35; cursor: default; background: transparent; }
.ed-menu {
  position: absolute; z-index: 1200; background: var(--card); border: 1px solid var(--border); border-radius: 0.75rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); width: 17rem; max-height: 22rem; overflow: auto; padding: 0.35rem;
}
.ed-menu input { width: 100%; margin-bottom: 0.3rem; }
.ed-menu .grp { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground); font-weight: 800; padding: 0.4rem 0.6rem 0.15rem; }
.ed-menu .item { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0.6rem; border-radius: 0.5rem; cursor: pointer; font-size: 0.88rem; font-weight: 600; width: 100%; border: 0; background: transparent; color: var(--foreground); text-align: left; }
.ed-menu .item:hover, .ed-menu .item.active { background: var(--muted); }
.ed-menu .item .icon { width: 1.05rem; height: 1.05rem; color: var(--muted-foreground); }
.ed-menu .item .sub { font-size: 0.72rem; color: var(--muted-foreground); font-weight: 500; }
.ed-toolbar { position: absolute; z-index: 1200; display: flex; gap: 0.1rem; background: var(--card); border: 1px solid var(--border); border-radius: 0.6rem; padding: 0.2rem; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35); }
.ed-toolbar button { border: 0; background: transparent; color: var(--foreground); width: 1.9rem; height: 1.9rem; border-radius: 0.4rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 0.85rem; }
.ed-toolbar button:hover, .ed-toolbar button.on { background: var(--muted); }
.ed-toolbar button .icon { width: 1rem; height: 1rem; }
.ed-saving { font-size: 0.78rem; color: var(--muted-foreground); }
.emoji-picker { position: absolute; z-index: 1300; background: var(--card); border: 1px solid var(--border); border-radius: 0.75rem; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35); width: 20rem; max-width: 92vw; padding: 0.5rem; }
.emoji-picker input { width: 100%; margin-bottom: 0.4rem; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 0.1rem; max-height: 13rem; overflow: auto; }
.emoji-grid button { border: 0; background: transparent; font-size: 1.35rem; line-height: 1; padding: 0.25rem 0; border-radius: 0.4rem; cursor: pointer; }
.emoji-grid button:hover { background: var(--muted); }
.emoji-picker .grp { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground); font-weight: 800; padding: 0.35rem 0.2rem 0.1rem; grid-column: 1 / -1; }
.emoji-picker .foot { display: flex; gap: 0.4rem; margin-top: 0.4rem; }

/* editor page layout: editor on the left, page tree on the right */
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 16rem; gap: 2rem; align-items: start; }
.editor-col { min-width: 0; padding-left: 3.2rem; }
.tree-col { position: sticky; top: 0; font-size: 0.85rem; border-left: 1px solid var(--border); padding-left: 1rem; max-height: calc(100dvh - 4rem); overflow: auto; }
.tree-col .tree-title { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted-foreground); font-weight: 800; margin-bottom: 0.4rem; }
.tree-node { display: flex; align-items: center; gap: 0.35rem; padding: 0.25rem 0.4rem; border-radius: 0.4rem; text-decoration: none; color: var(--foreground); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tree-node:hover { background: var(--muted); }
.tree-node.active { background: var(--muted); font-weight: 700; }
.tree-kids { padding-left: 0.9rem; border-left: 1px solid var(--border); margin-left: 0.7rem; }

/* leaderboard */
.lb-wrap { overflow-x: auto; }
.lb { border-collapse: collapse; font-size: 0.9rem; min-width: 100%; }
.lb th, .lb td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); text-align: center; white-space: nowrap; }
.lb th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted-foreground); background: var(--muted); }
.lb th:first-child, .lb td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); font-weight: 700; }
.lb th:first-child { background: var(--muted); }
.lb td.medal { font-size: 1.25rem; }
.lb td.dash { color: var(--muted-foreground); }

/* ---------- icons ---------- */
.icon { width: 1em; height: 1em; flex: none; vertical-align: -0.125em; }
.btn .icon { width: 1.1em; height: 1.1em; }
.nav-item .icon { width: 1.15em; height: 1.15em; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  #app { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); padding: 0.45rem 0.55rem; gap: 0.3rem; overflow-x: auto; scrollbar-width: none; }
  .sidebar::-webkit-scrollbar { display: none; }
  .brand { padding: 0.2rem 0.35rem; flex: none; }
  .brand-word { font-size: 1rem; max-width: 7rem; }
  .nav-items { flex-direction: row; gap: 0.25rem; }
  .nav-item { width: auto; flex: none; padding: 0.4rem 0.7rem; min-height: 2.25rem; font-size: 0.85rem; white-space: nowrap; }
  .nav-item .icon { display: none; }
  .nav-item .count { margin-left: 0.3rem; }
  .sidebar .spacer { display: none; }
  .sidebar-user { border-top: 0; margin: 0 0 0 auto; padding: 0.2rem 0.3rem; flex: none; }
  .sidebar-user .u-name { display: none; }
  .avatar { width: 1.75rem; height: 1.75rem; }
  .content-inner { padding: 1.1rem 0.85rem 2.5rem; }
  .card-grid, .module-list { grid-template-columns: 1fr; }
  .page-title { font-size: 1.35rem; }
  .doc-title { font-size: 1.6rem; }
  .doc-hero { font-size: 3rem; }
  .editor-layout { grid-template-columns: 1fr; }
  .tree-col { position: static; border-left: 0; padding-left: 0; max-height: none; border-top: 1px solid var(--border); padding-top: 0.8rem; }
  .editor-col { padding-left: 2.4rem; }
  .ed-gutter { width: 2.4rem; margin-left: -2.4rem; opacity: 1; }
  .ed-media-tools { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } .card, .card.clickable:hover { transform: none; transition: none; } }
