/* The Geometry Snacks library's styles (index.html, and every puzzle's copy of puzzle.html,
   which link this file rather than carry it: it is fetched once and cached). The page is the
   Catriona Agg library's (CatrionaAgg/catriona.css) with the books' look: solid red, inked
   outlines, no controls yet. */

: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);
  /* the books' red fill and black ink */
  --red: #EF303F;
  --blue: #0000FF;
  --figure-ink: #000000;
  --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);
  --red: #D9333F;
  --blue: #9DA3FF;
  --figure-ink: #E8EBF0;
  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 list ---------- */
.wrap {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 28px;
}

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 48px;
  align-items: center;
  padding: 34px 0 40px;
}

.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);
}

/* three shapes as the books draw them */
.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; }

/* the two books side by side under the title: the cover, and under it where to buy it */
.books {
  display: flex;
  gap: 24px;
  margin: 26px 0 28px;
}

.book {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: min(190px, 42vw);  /* no wider than its cover, so the links wrap on a phone */
}

/* the cover as the publisher prints it, the two at one height so the links under them line up;
   the shadow deepens under the mouse, nothing moves */
.book .cover {
  display: block;
  border-radius: 6px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.25s var(--ease);
}

.book .cover:hover { box-shadow: var(--shadow-lift); }

.book .cover img {
  display: block;
  height: min(190px, 42vw);
  width: auto;
  border-radius: 6px;
}

.book .shops { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }

.book .shops a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  border-radius: 15px;
  background: var(--chip);
  color: var(--chip-ink);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}

.book .shops a:hover { background: var(--line-strong); color: var(--ink); }
.book .out { width: 12px; height: 12px; color: var(--ink-faint); }

/* the right half of the hero is open: the donut turns behind the whole hero, under the text */
.hero > div { position: relative; z-index: 1; }

.hero-side { min-height: 1px; }

/* the low-poly donut of the books' cover (donut.js), subdued; the mouse turns it. The canvas
   spans the window, not the column, so the donut (centered on the open right half) isn't cut
   at the column's edge; the list clips what reaches under the scrollbar */
#gallery-view { overflow-x: clip; }

.donut {
  position: absolute;
  z-index: 0;
  top: -30px;
  left: calc(50% - 50vw);
  width: 100vw;
  height: calc(100% + 60px);
  opacity: 0.3;
  display: block;
}

/* the controls: search and arrangement, as the Catriona Agg library's */
.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);
}

.count {
  margin-left: auto;
  font-size: 13px;
  color: var(--ink-faint);
  white-space: nowrap;
}

/* the sections of the arrangement, each a filter */
.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 {
  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); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 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;
}

/* which book and which puzzle: "Geometry Snacks · #1" */
.panel .where { 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 24px;
  padding: 20px 22px 18px 24px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

/* the book's color along the edge of the question: the first book's red, the second's blue
   (the class is set by snacks.js, and written into a puzzle's page at build) */
.question::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18px;
  bottom: 18px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--red);
}

.question.book-2::before { background: var(--blue); }

.question p {
  margin: 0;
  font-size: 19px;
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: -0.01em;
}

.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; }
  .hero-side, .donut { display: none; }
  .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; }
  .books { gap: 16px; }
  .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; }
  .segmented .group-label { display: none; }
  .count { margin-left: 0; }
  .stage-tools span { display: none; }
  .stage-tools button { padding: 0 9px; }
  .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; }
}
