/* Snoozz Handbook: clinical reference layout */

:root {
	--hb-navy: #1b2f5b;
	--hb-accent: #2c4f9e;
	--hb-accent-soft: rgba(44, 79, 158, 0.08);
	--hb-glow: rgba(44, 79, 158, 0.55);
	--hb-glow-0: rgba(44, 79, 158, 0);
	--hb-bg: #ffffff;
	--hb-surface: #f5f7fb;
	--hb-border: #dfe4ee;
	--hb-text: #1c2230;
	--hb-muted: #5b6475;
	--hb-card: #eef3fc;
	--hb-radius: 10px;
}
html.snz-bedtime {
	--hb-navy: #f0c27d;
	--hb-accent: #f0b86e;
	--hb-accent-soft: rgba(240, 184, 110, 0.12);
	--hb-glow: rgba(240, 184, 110, 0.55);
	--hb-glow-0: rgba(240, 184, 110, 0);
	--hb-bg: #17140f;
	--hb-surface: #211c15;
	--hb-border: rgba(232, 220, 197, 0.16);
	--hb-text: #e8dcc5;
	--hb-muted: #b3a68f;
	--hb-card: #272016;
	color-scheme: dark;
}

/* ---------- Layout ---------- */

.hb-layout {
	position: relative; max-width: none; box-sizing: border-box;
	display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 40px; align-items: start;
	color: var(--hb-text); font-size: 0.97rem; line-height: 1.6;
}
.hb-main { min-width: 0; }
.hb-overlay { display: none; position: fixed; inset: 0; background: rgba(10, 14, 25, 0.45); z-index: 99999; }

/* ---------- Chapter menu ---------- */

.hb-nav {
	position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow-y: auto; overscroll-behavior: contain;
	background: var(--hb-surface); border: 1px solid var(--hb-border); border-radius: var(--hb-radius);
	padding: 14px; font-size: 0.875rem; line-height: 1.4; box-sizing: border-box;
}
.admin-bar .hb-nav { top: 56px; }
.hb-nav-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.hb-nav-home { font-weight: 700; color: var(--hb-navy) !important; text-decoration: none !important; box-shadow: none !important; letter-spacing: 0.01em; }
.hb-nav-close {
	appearance: none; border: 0 !important; background: transparent !important; color: var(--hb-text) !important;
	font-size: 26px; line-height: 1; padding: 4px 8px !important; cursor: pointer; box-shadow: none !important;
}
.hb-ch { border-top: 1px solid var(--hb-border); padding: 6px 0; }
.hb-ch:first-child { border-top: 0; }
.hb-ch summary {
	list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
	cursor: pointer; font-weight: 700; color: var(--hb-navy); padding: 6px 2px;
	text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.06em;
}
.hb-ch summary::-webkit-details-marker { display: none; }
.hb-ch ol { list-style: none; margin: 2px 0 6px; padding: 0; }
.hb-ch li { margin: 0; }
.hb-ch a {
	display: block; padding: 6px 10px; border-radius: 6px; color: var(--hb-text) !important;
	text-decoration: none !important; box-shadow: none !important; border-left: 3px solid transparent;
}
.hb-ch a:hover { background: var(--hb-accent-soft); }
.hb-ch a.is-current { background: var(--hb-accent-soft); border-left-color: var(--hb-accent); font-weight: 700; color: var(--hb-navy) !important; }
.hb-ch li.hb-hide, .hb-ch.hb-hide, .hb-home-ch.hb-hide, .hb-home-sub.hb-hide, .hb-home-ch li.hb-hide { display: none; }

/* Parent chapters and nested chapters */
.hb-parent > summary { font-size: 0.78rem; }
.hb-parent-body { margin: 2px 0 6px 4px; padding-left: 8px; border-left: 2px solid var(--hb-border); }
.hb-sub { border-top: 0; padding: 2px 0; }
.hb-sub > summary { text-transform: none; letter-spacing: normal; font-size: 0.85rem; font-weight: 700; padding: 5px 2px; }
.hb-home-sub h3 { font-size: 0.875rem !important; margin: 10px 0 4px !important; color: var(--hb-navy); }

/* ---------- Search ---------- */

.hb-search { margin: 0 0 10px; position: relative; }
.hb-search input[type="search"] {
	width: 100%; box-sizing: border-box; padding: 9px 12px 9px 34px; font: inherit; font-size: 0.875rem;
	border: 1px solid var(--hb-border) !important; border-radius: 8px; background: var(--hb-bg) !important; color: var(--hb-text) !important;
	background-image: radial-gradient(circle at 15px 50%, transparent 5px, transparent 5px) !important;
}
.hb-search::before {
	content: ''; position: absolute; left: 12px; top: 11px; width: 10px; height: 10px; border: 2px solid var(--hb-muted); border-radius: 50%; pointer-events: none;
}
.hb-search::after {
	content: ''; position: absolute; left: 23px; top: 23px; width: 6px; height: 2px; background: var(--hb-muted); transform: rotate(45deg); pointer-events: none;
}
.hb-nav .hb-search::before, .hb-nav .hb-search::after { display: none; }
.hb-nav .hb-search input[type="search"] { padding-left: 12px; }
.hb-search input:focus { outline: 2px solid var(--hb-accent); outline-offset: 1px; }
.hb-nomatch { font-size: 0.8125rem; color: var(--hb-muted); margin: 6px 2px 0; }

/* ---------- Head: reviewer, tools, listen ---------- */

.hb-head { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; margin-bottom: 18px; max-width: 100%; }
.hb-head > * { min-width: 0; max-width: 100%; box-sizing: border-box; }
.hb-head *, .hb-head *::before, .hb-head *::after { box-sizing: border-box; }
.hb-reviewed > span { min-width: 0; overflow-wrap: anywhere; }
.hb-main, .hb-bottomline, .hb-sec { max-width: 100%; box-sizing: border-box; }

/* Fixed icon sizes, so theme rules like svg { width: 100% } can't stretch them */
.hb-reviewed svg { width: 16px !important; height: 16px !important; flex: none; }
.hb-listen-hp { width: 24px !important; height: 24px !important; flex: none; }
.hb-moon svg { width: 22px !important; height: 22px !important; }

/* Keep the listen bar inside the screen no matter how the theme styles buttons and dropdowns */
.hb-listen button, .hb-listen select { min-width: 0 !important; width: auto !important; height: auto !important; margin: 0 !important; float: none !important; }
.hb-listen-play { white-space: normal !important; }
.hb-listen-speed { flex: none; margin: 0 !important; }
.hb-listen-speed select { width: auto !important; max-width: 76px !important; display: inline-block !important; }
.hb-listen-stop { flex: none; }
@media (max-width: 480px) {
	.hb-listen { padding: 0.4em 0.7em 0.4em 0.4em; gap: 0.45em; }
	.hb-listen-label { white-space: normal !important; overflow: visible !important; text-overflow: clip !important; line-height: 1.25; font-size: 0.875rem; }
	.hb-listen-circle { width: 36px; height: 36px; }
	.hb-listen-hp { width: 20px !important; height: 20px !important; }
	.hb-reviewed { align-items: flex-start; }
}
.hb-chapters-btn {
	justify-self: start; display: inline-flex; align-items: center; gap: 8px;
	padding: 8px 14px !important; min-height: 40px; border-radius: 999px; cursor: pointer;
	border: 1px solid var(--hb-border) !important; background: var(--hb-surface) !important; color: var(--hb-navy) !important;
	font: inherit; font-size: 0.875rem; font-weight: 700; text-transform: none; letter-spacing: normal; box-shadow: none !important;
}
.hb-burger, .hb-burger::before, .hb-burger::after { display: block; width: 16px; height: 2px; background: currentColor; border-radius: 2px; position: relative; }
.hb-burger::before, .hb-burger::after { content: ''; position: absolute; left: 0; }
.hb-burger::before { top: -5px; }
.hb-burger::after { top: 5px; }

.hb-reviewed {
	display: flex; align-items: center; gap: 8px; font-size: 0.875rem; color: var(--hb-muted);
	padding: 8px 12px; border-radius: var(--hb-radius); background: var(--hb-accent-soft);
}
.hb-reviewed svg { color: var(--hb-accent); flex: none; }
.hb-reviewed a { color: var(--hb-navy) !important; font-weight: 700; text-decoration: none !important; box-shadow: none !important; }
.hb-reviewed a:hover { text-decoration: underline !important; }

.hb-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.hb-btn {
	display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px !important; min-height: 36px; border-radius: 999px; cursor: pointer;
	border: 1px solid var(--hb-border) !important; background: transparent !important; color: var(--hb-text) !important;
	font: inherit; font-size: 0.8125rem; font-weight: 600; text-transform: none; letter-spacing: normal; box-shadow: none !important;
}
.hb-btn:hover, .hb-btn[aria-pressed="true"] { border-color: var(--hb-accent) !important; color: var(--hb-accent) !important; }
.hb-ico-moon { width: 11px; height: 11px; border-radius: 50%; box-shadow: inset -4px -2px 0 0 currentColor; transform: rotate(-20deg); display: inline-block; }

.hb-listen {
	display: flex; align-items: center; gap: 0.6em; width: 100%; box-sizing: border-box;
	padding: 0.45em 1em 0.45em 0.45em; border-radius: 999px; background: #000; color: #fff;
}
.hb-listen[hidden], .hb-listen-stop[hidden] { display: none !important; }
.hb-listen button {
	appearance: none; border: 0 !important; box-shadow: none !important; background: transparent !important; color: inherit !important;
	font: inherit; cursor: pointer; text-transform: none; letter-spacing: normal; margin: 0;
}
.hb-listen-play { flex: 1; min-width: 0; display: flex !important; align-items: center; gap: 0.7em; padding: 0 !important; min-height: 42px; text-align: left; }
.hb-listen-circle { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 38px; height: 38px; border-radius: 50%; background: #fff; color: #000; }
html.snz-bedtime .hb-listen-circle { background: #f0b86e; }
.hb-ico-play { width: 0; height: 0; border-style: solid; border-width: 6px 0 6px 10px; border-color: transparent transparent transparent currentColor; margin-left: 3px; }
.is-playing .hb-ico-play { border: 0; width: 10px; height: 12px; border-left: 3px solid currentColor; border-right: 3px solid currentColor; margin-left: 0; }
.hb-ico-stop { display: inline-block; width: 12px; height: 12px; background: currentColor; border-radius: 1px; }
.hb-listen-stop { padding: 0.5em !important; display: inline-flex; }
.hb-listen-label { font-size: 0.9rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hb-listen-speed select { font: inherit; font-size: 0.8125rem; min-height: 32px; padding: 0 0.4em; border: 1px solid rgba(255,255,255,0.35) !important; border-radius: 999px; background: #000 !important; color: #fff !important; }
.hb-listen-hp { flex: none; color: #fff; opacity: 0.9; }
.hb-listen.is-active .hb-listen-hp { animation: hb-pulse 1.6s ease-in-out infinite; }
.hb-reading { background: var(--hb-accent-soft); border-radius: 4px; box-shadow: 0 0 0 4px var(--hb-accent-soft); }

/* ---------- Bottom line card ---------- */

.hb-bottomline {
	margin: 0 0 22px; padding: 16px 18px; border-radius: var(--hb-radius);
	background: var(--hb-card); border: 1px solid var(--hb-border); border-left: 5px solid var(--hb-accent);
}
.hb-bl-label { font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--hb-accent); margin-bottom: 8px; }
.hb-bl-body > :first-child { margin-top: 0; }
.hb-bl-body > :last-child { margin-bottom: 0; }
.hb-bl-body ul, .hb-bl-body ol { margin-left: 1.1em; padding-left: 0.4em; }

/* ---------- Sections ---------- */

.hb-sec { border: 1px solid var(--hb-border); border-radius: var(--hb-radius); margin: 0 0 12px; background: var(--hb-bg); }
.hb-sec-head {
	list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
	padding: 12px 16px; cursor: pointer; border-radius: var(--hb-radius);
}
.hb-sec-head::-webkit-details-marker { display: none; }
.hb-sec-head:hover { background: var(--hb-accent-soft); }
.hb-sec-head:focus-visible { outline: 2px solid var(--hb-accent); outline-offset: 2px; }
.hb-sec-title { margin: 0 !important; font-size: 1.125rem !important; line-height: 1.3 !important; color: var(--hb-navy) !important; }
.hb-sec-body { padding: 0 16px 14px; }
.hb-sec-body > :first-child { margin-top: 0; }
.hb-sec-body ul, .hb-sec-body ol { margin-left: 1.1em; padding-left: 0.4em; }
.hb-sec-body li { margin: 0.25em 0; }
.hb-sec-body h3 { font-size: 1rem; color: var(--hb-navy); margin: 1em 0 0.4em; }
.hb-sec-body table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.hb-sec-body th, .hb-sec-body td { border: 1px solid var(--hb-border); padding: 6px 8px; text-align: left; }
.hb-sec-body th { background: var(--hb-surface); }
.hb-sec-body h2, .hb-sec-body h3, .hb-sec-body h4 { scroll-margin-top: 80px; }
.hb-refs .hb-sec-body { font-size: 0.8125rem; color: var(--hb-muted); }
.hb-refs li:target, .hb-refs .hb-ref-flash { background: var(--hb-accent-soft); border-radius: 4px; }

/* Glowing down arrows */
.hb-arrow {
	flex: none; width: 28px; height: 28px; border-radius: 50%;
	display: inline-flex; align-items: center; justify-content: center;
	background: var(--hb-accent); color: #fff;
	animation: hb-glow 1.8s ease-in-out infinite;
}
html.snz-bedtime .hb-arrow { color: #000; }
.hb-arrow::before {
	content: ''; width: 7px; height: 7px; margin-top: -4px;
	border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg);
	transition: transform 0.25s, margin 0.25s;
}
.hb-arrow--sm { width: 20px; height: 20px; }
.hb-arrow--sm::before { width: 5px; height: 5px; margin-top: -3px; }
details[open] > summary .hb-arrow { animation: none; }
details[open] > summary .hb-arrow::before { transform: rotate(-135deg); margin-top: 4px; }
details[open] > summary .hb-arrow--sm::before { margin-top: 3px; }

@keyframes hb-glow {
	0%, 100% { box-shadow: 0 0 0 0 var(--hb-glow); }
	50% { box-shadow: 0 0 0 7px var(--hb-glow-0); }
}
@keyframes hb-pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

/* Moon next to the title while bedtime mode is on */
.hb-moon {
	appearance: none; display: inline-flex; vertical-align: middle; margin-left: 0.35em; padding: 0.15em !important;
	border: 0 !important; background: transparent !important; box-shadow: none !important; cursor: pointer; line-height: 1;
	color: #f0b86e !important; filter: drop-shadow(0 0 6px rgba(240, 184, 110, 0.6));
}
.hb-moon[hidden] { display: none !important; }

/* ---------- Tooltips ---------- */

.hb-abbr { text-decoration: none; border-bottom: 1px dotted var(--hb-accent); cursor: help; }
.hb-cite {
	font-size: 0.72em; vertical-align: super; line-height: 0; font-weight: 700; padding: 0 1px;
	color: var(--hb-accent) !important; text-decoration: none !important; box-shadow: none !important; cursor: pointer;
}
.hb-cite:hover, .hb-cite:focus-visible { text-decoration: underline !important; }
.hb-tip {
	position: absolute; z-index: 100001; max-width: min(360px, calc(100vw - 24px)); box-sizing: border-box;
	padding: 10px 12px; border-radius: 8px; font-size: 0.8125rem; line-height: 1.45;
	background: #111827; color: #f3f4f6; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.hb-tip[hidden] { display: none; }
.hb-tip strong { color: #fff; }
.hb-tip p { margin: 0 0 6px; }
.hb-tip p:last-child { margin: 0; }
.hb-tip a { color: #9ec1ff !important; text-decoration: underline !important; }
html.snz-bedtime .hb-tip { background: #000; border: 1px solid rgba(240,184,110,0.3); }

/* ---------- Pager ---------- */

.hb-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 26px 0 8px; }
.hb-pg {
	display: grid; gap: 2px; padding: 12px 14px; border-radius: var(--hb-radius); border: 1px solid var(--hb-border);
	text-decoration: none !important; box-shadow: none !important; color: var(--hb-text) !important; background: var(--hb-bg);
}
.hb-pg:hover { border-color: var(--hb-accent); background: var(--hb-accent-soft); }
.hb-pg--next { text-align: right; }
.hb-pg-dir { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--hb-accent); }
.hb-pg-title { font-weight: 600; color: var(--hb-navy); }
.hb-pg--prev .hb-pg-dir::before { content: '\2190  '; }
.hb-pg--next .hb-pg-dir::after { content: '  \2192'; }

/* ---------- Home page ---------- */

.hb-home .hb-search { max-width: 520px; margin-bottom: 20px; }
.hb-home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.hb-home-ch { border: 1px solid var(--hb-border); border-radius: var(--hb-radius); padding: 14px 16px; background: var(--hb-surface); }
.hb-home-ch h2 { font-size: 1rem !important; margin: 0 0 6px !important; color: var(--hb-navy); text-transform: uppercase; letter-spacing: 0.05em; }
.hb-home-desc { font-size: 0.8125rem; color: var(--hb-muted); margin: 0 0 8px; }
.hb-home-ch ol { margin: 0; padding-left: 1.2em; }
.hb-home-ch li { margin: 4px 0; }

/* ---------- Bedtime page colors ---------- */

html.snz-bedtime body { background: var(--hb-bg) !important; color: var(--hb-text) !important; }
html.snz-bedtime body :where(div, section, article, main, header, footer, nav, p, span, li, h1, h2, h3, h4, td, th, blockquote, figure, figcaption):not(.hb-layout *, .hb-tip, .hb-tip *) {
	background-color: transparent !important; color: inherit !important; border-color: var(--hb-border) !important;
}
html.snz-bedtime body a:not(.hb-layout a) { color: #f0b86e !important; }
html.snz-bedtime .hb-layout img { filter: brightness(0.82); }
html.snz-bedtime .hb-layout :is(p, li, td, th, blockquote, strong, em, b, i) { color: inherit !important; }
html.snz-bedtime .hb-layout .hb-sec-body a:not(.hb-cite) { color: #f0b86e !important; }

@media (prefers-reduced-motion: reduce) {
	.hb-arrow, .hb-listen.is-active .hb-listen-hp { animation: none; }
	.hb-arrow::before, .hb-nav { transition: none !important; }
}
@media (max-width: 600px) {
	.hb-pager { grid-template-columns: 1fr; }
	.hb-pg--next { text-align: left; }
}

/* Theme-proof button sizing */
.hb-btn, .hb-chapters-btn { width: auto !important; min-width: 0 !important; height: auto !important; white-space: nowrap; }

/* Bedtime: theme form fields (comments, search) */
html.snz-bedtime body :is(input, textarea, select):not(.hb-layout *, .hb-search *) { background-color: var(--hb-surface) !important; color: var(--hb-text) !important; border-color: var(--hb-border) !important; }

/* ---------- Full-page chapter list: [snoozz_handbook_list] ---------- */
.hb-list { position: relative; box-sizing: border-box; width: 100%; color: var(--hb-text); font-size: 1rem; line-height: 1.5; }
.hb-list .hb-search { margin: 0 0 18px; }
.hb-list .hb-search::before, .hb-list .hb-search::after { display: none; }
.hb-list .hb-search input[type="search"] { width: 100% !important; max-width: none !important; padding: 13px 16px !important; font-size: 1rem; border-radius: 10px; }
.hb-list .hb-chapters { background: transparent; border: 0; padding: 0; }
.hb-list .hb-ch { padding: 8px 0; }
.hb-list .hb-ch > summary { font-size: 0.9rem; padding: 8px 4px; }
.hb-list .hb-sub > summary { font-size: 1rem; }
.hb-list .hb-ch a { padding: 8px 12px; font-size: 1rem; }
.hb-list .hb-ch a:hover { background: var(--hb-accent-soft); }
.hb-list .hb-parent-body { margin-left: 6px; padding-left: 14px; }
.hb-list .hb-arrow--sm { width: 24px; height: 24px; }

/* Search bar turns blue with white text while someone is typing */
.hb-search input[type="search"] { transition: background-color .15s, color .15s, border-color .15s; }
.hb-search input[type="search"],
.hb-search input[type="search"]:focus,
.hb-search input[type="search"]:not(:placeholder-shown) {
	background-color: #2c4f9e !important; background-image: none !important;
	color: #fff !important; border-color: #2c4f9e !important; caret-color: #fff;
}
.hb-search input[type="search"]:focus { outline: 2px solid rgba(44, 79, 158, 0.35); outline-offset: 2px; }
.hb-search input[type="search"]::placeholder { color: rgba(255, 255, 255, 0.8) !important; opacity: 1; }
.hb-search input[type="search"]::-webkit-search-cancel-button { filter: invert(1) brightness(2); cursor: pointer; }
