/* readgraph — a shelf, not a progress bar.
 *
 * The visual system is inherited from Prediger Today (pt.arc-codex.com):
 * the same three-role type (EB Garamond display / Literata reading /
 * Public Sans chrome), the centred masthead over a heavy ink rule, a held
 * measure, hairline-ruled sections, square corners, and no shadows or
 * gradients anywhere. Structure comes from rules and whitespace.
 *
 * What is deliberately NOT inherited is Prediger's parchment ground
 * (#faf6ef) and its warm taupe/oxblood palette. That warm off-white is
 * exactly the "beige" this site's reader rejected. The ground here is cool
 * and near-white, and every saturated colour is spent on the content layer:
 * shelf states, covers, genres, stat figures. Lean skeleton, vivid content.
 */

/* ── self-hosted faces ────────────────────────────────────────────────────
 * Self-hosted rather than CDN, per the Prediger sprint-6 §4 recommendation:
 * no third-party request on page load, no reader IP leaving the box. One
 * variable woff2 per family covers every weight used. */
@font-face {
	font-family: 'EB Garamond';
	src: url('fonts/EBGaramond-var-latin.woff2') format('woff2');
	font-weight: 400 700;
	font-style: normal;
	font-display: swap;
}
@font-face {
	font-family: 'Literata';
	src: url('fonts/Literata-var-latin.woff2') format('woff2');
	font-weight: 400 700;
	font-style: normal;
	font-display: swap;
}
@font-face {
	font-family: 'Public Sans';
	src: url('fonts/PublicSans-var-latin.woff2') format('woff2');
	font-weight: 400 700;
	font-style: normal;
	font-display: swap;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
	--font-head: 'EB Garamond', 'Times New Roman', Georgia, serif;
	--font-body: 'Literata', Georgia, 'Times New Roman', serif;
	--font-ui: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

	/* Ground is cool, not warm — the single biggest departure from Prediger. */
	--ground: #fcfbff;
	--ink: #17151f;
	--muted: #66627a;
	--rule: #e4e1ee;

	/* One hue per shelf state. Each has a darker `-ink` variant: the vivid
	 * value is for rules, bars and blocks; small text uses `-ink` so it
	 * clears 4.5:1 on the ground. Same contrast discipline Prediger applies
	 * to its own palette. */
	--tbr: #7c3aed;      --tbr-ink: #6321d4;
	--reading: #ea580c;  --reading-ink: #c2410c;
	--read: #059669;     --read-ink: #047857;

	--measure: 880px;
}

body {
	background: var(--ground);
	color: var(--ink);
	font-family: var(--font-body);
	font-size: 1.05rem;
	line-height: 1.7;
	/* Old-style figures: the cheapest "book, not screen" signal, and the
	 * reason the stat numerals sit into their line rather than on it. */
	font-feature-settings: "onum" 1, "liga" 1, "kern" 1;
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
	padding: 2.5rem 1rem 5rem;
}

.wrap { max-width: var(--measure); margin: 0 auto; }

/* ── masthead ─────────────────────────────────────────────────────────── */

.masthead {
	text-align: center;
	padding-bottom: 1.4rem;
	margin-bottom: 1.6rem;
	border-bottom: 2px solid var(--ink);
}
.masthead h1 {
	font-family: var(--font-head);
	font-size: 3rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	line-height: 1.1;
}
.masthead h1 a { color: inherit; text-decoration: none; }
.masthead .epigraph {
	font-family: var(--font-head);
	font-style: italic;
	font-size: 1.02rem;
	color: var(--muted);
	margin-top: 0.3rem;
}

/* ── nav ──────────────────────────────────────────────────────────────── */

nav {
	text-align: center;
	margin-bottom: 3rem;
	font-family: var(--font-ui);
	font-size: 0.82rem;
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--muted);
}
nav a {
	color: var(--ink);
	text-decoration: none;
	margin: 0 0.5rem;
	padding-bottom: 0.15rem;
	border-bottom: 2px solid transparent;
}
nav a:hover { border-bottom-color: var(--rule); }
nav a[aria-current="page"] { border-bottom-color: var(--ink); }
nav .sep { color: var(--rule); }

/* ── shelf sections ───────────────────────────────────────────────────── */

.shelf { margin-bottom: 3.25rem; }
.shelf:last-child { margin-bottom: 0; }

/* The state hue arrives here first: a heavy coloured rule under each
 * section head, echoing the masthead's 2px ink rule one level down. */
.shelf-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 1rem;
	padding-bottom: 0.5rem;
	margin-bottom: 1.5rem;
	border-bottom: 3px solid var(--hue);
}
.shelf-head h2 {
	font-family: var(--font-head);
	font-size: 1.7rem;
	font-weight: 600;
	letter-spacing: 0.03em;
	color: var(--hue-ink);
}
.shelf-count {
	font-family: var(--font-ui);
	font-size: 0.78rem;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--muted);
	white-space: nowrap;
}

.shelf[data-state="tbr"]     { --hue: var(--tbr);     --hue-ink: var(--tbr-ink); }
.shelf[data-state="reading"] { --hue: var(--reading); --hue-ink: var(--reading-ink); }
.shelf[data-state="read"]    { --hue: var(--read);    --hue-ink: var(--read-ink); }

.grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
	gap: 1.9rem 1.5rem;
}

/* ── book card ────────────────────────────────────────────────────────── */

.book { display: flex; flex-direction: column; }

.cover {
	position: relative;
	display: block;
	aspect-ratio: 2 / 3;
	margin-bottom: 0.6rem;
	background: var(--rule);
	border: 1px solid rgba(23, 21, 31, 0.14);
	/* Square corners and no shadow — the card sits on the page the way a
	 * catalogue card does, not like a floating tile. */
	overflow: hidden;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* A book with no cover art still has to carry colour, so the fallback is a
 * saturated block with the initial set in the display serif. These are
 * deterministic per title (see coverTint in app.js) so a book keeps its
 * colour between visits. */
.cover.blank {
	display: grid;
	place-items: center;
	border-color: transparent;
}
.cover.blank span {
	font-family: var(--font-head);
	font-size: 3.2rem;
	font-weight: 600;
	color: #fff;
	line-height: 1;
}

/* The state marker: a solid bar in the shelf hue across the head of the
 * cover. It is what makes a state legible when a card is seen on its own. */
.cover::after {
	content: "";
	position: absolute;
	inset: 0 0 auto 0;
	height: 6px;
	background: var(--hue);
}

.book-title {
	font-family: var(--font-body);
	font-size: 0.92rem;
	font-weight: 600;
	line-height: 1.35;
	text-wrap: balance;
	margin-bottom: 0.1rem;
}
.book-author {
	font-family: var(--font-ui);
	font-size: 0.78rem;
	line-height: 1.4;
	color: var(--muted);
}

/* ── genres ───────────────────────────────────────────────────────────── */

.genres {
	list-style: none;
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem;
	margin-top: 0.5rem;
}
.genre {
	font-family: var(--font-ui);
	font-size: 0.66rem;
	font-weight: 600;
	letter-spacing: 0.05em;
	text-transform: uppercase;
	padding: 0.1rem 0.42rem;
	color: var(--g-ink);
	background: var(--g-bg);
}

/* ── the one action per card ──────────────────────────────────────────── */

/* Cards are already grouped by state, so a card needs exactly one move:
 * forward. That keeps the shelf to three states and no controls to learn. */
.move {
	/* Pushed to the foot of the card so the actions line up across a row
	 * however many chips or title lines the cards above them carry. */
	margin-top: auto;
	padding-top: 0.55rem;
	font-family: var(--font-ui);
	font-size: 0.74rem;
	letter-spacing: 0.02em;
}
.move button {
	font: inherit;
	color: var(--hue-ink);
	background: transparent;
	border: 1px solid currentColor;
	padding: 0.14rem 0.6rem;
	cursor: pointer;
	transition: background 0.12s, color 0.12s;
}
.move button:hover { background: var(--hue); color: #fff; border-color: var(--hue); }

.move-back {
	/* The reverse move is available but never competes with the forward one:
	 * no border, muted, on its own line. */
	display: block;
	margin-top: 0.3rem;
	border: none !important;
	padding: 0 !important;
	color: var(--muted) !important;
	background: transparent !important;
	font-size: 0.7rem;
	text-align: left;
	text-decoration: underline;
	text-underline-offset: 0.15em;
}
.move-back:hover { color: var(--ink) !important; }

.shelf-empty {
	font-style: italic;
	color: var(--muted);
	font-size: 0.95rem;
	padding: 0.4rem 0 1rem;
}
.empty-shelf {
	text-align: center;
	color: var(--muted);
	padding: 3rem 0;
}
.empty-shelf a { color: var(--tbr-ink); text-underline-offset: 0.15em; }

/* ── flash ────────────────────────────────────────────────────────────── */

.flash {
	font-family: var(--font-ui);
	font-size: 0.88rem;
	padding: 0.55rem 1rem;
	margin-bottom: 1.75rem;
	border-left: 3px solid var(--read);
	background: #ecfdf5;
	color: var(--read-ink);
}
.flash.error {
	border-left-color: var(--reading);
	background: #fff7ed;
	color: var(--reading-ink);
}

/* ── add view ─────────────────────────────────────────────────────────── */

/* The section head reuses the shelf grammar, tinted with the to-be-read hue,
 * because that is where everything added lands. */
.shelf-head[data-hue="tbr"] { --hue: var(--tbr); --hue-ink: var(--tbr-ink); }

.add { max-width: 620px; }   /* a form wants the reading measure, not the grid */

.search-form { margin-bottom: 2rem; }
.search-form label,
.entry-form label {
	display: block;
	font-family: var(--font-ui);
	font-size: 0.78rem;
	font-weight: 600;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--muted);
	margin-bottom: 0.35rem;
}
.field-note {
	font-weight: 400;
	text-transform: none;
	letter-spacing: 0.02em;
	color: var(--muted);
	opacity: 0.8;
}

.search-row { display: flex; gap: 0.5rem; }

input[type="search"],
input[type="text"],
input[type="number"] {
	width: 100%;
	font-family: var(--font-body);
	font-size: 1rem;
	color: var(--ink);
	background: #fff;
	border: 1px solid #9d99b0;   /* ≥3:1 on the ground, per Prediger's own note */
	border-radius: 0;
	padding: 0.45rem 0.65rem;
	outline: none;
	transition: border-color 0.12s, box-shadow 0.12s;
	-webkit-appearance: none;
	appearance: none;
}
input:focus {
	border-color: var(--tbr);
	box-shadow: inset 0 0 0 1px var(--tbr);
}

.search-row input[type="search"] { font-size: 1.05rem; }

.btn,
.search-row button {
	font-family: var(--font-ui);
	font-size: 0.92rem;
	font-weight: 600;
	letter-spacing: 0.03em;
	background: var(--tbr);
	color: #fff;
	border: 1px solid var(--tbr);
	border-radius: 0;
	padding: 0.45rem 1.5rem;
	cursor: pointer;
	white-space: nowrap;
	transition: background 0.12s;
}
.btn:hover,
.search-row button:hover { background: var(--tbr-ink); border-color: var(--tbr-ink); }

.hint {
	font-family: var(--font-ui);
	font-size: 0.8rem;
	color: var(--muted);
	margin-top: 0.4rem;
}

.searching, .no-results, .search-error {
	font-style: italic;
	color: var(--muted);
	font-size: 0.95rem;
	padding: 0.5rem 0 1rem;
}
.search-error { color: var(--reading-ink); font-style: normal; }

/* results — Prediger's hairline-ruled list, one row per book */
.results { list-style: none; margin-bottom: 1.5rem; }
.result {
	display: flex;
	align-items: flex-start;
	gap: 0.9rem;
	padding: 0.85rem 0;
	border-bottom: 1px solid var(--rule);
}
.result:first-child { border-top: 1px solid var(--rule); }

.result-cover { flex: 0 0 44px; }
.result-cover .cover { margin-bottom: 0; }
.result-cover .cover::after { display: none; }   /* no state bar until it has one */
.result-cover .cover.blank span { font-size: 1.4rem; }

.result-meta { flex: 1 1 auto; min-width: 0; }
.result-meta h3 {
	font-family: var(--font-body);
	font-size: 1rem;
	font-weight: 600;
	line-height: 1.35;
	text-wrap: balance;
}
.result-meta p {
	font-family: var(--font-ui);
	font-size: 0.8rem;
	color: var(--muted);
	margin-top: 0.05rem;
}
.result-meta .unknown { font-style: italic; opacity: 0.75; }
.result-meta .genres { margin-top: 0.35rem; }

.result-pick {
	flex: 0 0 auto;
	align-self: center;
	font-family: var(--font-ui);
	font-size: 0.78rem;
	color: var(--tbr-ink);
	background: transparent;
	border: 1px solid currentColor;
	border-radius: 0;
	padding: 0.2rem 0.75rem;
	cursor: pointer;
	transition: background 0.12s, color 0.12s;
}
.result-pick:hover { background: var(--tbr); color: #fff; border-color: var(--tbr); }

.manual-open { margin-bottom: 1.75rem; }
.manual-open button,
.link-btn {
	font-family: var(--font-ui);
	font-size: 0.85rem;
	color: var(--muted);
	background: transparent;
	border: none;
	padding: 0;
	cursor: pointer;
	text-decoration: underline;
	text-underline-offset: 0.15em;
}
.manual-open button:hover,
.link-btn:hover { color: var(--ink); }

/* entry form — the one form both paths land in */
.entry-form {
	border-top: 2px solid var(--ink);
	padding-top: 1.4rem;
	display: grid;
	grid-template-columns: auto 1fr;
	gap: 0 1.4rem;
	align-items: start;
}
.entry-head {
	grid-column: 1 / -1;
	font-family: var(--font-head);
	font-size: 1.35rem;
	font-weight: 600;
	letter-spacing: 0.02em;
	margin-bottom: 1.1rem;
}
.entry-cover { grid-column: 1; width: 92px; }
.entry-cover .cover { margin-bottom: 0; }
.entry-cover .cover::after { display: none; }

.entry-fields { grid-column: 2; }
.entry-form.no-cover { grid-template-columns: 1fr; }
.entry-form.no-cover .entry-fields { grid-column: 1; }
.field { margin-bottom: 0.9rem; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }

.entry-actions {
	grid-column: 1 / -1;
	display: flex;
	align-items: center;
	gap: 1.2rem;
	margin-top: 0.4rem;
}

@media (max-width: 560px) {
	.entry-form { grid-template-columns: 1fr; }
	.entry-cover, .entry-fields { grid-column: 1; }
	.entry-cover { margin-bottom: 1rem; }
}

@media (max-width: 480px) {
	.masthead h1 { font-size: 2.2rem; }
	.grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 1.5rem 1.1rem; }
}
