/* Shared foundation: tokens, fonts, reset, controls. Public site and admin both load this first. */

@font-face {
  font-family: "Newsreader";
  src: url("../fonts/newsreader.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Public Sans";
  src: url("../fonts/publicsans.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Surfaces: a cool, slightly blue-grey paper so book covers carry the colour. */
  --paper: #f5f7f9;
  --sheet: #ffffff;
  --sunken: #eef2f5;

  /* Ink: four text levels. */
  --ink: #12222d;
  --ink-2: #33444f;
  --ink-3: #4c5e6c;
  --ink-4: #5f6f7c; /* lightest text tier that still passes WCAG AA (4.8:1) on --paper */

  /* Brand: the blue of the original site, as bookbinder's cloth. One accent only. */
  --cloth: #2a6d95;
  --cloth-deep: #1c4e6e;
  --cloth-wash: #e6f0f6;
  --cloth-line: #b9d3e2;

  /* Rules are low-opacity ink so they blend into any surface. */
  --rule: rgba(18, 34, 45, 0.13);
  --rule-soft: rgba(18, 34, 45, 0.07);
  --rule-strong: rgba(18, 34, 45, 0.28);

  /* Night: the brand blue taken dark, for the sections that need to stop the eye. Foil is the gilt
     stamping on a book cloth; it only ever appears on night surfaces. */
  --night: #0f2b3d;
  --night-deep: #0a1e2c;
  --night-line: rgba(232, 241, 247, 0.16);
  --on-night: #e8f1f7;
  --on-night-soft: #a9bfce;
  --foil: #e2b24a;
  --foil-deep: #f0c466;

  --ok: #1d6f46;
  --ok-wash: #e5f3ec;
  --warn: #8a5a00;
  --warn-wash: #fbf1dc;
  --bad: #a8261d;
  --bad-wash: #fbe9e7;

  --font-serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --font-sans: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* 4px base spacing scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 64px;
  --s9: 96px;

  --r-s: 4px;
  --r-m: 8px;
  --r-l: 12px;

  --hit: 44px;
  --ease: cubic-bezier(0.23, 1, 0.32, 1);
  --focus: 0 0 0 2px var(--sheet), 0 0 0 4px var(--cloth);
}

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

html {
  color-scheme: light;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Keep focused fields clear of the sticky save bar in the admin */
  scroll-padding-block: var(--s9);
}
a, button, summary, label, input, select, textarea { touch-action: manipulation; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.6 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.012em;
  text-wrap: balance;
}
p { margin: 0; text-wrap: pretty; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img { display: block; max-width: 100%; height: auto; }
a { color: var(--cloth-deep); text-underline-offset: 0.18em; text-decoration-thickness: 1px; }
a:hover { color: var(--cloth); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:target { scroll-margin-top: var(--s7); }

:where(a, button, input, select, textarea, summary):focus-visible {
  outline: none;
  box-shadow: var(--focus);
  border-radius: var(--r-s);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--s4);
  top: -100px;
  z-index: 100;
  padding: var(--s3) var(--s4);
  background: var(--ink);
  color: #fff;
  border-radius: var(--r-s);
}
.skip-link:focus { top: var(--s3); color: #fff; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: var(--hit);
  padding: 0 var(--s5);
  border: 1px solid transparent;
  border-radius: var(--r-s);
  background: var(--cloth);
  color: #fff;
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease), transform 140ms var(--ease);
}
/* Hover only where a pointer can hover, so touch screens never latch a "stuck" hover state after a tap. */
@media (hover: hover) {
  .btn:hover { background: var(--cloth-deep); color: #fff; }
}
.btn:active:not(:disabled):not([aria-disabled="true"]) { transform: scale(0.96); }
.btn:disabled, .btn[aria-disabled="true"] { background: var(--sunken); color: var(--ink-4); cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }

.btn--quiet {
  background: var(--sheet);
  color: var(--ink);
  border-color: var(--rule-strong);
}
@media (hover: hover) {
  .btn--quiet:hover { background: var(--sunken); color: var(--ink); border-color: var(--ink-4); }
}

.btn--danger { background: var(--bad); }
.btn--danger:hover { background: #8c1f17; }
.btn--small { min-height: 36px; padding: 0 var(--s4); font-size: 0.875rem; }

/* ---------- Form controls (inputs are inset: slightly darker than the surface they sit on) ---------- */
.field { display: grid; gap: var(--s2); }
.field > label, .field > .label { font-weight: 600; font-size: 0.875rem; color: var(--ink-2); }
.hint { font-size: 0.8125rem; color: var(--ink-3); }
.field-error { font-size: 0.8125rem; color: var(--bad); font-weight: 500; }

.input, .textarea, .select {
  width: 100%;
  min-height: var(--hit);
  padding: var(--s2) var(--s3);
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-s);
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease);
}
.textarea { min-height: 9rem; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--ink-4); }
.input:focus, .textarea:focus, .select:focus { background: var(--sheet); border-color: var(--cloth); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--bad); background: var(--bad-wash); }

.alert {
  padding: var(--s3) var(--s4);
  border: 1px solid var(--rule);
  border-left-width: 3px;
  border-radius: var(--r-s);
  background: var(--sheet);
  font-size: 0.9375rem;
}
.alert--ok { border-left-color: var(--ok); background: var(--ok-wash); }
.alert--error { border-left-color: var(--bad); background: var(--bad-wash); }

/* ---------- Covers ---------- */
.cover {
  position: relative;
  display: block;
  aspect-ratio: 2 / 3;
  background: var(--sunken);
  border-radius: 2px 4px 4px 2px;
  box-shadow: 0 1px 2px rgba(18, 34, 45, 0.14), 0 8px 16px -8px rgba(18, 34, 45, 0.28);
  overflow: hidden;
  transition: box-shadow 200ms var(--ease);
}
.cover img { width: 100%; height: 100%; object-fit: cover; }
/* Hinge line near the spine + a 1px edge so pale covers don't dissolve into the page */
.cover::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.16) 0, rgba(0, 0, 0, 0) 5%, rgba(255, 255, 255, 0.14) 6%, rgba(255, 255, 255, 0) 8%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
  pointer-events: none;
}
.cover--empty { display: grid; place-items: center; padding: var(--s4); background: var(--cloth-wash); }
.cover__title { font-family: var(--font-serif); font-size: 1.125rem; line-height: 1.25; text-align: center; color: var(--cloth-deep); }

/* ---------- Pager (public catalog and admin list) ---------- */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--s2); }
.pager ol { display: flex; flex-wrap: wrap; gap: var(--s1); }
.pager a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--hit);
  min-height: var(--hit);
  padding: 0 var(--s3);
  border-radius: var(--r-s);
  color: var(--ink-2);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
}
.pager a:hover { background: var(--sunken); color: var(--ink); }
.pager a[aria-current="page"] { background: var(--cloth); color: #fff; }
.pager__step { border: 1px solid var(--rule-strong); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
