/* ==========================================================================
   Torah Book — base: semantic tokens, dark mode, layout chrome, a11y.
   Palette source of truth = theme.json presets; dark mode re-points them.
   ========================================================================== */

:root {
	--tb-bg: var(--wp--preset--color--base);
	--tb-surface: var(--wp--preset--color--surface);
	--tb-surface-2: var(--wp--preset--color--surface-2);
	--tb-ink: var(--wp--preset--color--ink);
	--tb-muted: var(--wp--preset--color--muted);
	--tb-primary: var(--wp--preset--color--primary);
	--tb-on-primary: var(--wp--preset--color--on-primary);
	--tb-accent: var(--wp--preset--color--accent);
	--tb-accent-ink: var(--wp--preset--color--accent-ink);
	--tb-sage: var(--wp--preset--color--sage);
	--tb-sage-soft: var(--wp--preset--color--sage-soft);
	--tb-clay: var(--wp--preset--color--clay);
	--tb-clay-soft: var(--wp--preset--color--clay-soft);
	--tb-border: var(--wp--preset--color--border);
	--tb-primary-soft: #E3E9F1;
	--tb-accent-soft: #F6ECD6;
	--tb-hover: rgb(30 58 95 / .06);
	--tb-feature-bg: #1E3A5F;
	--tb-feature-ink: #F7F2E8;
	--tb-feature-muted: #C9D3E0;
	--tb-mark-gold: #D9AE5F;
	--tb-header-bg: rgb(247 242 232 / .86);
	--tb-focus: #B8862B;

	--tb-serif: var(--wp--preset--font-family--serif);
	--tb-sans: var(--wp--preset--font-family--sans);

	--tb-r-sm: 8px; --tb-r-md: 14px; --tb-r-lg: 20px; --tb-r-xl: 28px; --tb-r-pill: 999px;
	--tb-s-1: 4px; --tb-s-2: 8px; --tb-s-3: 12px; --tb-s-4: 16px; --tb-s-5: 20px; --tb-s-6: 24px; --tb-s-8: 32px; --tb-s-10: 40px; --tb-s-12: 48px; --tb-s-16: 64px;
	--tb-shadow-sm: var(--wp--preset--shadow--sm);
	--tb-shadow-md: var(--wp--preset--shadow--md);
	--tb-shadow-lg: var(--wp--preset--shadow--lg);
	--tb-fast: 150ms; --tb-base: 220ms; --tb-ease: cubic-bezier(.2,.7,.2,1);

	--tb-header-h: 56px;
	--tb-tabbar-h: 64px;
	--tb-fs: 100%;
	color-scheme: light;
}

/* ---- Dark: re-point presets so every core block follows too ------------- */
:root[data-theme="dark"] {
	--wp--preset--color--base: #0E141E;
	--wp--preset--color--surface: #151D2A;
	--wp--preset--color--surface-2: #1C2636;
	--wp--preset--color--ink: #ECE5D5;
	--wp--preset--color--muted: #A2ABB9;
	--wp--preset--color--primary: #93B6E2;
	--wp--preset--color--on-primary: #0E141E;
	--wp--preset--color--accent: #D9AE5F;
	--wp--preset--color--accent-ink: #E3BD77;
	--wp--preset--color--sage: #9BC2A1;
	--wp--preset--color--sage-soft: #1B2A22;
	--wp--preset--color--clay: #E69C80;
	--wp--preset--color--clay-soft: #2F211C;
	--wp--preset--color--border: #283346;
	--wp--preset--shadow--sm: 0 1px 2px rgb(0 0 0 / .3);
	--wp--preset--shadow--md: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px -8px rgb(0 0 0 / .5);
	--wp--preset--shadow--lg: 0 2px 6px rgb(0 0 0 / .35), 0 20px 50px -12px rgb(0 0 0 / .6);
	--tb-primary-soft: #1D2B40;
	--tb-accent-soft: #2E2616;
	--tb-hover: rgb(147 182 226 / .08);
	--tb-feature-bg: #1A2C47;
	--tb-feature-ink: #F2EBDB;
	--tb-feature-muted: #B5C2D3;
	--tb-header-bg: rgb(14 20 30 / .82);
	--tb-focus: #E3BD77;
	color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
	/* No-JS fallback; the head script normally sets data-theme explicitly. */
	:root:not([data-theme]) {
		--wp--preset--color--base: #0E141E; --wp--preset--color--surface: #151D2A; --wp--preset--color--surface-2: #1C2636;
		--wp--preset--color--ink: #ECE5D5; --wp--preset--color--muted: #A2ABB9; --wp--preset--color--primary: #93B6E2;
		--wp--preset--color--on-primary: #0E141E; --wp--preset--color--accent-ink: #E3BD77; --wp--preset--color--border: #283346;
		--tb-header-bg: rgb(14 20 30 / .82); --tb-feature-bg: #1A2C47; color-scheme: dark;
	}
}

/* ---- Text size control (A− / A+) ---------------------------------------- */
:root[data-fs="-1"] { --tb-fs: 93.75%; }
:root[data-fs="1"]  { --tb-fs: 112.5%; }
:root[data-fs="2"]  { --tb-fs: 125%; }
html { font-size: var(--tb-fs); -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--tb-header-h) + 16px); }

/* ---- Base ---------------------------------------------------------------- */
body {
	background: var(--tb-bg);
	color: var(--tb-ink);
	font-feature-settings: "kern";
	text-rendering: optimizeLegibility;
	-webkit-font-smoothing: antialiased;
	-webkit-tap-highlight-color: transparent;
	transition: background-color var(--tb-base) var(--tb-ease), color var(--tb-base) var(--tb-ease);
}
::selection { background: var(--tb-accent-soft); color: var(--tb-ink); }
img, svg, video { max-width: 100%; height: auto; }
.tb-icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.25em; }
.wp-site-blocks { min-height: 100dvh; display: flex; flex-direction: column; }
.wp-site-blocks > main, .tb-main { flex: 1 0 auto; }
.wp-site-blocks > * + * { margin-block-start: 0; }
.tb-header-part, .tb-footer-part { display: contents; }

h1, h2, h3, h4 { text-wrap: balance; letter-spacing: 0; }
p { text-wrap: pretty; }
a { text-underline-offset: .22em; text-decoration-thickness: 1px; }

/* ---- Focus + skip link --------------------------------------------------- */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
	outline: 2.5px solid var(--tb-focus);
	outline-offset: 2px;
	border-radius: 6px;
}
.tb-skip {
	position: fixed; inset-inline-start: 12px; top: -60px; z-index: 1000;
	background: var(--tb-primary); color: var(--tb-on-primary);
	padding: 10px 16px; border-radius: var(--tb-r-pill); font-weight: 600; text-decoration: none;
	transition: top var(--tb-fast) var(--tb-ease);
}
.tb-skip:focus { top: calc(12px + env(safe-area-inset-top, 0px)); }
#wp-skip-link { display: none !important; } /* core duplicate; .tb-skip is ours */
.screen-reader-text, .tb-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Header -------------------------------------------------------------- */
.tb-header {
	position: sticky; top: 0; z-index: 50;
	background: var(--tb-header-bg);
	-webkit-backdrop-filter: saturate(1.4) blur(14px);
	backdrop-filter: saturate(1.4) blur(14px);
	padding-top: env(safe-area-inset-top, 0px);
	border-block-end: 1px solid transparent;
	view-transition-name: tb-header;
	transition: border-color var(--tb-base) var(--tb-ease), box-shadow var(--tb-base) var(--tb-ease);
}
.admin-bar .tb-header { top: var(--wp-admin--admin-bar--height, 0px); }
.tb-header.is-scrolled { border-color: var(--tb-border); }
.tb-header__inner {
	max-width: 72rem; margin-inline: auto; height: var(--tb-header-h);
	padding-inline: max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-left));
	display: flex; align-items: center; gap: 16px;
}
.tb-brand { display: inline-flex; align-items: center; gap: 10px; min-height: 48px; color: var(--tb-ink); text-decoration: none; flex: none; }
.tb-brand__mark { width: 32px; height: 32px; color: var(--tb-primary); }
:root[data-theme="dark"] .tb-brand__mark { color: #24406A; }
.tb-brand__word { font-family: var(--tb-serif); font-weight: 700; font-size: 1.3125rem; line-height: 1; letter-spacing: -.005em; }
.tb-brand__word b { color: var(--tb-accent-ink); font-weight: 700; }

.tb-nav { display: none; margin-inline-start: 8px; }
.tb-nav ul { display: flex; gap: 2px; list-style: none; margin: 0; padding: 0; }
.tb-nav a {
	display: block; padding: 8px 12px; border-radius: var(--tb-r-pill);
	color: var(--tb-muted); text-decoration: none; font-size: .9375rem; font-weight: 500;
	transition: color var(--tb-fast), background-color var(--tb-fast);
}
.tb-nav a:hover { color: var(--tb-ink); background: var(--tb-hover); }
.tb-nav a[aria-current="page"] { color: var(--tb-primary); background: var(--tb-primary-soft); font-weight: 600; }

.tb-header__tools { margin-inline-start: auto; display: flex; align-items: center; gap: 4px; }
.tb-iconbtn {
	display: inline-grid; place-items: center; width: 48px; height: 48px; padding: 0;
	border: 0; border-radius: var(--tb-r-pill); background: transparent; color: var(--tb-ink);
	cursor: pointer; transition: background-color var(--tb-fast);
}
.tb-iconbtn:hover { background: var(--tb-hover); }
.tb-iconbtn .tb-icon { width: 22px; height: 22px; }
.tb-theme-btn .tb-icon--sun, :root[data-theme="dark"] .tb-theme-btn .tb-icon--moon { display: none; }
:root[data-theme="dark"] .tb-theme-btn .tb-icon--sun { display: block; }

@media (min-width: 960px) {
	.tb-nav { display: block; }
	:root { --tb-header-h: 72px; }
	.tb-header__inner { padding-inline: 24px; gap: 24px; }
}

/* ---- Bottom tab bar (mobile) -------------------------------------------- */
.tb-tabbar {
	position: fixed; inset-inline: 0; bottom: 0; z-index: 60;
	background: var(--tb-header-bg);
	-webkit-backdrop-filter: saturate(1.4) blur(14px);
	backdrop-filter: saturate(1.4) blur(14px);
	border-block-start: 1px solid var(--tb-border);
	padding-bottom: env(safe-area-inset-bottom, 0px);
	padding-inline: env(safe-area-inset-right, 0px) env(safe-area-inset-left, 0px);
	view-transition-name: tb-tabbar; user-select: none; -webkit-user-select: none;
}
.tb-tabbar ul { display: grid; grid-template-columns: repeat(5, 1fr); list-style: none; margin: 0 auto; padding: 0 4px; max-width: 34rem; }
.tb-tabbar a {
	display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
	height: var(--tb-tabbar-h); color: var(--tb-muted); text-decoration: none;
	font-size: .75rem; font-weight: 500; letter-spacing: .01em; position: relative;
}
.tb-tabbar .tb-icon { width: 24px; height: 24px; transition: transform var(--tb-fast) var(--tb-ease); }
.tb-tabbar a[aria-current="page"] { color: var(--tb-primary); font-weight: 700; }
.tb-tabbar a[aria-current="page"]::before {
	content: ""; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--tb-accent);
}
.tb-tabbar a:active .tb-icon { transform: scale(.88); }
.tb-tabbar a:active { color: var(--tb-ink); }
body { padding-bottom: calc(var(--tb-tabbar-h) + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 960px) {
	.tb-tabbar { display: none; }
	body { padding-bottom: 0; }
}

/* ---- Main / page scaffolding -------------------------------------------- */
.tb-main { padding-block: 24px 64px; }
@media (min-width: 960px) { .tb-main { padding-block: 40px 96px; } }
.tb-container { max-width: 72rem; margin-inline: auto; padding-inline: 16px; }
@media (min-width: 640px) { .tb-container { padding-inline: 24px; } }

.tb-pagehead { margin-block-end: 32px; }
.tb-eyebrow {
	display: inline-flex; align-items: center; gap: 8px; margin: 0 0 8px;
	font-size: .8125rem; font-weight: 600; letter-spacing: .02em; color: var(--tb-accent-ink);
}
.tb-eyebrow::before { content: ""; width: 18px; height: 1.5px; background: currentColor; border-radius: 2px; }
.tb-lede { font-size: 1.125rem; color: var(--tb-muted); max-width: 38rem; margin: 8px 0 0; }

/* Prose (single / page content) */
.tb-prose { font-size: 1.125rem; line-height: 1.85; }
.tb-prose > * { max-width: 40rem; margin-inline: auto; }
.tb-prose h2 { margin-block: 2.2em .6em; }
.tb-prose h3 { margin-block: 1.8em .5em; }
.tb-prose p { margin-block: 0 1.1em; }
.tb-prose blockquote { font-family: var(--tb-serif); }


/* ---- Today hero ------------------------------------------------------------ */
.tb-hero { padding-block: 8px 28px; }
.tb-hero__date { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 0 0 6px; font-size: .9375rem; color: var(--tb-muted); }
.tb-hebdate { font-family: var(--tb-serif); font-weight: 700; font-size: 1.0625rem; color: var(--tb-accent-ink); min-width: 6em; }
.tb-hero__dot { width: 4px; height: 4px; border-radius: 50%; background: var(--tb-accent); opacity: .7; }
.tb-hero__greet { margin: 0; font-family: var(--tb-serif); font-weight: 700; font-size: var(--wp--preset--font-size--display); line-height: 1.1; letter-spacing: -.01em; }
.tb-hero__lede { margin: 12px 0 0; max-width: 36rem; font-size: 1.0625rem; line-height: 1.7; color: var(--tb-muted); }
@media (min-width: 960px) { .tb-hero { padding-block: 16px 40px; } .tb-hero__lede { font-size: 1.1875rem; } }
.tb-today .tb-grid { margin-top: 0; }
.tb-today .tb-slot--wide[data-slot="paths"] { margin-top: 24px; }

/* ---- Lists, archives, singles --------------------------------------------- */
.tb-pagehead h1, .tb-pagehead .wp-block-post-title, .tb-pagehead .wp-block-query-title { margin: 0; font-size: var(--wp--preset--font-size--xxl); }
.tb-pagehead > * + * { margin-top: 8px; }
.tb-pagehead .tb-lede, .tb-pagehead .wp-block-post-excerpt__excerpt { margin-top: 10px; color: var(--tb-muted); font-size: 1.125rem; }
.tb-pagehead .wp-block-search { margin-top: 20px; }
.tb-meta { font-size: .875rem; color: var(--tb-muted); }
.wp-block-post-template.tb-grid { list-style: none; padding: 0; margin: 0; }
.tb-list .tb-card__title { font-size: 1.25rem; }
.tb-list .wp-block-post-excerpt__excerpt { margin: 0; }
.tb-list .wp-block-post-excerpt__more-text { display: none; }
.tb-postnav { margin-top: 48px; padding-top: 20px; border-top: 1px solid var(--tb-border); font-weight: 600; }
.tb-postnav a { text-decoration: none; }

/* ---- Empty / 404 ------------------------------------------------------------- */
.tb-empty { max-width: 34rem; text-align: center; padding-block: 24px 40px; }
.tb-empty h1 { margin: 0 0 4px; }
.tb-empty .tb-lede { margin: 0 auto 28px; }
.tb-empty .tb-eyebrow::before { display: none; }
.tb-empty__mark { width: 72px; height: 72px; margin: 0 auto 20px; border-radius: 24px; display: grid; place-items: center; background: var(--tb-accent-soft); color: var(--tb-accent-ink); }
.tb-empty__mark .tb-icon { width: 36px; height: 36px; }
.tb-empty__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 20px; }

/* ---- Footer -------------------------------------------------------------- */
.tb-footer { border-block-start: 1px solid var(--tb-border); background: var(--tb-surface-2); color: var(--tb-muted); font-size: .9375rem; }
.tb-footer__inner { max-width: 72rem; margin-inline: auto; padding: 40px 16px 32px; display: grid; gap: 28px; }
.tb-footer__ask {
	display: flex; gap: 14px; align-items: flex-start; padding: 16px 18px;
	border-radius: var(--tb-r-md); background: var(--tb-surface); border: 1px solid var(--tb-border); color: var(--tb-ink);
}
.tb-footer__ask .tb-icon { width: 24px; height: 24px; color: var(--tb-accent-ink); margin-top: 2px; }
.tb-footer__ask strong { display: block; font-family: var(--tb-serif); font-size: 1.125rem; margin-bottom: 2px; }
.tb-footer__ask p { margin: 0; color: var(--tb-muted); font-size: .9375rem; }
.tb-footer__cols { display: grid; gap: 24px; grid-template-columns: 1fr 1fr; }
.tb-footer h2 { font-family: var(--tb-sans); font-size: .8125rem; font-weight: 700; color: var(--tb-ink); margin: 0 0 10px; letter-spacing: .02em; }
.tb-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.tb-footer a { color: var(--tb-muted); text-decoration: none; }
.tb-footer a:hover { color: var(--tb-primary); text-decoration: underline; }
.tb-footer__brand p { margin: 10px 0 0; max-width: 26rem; }
.tb-footer__sources { grid-column: 1 / -1; }
.tb-footer__sources p { margin: 0; max-width: 32rem; }
@media (min-width: 800px) { .tb-footer__sources { grid-column: auto; } }
.tb-footer__legal { border-block-start: 1px solid var(--tb-border); padding-top: 18px; font-size: .8125rem; display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: space-between; }
@media (min-width: 800px) {
	.tb-footer__inner { grid-template-columns: 1.3fr 2fr; padding-block: 56px 40px; }
	.tb-footer__ask, .tb-footer__legal { grid-column: 1 / -1; }
	.tb-footer__cols { grid-template-columns: 1fr 1fr 1.6fr; }
}


/* ---- App shell: touch, transitions, standalone ------------------------------ */
a, button, summary, input, select, textarea, label, [role="button"], [role="tab"] { touch-action: manipulation; }
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 180ms; animation-timing-function: var(--tb-ease); }
::view-transition-group(tb-header), ::view-transition-group(tb-tabbar) { animation: none; }
@media (prefers-reduced-motion: reduce) {
	@view-transition { navigation: none; }
}
@media (display-mode: standalone) {
	/* Installed PWA: no browser chrome, so the shell carries the brand. */
	.tb-header { border-color: var(--tb-border); }
	.tb-main { padding-top: 16px; }
}

/* ---- Motion ------------------------------------------------------------- */
@keyframes tb-fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes tb-fade { from { opacity: 0; } to { opacity: 1; } }
.tb-reveal { animation: tb-fade-up var(--tb-base) var(--tb-ease) both; }
@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

/* ---- Print ---------------------------------------------------------------- */
@media print {
	.tb-header, .tb-tabbar, .tb-sheet, .tb-footer__cols, .tb-skip { display: none !important; }
	body { background: #fff; color: #000; padding: 0; }
}
