/**
 * Archie Drexel - component styles.
 *
 * theme.json owns the tokens (colour, type, spacing). This file owns the things
 * theme.json cannot express: the torn edges, the hard offset shadows, the evidence
 * chips, and the per-book accent cascade.
 *
 * The whole design rests on one idea: site chrome is cream and ink, and each book
 * supplies its own accent. Everything below reads --accent rather than a fixed hue.
 */

/* ---------------------------------------------------------------- accents */

body {
	--accent: var(--wp--preset--color--red);
	--accent-fill: var(--wp--preset--color--red);
	--on-accent: #fff7ea;
	--edge: var(--wp--preset--color--ink);
	--torn: 13px;
}

/* Usable on <body> (set from the book's own field) or on any Group block,
   via the block's Additional CSS class. */
.accent-blue  { --accent: var(--wp--preset--color--blue);     --accent-fill: var(--wp--preset--color--blue);  --on-accent: #fff7ea; }
.accent-green { --accent: var(--wp--preset--color--green);    --accent-fill: var(--wp--preset--color--green); --on-accent: #fff7ea; }
.accent-red   { --accent: var(--wp--preset--color--red);      --accent-fill: var(--wp--preset--color--red);   --on-accent: #fff7ea; }
/* Gold is the one that needs two values: the cover gold is too light for small
   text on cream, so text uses the darkened gold and fills keep the cover gold. */
.accent-gold  { --accent: var(--wp--preset--color--gold-ink); --accent-fill: var(--wp--preset--color--gold);  --on-accent: var(--wp--preset--color--ink); }

/* ------------------------------------------------------------ foundations */

body { -webkit-font-smoothing: antialiased; }

:where(a):focus-visible,
:where(button):focus-visible,
:where(input):focus-visible {
	outline: 3px solid var(--accent);
	outline-offset: 3px;
}

.archie-eyebrow {
	font-family: var(--wp--preset--font-family--file);
	font-size: var(--wp--preset--font-size--x-small);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.15em;
	color: var(--accent);
	margin: 0;
}

.archie-lede {
	font-size: var(--wp--preset--font-size--large);
	color: var(--wp--preset--color--muted);
	max-width: 56ch;
}

.archie-muted { color: var(--wp--preset--color--muted); }

/* ------------------------------------------------------------------ chrome */

.archie-header {
	position: sticky;
	top: 0;
	z-index: 40;
	background: var(--wp--preset--color--cream);
	border-bottom: 2px solid var(--edge);
}

.archie-header .wp-block-site-title a { text-decoration: none; }

.archie-header .wp-block-navigation a {
	text-decoration: none;
	padding: 7px 13px;
	border-radius: 999px;
}

.archie-header .wp-block-navigation a:hover {
	background: var(--wp--preset--color--paper);
	color: var(--wp--preset--color--ink);
}

/* The page you are on is an accent pill, matching the approved design. */
.archie-header .wp-block-navigation .current-menu-item > a,
.archie-header .wp-block-navigation .current-menu-ancestor > a {
	background: var(--accent-fill);
	color: var(--on-accent);
}

/* Submenus - a Books dropdown listing individual titles. Core gives these a plain
   white box by default, which is the one place the theme's paper-and-ink chrome
   would otherwise break. */
.archie-header .wp-block-navigation__submenu-container {
	background: var(--wp--preset--color--paper);
	border: 2px solid var(--edge);
	border-radius: 4px;
	box-shadow: 5px 5px 0 var(--edge);
	padding: 6px;
	min-width: 230px;
}

.archie-header .wp-block-navigation__submenu-container li a {
	border-radius: 6px;
	padding: 8px 12px;
}

.archie-header .wp-block-navigation__submenu-icon { margin-left: 4px; }

/* Mobile overlay keeps the cream ground rather than core's default white. */
.archie-header .wp-block-navigation__responsive-container.is-menu-open {
	background: var(--wp--preset--color--cream);
	color: var(--wp--preset--color--ink);
	padding: 24px;
}

.archie-footer {
	border-top: 2px solid var(--edge);
	margin-top: var(--wp--preset--spacing--50);
	padding-block: var(--wp--preset--spacing--50);
}

.archie-footer a { text-decoration: none; color: var(--wp--preset--color--muted); }
.archie-footer a:hover { color: var(--wp--preset--color--ink); }
.archie-footer .wp-block-heading { color: var(--accent); }

/* ----------------------------------------------------------- torn edges */

/* Both styles get their polygon from assets/js/torn.js. Without JS the band is
   still a coloured band and the frame is still a coloured border, so nothing
   breaks - it just loses the ripped edge. */
.wp-block-group.is-style-torn-band {
	background: var(--accent-fill);
	color: var(--on-accent);
	padding-block: var(--wp--preset--spacing--60);
	margin-block: var(--wp--preset--spacing--40);
}

:is( .is-style-torn-band, .is-style-torn-masthead ) :where( h1, h2, h3, p, li ) { color: var(--on-accent); }

/*
 * One torn edge per page, at the top, the way each cover carries one frame. Body
 * sections stay clean - three of these stacked down a page turns the signature into
 * wallpaper. The homepage is the exception: its hero already holds a real cover, so
 * it gets no masthead.
 */
.wp-block-group.is-style-torn-masthead {
	background: var(--accent-fill);
	color: var(--on-accent);
	padding-block: var(--wp--preset--spacing--50) calc( var(--wp--preset--spacing--50) + 18px );
	margin-block: 0 var(--wp--preset--spacing--40);
}

.is-style-torn-masthead > * { margin-block: 0; }
.is-style-torn-masthead > * + * { margin-block-start: 0.6rem; }

.is-style-torn-masthead p {
	font-size: var(--wp--preset--font-size--large);
	max-width: 56ch;
	opacity: 0.92;
}

.is-style-torn-masthead .archie-shelf-line { gap: 0; }

.wp-block-group.is-style-torn-frame {
	background: var(--accent-fill);
	padding: 14px;
}

.is-style-torn-frame > *,
.archie-torn-inner {
	background: var(--wp--preset--color--paper);
	height: 100%;
}

/* torn.js clips this element specifically when it is present, so a frame can hold
   several blocks without the ripped edge landing on only the first one. */
.archie-torn-inner > .wp-block-image { margin: 0; }
.archie-torn-inner .wp-block-image img { width: 100%; display: block; }

/*
 * A torn frame at section scale: the cover construction applied to content rather
 * than to a photo. This is the homepage's one torn edge - it has no masthead, so the
 * rule still holds at one per page. Posts stay on cream inside it and stay readable,
 * which a full accent band costs you.
 */
.archie-section-frame {
	padding: clamp( 24px, 3vw, 36px ) clamp( 20px, 2.6vw, 32px ) clamp( 28px, 3.4vw, 40px );
}

.archie-section-frame > * + * { margin-block-start: var(--wp--preset--spacing--30); }
.archie-section-frame .archie-posts { margin-block-start: var(--wp--preset--spacing--30); }

/* --------------------------------------------------------- hard shadows */

.wp-block-image.is-style-hard-shadow img {
	border: 2px solid var(--edge);
	box-shadow: 14px 14px 0 var(--edge);
}

.archie-cover img {
	border: 2px solid var(--edge);
	box-shadow: 7px 7px 0 var(--accent-fill);
	transition: transform 0.15s ease, box-shadow 0.15s ease;
}

a:hover > .archie-cover img,
.archie-card:hover .archie-cover img {
	transform: translate( -3px, -3px );
	box-shadow: 10px 10px 0 var(--accent-fill);
}

.wp-block-button__link {
	box-shadow: 4px 4px 0 var(--edge);
	transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.wp-block-button__link:hover {
	transform: translate( 2px, 2px );
	box-shadow: 2px 2px 0 var(--edge);
}

.is-style-outline > .wp-block-button__link {
	background: transparent;
	color: var(--wp--preset--color--ink);
	border-color: var(--edge);
}

/* ------------------------------------------------------- topics + support */

/*
 * This section is the one place on the site that is not being playful. The rest of
 * the design shouts - marker headlines, torn edges, hard shadows, sparkles. Grief and
 * loneliness in that register reads as a joke at the reader's expense, so everything
 * here steps down a level: the body face instead of the case-file mono, sentence case
 * instead of uppercase, a soft tint instead of a hard outline, and no sparkle.
 */
.archie-topics {
	margin-block-start: var(--wp--preset--spacing--30);
}

.archie-topics__list {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	list-style: none;
	margin: 0.7rem 0 0;
	padding: 0;
}

.archie-topic {
	font-family: var(--wp--preset--font-family--body);
	font-size: var(--wp--preset--font-size--small);
	line-height: 1.4;
	color: var(--wp--preset--color--ink);
	background: color-mix( in srgb, var(--accent) 12%, transparent );
	border: 1px solid color-mix( in srgb, var(--accent) 28%, transparent );
	border-radius: 5px;
	padding: 6px 11px;
	max-width: 34ch;
}

/* Older browsers with no color-mix still get a legible tag, just flatter. */
@supports not ( background: color-mix( in srgb, red 10%, transparent ) ) {
	.archie-topic {
		background: var(--wp--preset--color--paper);
		border-color: var(--wp--preset--color--line);
	}
}

.archie-topics__prose {
	font-size: var(--wp--preset--font-size--x-small);
	line-height: 1.6;
	color: var(--wp--preset--color--muted);
	max-width: 68ch;
	margin-top: 0.6rem;
}

/*
 * No left rule here. A vertical rule reads as a quotation, and .archie-pull already
 * uses one for the book's actual pull quote - two unrelated things in the same
 * costume on the same page. This is a note attached to the topics above it, so it
 * gets the faintest version of the same tint and sits as a panel, not a quote.
 */
.archie-support {
	margin-block-start: 1rem;
	max-width: 62ch;
	padding: 14px 16px;
	border-radius: 6px;
	background: color-mix( in srgb, var(--accent) 7%, transparent );
}

@supports not ( background: color-mix( in srgb, red 10%, transparent ) ) {
	.archie-support {
		background: none;
		padding-inline: 0;
		border-top: 1.5px solid var(--wp--preset--color--line);
		border-radius: 0;
	}
}

.archie-support__text {
	font-size: var(--wp--preset--font-size--small);
	line-height: 1.65;
	color: var(--wp--preset--color--muted);
	text-wrap: pretty;
}

.archie-support__link {
	margin-top: 0.45rem;
	font-size: var(--wp--preset--font-size--small);
	font-weight: 700;
}

.archie-support__link a {
	color: var(--accent);
	text-underline-offset: 3px;
}

/* ------------------------------------------------------------- retailers */

.archie-buy {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	list-style: none;
	margin: 0;
	padding: 0;
}

.archie-buy a,
.archie-buy span {
	display: inline-block;
	font-weight: 700;
	font-size: var(--wp--preset--font-size--small);
	text-decoration: none;
	padding: 10px 18px;
	border: 2px solid var(--wp--preset--color--line);
	border-radius: 999px;
	transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.archie-buy a:hover {
	background: var(--accent-fill);
	color: var(--on-accent);
	border-color: var(--accent-fill);
}

/* ------------------------------------------------------------ book facts */

.archie-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 36px;
	margin: 0;
	font-family: var(--wp--preset--font-family--file);
	font-size: var(--wp--preset--font-size--small);
	text-transform: uppercase;
	letter-spacing: 0.07em;
}

.archie-meta div { margin: 0; }
.archie-meta dd { margin: 0; }

.archie-meta dt {
	color: var(--wp--preset--color--muted);
	font-size: var(--wp--preset--font-size--x-small);
	letter-spacing: 0.13em;
}

.archie-block-notice {
	font-family: var(--wp--preset--font-family--file);
	font-size: var(--wp--preset--font-size--x-small);
	color: var(--wp--preset--color--muted);
	border: 1px dashed var(--wp--preset--color--line);
	padding: 12px 14px;
	border-radius: 4px;
}

/* -------------------------------------------------------- reading order */

.archie-order .wp-block-post-template {
	display: grid;
	grid-template-columns: repeat( 4, 1fr );
	gap: 26px;
}

.archie-order .wp-block-post-title {
	font-size: 0.97rem;
	line-height: 1.18;
	margin: 0.6rem 0 0;
}

.archie-order .wp-block-post-title a { text-decoration: none; }

.archie-number {
	font-family: var(--wp--preset--font-family--display);
	font-size: 1.3rem;
	line-height: 1;
	color: var(--accent);
}

/* ------------------------------------------------------------ book cards */

.archie-books .wp-block-post-template {
	display: grid;
	grid-template-columns: repeat( 2, 1fr );
	gap: 36px;
}

.archie-card {
	display: grid;
	grid-template-columns: 168px 1fr;
	gap: 24px;
	align-items: start;
}

.archie-card .wp-block-post-title { margin: 0; }
.archie-card .wp-block-post-title a { text-decoration: none; }
.archie-card .wp-block-post-excerpt { color: var(--wp--preset--color--muted); font-size: var(--wp--preset--font-size--small); }

/* -------------------------------------------------------------- posts */

.archie-posts .wp-block-post-template { display: flex; flex-direction: column; }

.archie-posts .wp-block-post {
	display: grid;
	grid-template-columns: 150px 1fr;
	gap: 28px;
	padding-block: 26px;
	border-top: 2px solid var(--wp--preset--color--line);
}

.archie-posts .wp-block-post:last-child { border-bottom: 2px solid var(--wp--preset--color--line); }
.archie-posts .wp-block-post-title { font-size: 1.16rem; margin: 0; }
.archie-posts .wp-block-post-title a { text-decoration: none; }
.archie-posts .wp-block-post-title a:hover { color: var(--accent); }
.archie-posts .wp-block-post-excerpt { color: var(--wp--preset--color--muted); font-size: var(--wp--preset--font-size--small); margin-top: 6px; }

/* ------------------------------------------------------------ book page */

.archie-book-layout { align-items: start; }
.archie-book-layout .wp-block-post-featured-image img { width: 100%; }

.archie-pull {
	font-family: var(--wp--preset--font-family--display);
	font-size: 1.13rem;
	line-height: 1.32;
	color: var(--accent);
	border-left: 5px solid var(--accent);
	padding-left: 20px;
	margin: 0;
}

/* ---------------------------------------------------------------- facts */

.archie-facts { border-collapse: collapse; width: 100%; }

.archie-facts th,
.archie-facts td {
	text-align: left;
	padding: 12px 0;
	border-top: 1.5px solid var(--wp--preset--color--line);
	vertical-align: top;
}

.archie-facts th {
	font-family: var(--wp--preset--font-family--file);
	font-size: var(--wp--preset--font-size--x-small);
	text-transform: uppercase;
	letter-spacing: 0.09em;
	color: var(--accent);
	width: 130px;
	font-weight: 700;
}

/* -------------------------------------------------------------- forms */

.archie-signup input[type="email"],
.archie-signup input[type="text"] {
	font-family: inherit;
	font-size: 1rem;
	padding: 14px 18px;
	border: 2px solid var(--wp--preset--color--ink);
	border-radius: 999px;
	background: #fffdf7;
	color: var(--wp--preset--color--ink);
	min-width: 240px;
}

/* --------------------------------------------------------- responsive */

@media ( max-width: 900px ) {
	.archie-order .wp-block-post-template { grid-template-columns: repeat( 2, 1fr ); }
	.archie-books .wp-block-post-template { grid-template-columns: 1fr; }
	.archie-posts .wp-block-post { grid-template-columns: 1fr; gap: 4px; }
}

@media ( max-width: 560px ) {
	.archie-card { grid-template-columns: 110px 1fr; gap: 16px; }
	.archie-meta { gap: 20px; }
}

@media ( prefers-reduced-motion: reduce ) {
	*, *::before, *::after { transition: none !important; animation: none !important; }
}

/* --------------------------------------------------------- shelf line */

.archie-shelf-line {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.archie-tagline {
	font-family: var(--wp--preset--font-family--file);
	font-size: var(--wp--preset--font-size--x-small);
	text-transform: uppercase;
	letter-spacing: 0.09em;
	color: var(--wp--preset--color--muted);
}

/* Reading-order items stack: number, cover, title, tagline. */
.archie-order .wp-block-post {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.archie-order .wp-block-post-featured-image { margin: 0; }
.archie-order .wp-block-post-featured-image img { width: 100%; }
.archie-order .archie-shelf-line { gap: 0; }

/* ---------------------------------------------------- rights small print */

/* Deliberately quiet: this is a notice, not content. Narrower measure than the
   body copy and a size below it, so it reads as the fine print it is. */
.archie-legal {
	max-width: 68ch;
	margin-block-start: var(--wp--preset--spacing--40);
	padding-block-start: var(--wp--preset--spacing--30);
	border-top: 1.5px solid var(--wp--preset--color--line);
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.archie-legal p {
	font-size: var(--wp--preset--font-size--x-small);
	line-height: 1.65;
	color: var(--wp--preset--color--muted);
	text-wrap: pretty;
}

.archie-colophon {
	color: var(--wp--preset--color--muted);
	line-height: 1.85;
	font-variant-numeric: tabular-nums;
}

/* The pull quote is one line of hook, not a blurb. Past a couple of lines the marker
   face stops being readable, so long text steps down and loses the all-marker look. */
.archie-pull {
	max-width: 46ch;
	text-wrap: pretty;
}

/* Core List block, borrowing the topic-tag look via the "Topic tags" style. */
.wp-block-list.is-style-tags {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	list-style: none;
	padding: 0;
}

.wp-block-list.is-style-tags li {
	font-size: var(--wp--preset--font-size--small);
	line-height: 1.4;
	background: color-mix( in srgb, var(--accent) 12%, transparent );
	border: 1px solid color-mix( in srgb, var(--accent) 28%, transparent );
	border-radius: 5px;
	padding: 6px 11px;
}

/* The sparkle stays a cover motif, used in patterns rather than on topics. */
.archie-sparkle { width: 11px; height: 11px; flex: none; color: var(--accent); }

/* ------------------------------------------------------ quote citations */

/*
 * Core saves a bare <cite> with no class of its own, so this styles the element.
 * It also fixes a real collision: theme.json colours core/quote with var(--accent),
 * and the torn-band override only reaches h1-h3, p and li - so a citation inside the
 * accent band was rendering red on red.
 */
.wp-block-quote cite,
.wp-block-pullquote cite {
	display: block;
	margin-top: 0.7rem;
	font-family: var(--wp--preset--font-family--file);
	font-size: var(--wp--preset--font-size--x-small);
	font-style: normal;
	font-weight: 400;
	line-height: 1.6;
	text-transform: uppercase;
	letter-spacing: 0.09em;
	color: var(--wp--preset--color--muted);
}

:is( .is-style-torn-band, .is-style-torn-masthead ) .wp-block-quote cite,
:is( .is-style-torn-band, .is-style-torn-masthead ) blockquote cite {
	color: var(--on-accent);
	opacity: 0.82;
}

/* Centre the attribution with the quote when the block is centre-aligned. */
.wp-block-quote.has-text-align-center cite { text-align: center; }

/* --------------------------------------------- safety inside accent bands */

/*
 * STRUCTURAL FIX, and the important one.
 *
 * Three separate things went invisible inside an accent band before this existed: a
 * citation, a button, and an eyebrow - each red-on-red or blue-on-blue, each found
 * only by reading computed styles. Enumerating selectors was always going to lose
 * that race, because any new component that reaches for var(--accent) reintroduces
 * the bug.
 *
 * So the band rewrites the tokens for its children instead. Inside a band, "accent"
 * IS the on-accent colour and "muted" is a translucent version of it, so a component
 * written the normal way is legible here without knowing bands exist.
 *
 * Applied to children, never the band itself - the band's own background still needs
 * the real --accent-fill to paint with.
 */
:is( .is-style-torn-band, .is-style-torn-masthead ) > * {
	--accent: var(--on-accent);
	--wp--preset--color--muted: color-mix( in srgb, var(--on-accent) 76%, transparent );
	--wp--preset--color--ink: var(--on-accent);
	--wp--preset--color--line: color-mix( in srgb, var(--on-accent) 35%, transparent );
}

@supports not ( color: color-mix( in srgb, red 50%, transparent ) ) {
	:is( .is-style-torn-band, .is-style-torn-masthead ) > * {
		--wp--preset--color--muted: var(--on-accent);
		--wp--preset--color--line: var(--on-accent);
	}
}

/* --accent-fill is deliberately NOT remapped: the band paints with it, and a button
   that inherited it would be invisible. Buttons get an explicit flip below. */


/*
 * A torn band paints the whole area in --accent-fill, so anything that also draws
 * itself in an accent or a muted grey disappears into it. This caught a shipped
 * placeholder citation (red on red, invisible, and therefore unremovable because
 * nobody could see it was there). These rules cover the rest of the same class of
 * bug before it happens.
 */

/* A button in an accent band would otherwise be accent-on-accent. Flip to ink. */
:is( .is-style-torn-band, .is-style-torn-masthead ) .wp-block-button__link,
:is( .is-style-torn-band, .is-style-torn-masthead ) .wp-element-button {
	background: var(--wp--preset--color--ink);
	color: var(--wp--preset--color--cream);
	border-color: var(--wp--preset--color--ink);
	box-shadow: 4px 4px 0 rgba( 0, 0, 0, 0.28 );
}

:is( .is-style-torn-band, .is-style-torn-masthead ) .wp-block-button__link:hover,
:is( .is-style-torn-band, .is-style-torn-masthead ) .wp-element-button:hover {
	box-shadow: 2px 2px 0 rgba( 0, 0, 0, 0.28 );
}

:is( .is-style-torn-band, .is-style-torn-masthead ) .is-style-outline > .wp-block-button__link {
	background: transparent;
	color: var(--on-accent);
	border-color: var(--on-accent);
}

/* Muted greys and hairlines are near-invisible on a saturated ground. */
:is( .is-style-torn-band, .is-style-torn-masthead ) figcaption,
:is( .is-style-torn-band, .is-style-torn-masthead ) .wp-block-post-date,
:is( .is-style-torn-band, .is-style-torn-masthead ) .wp-block-post-terms,
:is( .is-style-torn-band, .is-style-torn-masthead ) dt,
:is( .is-style-torn-band, .is-style-torn-masthead ) dd,
:is( .is-style-torn-band, .is-style-torn-masthead ) small {
	color: var(--on-accent);
	opacity: 0.82;
}

:is( .is-style-torn-band, .is-style-torn-masthead ) hr,
:is( .is-style-torn-band, .is-style-torn-masthead ) .wp-block-separator {
	color: var(--on-accent);
	border-color: currentColor;
	opacity: 0.4;
}

/* Form fields keep the paper ground they need to stay legible. */
:is( .is-style-torn-band, .is-style-torn-masthead ) input,
:is( .is-style-torn-band, .is-style-torn-masthead ) textarea,
:is( .is-style-torn-band, .is-style-torn-masthead ) select {
	background: var(--wp--preset--color--paper);
	color: var(--wp--preset--color--ink);
	border: 2px solid var(--wp--preset--color--ink);
}

.archie-section-head { align-items: flex-end; gap: 16px; }
.archie-section-head h5 { margin-bottom: 6px; }

/* The frame already encloses the list, so the outer hairlines are redundant. */
.archie-section-frame .archie-posts .wp-block-post:first-child { border-top: 0; padding-top: 0; }
.archie-section-frame .archie-posts .wp-block-post:last-child { border-bottom: 0; padding-bottom: 0; }
