/* Kiwwwi — PDF catalog list & reader
   Tokens and rules are specified in design-plan.md. No ad-hoc values below. */

/* ---------------------------------------------------------------- fonts -- */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/inter-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('../fonts/inter-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

/* --------------------------------------------------------------- tokens -- */

:root {
  /* A white design — light only, no dark variant. */
  color-scheme: light;

  --bg: #ffffff;
  --surface: #f6f8f1; /* lime-tinted wash, never neutral grey */
  --stage: #eaeede; /* reader backdrop; white pages read as paper on it */
  --ink: #333333; /* Kiwwwi wordmark charcoal */
  --ink-muted: #646d59; /* a tint of the ink, pulled toward the brand */
  --accent: #abd629; /* Kiwwwi lime — fills and marks only */
  --accent-ink: #333333; /* what sits ON the lime: 7.45:1 */
  --accent-text: #5a7410; /* lime deepened until it carries text: 5.33:1 */
  --line: #e4e8da;
  --line-strong: #848d77; /* control borders, 3.47:1 */

  --shadow-1: 0 1px 2px rgba(51, 58, 36, 0.07);
  --shadow-2: 0 10px 24px -12px rgba(51, 58, 36, 0.3);
  --shadow-3: 0 18px 44px -16px rgba(51, 58, 36, 0.45);

  /* 4px rhythm; three vertical tiers */
  --space-component: 16px;
  --space-section: 32px;
  --space-page: 96px;

  --radius: 6px;
  --measure: 68ch;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur-press: 150ms;
  --dur-panel: 200ms;
  --dur-reveal: 300ms;
}

/* ---------------------------------------------------------------- reset -- */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 0.9375rem;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

img,
svg {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
  padding: 0;
  cursor: pointer;
}

a {
  color: var(--accent-text);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

:focus-visible {
  outline: 3px solid var(--accent-text);
  outline-offset: 2px;
  border-radius: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.shell {
  width: min(1240px, 100% - (var(--space-section) * 2));
  margin-inline: auto;
}

.shell--narrow {
  width: min(880px, 100% - (var(--space-section) * 2));
}

/* --------------------------------------------------------------- header -- */

.masthead {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.masthead__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-component);
  min-height: 72px;
}

.wordmark {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.wordmark img {
  width: 92px;
  height: 36px;
  object-fit: contain;
}

.masthead__nav {
  display: flex;
  align-items: center;
  gap: var(--space-component);
  font-weight: 500;
}

.masthead__nav a {
  color: var(--ink-muted);
  text-decoration: none;
  padding: 10px 2px;
  transition: color var(--dur-press) var(--ease);
}

.masthead__nav a:hover,
.masthead__nav a[aria-current='page'] {
  color: var(--ink);
}

/* -------------------------------------------------------------- listing -- */

.page-head {
  padding-block: calc(var(--space-page) * 0.62) var(--space-section);
  max-width: var(--measure);
}

.page-head h1 {
  margin: 0;
  font-size: clamp(1.9rem, 1.2rem + 2.4vw, 3.1rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.06;
}

.page-head p {
  margin: var(--space-component) 0 0;
  color: var(--ink-muted);
  font-size: 1.0625rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-component);
  padding-bottom: var(--space-section);
  border-bottom: 1px solid var(--line);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 14px;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--ink-muted);
  font-weight: 500;
  font-size: 0.875rem;
  transition: color var(--dur-press) var(--ease),
    border-color var(--dur-press) var(--ease),
    background-color var(--dur-press) var(--ease);
}

.chip:hover {
  color: var(--ink);
  border-color: var(--ink-muted);
}

.chip[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.chip__count {
  color: inherit;
  opacity: 0.62;
  margin-left: 6px;
}

/* --------------------------------------------------------------- search -- */

.search {
  position: relative;
  flex: 0 1 280px;
}

.search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  translate: 0 -50%;
  width: 16px;
  height: 16px;
  color: var(--ink-muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px 0 36px;
  font: inherit;
  font-size: 0.875rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  transition: border-color var(--dur-press) var(--ease);
}

.search input::placeholder {
  color: var(--ink-muted);
}

.search input:hover {
  border-color: var(--ink-muted);
}

/* A document list, not a card grid: rows read correctly whether there is one
   catalog or thirty, and the hairline is the only chrome. */
.catalog-list {
  list-style: none;
  margin: 0;
  padding: 8px 0 var(--space-page);
}

.catalog-row {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-section);
  padding-block: var(--space-component);
  border-bottom: 1px solid var(--line);
}

.catalog-row__cover {
  display: block;
  aspect-ratio: 612 / 792;
  background: var(--bg);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  transition: transform var(--dur-press) var(--ease),
    box-shadow var(--dur-press) var(--ease);
}

.catalog-row__cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.catalog-row:hover .catalog-row__cover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-3);
}

.catalog-row__body {
  min-width: 0;
}

.catalog-row__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.catalog-row__title a {
  color: var(--ink);
  text-decoration: none;
}

.catalog-row__title a:hover {
  text-decoration: underline;
}

.catalog-row__subtitle {
  margin: 4px 0 0;
  color: var(--ink-muted);
  font-size: 0.9375rem;
}

.catalog-row__meta {
  margin: 8px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  color: var(--ink-muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.catalog-row__meta span:not(:last-child)::after {
  content: '·';
  margin-left: 10px;
  opacity: 0.6;
}

.catalog-row__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --------------------------------------------------------------- button -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.875rem;
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
  transition: transform var(--dur-press) var(--ease),
    background-color var(--dur-press) var(--ease),
    border-color var(--dur-press) var(--ease), color var(--dur-press) var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn--primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, var(--ink));
}

.btn--quiet {
  border-color: var(--line-strong);
  color: var(--ink);
  background: transparent;
}

.btn--quiet:hover {
  border-color: var(--ink-muted);
  background: var(--surface);
}

.btn svg {
  flex: none;
  width: 16px;
  height: 16px;
}

/* ---------------------------------------------------------------- empty -- */

.empty {
  padding: var(--space-page) 0;
  text-align: center;
  color: var(--ink-muted);
}

.empty p {
  margin: 0 0 var(--space-component);
  font-size: 1.0625rem;
}

/* --------------------------------------------------------------- footer -- */

.colophon {
  border-top: 1px solid var(--line);
  padding-block: var(--space-section);
  color: var(--ink-muted);
  font-size: 0.8125rem;
}

/* ================================================== READER (a component) == */

/* The reader builds its own DOM inside whatever element it is given, so the
   same code serves the full-screen page and the in-content embed — and, later,
   a WordPress shortcode that prints one empty div. */
.reader {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  background: var(--stage);
  color: var(--ink);
}

.reader--full {
  height: 100dvh;
  overflow: hidden;
}

.reader--embed {
  height: min(76vh, 680px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.reader__bar {
  display: flex;
  align-items: center;
  gap: var(--space-component);
  min-width: 0;
  padding: 8px clamp(10px, 2vw, 20px);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.reader__back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding-inline: 10px;
  margin-inline-start: -10px;
  border-radius: var(--radius);
  color: var(--ink-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.875rem;
  white-space: nowrap;
  transition: color var(--dur-press) var(--ease),
    background-color var(--dur-press) var(--ease);
}

.reader__back:hover {
  color: var(--ink);
  background: var(--surface);
}

.reader__titles {
  flex: 1;
  min-width: 0;
  text-align: center;
}

/* No back link in the embed, so there is nothing to centre between — the title
   belongs at the start of the bar. */
.reader--embed .reader__titles {
  text-align: start;
}

.reader__title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader__sub {
  margin: 0;
  font-size: 0.75rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader__tools {
  display: flex;
  align-items: center;
  gap: 2px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  color: var(--ink-muted);
  transition: color var(--dur-press) var(--ease),
    background-color var(--dur-press) var(--ease),
    transform var(--dur-press) var(--ease);
}

.icon-btn:hover {
  color: var(--ink);
  background: var(--surface);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn[aria-pressed='true'] {
  color: var(--accent-ink);
  background: var(--accent);
}

.icon-btn:disabled,
.icon-btn[aria-disabled='true'] {
  color: var(--line-strong);
  cursor: not-allowed;
  background: none;
  pointer-events: none;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ---------------------------------------------------------------- stage -- */

.reader__stage {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: clamp(10px, 2.2vh, 24px) clamp(10px, 2vw, 28px);
  overflow: hidden;
}

.reader__book {
  filter: drop-shadow(var(--shadow-3));
  touch-action: pan-y;
}

.reader__book.is-hidden {
  visibility: hidden;
}

/* Pages are canvases injected by the reader. Paper has square corners. */
.reader__book .page {
  background: #ffffff;
  overflow: hidden;
  cursor: pointer;
}

.reader__stage--zoomed .reader__book .page {
  cursor: inherit;
}

.reader__book .page canvas,
.reader__book .page img {
  width: 100%;
  height: 100%;
  display: block;
}

/* The gutter shadow lands on the real seam — these are split spreads. */
.reader__book .page--left::after,
.reader__book .page--right::after {
  content: '';
  position: absolute;
  inset-block: 0;
  width: 34px;
  pointer-events: none;
}

.reader__book .page--left::after {
  right: 0;
  background: linear-gradient(to right, rgba(51, 58, 36, 0), rgba(51, 58, 36, 0.16));
}

.reader__book .page--right::after {
  left: 0;
  background: linear-gradient(to left, rgba(51, 58, 36, 0), rgba(51, 58, 36, 0.16));
}

/* ----------------------------------------------------------------- hints -- */

/* Clicking a page turns it — StPageFlip handles that — but nothing said so.
   These chevrons sit over the click target and are `pointer-events: none`, so
   the click still lands on the page underneath. They are an affordance, not a
   control: the pager, the arrow keys and dragging are the real ways through,
   and all three stay reachable without a pointer. */
.reader__hint {
  position: absolute;
  top: 50%;
  translate: 0 -50%;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow-2);
  color: var(--ink);
  opacity: 0.68;
  pointer-events: none;
  transition: opacity var(--dur-press) var(--ease);
}

.reader__hint[hidden] {
  display: none;
}

.reader__hint svg {
  width: 20px;
  height: 20px;
}

.reader__hint--prev {
  left: clamp(4px, 1vw, 14px);
}

.reader__hint--next {
  right: clamp(4px, 1vw, 14px);
}

.reader__stage:hover .reader__hint {
  opacity: 1;
}

/* ----------------------------------------------------------------- zoom -- */

/* Start-aligned vertically so an over-tall page can still be scrolled to its
   top; centred horizontally while it is narrower than the stage. */
.reader__stage--zoomed {
  place-items: start center;
  overflow: auto;
  overscroll-behavior: contain;
  cursor: grab;
}

.reader__stage--dragging {
  cursor: grabbing;
}

/* -------------------------------------------------------------- loading -- */

.reader__loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-component);
  padding: var(--space-component);
  text-align: center;
  background: var(--stage);
  transition: opacity var(--dur-panel) var(--ease),
    visibility var(--dur-panel) var(--ease);
}

.reader__loader[hidden] {
  display: grid;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.reader__label {
  margin: 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink-muted);
}

/* Determinate — the page count is known up front. */
.reader__track {
  width: min(260px, 60vw);
  height: 3px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.reader__fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width var(--dur-panel) linear;
}

/* ---------------------------------------------------------------- pager -- */

.reader__pager {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.6vw, 20px);
  min-width: 0;
  padding: 6px clamp(10px, 2vw, 20px);
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.reader--full .reader__pager {
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}

.reader__scrub {
  flex: 1;
  min-width: 0;
  height: 44px;
  margin: 0;
  background: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.reader__scrub::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

.reader__scrub::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

.reader__scrub::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--accent);
  transition: transform var(--dur-press) var(--ease);
}

.reader__scrub::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: var(--accent);
}

.reader__scrub:hover::-webkit-slider-thumb {
  transform: scale(1.15);
}

.reader__count {
  flex: none;
  min-width: 11ch;
  text-align: center;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink-muted);
  white-space: nowrap;
}

/* ------------------------------------------------------------ embed page - */

.article {
  padding-block: var(--space-section) var(--space-page);
}

.article h1 {
  margin: 0 0 var(--space-component);
  font-size: clamp(1.7rem, 1.1rem + 2vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.article p {
  margin: 0 0 var(--space-component);
  max-width: var(--measure);
  font-size: 1.0625rem;
  color: var(--ink-muted);
}

.article h2 {
  margin: var(--space-section) 0 var(--space-component);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.article .reader {
  margin-block: var(--space-section);
}

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: var(--space-component);
  color: var(--ink-muted);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
}

.crumb:hover {
  color: var(--ink);
}

.article__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: var(--space-section);
}

/* -------------------------------------------------------------- reveal --- */

.js .reveal {
  opacity: 0;
  transform: translateY(12px);
}

.js .reveal.is-in {
  opacity: 1;
  transform: none;
  transition: opacity var(--dur-reveal) var(--ease),
    transform var(--dur-reveal) var(--ease);
  transition-delay: var(--reveal-delay, 0ms);
}

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

@media (max-width: 720px) {
  .shell,
  .shell--narrow {
    width: calc(100% - (var(--space-component) * 2));
  }

  .catalog-row {
    grid-template-columns: 64px minmax(0, 1fr);
    gap: var(--space-component);
    row-gap: 12px;
  }

  .catalog-row__actions {
    grid-column: 1 / -1;
    flex-wrap: wrap;
  }

  .catalog-row__actions .btn {
    flex: 1 1 auto;
  }

  .search {
    flex: 1 1 100%;
  }

  .masthead__nav {
    gap: 12px;
  }

  .reader__sub {
    display: none;
  }

  .reader--embed {
    height: min(70vh, 520px);
  }
}

/* ------------------------------------------------------- reduced motion -- */

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

  .js .reveal {
    opacity: 1;
    transform: none;
  }
}
