/* Britpage — calm, paper-like, softly dreamy */

:root {
  --paper: #f5efe4;
  --paper-2: #efe7d9;
  --paper-3: #e7dccb;
  --ink: #2e2926;
  --ink-2: #5c534b;
  --ink-3: #8b8177;
  --line: rgba(64, 48, 30, 0.13);
  --line-2: rgba(64, 48, 30, 0.07);
  --rose: #e2c3bb;
  --sky: #c4cfdf;
  --sage: #c6d1bd;
  --lilac: #d4c8dd;
  --gold: #dcc8a0;
  --accent: #9a6f5f;
  --accent-ink: #7d5648;
  --shadow: 0 1px 1px rgba(60, 40, 20, 0.05), 0 12px 34px -14px rgba(60, 40, 20, 0.35);
  --shadow-lift: 0 2px 2px rgba(60, 40, 20, 0.05), 0 26px 50px -18px rgba(60, 40, 20, 0.42);
  --radius: 10px;
  --display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --ui: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

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

html { color-scheme: light; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

a { color: var(--accent-ink); text-decoration: none; border-bottom: 1px solid rgba(154, 111, 95, 0.35); transition: border-color .3s; }
a:hover { border-color: var(--accent-ink); }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- atmosphere ---------- */

.wash {
  position: fixed; inset: 0; z-index: -2; pointer-events: none; overflow: hidden;
  background:
    radial-gradient(120% 80% at 50% -10%, #fbf7ef 0%, transparent 60%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-2) 100%);
}
.blob {
  position: absolute; border-radius: 50%; filter: blur(70px); opacity: .55;
  will-change: transform; animation: drift 46s var(--ease) infinite alternate;
}
.blob-a { width: 52vw; height: 52vw; left: -14vw; top: -18vw; background: var(--rose); }
.blob-b { width: 46vw; height: 46vw; right: -12vw; top: 8vh; background: var(--sky); animation-duration: 58s; animation-delay: -20s; }
.blob-c { width: 42vw; height: 42vw; left: 28vw; bottom: -22vw; background: var(--sage); animation-duration: 64s; animation-delay: -35s; }
@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(6vw, 4vh, 0) scale(1.12); }
}
.grain {
  position: fixed; inset: 0; z-index: -1; width: 100%; height: 100%;
  pointer-events: none; opacity: .05; mix-blend-mode: multiply;
}
@media (prefers-reduced-motion: reduce) {
  .blob { animation: none; }
  html { scroll-behavior: auto; }
}

/* ---------- masthead ---------- */

.masthead { padding: clamp(40px, 8vh, 88px) 24px 20px; }
.masthead-inner {
  max-width: 1320px; margin: 0 auto;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "mark count" "tag count";
  align-items: end; column-gap: 24px;
}
.wordmark {
  grid-area: mark; border: 0;
  font-family: var(--display); font-weight: 300; font-style: italic;
  font-size: clamp(44px, 7vw, 84px); line-height: .95; letter-spacing: -.01em;
  color: var(--ink); font-variation-settings: "opsz" 144, "SOFT" 100;
}
.wordmark-b {
  font-style: normal; font-weight: 500; color: var(--accent-ink);
}
.tagline {
  grid-area: tag; margin: 14px 0 0;
  font-family: var(--display); font-size: clamp(16px, 1.6vw, 19px); font-weight: 400;
  color: var(--ink-2); letter-spacing: .01em;
}
.tagline em { font-style: italic; color: var(--ink); }
.count {
  grid-area: count; margin: 0 0 6px;
  font-family: var(--display); font-variant-numeric: tabular-nums; font-size: 15px;
  color: var(--ink-3); letter-spacing: .04em; text-transform: lowercase;
}
@media (max-width: 640px) {
  .masthead-inner { grid-template-columns: 1fr; grid-template-areas: "mark" "tag" "count"; }
  .count { margin-top: 10px; }
}

/* ---------- page + toolbar ---------- */

.page { max-width: 1320px; margin: 0 auto; padding: 0 24px 80px; }

.toolbar {
  position: sticky; top: 12px; z-index: 5;
  margin: 18px 0 26px; padding: 12px 14px;
  display: grid; grid-template-columns: minmax(220px, 1.2fr) auto auto; gap: 12px 16px; align-items: center;
  background: rgba(250, 246, 238, 0.72);
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border: 1px solid var(--line-2); border-radius: 16px;
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset, 0 8px 30px -18px rgba(60,40,20,.35);
}
@media (max-width: 1080px) {
  .toolbar { grid-template-columns: 1fr auto; }
  .facets { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .toolbar { position: static; grid-template-columns: 1fr; }
  .actions { justify-content: flex-end; }
}

.search {
  display: flex; align-items: center; gap: 10px; position: relative;
  padding: 0 12px; height: 42px;
  background: rgba(255,255,255,.45); border: 1px solid var(--line); border-radius: 12px;
  transition: box-shadow .35s var(--ease), border-color .35s;
}
.search:focus-within { border-color: rgba(154,111,95,.55); box-shadow: 0 0 0 4px rgba(154,111,95,.12); }
.search svg { width: 17px; height: 17px; fill: none; stroke: var(--ink-3); stroke-width: 1.7; stroke-linecap: round; flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none; height: 100%;
  font-size: 15px; color: var(--ink);
}
.search input::placeholder { color: var(--ink-3); }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear {
  border: 0; background: var(--paper-3); color: var(--ink-2);
  width: 22px; height: 22px; border-radius: 50%; line-height: 1; font-size: 15px;
}

.facets { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; transition: opacity .3s; }
.facets.muted { opacity: .38; pointer-events: none; }

.field { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13.5px; }
.field > span:first-child { color: var(--ink-3); letter-spacing: .02em; }
.field select, .field input[type=number] {
  height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 9px;
  background: rgba(255,255,255,.45); color: var(--ink); outline: none;
  transition: border-color .3s, box-shadow .3s;
}
.field select { padding-right: 26px; appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238b8177' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.field select:focus, .field input:focus { border-color: rgba(154,111,95,.55); box-shadow: 0 0 0 3px rgba(154,111,95,.12); }
.field input[type=number] { width: 72px; -moz-appearance: textfield; text-align: center; font-variant-numeric: tabular-nums; }
.field input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; }
.range { display: inline-flex; align-items: center; gap: 6px; }
.range i { color: var(--ink-3); font-style: normal; }

.toggle { cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch {
  width: 36px; height: 20px; border-radius: 20px; position: relative;
  background: var(--paper-3); border: 1px solid var(--line); transition: background .35s var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18); transition: transform .35s var(--ease);
}
.toggle input:checked + .switch { background: var(--accent); border-color: transparent; }
.toggle input:checked + .switch::after { transform: translateX(16px); }
.toggle input:focus-visible + .switch { box-shadow: 0 0 0 3px rgba(154,111,95,.2); }

.actions { display: flex; gap: 8px; align-items: center; }
.btn {
  height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid transparent;
  background: var(--ink); color: var(--paper); font-weight: 500; font-size: 13.5px; letter-spacing: .01em;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: transform .25s var(--ease), background .25s, box-shadow .25s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 8px 18px -10px rgba(0,0,0,.4); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn.ghost:hover { background: rgba(255,255,255,.5); color: var(--ink); box-shadow: none; }
.spark { color: var(--gold); filter: drop-shadow(0 0 4px rgba(220,200,160,.8)); }
.btn:hover .spark { animation: twinkle 1.2s ease-in-out infinite; }
@keyframes twinkle { 50% { transform: scale(1.35) rotate(20deg); opacity: .7; } }

.hint { grid-column: 1 / -1; margin: -2px 0 0; font-size: 13px; color: var(--ink-3); font-style: italic; font-family: var(--display); }

.status {
  min-height: 22px; margin: 0 4px 16px;
  font-family: var(--display); font-size: 15px; color: var(--ink-3); font-variant-numeric: tabular-nums;
}
.status.error { color: #9a4d3f; }
.status .retry { margin-left: 8px; border: 0; background: none; color: var(--accent-ink); text-decoration: underline; }

/* ---------- gallery ---------- */

.gallery {
  column-width: 230px; column-gap: 22px;
}
@media (min-width: 1500px) { .gallery { column-width: 250px; } }
@media (max-width: 520px) { .gallery { column-width: 150px; column-gap: 14px; } }

.card {
  break-inside: avoid; margin: 0 0 22px; display: block;
  animation: rise .7s var(--ease) both;
}
@media (max-width: 520px) { .card { margin-bottom: 14px; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

.card-btn {
  display: block; width: 100%; padding: 0; border: 0; background: none; text-align: left;
  border-radius: var(--radius); outline: none;
}
.card-btn:focus-visible .mat { box-shadow: var(--shadow-lift), 0 0 0 3px rgba(154,111,95,.35); }
.mat {
  display: block; padding: 6px; border-radius: var(--radius);
  background: linear-gradient(160deg, #fffdf8, #f3ecdf);
  border: 1px solid rgba(255,255,255,.7);
  box-shadow: var(--shadow);
  transition: transform .5s var(--ease), box-shadow .5s var(--ease);
}
.card-btn:hover .mat { transform: translateY(-4px) rotate(-.25deg); box-shadow: var(--shadow-lift); }
.mat img {
  display: block; width: 100%; height: auto; border-radius: 5px;
  background: var(--paper-2);
  mix-blend-mode: multiply; filter: saturate(.92) contrast(.98);
  opacity: 0; transition: opacity .9s var(--ease);
}
.mat img:not(.in) { aspect-ratio: 0.68; }   /* typical page proportion until the scan arrives */
.mat img.in { opacity: 1; }
.card.missing .mat { background: repeating-linear-gradient(135deg, #f3ecdf 0 8px, #ede5d6 8px 16px); }
.card.missing .mat img { opacity: 0; aspect-ratio: 0.68; }
.card-cap {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding: 8px 6px 0; font-size: 12.5px; color: var(--ink-3);
  font-family: var(--display); letter-spacing: .01em; font-variant-numeric: tabular-nums;
}
.cap-ed { color: var(--ink-2); }
.cap-ed .tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 4px;
  font-family: var(--ui); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase;
  background: var(--lilac); color: #5a4d6b;
}

/* skeleton */
.skel {
  break-inside: avoid; margin: 0 0 22px; border-radius: var(--radius);
  background: linear-gradient(100deg, var(--paper-2) 30%, #f8f3ea 50%, var(--paper-2) 70%);
  background-size: 300% 100%; animation: shimmer 2.2s ease-in-out infinite;
  border: 1px solid rgba(255,255,255,.6);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.empty {
  padding: 80px 20px; text-align: center; color: var(--ink-3);
  font-family: var(--display); font-size: 20px; font-style: italic;
}

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

.pager {
  margin-top: 30px; display: flex; justify-content: center; align-items: center; gap: 16px;
  font-family: var(--display); color: var(--ink-2); font-variant-numeric: tabular-nums;
}
.pager-mid { display: inline-flex; align-items: center; gap: 6px; }
#page-input {
  width: 64px; height: 32px; text-align: center; border: 1px solid var(--line); border-radius: 8px;
  background: rgba(255,255,255,.45); outline: none; -moz-appearance: textfield;
}
#page-input::-webkit-inner-spin-button { -webkit-appearance: none; }
#page-input:focus { border-color: rgba(154,111,95,.55); }

/* ---------- colophon ---------- */

.colophon {
  max-width: 720px; margin: 0 auto; padding: 40px 24px 70px; text-align: center;
  font-family: var(--display); color: var(--ink-3); font-size: 14.5px; line-height: 1.65;
  border-top: 1px solid var(--line-2);
}
.colophon p { margin: 0; }
.colophon .sep { margin: 0 8px; color: var(--line); }
@media (max-width: 640px) { .colophon .sep { display: block; height: 6px; overflow: hidden; color: transparent; } }

/* ---------- lightbox ---------- */

.lightbox {
  border: 0; padding: 0; margin: 0; max-width: 100vw; max-height: 100dvh; width: 100vw; height: 100dvh;
  background: transparent; color: var(--ink); overflow: hidden;
}
.lightbox::backdrop { background: rgba(240, 232, 218, 0.72); backdrop-filter: blur(18px) saturate(1.1); -webkit-backdrop-filter: blur(18px) saturate(1.1); }
.lightbox[open] { animation: fade .35s var(--ease); }
@keyframes fade { from { opacity: 0; } }

.lb-body {
  height: 100%; display: grid; grid-template-columns: 1fr minmax(260px, 340px);
  gap: 28px; padding: 40px clamp(56px, 6vw, 110px); align-items: center;
}
@media (max-width: 860px) {
  /* single scrolling column: the image keeps its natural height and the
     meta panel + ask box flow below it instead of overlapping */
  .lb-body { display: block; overflow-y: auto; height: 100%; padding: 56px 18px 96px; }
}
.lb-figure {
  margin: 0; height: 100%; min-height: 0; display: flex; align-items: center; justify-content: center;
}
.lb-figure img {
  max-width: 100%; max-height: calc(100dvh - 80px); height: auto; width: auto;
  padding: 8px; border-radius: 8px;
  background: linear-gradient(160deg, #fffdf8, #f3ecdf);
  box-shadow: 0 30px 80px -30px rgba(60,40,20,.55), 0 2px 4px rgba(60,40,20,.08);
  mix-blend-mode: multiply;
  animation: rise .5s var(--ease);
}
@media (max-width: 860px) {
  .lb-figure { height: auto; margin-bottom: 18px; }
  .lb-figure img { max-height: 58dvh; }
}

.lb-meta { font-family: var(--display); }
.lb-kicker { margin: 0 0 6px; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-ink); }
.lb-title { margin: 0 0 18px; font-weight: 400; font-size: 21px; line-height: 1.3; color: var(--ink); font-variation-settings: "opsz" 40; }
.lb-facts { margin: 0 0 20px; display: grid; grid-template-columns: auto 1fr; gap: 5px 14px; font-size: 14px; }
.lb-facts dt { color: var(--ink-3); }
.lb-facts dd { margin: 0; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.lb-links { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.lb-links a { width: fit-content; }

.lb-ask { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line-2); }
.lb-ask-label { margin: 0 0 10px; font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent-ink); }
.lb-ask-log {
  max-height: 220px; overflow-y: auto; margin: 0 0 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.lb-ask-msg {
  font-family: var(--ui); font-size: 13.5px; line-height: 1.5;
  padding: 8px 11px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.lb-ask-msg.q { align-self: flex-end; max-width: 90%; background: var(--ink); color: var(--paper); border-bottom-right-radius: 3px; }
.lb-ask-msg.a { align-self: flex-start; background: rgba(255,255,255,.6); border: 1px solid var(--line-2); color: var(--ink-2); border-bottom-left-radius: 3px; }
.lb-ask-msg.a.pending { color: var(--ink-3); font-style: italic; animation: askPulse 1.6s ease-in-out infinite; }
.lb-ask-msg.a.err { color: #9a4d3f; }
@keyframes askPulse { 50% { opacity: .55; } }
.lb-ask-form { display: flex; gap: 8px; }
.lb-ask-form input {
  flex: 1; min-width: 0; height: 36px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255,255,255,.55); color: var(--ink); outline: none; font-size: 13.5px;
  transition: border-color .3s, box-shadow .3s;
}
.lb-ask-form input:focus { border-color: rgba(154,111,95,.55); box-shadow: 0 0 0 3px rgba(154,111,95,.12); }
.lb-ask-form input::placeholder { color: var(--ink-3); }

/* ---------- mobile comfort ---------- */
/* (.lightbox prefix outweighs the single-class desktop lightbox rules) */

@media (max-width: 860px) {
  .lightbox .lb-nav { top: auto; bottom: 14px; transform: none; }
  .lightbox .lb-nav:hover { transform: scale(1.06); }
  .lightbox .lb-prev { left: 12px; }
  .lightbox .lb-next { right: 12px; }
}

@media (max-width: 640px) {
  /* 16px stops iOS Safari from zooming into focused fields */
  .search input, .field select, .field input[type=number], .lb-ask-form input, #page-input { font-size: 16px; }
  .lb-ask-form input, .lb-ask-form .btn { height: 44px; }
  .lightbox .lb-close { top: 12px; right: 12px; }
}

.lb-close, .lb-nav {
  position: absolute; z-index: 2; border: 1px solid var(--line); background: rgba(255,255,255,.55);
  color: var(--ink-2); border-radius: 50%; display: grid; place-items: center;
  transition: background .25s, transform .25s var(--ease);
}
.lb-close:hover, .lb-nav:hover { background: #fff; color: var(--ink); transform: scale(1.06); }
.lb-close { top: 18px; right: 18px; width: 40px; height: 40px; font-size: 22px; line-height: 1; }
.lb-nav { top: 50%; transform: translateY(-50%); width: 44px; height: 44px; font-size: 28px; line-height: 1; }
.lb-nav:hover { transform: translateY(-50%) scale(1.06); }
.lb-prev { left: 14px; } .lb-next { right: 14px; }
.lb-nav:disabled { opacity: .25; pointer-events: none; }
