/* ============================================================
   APP SHELL - full-screen frame. No outer document scroll; the
   sidebar and the main reading pane each scroll independently,
   like a native app rather than a scrolling web page.
   ============================================================ */
html, body {
	height: 100%;
	overflow: hidden;
}

.shell {
	display: flex;
	flex-direction: column;
	height: 100%;
}

/* hidden state-driver for the mobile nav drawer - lives before
   .app-body so :has() on .shell can read it from anywhere */
.nav-toggle-input {
	position: absolute;
	opacity: 0;
	width: 1px;
	height: 1px;
	pointer-events: none;
}

/* ============================================================
   TOPBAR - full-bleed, always visible
   ============================================================ */
.topbar {
	flex: 0 0 auto;
	height: var(--topbar-h);
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-4);
	padding: 0 var(--space-5);
	border-bottom: var(--border-width) solid var(--color-border);
	background: var(--color-surface);
}

.topbar-left {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	min-width: 0;
}

.brand {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	min-width: 0;
}

.brand-mark {
	width: 2rem;
	height: 2rem;
	flex-shrink: 0;
	background: var(--gradient-teal);
	color: #FFFFFF;
	border-radius: var(--radius-sm);
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: var(--font-mono);
	font-size: var(--fs-xs);
	font-weight: 600;
}

.brand-text {
	display: flex;
	flex-direction: column;
	gap: 0.15rem;
	min-width: 0;
	line-height: 1.1;
}

.brand-title {
	font-weight: 600;
	font-size: var(--fs-sm);
	color: var(--color-text);
	white-space: nowrap;
}

.brand-eyebrow {
	font-family: var(--font-mono);
	font-size: var(--fs-2xs);
	color: var(--color-text-faint);
	text-transform: uppercase;
	letter-spacing: var(--tracking-wide);
	white-space: nowrap;
}

.topbar-right {
	display: flex;
	align-items: center;
	gap: var(--space-4);
	flex-shrink: 0;
}

/* ============================================================
   HAMBURGER - mobile-only trigger for the nav drawer
   ============================================================ */
.hamburger {
	display: none;
	position: relative;
	width: 1.75rem;
	height: 1.75rem;
	align-items: center;
	justify-content: center;
	color: var(--color-text-muted);
	cursor: pointer;
	flex-shrink: 0;
}

.hamburger svg {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
}

.icon-close { opacity: 0; }
.shell:has(.nav-toggle-input:checked) .icon-menu { opacity: 0; }
.shell:has(.nav-toggle-input:checked) .icon-close { opacity: 1; }

/* ============================================================
   THEME TOGGLE - checkbox-driven, no JS for the swap itself.
   Its checked state drives html:has(#theme-toggle-input:checked)
   in tokens.css. app.js only persists the choice across pages.
   ============================================================ */
.theme-toggle {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 1.375rem;
	height: 1.375rem;
	cursor: pointer;
	color: var(--color-text-muted);
	transition: color 0.15s ease;
}

.theme-toggle:hover { color: var(--color-text); }

.theme-toggle-input {
	position: absolute;
	opacity: 0;
	width: 1px;
	height: 1px;
}

.theme-toggle svg {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	transition: opacity 0.15s ease;
}

.icon-moon { opacity: 0; }
.icon-sun { opacity: 1; }
.theme-toggle-input:checked ~ .icon-moon { opacity: 1; }
.theme-toggle-input:checked ~ .icon-sun { opacity: 0; }

.theme-toggle-input:focus-visible ~ svg {
	outline: 2px solid var(--color-accent);
	outline-offset: 2px;
}

/* ============================================================
   APP BODY - sidebar + main, sits below the topbar and fills
   the rest of the viewport
   ============================================================ */
.app-body {
	flex: 1 1 auto;
	display: flex;
	min-height: 0;
	position: relative;
}

/* ============================================================
   SIDEBAR - full height, app-like nav rail. Desktop: always
   visible, part of the flex row. Mobile: off-canvas drawer
   toggled by the hamburger (see media query below).
   ============================================================ */
.sidebar {
	flex: 0 0 var(--sidebar-w);
	width: var(--sidebar-w);
	overflow-y: auto;
	background: var(--color-bg-alt);
	border-right: var(--border-width) solid var(--color-border);
	padding: var(--space-5) var(--space-3) var(--space-8) 0;
}

.nav-group + .nav-group {
	margin-top: var(--space-6);
}

.nav-group-label {
	padding: 0 var(--space-3) 0 var(--space-5);
	margin-bottom: var(--space-2);
	font-family: var(--font-mono);
	font-size: var(--fs-2xs);
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: var(--tracking-wider);
	color: var(--color-text-faint);
}

.nav-item {
	display: flex;
	align-items: flex-start;
	gap: var(--space-3);
	padding: var(--space-3) var(--space-3) var(--space-3) var(--space-5);
	border-radius: 0 var(--radius-md) var(--radius-md) 0;
	border-left: var(--border-width-strong) solid transparent;
}

a.nav-item {
	transition: background 0.15s ease;
}

a.nav-item:hover {
	background: var(--color-surface);
}

.nav-item.is-active {
	background: var(--color-surface);
	border-left-color: var(--color-accent);
	box-shadow: var(--shadow-soft);
}

.nav-item.is-active .nav-item-title { color: var(--color-text); }
.nav-item.is-active .nav-item-num { color: var(--color-accent); }

.nav-item.is-disabled {
	cursor: default;
	opacity: 0.55;
}

.nav-item-num {
	flex-shrink: 0;
	width: 1.75rem;
	padding-top: 0.1rem;
	font-family: var(--font-mono);
	font-size: var(--fs-xs);
	color: var(--color-text-faint);
}

.nav-item-text {
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
	min-width: 0;
}

.nav-item-title {
	font-size: var(--fs-sm);
	font-weight: 600;
	color: var(--color-text-muted);
	line-height: var(--lh-snug);
}

.nav-item-tag {
	display: inline-block;
	margin-left: var(--space-1);
	padding: 0.05em 0.45em;
	font-family: var(--font-mono);
	font-size: 0.62em;
	font-weight: 500;
	text-transform: uppercase;
	letter-spacing: var(--tracking-wider);
	color: var(--color-accent);
	border: var(--border-width) solid var(--color-accent);
	border-radius: 999px;
	vertical-align: 0.15em;
}

.nav-item-desc {
	font-size: var(--fs-xs);
	color: var(--color-text-faint);
	line-height: var(--lh-snug);
}

/* scrim behind the mobile drawer - inert and invisible on desktop */
.nav-scrim {
	display: none;
}

/* ============================================================
   MAIN - the reading pane, scrolls independently of the sidebar
   ============================================================ */
.main {
	flex: 1 1 auto;
	min-width: 0;
	overflow-y: auto;
}

.content-header {
	max-width: calc(var(--article-w) + var(--content-gap) + var(--notes-w));
	margin: 0 auto;
	padding: var(--space-8) var(--space-6) 0;
}

.content-header h1 {
	margin-top: var(--space-3);
	font-size: var(--fs-2xl);
	font-weight: 700;
	line-height: var(--lh-tight);
	color: var(--color-text);
}

.content-header .dek {
	margin-top: var(--space-4);
	max-width: var(--article-w);
	font-size: var(--fs-md);
	line-height: var(--lh-relaxed);
	color: var(--color-text-muted);
}

.content-meta {
	margin-top: var(--space-5);
	padding-bottom: var(--space-6);
	border-bottom: var(--border-width) solid var(--color-border);
	display: flex;
	gap: var(--space-4);
	font-family: var(--font-mono);
	font-size: var(--fs-2xs);
	color: var(--color-text-faint);
	text-transform: uppercase;
	letter-spacing: var(--tracking-wide);
}

/* ============================================================
   CHAPTER PAGER - prev/next, book-style navigation between pages
   ============================================================ */
.chapter-pager {
	max-width: calc(var(--article-w) + var(--content-gap) + var(--notes-w));
	margin: 0 auto;
	padding: var(--space-7) var(--space-6) var(--space-9);
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: var(--space-4);
}

.pager-link {
	display: flex;
	flex-direction: column;
	gap: var(--space-1);
	padding: var(--space-4) var(--space-5);
	border: var(--border-width) solid var(--color-border);
	border-radius: var(--radius-md);
	transition: border-color 0.15s ease, background 0.15s ease;
}

.pager-link:hover {
	border-color: var(--color-border-strong);
	background: var(--color-bg-alt);
}

.pager-next { text-align: right; }

.pager-label {
	font-family: var(--font-mono);
	font-size: var(--fs-2xs);
	text-transform: uppercase;
	letter-spacing: var(--tracking-wide);
	color: var(--color-text-faint);
}

.pager-title {
	font-size: var(--fs-sm);
	font-weight: 600;
	color: var(--color-text);
}

.pager-placeholder { visibility: hidden; }

/* ============================================================
   RESPONSIVE - below this width the sidebar becomes an
   off-canvas drawer. Covers phones; iPads/laptops/desktops all
   keep the full app layout.
   ============================================================ */
@media (max-width: 48rem) {
	.hamburger { display: flex; }

	.sidebar {
		position: fixed;
		top: var(--topbar-h);
		bottom: 0;
		left: 0;
		z-index: 30;
		width: min(85vw, 22rem);
		border-right: var(--border-width) solid var(--color-border);
		box-shadow: var(--shadow-card);
		transform: translateX(-100%);
		transition: transform 0.2s ease;
	}

	.shell:has(.nav-toggle-input:checked) .sidebar {
		transform: translateX(0);
	}

	.nav-scrim {
		display: block;
		position: fixed;
		top: var(--topbar-h);
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 20;
		background: rgba(0, 0, 0, 0.45);
		opacity: 0;
		pointer-events: none;
		transition: opacity 0.2s ease;
	}

	.shell:has(.nav-toggle-input:checked) .nav-scrim {
		opacity: 1;
		pointer-events: auto;
	}

	.content-header { padding-top: var(--space-6); }
	.chapter-pager { grid-template-columns: 1fr; }
	.pager-next { text-align: left; }
}
