/* The Catriona Agg library's styles (index.html, and every puzzle's copy of it, which link this
   file rather than carry it: it is fetched once and cached) */

:root {
  --page: #F7F5F0;
  --surface: #FFFFFF;
  --paper: #FFFFFF;
  --ink: #1F2430;
  --ink-soft: #586173;
  --ink-faint: #8A93A3;
  --line: #E4E0D7;
  --line-strong: #CFCAC0;
  --chip: #EEEBE4;
  --chip-ink: #3A4150;
  --accent: #2F6FDB;
  --accent-soft: rgba(47, 111, 219, 0.1);
  --shadow: 0 1px 2px rgba(40, 32, 20, 0.06), 0 4px 14px rgba(40, 32, 20, 0.06);
  --shadow-lift: 0 2px 4px rgba(40, 32, 20, 0.08), 0 14px 34px rgba(40, 32, 20, 0.14);
  --pink: #F5589B;
  --orange: #F26313;
  --yellow: #FFD400;
  --green: #14B67F;
  --blue: #1689F2;
  --purple: #8A12B5;
  --sans: "Inter", "Segoe UI", system-ui, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --page: #1B1E23;
  --surface: #24282F;
  --paper: #2B2B2B;
  --ink: #E8EBF0;
  --ink-soft: #A9B0BC;
  --ink-faint: #949CAA;
  --line: #353A43;
  --line-strong: #474D58;
  --chip: #2E333B;
  --chip-ink: #D4D9E2;
  --accent: #7FABFF;
  --accent-soft: rgba(127, 171, 255, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.25);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.35), 0 16px 36px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

a { color: inherit; }

button { font: inherit; color: inherit; }

svg { display: block; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- the bar along the top of both views ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 56px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--page) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.topbar.scrolled { border-bottom-color: var(--line); }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  text-decoration: none;
  color: var(--ink);
}

.brand img { width: 28px; height: 28px; flex: none; }

.brand .site { font-weight: 600; font-size: 14px; color: var(--ink-soft); white-space: nowrap; }

.crumb-sep { width: 1px; height: 22px; background: var(--line-strong); flex: none; }

.crumb {
  font-weight: 600;
  font-size: 16px;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spacer { flex: 1 1 auto; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  text-decoration: none;
  flex: none;
  -webkit-tap-highlight-color: transparent;
}

.icon-button:hover { background: var(--chip); color: var(--ink); }
.icon-button svg { width: 20px; height: 20px; }
.icon-button .moon { display: none; }
:root[data-theme="dark"] .icon-button .sun { display: none; }
:root[data-theme="dark"] .icon-button .moon { display: block; }

/* ---------- the gallery ---------- */
.wrap {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 28px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 48px;
  align-items: center;
  padding: 34px 0 40px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: clamp(16px, 1.7vw, 21px);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.hero h1 {
  margin: 0;
  font-weight: 700;
  font-size: clamp(44px, 6.2vw, 80px);
  line-height: 1;
  letter-spacing: -0.03em;
}

.hero h1 .sub {
  display: block;
  margin-top: 12px;
  font-weight: 500;
  font-size: 0.4em;
  letter-spacing: -0.01em;
  color: var(--ink-soft);
}

/* six felt-tip strokes, her pens */
.pens {
  display: flex;
  gap: 7px;
  margin: 22px 0 22px 2px;
}

.pens span {
  width: 34px;
  height: 7px;
  border-radius: 6px 3px 7px 2px;
  transform: rotate(-4deg);
}

.pens span:nth-child(2n) { transform: rotate(3deg); width: 28px; }

.lede {
  max-width: 640px;
  margin: 0;
  font-size: 17px;
  line-height: 1.6;
  color: var(--ink-soft);
}

.lede + .lede { margin-top: 14px; }

.lede strong { color: var(--ink); font-weight: 600; }

.people {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 26px;
}

.person {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: box-shadow 0.25s var(--ease), border-color 0.2s;
}

.person:hover { box-shadow: var(--shadow-lift); border-color: var(--line-strong); }

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex: none;
  color: #FFFFFF;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.person b { display: block; font-size: 15px; font-weight: 600; }
.person small { display: block; font-size: 13px; color: var(--ink-soft); line-height: 1.35; }
.person .out { width: 14px; height: 14px; color: var(--ink-faint); margin-left: 2px; }

.feature {
  position: relative;
  display: block;
  aspect-ratio: 1;
  max-width: 460px;
  width: 100%;
  justify-self: end;
  border-radius: 22px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-decoration: none;
  transition: box-shadow 0.3s var(--ease), border-color 0.2s;
}

.feature:hover { box-shadow: var(--shadow-lift); border-color: var(--line-strong); }

/* square, as high as the card leaves room for, in the middle */
.feature .art { position: absolute; top: 18px; bottom: 62px; left: 50%; aspect-ratio: 1; transform: translateX(-50%); }

.feature .caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 14px 20px 16px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.feature .caption .label { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); }
.feature .caption .name { font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* the controls: search, arrangement, order */
.controls {
  position: sticky;
  top: 56px;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 0;
  background: var(--page);
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 240px;
  max-width: 360px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search svg { width: 17px; height: 17px; color: var(--ink-faint); flex: none; }

.search input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  font: inherit;
  color: var(--ink);
}

.search input::placeholder { color: var(--ink-faint); }

.segmented {
  position: relative;
  display: inline-flex;
  padding: 4px;
  border-radius: 12px;
  background: var(--chip);
}

.segmented button {
  position: relative;
  z-index: 1;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--chip-ink);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.segmented button[aria-pressed="true"] { color: var(--ink); font-weight: 600; }

/* the plate under the chosen button slides from one to the next */
.segmented .thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 0;
  width: 0;
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: transform 0.35s var(--ease), width 0.35s var(--ease);
}

.segmented .group-label {
  align-self: center;
  padding: 0 6px 0 8px;
  font-size: 13px;
  color: var(--ink-faint);
}

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.chip-toggle:hover { border-color: var(--line-strong); }
.chip-toggle svg { width: 16px; height: 16px; }

.count {
  margin-left: auto;
  font-size: 13px;
  color: var(--ink-faint);
  white-space: nowrap;
}

.jump {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 2px 0 6px;
}

.jump button {
  height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 15px;
  background: var(--chip);
  color: var(--chip-ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.jump button:hover { background: var(--line-strong); }
.jump button span { color: var(--ink-faint); margin-left: 4px; font-weight: 400; }

/* the section shown alone, or All when none is */
.jump button[aria-pressed="true"] { background: var(--ink); color: var(--page); font-weight: 600; }
.jump button[aria-pressed="true"] span { color: inherit; opacity: 0.7; }

.groups { padding-bottom: 30px; }

.group { padding-top: 18px; scroll-margin-top: 130px; }

.group h2 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 8px 2px 14px;
  font-weight: 700;
  font-size: 24px;
  letter-spacing: -0.02em;
}

.group h2 .n { font-size: 14px; font-weight: 500; color: var(--ink-faint); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 22px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: box-shadow 0.3s var(--ease), border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tile:hover { box-shadow: var(--shadow-lift); border-color: var(--line-strong); }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.tile .art {
  position: relative;
  aspect-ratio: 1;
  margin: 8px 8px 0;
  border-radius: 11px;
  background: var(--paper);
  overflow: hidden;
}

.tile .art img,
.tile .art canvas,
.feature .art canvas,
.feature .art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.tile .art img { opacity: 0; transition: opacity 0.35s; }
.tile .art img.shown { opacity: 1; }

.tile .meta { padding: 10px 14px 13px; min-width: 0; }

.tile .title {
  display: block;
  font-weight: 600;
  font-size: 14.5px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile .sub { display: block; margin-top: 2px; font-size: 12.5px; color: var(--ink-faint); }

/* a puzzle with something to drag */
.tile .live {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14);
  opacity: 0.85;
}

.tile .live svg { width: 15px; height: 15px; }

.empty { padding: 40px 2px; color: var(--ink-soft); font-size: 16px; }

.footer {
  margin-top: 30px;
  padding: 30px 0 44px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.7;
}

.footer p { margin: 0 0 8px; max-width: 820px; }
.footer a { color: var(--ink); text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.footer a:hover { text-decoration-color: currentColor; }

/* ---------- a puzzle ---------- */
#puzzle-view {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  background: var(--page);
}

#puzzle-view .topbar { position: static; flex: none; border-bottom-color: var(--line); }

.stepper { display: flex; align-items: center; gap: 2px; }
.stepper .position { min-width: 54px; text-align: center; font-size: 13px; font-weight: 500; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px 0 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-soft);
  text-decoration: none;
  white-space: nowrap;
}

.back:hover { background: var(--chip); color: var(--ink); }
.back svg { width: 20px; height: 20px; }

.puzzle-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  margin: 16px 0 16px 16px;
  border-radius: 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: hidden;
}

#player { position: absolute; inset: 0; }

.stage-tools {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
}

.stage-tools button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.stage-tools button:hover { color: var(--ink); border-color: var(--line-strong); }
.stage-tools svg { width: 16px; height: 16px; }

.panel {
  min-height: 0;
  overflow-y: auto;
  padding: 26px 30px 30px 28px;
}

.panel .date { margin: 0 0 6px; font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-faint); }

.panel h1 {
  margin: 0 0 20px;
  font-weight: 700;
  font-size: 32px;
  line-height: 1.12;
  letter-spacing: -0.025em;
}

.question {
  position: relative;
  margin: 0 0 18px;
  padding: 20px 22px 18px 24px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.question::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18px;
  bottom: 18px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: linear-gradient(var(--pink), var(--orange), var(--yellow), var(--green), var(--blue), var(--purple));
}

.question p {
  margin: 0;
  font-size: 19px;
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: -0.01em;
}

.question footer { margin-top: 12px; font-size: 13.5px; color: var(--ink-soft); }
.question footer a { color: var(--ink); font-weight: 500; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }

/* Andrew Stacey's three pages for the puzzle, side by side */
.links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 22px; }

.link-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: box-shadow 0.25s var(--ease), border-color 0.2s;
}

.link-card:hover { box-shadow: var(--shadow-lift); border-color: var(--line-strong); }
.link-card svg { width: 17px; height: 17px; flex: none; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 24px; }

.tags a {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: 14px;
  background: var(--chip);
  color: var(--chip-ink);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
}

.tags a:hover { background: var(--line-strong); }

.credit {
  margin: 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-faint);
}

.credit + .credit { margin-top: 8px; padding-top: 0; border-top: 0; }

.credit a { color: var(--ink-soft); text-underline-offset: 2px; }

/* the address said a puzzle the catalog doesn't have */
.missing { padding: 40px 28px; font-size: 16px; color: var(--ink-soft); }

/* ---------- smaller windows ---------- */
@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; gap: 28px; padding-top: 22px; }
  .feature { justify-self: start; max-width: 380px; }
  .puzzle-body { grid-template-columns: minmax(0, 1fr) 360px; }
}

@media (max-width: 760px) {
  .wrap { padding: 0 16px; }
  .topbar { padding: 0 8px 0 12px; gap: 6px; }
  .brand .site, .crumb-sep.optional { display: none; }
  .hero h1 { font-size: 46px; }
  .lede { font-size: 16px; }
  .feature { display: none; }
  .controls { top: 56px; gap: 8px; }
  .search { max-width: none; flex-basis: 100%; }
  .segmented { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
  .segmented::-webkit-scrollbar { display: none; }
  .stage-tools span { display: none; }
  .stage-tools button { padding: 0 9px; }
  .segmented .group-label { display: none; }
  .count { margin-left: 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
  .tile .meta { padding: 8px 10px 10px; }
  .tile .title { font-size: 13.5px; }
  .tile .live { top: 13px; right: 13px; width: 22px; height: 22px; }
  .tile .live svg { width: 13px; height: 13px; }
  .puzzle-body { display: flex; flex-direction: column; overflow-y: auto; }
  .stage { flex: none; height: min(62vh, 100vw); margin: 10px 10px 0; }
  .panel { overflow: visible; padding: 20px 18px 28px; }
  .panel h1 { font-size: 28px; }
  .question p { font-size: 19px; }
  #puzzle-view .back .label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}
