/* Neuroscribe — minimalist, modern, light. */

:root {
	color-scheme: light;
	--bg: #ffffff;
	--bg-soft: #f7f7f8;
	--border: #e4e4e7;
	--hover: #ececf1;
	--text: #1c1c21;
	--text-dim: #6b6b76;
	--accent: #4f46e5;
	--accent-hover: #4338ca;
	--accent-soft: #eef2ff;
	--danger: #dc2626;
	--danger-soft: #fef2f2;
	--warn-bg: #fff7ed;
	--warn-border: #fed7aa;
	--warn-text: #9a3412;
	--ok: #16a34a;
	--radius: 8px;
	--font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
	--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* dark palette, applied when chosen explicitly or via system preference */
:root[data-theme="dark"] {
	color-scheme: dark;
	--bg: #17171c;
	--bg-soft: #1f1f26;
	--border: #32323c;
	--hover: #2a2a33;
	--text: #e7e7ec;
	--text-dim: #9c9ca8;
	--accent: #818cf8;
	--accent-hover: #a5b4fc;
	--accent-soft: #27274a;
	--danger: #f87171;
	--danger-soft: #3a1f22;
	--warn-bg: #2d2417;
	--warn-border: #6b4d1f;
	--warn-text: #fbbf24;
	--ok: #4ade80;
}
@media (prefers-color-scheme: dark) {
	:root[data-theme="auto"] {
		color-scheme: dark;
		--bg: #17171c;
		--bg-soft: #1f1f26;
		--border: #32323c;
		--hover: #2a2a33;
		--text: #e7e7ec;
		--text-dim: #9c9ca8;
		--accent: #818cf8;
		--accent-hover: #a5b4fc;
		--accent-soft: #27274a;
		--danger: #f87171;
		--danger-soft: #3a1f22;
		--warn-bg: #2d2417;
		--warn-border: #6b4d1f;
		--warn-text: #fbbf24;
		--ok: #4ade80;
	}
}

* { box-sizing: border-box; }

/* An author display rule on button/input silently defeats the UA's [hidden]
   style — hidden buttons were showing. This puts the attribute back in charge. */
[hidden] { display: none !important; }

html, body {
	margin: 0;
	height: 100%;
	font-family: var(--font);
	color: var(--text);
	background: var(--bg);
	font-size: 15px;
	line-height: 1.6;
}

.app { display: flex; min-height: 100vh; }

/* ---- sidebar ---- */

.sidebar {
	width: var(--sidebar-w, 270px);
	flex-shrink: 0;
	background: var(--bg-soft);
	border-right: 1px solid var(--border);
	padding: 1rem 0.75rem;
	overflow-y: auto;
	position: sticky;
	top: 0;
	height: 100vh;
}

.sidebar-toggle {
	position: absolute;
	top: 0.8rem;
	right: 0.6rem;
	border: 1px solid var(--border);
	border-radius: 6px;
	background: var(--bg);
	padding: 0.2rem 0.55rem;
	font-size: 0.95rem;
	font-weight: 700;
	color: var(--accent);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
	z-index: 2;
}
.sidebar-toggle:hover {
	color: #fff;
	border-color: var(--accent);
	background: var(--accent);
}

.sidebar-resizer {
	width: 5px;
	flex-shrink: 0;
	cursor: col-resize;
	background: transparent;
	margin-left: -3px;
	z-index: 1;
}
.sidebar-resizer:hover, body.resizing .sidebar-resizer { background: var(--accent-soft); }
body.resizing { user-select: none; cursor: col-resize; }

@media (min-width: 761px) {
	html[data-sidebar="collapsed"] .sidebar {
		width: 3rem !important;
		padding: 1rem 0.4rem;
		overflow: hidden;
	}
	html[data-sidebar="collapsed"] .sidebar-actions,
	html[data-sidebar="collapsed"] .treewrap,
	html[data-sidebar="collapsed"] .sidebar-footer,
	html[data-sidebar="collapsed"] .brand a { display: none; }
	html[data-sidebar="collapsed"] .sidebar-toggle {
		position: static;
		display: block;
		margin: 0 auto;
		font-size: 0;
	}
	html[data-sidebar="collapsed"] .sidebar-toggle::before { content: "⟩"; font-size: 0.95rem; }
	html[data-sidebar="collapsed"] .sidebar-resizer { display: none; }
}

.mobile-topbar, .nav-backdrop { display: none; }

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

.modal {
	border: 1px solid var(--border);
	border-radius: 12px;
	background: var(--bg);
	color: var(--text);
	padding: 1.4rem 1.6rem;
	width: min(24rem, 92vw);
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}
.modal::backdrop { background: rgba(0, 0, 0, 0.35); }
.modal h3 { margin: 0 0 0.9rem; font-size: 1.05rem; font-weight: 600; }
.modal form { display: flex; flex-direction: column; gap: 0.8rem; }
.modal-actions { justify-content: flex-end; }

/* ---- toasts ---- */

#toasts {
	position: fixed;
	bottom: 1.2rem;
	right: 1.2rem;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	z-index: 50;
	max-width: min(24rem, 90vw);
}
.toast {
	background: var(--warn-bg);
	border: 1px solid var(--warn-border);
	color: var(--warn-text);
	border-radius: var(--radius);
	padding: 0.6rem 0.9rem;
	font-size: 0.9rem;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
	cursor: pointer;
}

/* ---- trash ---- */

.trash-item { display: flex; flex-direction: column; padding: 0.4rem 0.4rem; flex: 1; min-width: 0; }
.trash-title { font-weight: 600; }
.trash-meta { color: var(--text-dim); font-size: 0.8rem; }
.trash-list .chapter-list-actions { align-items: center; }
.trash-list .chapter-list-actions button { padding: 0.3rem 0.7rem; }

.brand a {
	font-size: 1.15rem;
	font-weight: 700;
	color: var(--text);
	text-decoration: none;
}

.sidebar-actions { display: flex; gap: 0.4rem; margin: 0.9rem 0; }

.sidebar-actions button {
	flex: 1;
	padding: 0.35rem 0.5rem;
	font-size: 0.85rem;
}

.tree { list-style: none; margin: 0; padding-left: 0.9rem; }
.treewrap > .tree { padding-left: 0; }

.tree summary {
	display: flex;
	align-items: center;
	gap: 0.3rem;
	cursor: pointer;
	padding: 0.15rem 0.3rem;
	border-radius: 6px;
	font-weight: 600;
	color: var(--text-dim);
	user-select: none;
}
.tree summary::before { content: "▸"; font-size: 0.7rem; transition: transform 0.12s; }
.tree details[open] > summary::before { transform: rotate(90deg); }
.tree summary:hover { background: var(--hover); }
.dir-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.row-actions { display: none; gap: 0.1rem; }
.tree summary:hover .row-actions { display: inline-flex; }
.row-actions button {
	border: none;
	background: none;
	padding: 0 0.2rem;
	font-size: 0.75rem;
	cursor: pointer;
	color: var(--text-dim);
}
.row-actions button:hover { color: var(--accent); }

.notelink a {
	display: block;
	padding: 0.18rem 0.5rem;
	border-radius: 6px;
	color: var(--text);
	text-decoration: none;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.notelink a:hover { background: var(--hover); }
.notelink a { cursor: grab; }
.tree summary.drag-over, .treewrap.drag-over {
	background: var(--accent-soft);
	outline: 1.5px dashed var(--accent);
	outline-offset: -1.5px;
	border-radius: 6px;
}
.notelink a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---- main ---- */

.content {
	flex: 1;
	min-width: 0;
	padding: 2rem 3rem 4rem;
	max-width: 60rem;
	margin: 0 auto;
}

.hero { max-width: 38rem; margin-top: 3rem; }
.hero h1 { font-size: 2.2rem; margin-bottom: 0.2rem; }
.tagline { color: var(--text-dim); font-size: 1.1rem; margin-top: 0; }
.hints { padding-left: 1.2rem; }
.hints li { margin: 0.45rem 0; }

.warn {
	background: var(--warn-bg);
	border: 1px solid var(--warn-border);
	color: var(--warn-text);
	padding: 0.5rem 0.8rem;
	border-radius: var(--radius);
	font-size: 0.9rem;
}
.warn.slim { margin: 0 0 1rem; }
.warn.flash {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin: 0 0 1.2rem;
}
.flash-close {
	border: none;
	background: none;
	color: inherit;
	padding: 0 0.2rem;
	font-size: 0.9rem;
	cursor: pointer;
}

/* ---- note header ---- */

.note-header {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1rem;
	border-bottom: 1px solid var(--border);
	padding-bottom: 0.8rem;
	margin-bottom: 1.5rem;
	flex-wrap: wrap;
}
.note-header h1 { margin: 0; font-size: 1.7rem; }
.note-actions { display: flex; gap: 0.4rem; }

/* ---- buttons & forms ---- */

button, .btn {
	font-family: var(--font);
	font-size: 0.88rem;
	padding: 0.4rem 0.8rem;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg);
	color: var(--text);
	cursor: pointer;
	text-decoration: none;
	display: inline-block;
	line-height: 1.3;
}
button:hover, .btn:hover { border-color: var(--text-dim); background: var(--bg-soft); }
button:disabled { opacity: 0.4; cursor: default; }
button.primary, .btn.primary {
	background: var(--accent);
	border-color: var(--accent);
	color: #fff;
}
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); }
button.danger, .btn.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); background: var(--danger-soft); }

input:not([type="checkbox"]):not([type="file"]), textarea, select {
	font-family: var(--font);
	font-size: 0.95rem;
	padding: 0.45rem 0.7rem;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	width: 100%;
	background: var(--bg);
	color: var(--text);
}
textarea { font-family: var(--mono); font-size: 0.87rem; line-height: 1.5; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---- chapters ---- */

.chapter {
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 1.1rem 1.4rem;
	margin-bottom: 1.2rem;
	background: var(--bg);
}
.chapter-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 0.4rem;
}
.chapter-head h2 { margin: 0; font-size: 1.25rem; }
.chapter-num { color: var(--text-dim); font-weight: 500; }
.chapter-actions { display: flex; gap: 0.3rem; flex-shrink: 0; }
.chapter-actions button { padding: 0.25rem 0.55rem; font-size: 0.8rem; }

.chapter.editing form { display: flex; flex-direction: column; gap: 0.6rem; }
.chapter-title-input { font-weight: 600; font-size: 1.05rem; }
.edit-actions { display: flex; gap: 0.4rem; }

.add-chapter { display: flex; gap: 0.5rem; margin-top: 1.5rem; }
.add-chapter input { flex: 1; }
.add-chapter button { flex-shrink: 0; }

/* ---- rendered markdown ---- */

.md h1 { font-size: 1.35rem; border-bottom: 1px solid var(--border); padding-bottom: 0.2rem; }
.md h2 { font-size: 1.2rem; }
.md h3 { font-size: 1.05rem; }
.md a { color: var(--accent); }
.md blockquote {
	margin: 0.8rem 0;
	padding: 0.1rem 1rem;
	border-left: 3px solid var(--accent);
	background: var(--bg-soft);
	color: var(--text-dim);
	border-radius: 0 var(--radius) var(--radius) 0;
}
.md table { border-collapse: collapse; margin: 0.8rem 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 0.35rem 0.7rem; }
.md th { background: var(--bg-soft); }
.md code {
	font-family: var(--mono);
	font-size: 0.86em;
	background: var(--bg-soft);
	border: 1px solid var(--border);
	border-radius: 4px;
	padding: 0.08em 0.35em;
}
.md pre code, .codeblock code { background: none; border: none; padding: 0; font-size: inherit; }
.md img { max-width: 100%; }

.math.display { display: block; text-align: center; margin: 1rem 0; overflow-x: auto; }

/* ---- code blocks ---- */

.codeblock {
	border: 1px solid var(--border);
	border-radius: var(--radius);
	margin: 0.9rem 0;
	overflow: hidden;
}
.codehead {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.25rem 0.8rem;
	background: var(--bg-soft);
	border-bottom: 1px solid var(--border);
	font-size: 0.75rem;
	color: var(--text-dim);
}
.codelang { text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.codeblock > pre {
	margin: 0;
	padding: 0.8rem 1rem;
	overflow-x: auto;
	font-family: var(--mono);
	font-size: 0.85rem;
	line-height: 1.5;
	background: var(--bg) !important;
}
.run-btn {
	padding: 0.15rem 0.6rem;
	font-size: 0.75rem;
	background: var(--accent);
	color: #fff;
	border-color: var(--accent);
}
.run-btn:hover { background: var(--accent-hover); }

.run-output { border-top: 1px solid var(--border); }
.run-head {
	display: flex;
	gap: 0.7rem;
	padding: 0.25rem 0.8rem;
	background: var(--bg-soft);
	font-size: 0.75rem;
}
.run-ok { color: var(--ok); font-weight: 600; }
.run-bad { color: var(--danger); font-weight: 600; }
.run-meta { color: var(--text-dim); }
.run-out {
	margin: 0;
	padding: 0.6rem 1rem;
	font-family: var(--mono);
	font-size: 0.83rem;
	background: #0f172a;
	color: #e2e8f0;
	overflow-x: auto;
	white-space: pre-wrap;
}
.run-out.run-empty { color: #64748b; font-style: italic; }

/* ---- sidebar footer ---- */

.sidebar-footer {
	margin-top: 1.2rem;
	border-top: 1px solid var(--border);
	padding-top: 0.7rem;
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	align-items: flex-start;
}
.sidebar-footer a { color: var(--text-dim); text-decoration: none; font-size: 0.85rem; display: block; }
.sidebar-footer a:hover { color: var(--accent); }

/* ---- note metadata card ---- */

.meta-card {
	border: 1px solid var(--border);
	border-radius: 10px;
	background: var(--bg-soft);
	padding: 0.9rem 1.2rem;
	margin-bottom: 1.6rem;
}
.meta-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.meta-head button { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.type-badge {
	background: var(--accent-soft);
	color: var(--accent);
	font-size: 0.78rem;
	font-weight: 700;
	letter-spacing: 0.03em;
	padding: 0.15rem 0.6rem;
	border-radius: 999px;
	text-transform: uppercase;
}
.note-desc { margin: 0.6rem 0 0.2rem; color: var(--text-dim); }
.meta-fields {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
	gap: 0.4rem 1.5rem;
	margin: 0.8rem 0 0.1rem;
}
.meta-field { display: flex; gap: 0.5rem; align-items: baseline; }
.meta-field dt { font-weight: 600; font-size: 0.85rem; color: var(--text-dim); white-space: nowrap; }
.meta-field dd { margin: 0; overflow-wrap: anywhere; }
.meta-card.editing form { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.2rem; }
.meta-label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; font-weight: 600; color: var(--text-dim); }
.meta-label input, .meta-label select, .meta-label textarea { font-weight: 400; color: var(--text); }
.meta-label input[type="checkbox"] { width: auto; align-self: flex-start; }
.meta-label select { padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); font-size: 0.9rem; }

/* ---- chapter list (note page TOC) ---- */

.toc-title { margin: 1.4rem 0 0.6rem; font-size: 1.15rem; }
.chapter-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.chapter-list li {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.8rem;
	padding: 0.15rem 0.6rem;
	border-bottom: 1px solid var(--border);
	background: var(--bg);
}
.chapter-list li:last-child { border-bottom: none; }
.chapter-list li:hover { background: var(--bg-soft); }
.chapter-link {
	flex: 1;
	padding: 0.5rem 0.4rem;
	color: var(--text);
	text-decoration: none;
	font-weight: 600;
}
.chapter-link:hover { color: var(--accent); }
.chapter-list-actions { display: flex; gap: 0.25rem; }
.chapter-list-actions button { padding: 0.2rem 0.5rem; font-size: 0.78rem; }
.chapter-list-empty { color: var(--text-dim); font-style: italic; padding: 0.7rem 1rem !important; }

/* ---- chapter page ---- */

.breadcrumb { font-size: 0.9rem; color: var(--text-dim); margin-bottom: 1rem; }
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.crumb-sep { margin: 0 0.4rem; }
.chapter-page-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1rem;
	border-bottom: 1px solid var(--border);
	padding-bottom: 0.6rem;
	margin-bottom: 1rem;
}
.chapter-page-head h1 { margin: 0; font-size: 1.6rem; }
.chapter-view.editing form, .chapter.editing form { display: flex; flex-direction: column; gap: 0.6rem; }
.chapter-view.editing textarea { min-height: 60vh; }
.chapter-nav {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	margin-top: 2rem;
	border-top: 1px solid var(--border);
	padding-top: 1rem;
}
.chapter-nav .btn { max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- types page ---- */

.page-hint { color: var(--text-dim); margin-top: -0.5rem; }
.type-card {
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 1rem 1.3rem;
	margin: 1.2rem 0;
}
.type-card-head { display: flex; align-items: center; gap: 0.8rem; }
.type-card-head h2 { margin: 0; font-size: 1.2rem; flex: 1; }
.type-usage { color: var(--text-dim); font-size: 0.85rem; }
.type-empty { color: var(--text-dim); font-style: italic; font-size: 0.9rem; }
.inline-form { display: inline; }
.fields-table { border-collapse: collapse; margin: 0.7rem 0; width: 100%; }
.fields-table th, .fields-table td { text-align: left; padding: 0.3rem 0.7rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.fields-table th { color: var(--text-dim); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.fields-table td:last-child { width: 2rem; text-align: right; }
.fields-table button { padding: 0.1rem 0.45rem; font-size: 0.75rem; }
/* the disclosure table needs room for prose, unlike the field editor */
.fields-table.disclosure td:last-child,
.fields-table.disclosure th:last-child { width: 55%; text-align: left; }
.fields-table.disclosure td { vertical-align: top; }

.add-field { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.add-field input { flex: 1 1 auto; }
.add-field select, .add-field button { width: auto; flex: 0 0 auto; }
.add-field select { padding: 0.4rem 0.6rem; font-size: 0.88rem; }

/* ---- brand / logo ---- */

.brand a { display: flex; align-items: center; gap: 0.5rem; }
.logo { width: 26px; height: 26px; }

/* ---- sidebar footer extras ---- */

.logout-form { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.4rem; }
.whoami { color: var(--text-dim); font-size: 0.85rem; }
.linklike {
	border: none;
	background: none;
	padding: 0;
	color: var(--accent);
	font-size: 0.85rem;
	cursor: pointer;
}
.linklike:hover { text-decoration: underline; background: none; border: none; }

/* ---- markdown editor toolbar ---- */

.md-toolbar {
	display: flex;
	align-items: center;
	gap: 0.15rem;
	flex-wrap: wrap;
	border: 1px solid var(--border);
	border-radius: var(--radius);
	background: var(--bg-soft);
	padding: 0.25rem 0.4rem;
}
.md-toolbar button {
	border: none;
	background: none;
	padding: 0.25rem 0.55rem;
	font-size: 0.85rem;
	border-radius: 6px;
	min-width: 2rem;
}
.md-toolbar button:hover { background: var(--hover); border: none; }
.tb-sep { width: 1px; height: 1.2rem; background: var(--border); margin: 0 0.3rem; }

/* ---- attachments ---- */

.attachments {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
	gap: 0.8rem;
	margin-bottom: 1.5rem;
}
.attachment {
	margin: 0;
	border: 1px solid var(--border);
	border-radius: 10px;
	overflow: hidden;
	background: var(--bg);
	display: flex;
	flex-direction: column;
}
.attachment img { width: 100%; height: 7rem; object-fit: cover; display: block; }
.attachment figcaption {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.3rem;
	padding: 0.3rem 0.5rem;
	font-size: 0.75rem;
	background: var(--bg-soft);
	border-top: 1px solid var(--border);
}
.attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
.attachment-actions { display: flex; gap: 0.15rem; flex-shrink: 0; }
.attachment-actions button { padding: 0.1rem 0.4rem; font-size: 0.75rem; border: none; background: none; }
.upload-tile { border-style: dashed; justify-content: center; min-height: 9rem; }
.upload-label {
	display: flex;
	align-items: center;
	justify-content: center;
	text-align: center;
	height: 100%;
	min-height: 9rem;
	cursor: pointer;
	color: var(--text-dim);
	font-size: 0.85rem;
}
.upload-label:hover { color: var(--accent); }

/* ---- settings ---- */

.settings-form { display: flex; flex-direction: column; gap: 0.8rem; max-width: 22rem; }
.type-card .btn + .page-hint { margin-top: 0.7rem; }
.btn.is-busy { opacity: 0.6; pointer-events: none; }
.type-card > h2 { margin-top: 0; font-size: 1.15rem; }
.cli-hint {
	background: var(--bg-soft);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 0.6rem 0.9rem;
	font-family: var(--mono);
	font-size: 0.85rem;
	overflow-x: auto;
}

/* ---- landing ---- */

.landing-body {
	background: var(--bg);
	position: relative;
	overflow-x: hidden;
}
/* soft colour wash + the neuron constellation, both behind everything */
.landing-glow {
	position: absolute;
	inset: 0 0 auto 0;
	height: min(52rem, 90vh);
	pointer-events: none;
	z-index: 0;
	background:
		url("/static/hero-art.svg") center top / min(78rem, 130%) auto no-repeat,
		radial-gradient(60rem 30rem at 18% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%),
		radial-gradient(45rem 28rem at 88% 4%, color-mix(in srgb, #a855f7 18%, transparent), transparent 70%);
	opacity: 0.42;
	mask-image: linear-gradient(to bottom, #000 55%, transparent);
	-webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent);
}
:root[data-theme="dark"] .landing-glow { opacity: 0.5; }

/* keep the headline legible where the constellation crosses it */
.landing-hero { position: relative; }
.landing-hero::before {
	content: "";
	position: absolute;
	inset: -3rem -5rem 1rem;
	background: radial-gradient(closest-side, var(--bg) 58%, transparent 100%);
	z-index: -1;
}

.landing-nav {
	position: relative;
	z-index: 1;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 1.1rem clamp(1rem, 5vw, 3rem);
	flex-wrap: wrap;
}
.landing-brand {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	font-size: 1.15rem;
	font-weight: 700;
	color: var(--text);
	text-decoration: none;
}
.landing-actions { display: flex; gap: 0.5rem; align-items: center; }
/* the repo link: an icon among buttons, so it gets their hit area without
   their chrome */
.gh-link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0.45rem;
	border-radius: 8px;
	color: var(--text-dim);
}
.gh-link:hover { color: var(--text); background: var(--bg-soft); }
.gh-mark { display: block; }
.landing {
	position: relative;
	z-index: 1;
	max-width: 64rem;
	margin: 0 auto;
	padding: clamp(2rem, 7vw, 4.5rem) clamp(1rem, 5vw, 3rem) 4rem;
}

.landing-hero { text-align: center; max-width: 44rem; margin: 0 auto; }
.landing-hero h1 {
	font-size: clamp(2rem, 5.4vw, 3.2rem);
	line-height: 1.08;
	letter-spacing: -0.03em;
	margin: 0 0 0.7rem;
}
.landing-hero .tagline {
	font-size: clamp(1rem, 2.2vw, 1.15rem);
	margin: 0 auto;
	max-width: 34rem;
	color: var(--text-dim);
}
.landing-cta { display: flex; gap: 0.7rem; justify-content: center; flex-wrap: wrap; margin-top: 1.9rem; }
.btn.big { padding: 0.62rem 1.5rem; font-size: 1rem; }

/* ---- product shot ---- */

.shot {
	margin: clamp(2.5rem, 7vw, 4.5rem) auto 0;
	border: 1px solid var(--border);
	border-radius: 14px;
	overflow: hidden;
	background: var(--bg);
	box-shadow: 0 24px 60px -24px rgba(30, 27, 75, 0.45);
	max-width: 54rem;
}
.shot-bar {
	display: flex;
	gap: 0.4rem;
	padding: 0.6rem 0.9rem;
	background: var(--bg-soft);
	border-bottom: 1px solid var(--border);
}
.shot-bar span { width: 0.62rem; height: 0.62rem; border-radius: 50%; background: var(--border); }
.shot-body { display: flex; min-height: 19rem; }
.shot-side {
	width: 12rem;
	flex-shrink: 0;
	border-right: 1px solid var(--border);
	background: var(--bg-soft);
	padding: 0.9rem 0.7rem;
	font-size: 0.82rem;
}
.shot-side p { margin: 0.15rem 0; padding: 0.2rem 0.45rem; border-radius: 6px; color: var(--text); }
.shot-folder { color: var(--text-dim) !important; font-weight: 600; }
.shot-note { padding-left: 1rem !important; }
.shot-note.is-active { background: var(--accent-soft); color: var(--accent) !important; font-weight: 600; }
.shot-main { flex: 1; padding: 1.1rem 1.4rem; min-width: 0; }
.shot-crumb { color: var(--text-dim); font-size: 0.78rem; margin: 0 0 0.5rem; }
.shot-crumb span { margin: 0 0.35rem; }
.shot-main h3 { margin: 0 0 0.6rem; font-size: 1.15rem; }
.shot-text { margin: 0; font-size: 0.9rem; color: var(--text-dim); }
.shot-math { margin: 0.7rem 0 1rem; font-size: 1.05rem; }
.shot-code { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.shot-code-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0.28rem 0.7rem;
	background: var(--bg-soft);
	border-bottom: 1px solid var(--border);
	font-size: 0.7rem;
	letter-spacing: 0.06em;
	color: var(--text-dim);
	font-weight: 600;
}
.shot-run { background: var(--accent); color: #fff; border-radius: 5px; padding: 0.1rem 0.5rem; letter-spacing: 0; }
.shot-code pre {
	margin: 0;
	padding: 0.7rem 0.9rem;
	font-family: var(--mono);
	font-size: 0.8rem;
	line-height: 1.5;
	overflow-x: auto;
}
.shot-code .k { color: var(--accent); }
.shot-out {
	border-top: 1px solid var(--border);
	padding: 0.45rem 0.9rem;
	font-family: var(--mono);
	font-size: 0.76rem;
	background: #0f172a;
	color: #a5b4fc;
}

/* ---- feature lines (no boxes) ---- */

.landing-points {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
	gap: 0.9rem 2.5rem;
	margin-top: clamp(2.5rem, 7vw, 4rem);
	max-width: 54rem;
	margin-left: auto;
	margin-right: auto;
}
.landing-points p { margin: 0; color: var(--text-dim); font-size: 0.94rem; line-height: 1.6; }
.landing-points strong { color: var(--text); display: block; font-size: 1rem; }

.landing-next {
	max-width: 54rem;
	margin: clamp(2.5rem, 7vw, 4rem) auto 0;
	padding: 1.4rem 1.6rem;
	border: 1px dashed var(--border);
	border-radius: 12px;
	background: color-mix(in srgb, var(--accent) 6%, transparent);
}
.landing-next h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.landing-next p { margin: 0; color: var(--text-dim); font-size: 0.94rem; line-height: 1.6; }
.landing-next-status { margin-top: 0.6rem !important; font-size: 0.85rem !important; opacity: 0.85; }
.landing-by { display: inline-block; margin-left: 0.4rem; }
.landing-by a { color: var(--accent); }

.landing-footer {
	position: relative;
	z-index: 1;
	border-top: 1px solid var(--border);
	padding: 1.2rem clamp(1rem, 5vw, 3rem);
	color: var(--text-dim);
	font-size: 0.85rem;
	margin-top: 3rem;
}

@media (max-width: 640px) {
	.shot-side { display: none; }
}

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

/* Centred vertically when it fits, and top-aligned when it does not.
   align-items:center would centre it either way, which overflows equally in
   both directions — and the part above the viewport cannot be scrolled to, so
   a tall form simply loses its top. Auto margins centre only while there is
   free space, and collapse to zero when there is not. */
.login-body {
	display: flex;
	justify-content: center;
	/* html and body are height:100% for the app shell; auth pages have to be
	   free to grow past the viewport, or the body box stops at 100vh and its
	   background ends mid-page while the content keeps going. */
	height: auto;
	min-height: 100vh;
	padding: 2rem 1rem;
	background: var(--bg-soft);
}
.login-box {
	margin: auto 0;
	width: min(22rem, 100%);
	background: var(--bg);
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 2rem;
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.06);
}
.login-brand {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	color: var(--text);
	text-decoration: none;
	font-size: 1.15rem;
	font-weight: 700;
	font-size: 1.3rem;
	font-weight: 700;
	margin-bottom: 1.2rem;
}
.login-form { display: flex; flex-direction: column; gap: 0.8rem; }
.login-alt { margin: 1rem 0 0; font-size: 0.88rem; color: var(--text-dim); text-align: center; }
.login-alt a { color: var(--accent); }
.resend-form { margin-bottom: 1.2rem; }
.notice {
	background: var(--accent-soft);
	border: 1px solid var(--accent);
	color: var(--accent);
	padding: 0.6rem 0.9rem;
	border-radius: var(--radius);
	font-size: 0.9rem;
}
altcha-widget {
	--altcha-border-width: 1px;
	--altcha-border-radius: var(--radius);
	--altcha-color-base: var(--bg);
	--altcha-color-border: var(--border);
	--altcha-color-text: var(--text);
	--altcha-color-border-focus: var(--accent);
	--altcha-max-width: 100%;
	display: block;
}
.login-form input { font-size: 1rem; }
.login-form button { margin-top: 0.4rem; padding: 0.55rem; font-size: 0.95rem; }

@media (max-width: 760px) {
	.sidebar-resizer, .sidebar-toggle { display: none; }

	.mobile-topbar {
		display: flex;
		align-items: center;
		gap: 0.7rem;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		height: 3.2rem;
		padding: 0 0.9rem;
		background: var(--bg-soft);
		border-bottom: 1px solid var(--border);
		z-index: 30;
	}
	.mobile-nav-btn { padding: 0.2rem 0.6rem; font-size: 1.05rem; }
	.mobile-brand {
		display: flex;
		align-items: center;
		gap: 0.5rem;
		font-weight: 700;
		font-size: 1.05rem;
		color: var(--text);
		text-decoration: none;
	}

	/* sidebar becomes an off-canvas drawer */
	.sidebar {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		height: 100vh;
		width: min(19rem, 85vw) !important;
		transform: translateX(-105%);
		transition: transform 0.18s ease;
		z-index: 41;
		box-shadow: none;
	}
	body.mobile-nav-open .sidebar {
		transform: translateX(0);
		box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
	}
	body.mobile-nav-open .nav-backdrop {
		display: block;
		position: fixed;
		inset: 0;
		background: rgba(0, 0, 0, 0.35);
		z-index: 40;
	}

	.content { padding: 4.2rem 1rem 3rem; }
	.hero { margin-top: 0.5rem; }
	.note-header h1 { font-size: 1.35rem; }
	.note-header, .note-actions { flex-wrap: wrap; }
	.chapter-page-head h1 { font-size: 1.25rem; }
	.md-toolbar { overflow-x: auto; flex-wrap: nowrap; }
	.attachments { grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr)); }
	.chapter-nav { flex-wrap: wrap; }
	.chapter-nav .btn { max-width: 100%; }
}

/* ---- password strength meter ---- */

/* The sign-up form carries more than the sign-in form does: two password
   fields, a strength meter, the guidance, the disclosure and a captcha. It
   gets room to breathe rather than becoming a very tall column. */
.register-box { width: min(30rem, 100%); }

.pw-meter { margin: -0.4rem 0 0.6rem; }
.pw-meter[hidden] { display: none; }
.pw-bar {
	height: 4px;
	border-radius: 2px;
	background: var(--border);
	overflow: hidden;
}
.pw-bar > span {
	display: block;
	height: 100%;
	width: 0;
	background: var(--danger);
	transition: width 0.2s ease, background 0.2s ease;
}
.pw-meter[data-score="2"] .pw-bar > span { background: var(--warn-border); }
.pw-meter[data-score="3"] .pw-bar > span,
.pw-meter[data-score="4"] .pw-bar > span { background: var(--ok); }
.pw-label {
	margin: 0.3rem 0 0;
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--text-dim);
}
.pw-meter[data-score="3"] .pw-label,
.pw-meter[data-score="4"] .pw-label { color: var(--ok); }
.pw-detail { margin: 0.15rem 0 0; }

/* ---- PIN lock ---- */

.pin-input {
	font-size: 1.5rem;
	letter-spacing: 0.5em;
	text-align: center;
	font-variant-numeric: tabular-nums;
}
.pin-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.25rem; }
/* the caveat below the buttons needs room to read as a caveat, not a label */
.pin-note {
	margin-top: 1.5rem;
	padding-top: 1rem;
	border-top: 1px solid var(--border);
}

body.is-locked { overflow: hidden; }

/* Opaque, not translucent: the page underneath is reloaded and holds only
   ciphertext, but there is no reason to show a skeleton of it either. */
.lock-screen {
	position: fixed;
	inset: 0;
	z-index: 1000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1.5rem;
	background: var(--bg);
}
.lock-box {
	width: min(22rem, 100%);
	text-align: center;
}
.lock-box h1 { margin: 0.75rem 0 0.25rem; font-size: 1.4rem; }
/* Unlike the sidebar brand, this one has no anchor inside — the flex rule
   that lines the logo up with the name has to live on the element itself. */
.lock-brand {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	margin-bottom: 0.5rem;
	font-size: 1.15rem;
	font-weight: 700;
}
.lock-form {
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	margin: 1rem 0 0.5rem;
}
.lock-error { margin: 0.5rem 0 0; }

/* ---- offline runtime switches ---- */

.runtime-list { list-style: none; margin: 0; padding: 0; }
.runtime-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.7rem 0;
	border-top: 1px solid var(--border);
}
.runtime-row:first-child { border-top: none; }
.runtime-name { min-width: 0; }
.runtime-row button { flex: none; }

/* ---- sync status in the sidebar ---- */

.sync-status {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	font-size: 0.85rem;
	padding: 0.35rem 0;
}

/* ---- boot splash ----
 *
 * Shown by the shell itself before any script has run, so a slow connection
 * or a cold cache gets a breathing page instead of a blank column.
 */

.boot-splash {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 1rem;
	min-height: 60vh;
}
.boot-logo { width: 48px; height: 48px; }
.boot-spinner {
	width: 22px;
	height: 22px;
	border-radius: 50%;
	border: 2px solid var(--border);
	border-top-color: var(--accent);
	animation: ng-spin 0.9s linear infinite;
}
@keyframes ng-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
	.boot-spinner { animation: none; border-top-color: var(--border); }
}
