/**
 * Scripture references and the panel they open.
 *
 * Every colour here is an --atn-* token, never a literal, so the whole thing
 * follows the theme toggle without a second rule. The tokens are re-pointed at
 * the dark set in style.css; nothing below needs to know which set is live.
 */

/* ── the reference in the prose ────────────────────────────────────────
 *
 * It has to read as a link inside a sentence without shouting. Gold ink plus a
 * dotted underline: the dotted rule is the convention for "this reveals
 * something" rather than "this navigates", which is exactly the difference here.
 *
 * `button` resets first — a UA button inside a paragraph brings its own font,
 * background and padding, and would break the line's rhythm.
 */
.atn-verse {
	appearance: none;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	font: inherit;
	color: var(--atn-gold-ink);
	text-decoration: underline;
	text-decoration-style: dotted;
	text-underline-offset: 0.18em;
	text-decoration-thickness: 1px;
	cursor: pointer;
	/* Keeps a reference from being split across two lines mid-citation. */
	white-space: nowrap;
	transition: color 0.15s ease, text-decoration-color 0.15s ease;
}

.atn-verse:hover,
.atn-verse:focus-visible {
	color: var(--atn-ember);
	text-decoration-style: solid;
}

.atn-verse:focus-visible {
	outline: 2px solid var(--atn-gold);
	outline-offset: 2px;
	border-radius: 2px;
}

/* Open state, so it is obvious which of six references on the page the panel
   belongs to — the panel can otherwise sit some distance from its trigger. */
.atn-verse[aria-expanded='true'] {
	color: var(--atn-ember);
	text-decoration-style: solid;
	background: var(--atn-gold-wash);
	box-shadow: 0 0 0 3px var(--atn-gold-wash);
	border-radius: 2px;
}

/* ── the panel ─────────────────────────────────────────────────────── */

.atn-verse-panel {
	position: fixed;
	z-index: 999;
	width: min(30rem, calc(100vw - 2rem));
	max-height: min(26rem, 70vh);
	overflow-y: auto;
	padding: 1.15rem 1.25rem 1rem;
	background: var(--atn-surface);
	color: var(--atn-body);
	border: 1px solid var(--atn-hairline);
	border-radius: 14px;
	box-shadow: var(--atn-shadow);
	/* Overscroll containment: flicking to the end of a long psalm should not then
	   start scrolling the page underneath it. */
	overscroll-behavior: contain;
}

.atn-verse-panel[hidden] {
	display: none;
}

.atn-verse-panel__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 0.5rem;
}

.atn-verse-panel__ref {
	margin: 0;
	font-family: var(--wp--preset--font-family--display);
	font-size: 1.35rem;
	line-height: 1.1;
	letter-spacing: 0.01em;
	color: var(--atn-ink);
}

.atn-verse-panel__close {
	appearance: none;
	flex: none;
	width: 1.75rem;
	height: 1.75rem;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--atn-surface-2);
	color: var(--atn-muted);
	font-size: 1.1rem;
	line-height: 1;
	cursor: pointer;
}

.atn-verse-panel__close:hover {
	color: var(--atn-ink);
}

/* The gold rule under the heading, matching the app's verse sheet. */
.atn-verse-panel__head::after {
	content: none;
}

.atn-verse-panel__body {
	border-top: 2px solid var(--atn-gold);
	padding-top: 0.85rem;
}

.atn-verse-panel__text {
	margin: 0;
	font-size: 1.02rem;
	line-height: 1.62;
	color: var(--atn-body);
}

/* Verse numbers sit above the reading line rather than in it — the same call the
   app's sheet makes. `sup` alone would inherit the line's leading and push the
   lines apart, hence the explicit zero line-height. */
.atn-verse-panel__num {
	font-family: var(--wp--preset--font-family--util);
	font-size: 0.62em;
	line-height: 0;
	font-weight: 700;
	color: var(--atn-gold-ink);
	vertical-align: super;
	margin-inline-end: 0.1em;
}

.atn-verse-panel__loading,
.atn-verse-panel__error {
	margin: 0;
	font-size: 0.95rem;
	color: var(--atn-muted);
}

.atn-verse-panel__foot {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-top: 0.9rem;
	padding-top: 0.7rem;
	border-top: 1px solid var(--atn-hairline);
}

.atn-verse-panel__foot:empty {
	display: none;
}

.atn-verse-panel__version {
	font-family: var(--wp--preset--font-family--util);
	font-size: 0.72rem;
	letter-spacing: 0.09em;
	text-transform: uppercase;
	color: var(--atn-muted);
}

.atn-verse-panel__copy {
	appearance: none;
	padding: 0.34rem 0.9rem;
	border: 1px solid var(--atn-hairline-strong);
	border-radius: 999px;
	background: none;
	color: var(--atn-ink);
	font-family: var(--wp--preset--font-family--util);
	font-size: 0.75rem;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	cursor: pointer;
}

.atn-verse-panel__copy:hover {
	background: var(--atn-surface-2);
}

/* ── narrow screens: a bottom sheet, not a popover ─────────────────────
 *
 * Anchoring to a word is meaningless on a 360px column — the panel would cover
 * the sentence anyway — so below 640px it docks to the bottom edge, which is
 * where a thumb is and what the app already does.
 *
 * The class is set from JS rather than by media query alone because the
 * positioning code has to stop writing inline left/top at the same breakpoint;
 * a media query cannot un-set an inline style.
 */
.atn-verse-panel.is-sheet {
	left: 0 !important;
	right: 0;
	top: auto !important;
	bottom: 0;
	width: 100%;
	max-height: 70vh;
	border-radius: 18px 18px 0 0;
	border-bottom: 0;
	padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

@media (prefers-reduced-motion: no-preference) {
	.atn-verse-panel {
		animation: atn-verse-in 0.14s ease-out;
	}

	@keyframes atn-verse-in {
		from {
			opacity: 0;
			transform: translateY(-4px);
		}
	}

	.atn-verse-panel.is-above {
		animation-name: atn-verse-in-above;
	}

	@keyframes atn-verse-in-above {
		from {
			opacity: 0;
			transform: translateY(4px);
		}
	}

	.atn-verse-panel.is-sheet {
		animation-name: atn-verse-in-sheet;
	}

	@keyframes atn-verse-in-sheet {
		from {
			opacity: 0;
			transform: translateY(14px);
		}
	}
}

/* ── print ────────────────────────────────────────────────────────────
 *
 * On paper a popover cannot be opened, so the reference goes back to being plain
 * text. The panel itself never prints — if one happened to be open, it would land
 * mid-page over the article.
 */
@media print {
	.atn-verse {
		color: inherit;
		text-decoration: none;
	}

	.atn-verse-panel {
		display: none !important;
	}
}
