/* ==========================================================================
   Books — "brick stack" layout experiment

   A non-destructive prototype that reuses the live data (../data/books.json)
   but lays the covers out like a woven brick wall instead of a grid. Clicking
   a book lifts it out of the wall: it rotates upright, scales up a touch, casts
   a deep shadow, and the rest of the wall dims + desaturates behind it.

   The layout (tile size, rows, brick offset) is computed in brick-stack.js and
   written onto each tile as inline left/top/width/height + a --rot custom
   property. Everything visual — the lift, the dimming, the label — lives here.
   ========================================================================== */

:root {
  /* A cool, neutral "mortar" so the lifted cover's colour pops, echoing the
     greyed-out mock-ups. */
  --bg: #e7e7e9;
  --wall: #dededf;
  --ink: #23252b;
  --ink-soft: #6b6f78;
  --line: #cfcfd2;
  --label-bg: #ffffff;

  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia,
    "Times New Roman", serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;

  /* Motion + depth for the lift interaction */
  --lift-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --tile-shadow: 0 2px 5px rgba(20, 22, 28, 0.22);
  --lift-shadow: 0 26px 50px rgba(15, 18, 26, 0.42),
    0 10px 20px rgba(15, 18, 26, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131419;
    --wall: #1b1d23;
    --ink: #eef0f4;
    --ink-soft: #9aa0ab;
    --line: #2c2f37;
    --label-bg: #20232b;
    --tile-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    --lift-shadow: 0 26px 55px rgba(0, 0, 0, 0.6),
      0 10px 22px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.5;
  min-height: 100vh;
}

.muted {
  color: var(--ink-soft);
}

a {
  color: inherit;
}

/* ---- Header --------------------------------------------------------------- */

.topbar {
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(28px, 6vw, 60px) clamp(16px, 4vw, 40px) clamp(6px, 2vw, 16px);
  text-align: center;
}

.eyebrow {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.title {
  margin: 0.2rem 0 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2rem, 6vw, 3.2rem);
  letter-spacing: -0.01em;
}

.tagline {
  margin: 0.5rem auto 0;
  max-width: 44ch;
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1rem, 2.4vw, 1.18rem);
  color: var(--ink-soft);
}

.period {
  margin: 0.9rem 0 0;
  min-height: 1.4em;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ---- The wall ------------------------------------------------------------- */

.board {
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 40px);
}

.stage {
  position: relative;
  margin: 0 auto;
  /* width/height are set in JS once the tiles are placed */
}

.stage[aria-busy="true"] {
  display: grid;
  place-items: center;
  min-height: 40vh;
}

/* ---- A tile (one book) ---------------------------------------------------- */

.tile {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  /* Placed by JS: left, top, width, height, --rot */
  transform: rotate(var(--rot, 0deg));
  transform-origin: center center;
  transition: transform 0.5s var(--lift-ease), filter 0.45s ease,
    opacity 0.45s ease, box-shadow 0.45s ease;
  will-change: transform, filter;
  -webkit-tap-highlight-color: transparent;
}

.tile:focus-visible {
  outline: 3px solid #5aa9ff;
  outline-offset: 3px;
}

.tile-cover {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  overflow: hidden;
  background: var(--cover-bg, #555);
  color: #fff;
  box-shadow: var(--tile-shadow);
  border-left: 3px solid rgba(255, 255, 255, 0.25);
  transition: box-shadow 0.45s ease;
}

/* Generated typographic cover, shown until/unless a real image loads */
.gen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 12px 11px;
  text-align: left;
}

.gen-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(0.85rem, 2.2vw, 1rem);
  line-height: 1.16;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.gen-author {
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  opacity: 0.92;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.tile-cover img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.tile-cover img.loaded {
  opacity: 1;
}

/* ---- The lift ------------------------------------------------------------- */

/* When something is picked, the whole wall dims + desaturates… */
.stage.has-selection .tile {
  filter: grayscale(0.72) saturate(0.45) brightness(0.86);
  opacity: 0.72;
}

/* …except the chosen book, which straightens, grows, lifts, and sharpens. */
.stage.has-selection .tile.is-selected {
  transform: translateY(-10px) scale(1.16) rotate(0deg);
  filter: none;
  opacity: 1;
  z-index: 50;
}

.stage.has-selection .tile.is-selected .tile-cover {
  box-shadow: var(--lift-shadow);
}

/* ---- Floating label (title / author / date of the lifted book) ------------ */

.tile-label {
  position: absolute;
  z-index: 60;
  max-width: 230px;
  padding: 10px 14px;
  background: var(--label-bg);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(15, 18, 26, 0.28);
  text-align: center;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s ease, transform 0.3s var(--lift-ease);
  pointer-events: none;
}

.tile-label.show {
  opacity: 1;
  transform: translateY(0);
}

.tile-label .l-title {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
}

.tile-label .l-author {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-top: 1px;
}

.tile-label .l-date {
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 3px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ---- Footer --------------------------------------------------------------- */

.footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 40px) 48px;
  text-align: center;
}

.error {
  color: #b3402f;
}

/* Honour reduced-motion: keep the state changes, drop the long animations. */
@media (prefers-reduced-motion: reduce) {
  .tile,
  .tile-cover,
  .tile-label,
  .tile-cover img {
    transition-duration: 0.01ms;
  }
}
