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

/* ── Theme tokens ─────────────────────────────────────────── */

:root {
  --gap: 18px;
  --row-unit: 8px;
  --max-width: 1400px;

  --bg: #f4f1ea;          /* off-white */
  --surface: #ffffff;
  --surface-2: #faf8f3;
  --text: #1a1a1a;
  --text-muted: #6f6a60;
  --border: #e4ded1;
  --accent: #1a1a1a;
  --on-accent: #f4f1ea;
  --shadow: 0 10px 30px -14px rgba(40, 33, 20, 0.30);
  --shadow-hover: 0 24px 52px -18px rgba(40, 33, 20, 0.42);
}

:root[data-theme="dark"] {
  --bg: #0e0e10;          /* almost black */
  --surface: #18181b;
  --surface-2: #161618;
  --text: #ece9e1;
  --text-muted: #8f8a80;
  --border: #2a2a2e;
  --accent: #ece9e1;
  --on-accent: #18181b;
  --shadow: 0 10px 30px -14px rgba(0, 0, 0, 0.6);
  --shadow-hover: 0 24px 55px -16px rgba(0, 0, 0, 0.78);
}

html { color-scheme: light dark; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
  transition: background 0.4s ease, color 0.4s ease;
}

/* ── Theme toggle ─────────────────────────────────────────── */

#theme-toggle {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 50;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  transition: transform 0.25s ease, background 0.3s ease, border-color 0.3s ease;
}

#theme-toggle:hover { transform: rotate(-18deg) scale(1.08); }

/* ── Header ───────────────────────────────────────────────── */

header {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 24px;
  padding: 72px 20px 0;
  margin-bottom: 68px;        /* big breathing room before the grid */
}

.site-name {
  font-family: "New Rocker", system-ui, cursive;
  font-weight: 400;
  font-size: clamp(3rem, 9vw, 5.5rem);
  line-height: 0.9;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text);
  text-decoration: none;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

#search {
  width: 100%;
  max-width: 380px;
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 10px 18px;
  font-size: 0.85rem;
  text-align: center;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search::placeholder { color: var(--text-muted); }

#search:focus {
  border-color: var(--text-muted);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-muted) 18%, transparent);
}

#tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 760px;
}

.tag-pill {
  font-size: 0.72rem;
  padding: 6px 13px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  user-select: none;
  transition: all 0.15s;
}

.tag-pill::before { content: "#\00a0"; }

.tag-pill:hover { border-color: var(--text-muted); color: var(--text); }
.tag-pill:hover::before { content: "+\00a0"; }

.tag-pill.active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

.tag-pill.active:hover::before { content: "×\00a0"; }

/* ── Grid (centred, capped, masonry) ──────────────────────── */

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  grid-auto-rows: var(--row-unit);
  gap: var(--gap);
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px 90px;
  align-items: start;
}

/* ── Cards (shared) ───────────────────────────────────────── */

.card {
  perspective: 950px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(32px);
  transition: opacity 0.6s cubic-bezier(.2, .7, .2, 1),
              transform 0.6s cubic-bezier(.2, .7, .2, 1);
}

.card.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.card--hidden { display: none; }

.card-inner {
  position: relative;
  height: 100%;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: box-shadow 0.25s ease, transform 0.4s ease;
  will-change: transform;
}

/* while the pointer is actively tilting, follow it instantly */
.card-inner.tilting { transition: box-shadow 0.25s ease; }

.card:hover .card-inner { box-shadow: var(--shadow-hover); }

/* ── Image cards ──────────────────────────────────────────── */

.card--image .card-inner { background: var(--surface-2); }

.card--image img {
  width: 100%;
  height: auto;
  display: block;
}

/* ── Quote cards ──────────────────────────────────────────── */

.card--quote .card-inner {
  padding: 26px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--border);
}

.quote-text {
  font-size: 1rem;
  font-style: italic;
  line-height: 1.6;
  color: var(--text);
  flex: 1;
}

.quote-source {
  font-size: 0.72rem;
  font-variant: small-caps;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* ── Link cards ───────────────────────────────────────────── */

.card--link .card-inner {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  border: 1px solid var(--border);
}

.link-domain {
  font-size: 0.66rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 8px;
  color: var(--text-muted);
  align-self: flex-start;
}

.link-title {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

.link-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.55;
  flex: 1;
}

/* ── Shared small tag rows on quote/link cards ────────────── */

.card-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.card-tag { font-size: 0.64rem; color: var(--text-muted); }

/* ── No results ───────────────────────────────────────────── */

.no-results {
  grid-column: 1 / -1;
  padding: 90px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Modal ────────────────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 45%, rgba(0, 0, 0, 0.7));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade 0.25s ease;
}

.modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 760px;
  max-height: 88vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-hover);
  animation: pop 0.32s cubic-bezier(.2, .8, .2, 1);
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
  from { opacity: 0; transform: translateY(20px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s, transform 0.2s;
}

.modal-close:hover { background: rgba(0, 0, 0, 0.72); transform: rotate(90deg); }

/* image modals shrink-wrap the photo so portraits get no side air */
.modal--image .modal-card {
  width: fit-content;
  max-width: min(88vw, 680px);
}

.modal-img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(88vw, 680px);
  max-height: 60vh;
  object-fit: contain;
  background: var(--surface-2);
}

.modal-text {
  padding: 26px 30px 30px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-title { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.modal-quote { font-size: 1.3rem; font-style: italic; line-height: 1.55; }
.modal-desc { font-size: 0.95rem; color: var(--text-muted); line-height: 1.6; }

.modal-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant: small-caps;
  letter-spacing: 0.05em;
}

.modal-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

.modal-tag {
  font-size: 0.74rem;
  padding: 6px 13px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.modal-tag:hover {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

.modal-link {
  align-self: flex-start;
  margin-top: 6px;
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  background: var(--accent);
  color: var(--on-accent);
  transition: opacity 0.2s, transform 0.2s;
}

.modal-link:hover { transform: translateY(-2px); opacity: 0.9; }

/* ── Mobile ───────────────────────────────────────────────── */

@media (max-width: 600px) {
  header { padding: 54px 16px 0; margin-bottom: 44px; }

  #grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding: 0 12px 64px;
  }

  .modal-text { padding: 22px 22px 26px; }
}

/* ── Reduced motion ───────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .card { opacity: 1; transform: none; transition: none; }
  .card-inner { transition: box-shadow 0.25s ease; transform: none; }
}
