/* Run Wild – Murder Mystery
   Styled after the Canva design: rust background, white "paper" with a wavy
   orange edge, a drippy title, soft serif headings and body text, rat bullets,
   and hand-lettered, colour-coded case-file cards (suspects rust, locations
   slate blue, weapons ochre, motives purple).
   Mobile-first, one column on phones, large text, high contrast for bright barn light.
   All fonts are bundled in fonts/ (SIL Open Font License). Nothing loads from
   other websites, and there are no inline styles, so a strict Content-Security-Policy works. */

@font-face { font-family: "Playfair Display"; src: url("fonts/playfair-display-latin-400-normal.1fe9ad5d8b.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Montserrat"; src: url("fonts/montserrat-latin-400-normal.e66bcd2761.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("fonts/fraunces-latin-400-normal.e558f39453.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Fraunces"; src: url("fonts/fraunces-latin-700-normal.c38570d224.woff2") format("woff2"); font-weight: 700; font-display: swap; }
/* Subset to basic Latin (A–Z, digits, punctuation): it's only used for titles. */
@font-face { font-family: "Rubik Wet Paint"; src: url("fonts/rubik-wet-paint-latin-400-normal.d6e0a5b01b.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Patrick Hand"; src: url("fonts/patrick-hand-latin-400-normal.ac5bc9033b.woff2") format("woff2"); font-weight: 400; font-display: swap; }

:root {
  /* Colours sampled from the Canva design */
  --rust: #9B4922;        /* page background (Canva cover) */
  --rust-dark: #3E1D0F;   /* top bar: deep espresso so it stands apart from the rust (2.4:1) */
  --wave: #B65020;        /* drippy title (5:1 on white) */
  --peach: #E3B6A0;       /* "Run Wild" on rust (large text, 3.4:1) */
  --peach-text: #F6DCCD;  /* smaller text on rust (4.8:1) */
  --cream: #FFF5E3;       /* text on rust strips (5.8:1) */
  --paper: #FFFDF9;       /* the wavy-edged page */
  --tint: #F7EADF;        /* boxes inside the paper */
  --card: #F7F5EF;        /* card body */
  --frame: #FFF5E3;       /* card picture background */
  --brown: #572920;       /* headings and body text (12:1 on paper) */
  --ink: #111;
  --rule: #B9B7B3;        /* thin line under card names */
  --o-green: #1F6B3A;
  --x-red: #A3201B;

  /* Card-set colours (Canva) */
  --who: #9B4922;
  --where: #59739D;
  --what: #CC7A00;
  --why: #8C52FF;

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --title: "Playfair Display", Didot, "Bodoni 72", Georgia, serif;
  --caps: "Montserrat", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --drip: "Rubik Wet Paint", "Arial Black", Impact, sans-serif;
  --hand: "Patrick Hand", "Chalkboard SE", "Comic Sans MS", "Marker Felt", cursive;

  --edge: 28px; /* width of the wavy frame; must match EDGE in scripts/make_paper_edge.py */
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--rust);
  color: var(--brown);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.55;
}
[id] { scroll-margin-top: 72px; }  /* keep anchored sections clear of the sticky bar */
[tabindex="-1"]:focus { outline: none; box-shadow: none; }  /* sections focused by a jump link (app.js) */
main { max-width: 700px; margin: 0 auto; padding: 0 0 24px; }
a { color: var(--brown); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.center { text-align: center; }

/* Focus ring that shows up on both rust and white: dark ring with a gold halo. */
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 6px #F2A900; }

/* ---------- sticky top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px;
  background: var(--rust-dark);
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.topbar-title { color: var(--peach-text); text-decoration: none; font-family: var(--title); font-size: 24px; }
.topnav { display: none; }

/* ---------- hero (the rust cover page) ---------- */
.hero { text-align: center; padding: 44px 16px 8px; }
.hero .script {
  font-family: var(--title); font-weight: 400;
  color: var(--peach);
  font-size: clamp(60px, 19vw, 112px); line-height: 1; margin: 0 0 14px;
  letter-spacing: -.01em;
}
.hero h1 {
  font-family: var(--caps); font-weight: 400; color: var(--peach-text);
  font-size: clamp(19px, 5.6vw, 34px);
  letter-spacing: .32em; margin: 0 0 18px; padding-left: .32em; /* re-centre spaced text */
  white-space: nowrap;
}
.hero .subtitle {
  font-family: var(--serif); color: var(--cream); font-size: 21px; margin: 0;
  font-variant-numeric: oldstyle-nums;
}
.notice {
  max-width: 520px; margin: 22px auto 0; padding: 12px 16px;
  color: var(--cream); font-size: 18px; line-height: 1.45;
  border: 2px solid var(--peach-text); border-radius: 10px;
}
.notice strong { color: #fff; }

/* ---------- the cast: suspect photos pinned to the case board ----------
   A row of tilted polaroids above the title; on wide screens they scatter round it. */
.cast { list-style: none; max-width: 720px; margin: 0 auto 26px; padding: 6px 4px 0; display: flex; justify-content: center; flex-shrink: 0; }
.cast li { position: relative; flex: 0 1 19%; max-width: 132px; margin: 0 -1.2%; }
.cast a {
  position: relative; display: block; text-decoration: none;
  background: var(--paper); padding: 6% 6% 0; border-radius: 2px;
  box-shadow: 0 6px 14px rgba(0,0,0,.35);
  transform: rotate(var(--tilt, 0deg)) translateY(var(--drop, 0));
  transition: transform .2s ease;
}
.cast a:hover, .cast a:focus-visible { transform: rotate(0) scale(1.08); z-index: 2; }
/* red push-pin */
.cast a::before {
  content: ""; position: absolute; top: -5px; left: 50%; width: 14px; height: 14px; margin-left: -7px;
  border-radius: 50%; background: radial-gradient(circle at 35% 35%, #ff7a6b, #C0261B 55%, #7d140d);
  box-shadow: 0 2px 3px rgba(0,0,0,.45);
}
.cast img { display: block; width: 100%; height: auto; }
.cast-name {
  display: block; font-family: var(--hand); color: var(--brown); line-height: 1.1;
  font-size: clamp(14px, 3.6vw, 21px); padding: 3px 0 5px;
}
.cast li:nth-child(1) { --tilt: -7deg; --drop: 6px; }
.cast li:nth-child(2) { --tilt: 4deg;  --drop: -2px; }
.cast li:nth-child(3) { --tilt: -2deg; --drop: 4px; z-index: 1; }
.cast li:nth-child(4) { --tilt: 6deg;  --drop: -3px; }
.cast li:nth-child(5) { --tilt: -5deg; --drop: 5px; }
@media (min-width: 1024px) { .cast { max-width: 760px; } }
/* Big screens: scatter the photos out towards the window edges, clear of the title and buttons.
   calc(50% - 50vw) is the window edge, measured from the centred page column. */
@media (min-width: 1360px) and (min-height: 820px) {
  .hero { position: relative; }
  .cast { position: absolute; inset: 0; max-width: none; margin: 0; padding: 0; display: block; pointer-events: none; }
  .cast li { position: absolute; width: 150px; max-width: none; margin: 0; pointer-events: auto; }
  .cast li:nth-child(1) { left: calc(50% - 50vw + 5vw);    top: 10%; --tilt: -8deg; }
  .cast li:nth-child(2) { left: calc(50% - 50vw + 13vw);   top: 40%; --tilt: 6deg; }
  .cast li:nth-child(3) { left: calc(50% - 50vw + 2.5vw);  top: 68%; --tilt: -3deg; }
  .cast li:nth-child(4) { right: calc(50% - 50vw + 6vw);   top: 14%; --tilt: 7deg; }
  .cast li:nth-child(5) { right: calc(50% - 50vw + 2.5vw); top: 60%; --tilt: -6deg; }
}
@media (prefers-reduced-motion: reduce) { .cast a { transition: none; } }

.jump-panel { margin: 34px auto 0; width: 100%; max-width: 520px; }
.jump-heading { color: var(--cream); font-size: 18px; margin: 0 0 10px; }
.jump-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 1023px) { .jump-list li:last-child:nth-child(odd) { grid-column: 1 / -1; } }  /* odd one out spans the row */

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 12px 18px;
  background: var(--frame); color: var(--brown);
  border: 2px solid var(--brown); border-radius: 10px;
  box-shadow: 0 2px 0 rgba(0,0,0,.25);
  font-family: var(--serif); font-weight: 700; font-size: 19px;
  text-decoration: none; cursor: pointer;
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(1px); box-shadow: none; background: var(--tint); }
.jump { width: 100%; }
.top-btn {
  min-height: 44px; padding: 8px 14px; font-size: 17px;
  background: transparent; color: var(--peach-text); border-color: var(--peach-text); box-shadow: none;
}
.top-btn:hover { background: rgba(255,255,255,.08); }

/* ---------- the white "paper" with a wavy orange edge ---------- */
.paper {
  position: relative;
  background: var(--paper);
  margin: calc(var(--edge) + 36px) var(--edge) calc(var(--edge) + 20px);
}
.paper > section { color: var(--brown); }
/* The wavy orange frame: one image (site/assets/paper-edge.svg, made by
   scripts/make_paper_edge.py). "round" fits a whole number of waves along each
   side, so all four corners meet the same way. It overlaps the paper by 1px. */
.paper::before {
  content: ""; position: absolute; inset: calc(1px - var(--edge)); pointer-events: none;
  border: var(--edge) solid transparent;
  border-image: url("assets/paper-edge.145575f306.svg") 28 round;
}

.panel { padding: 14px 10px 26px; }

/* ---------- headings ---------- */
.drip {
  font-family: var(--drip); font-weight: 400;
  font-size: clamp(26px, 6.4vw, 44px); line-height: 1.1;
  text-align: center; text-transform: uppercase;
  margin: 6px 0 4px;
  color: var(--wave);
}
h2 {
  font-family: var(--serif); font-weight: 700;
  color: var(--brown);
  font-size: clamp(30px, 9vw, 42px); line-height: 1.1;
  text-transform: uppercase; text-align: center;
  margin: 10px 0 14px;
}
h3 { font-family: var(--serif); font-weight: 700; color: var(--brown); font-size: 23px; margin: 20px 0 8px; line-height: 1.2; }
p { margin: 0 0 14px; }
strong { color: var(--ink); }

#case p { text-align: center; }
.question { font-weight: 700; letter-spacing: .06em; font-size: 21px; }

/* ---------- lists: rat bullets, hollow-circle sub-bullets, paws ---------- */
.ico { width: 26px; height: 26px; flex: none; fill: currentColor; }
.rats, .paws { list-style: none; padding: 0; margin: 0; }
.rats > li { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 14px; }
.rats > li > span { flex: 1; min-width: 0; }
.rats > li > .ico { margin-top: 2px; color: var(--brown); }
/* Sub-items as a small chart: how (left) and what you get (right). */
.sub {
  list-style: none; margin: 8px 0 2px; padding: 2px 12px;
  background: var(--tint); border-radius: 8px; font-size: 17px; line-height: 1.35;
}
.sub li { display: flex; flex-wrap: wrap; gap: 0 12px; padding: 7px 0; border-top: 1px solid rgba(87,41,32,.12); }
.sub li:first-child { border-top: 0; }
.sub .get { margin-left: auto; text-align: right; font-weight: 700; color: var(--rust); }
.paws li { display: flex; gap: 10px; align-items: flex-start; margin: 0 0 8px; }
.paws .ico { width: 22px; height: 22px; color: var(--rust); margin-top: 4px; }

/* ---------- logic grid ---------- */
.legend { display: grid; gap: 8px; margin: 6px 0 16px; }
.legend-item { display: flex; align-items: center; gap: 12px; font-weight: 700; }
.mark {
  width: 44px; height: 44px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 3px solid var(--ink); border-radius: 8px; background: #fff;
  font-family: var(--caps); font-size: 26px;
}
.mark.x { color: var(--x-red); }
.mark.o { color: var(--o-green); }

.clues, .tips, .try-it, .step { background: var(--tint); border-radius: 12px; padding: 4px 14px 14px; margin: 14px 0; }
.clues ol { margin: 0; padding-left: 24px; }

.grid { border-collapse: collapse; margin: 8px 0 4px; width: 100%; max-width: 420px; table-layout: fixed; background: #fff; }
.grid th, .grid td { border: 2px solid var(--ink); text-align: center; padding: 0; height: 52px; }
.grid thead th, .grid tbody th { background: var(--card); font-size: 16px; font-weight: 700; padding: 4px; }
.grid .corner { font-size: 13px; font-weight: 400; width: 31%; }
.grid td { font-family: var(--caps); font-size: 28px; }
.grid td.x { color: var(--x-red); }
.grid td.o { color: var(--o-green); }
.grid td.new { background: #FFE38A; }
.cell { width: 100%; height: 52px; border: 0; background: transparent; cursor: pointer; font-family: var(--caps); font-size: 28px; color: var(--ink); }
.cell[data-v="X"] { color: var(--x-red); }
.cell[data-v="O"] { color: var(--o-green); }
.reset-grid { margin-top: 12px; }

/* The practice grid needs JavaScript; hide it if scripts are off. */
.js-only { display: none; }
.js .js-only { display: block; }

/* ---------- case-file cards (Canva pages 5–6) ----------
   One component for all four sets; each set has its own strip colour. */
.cards { display: grid; gap: 20px; }
.card {
  --strip: var(--who); --strip-text: var(--cream);
  display: grid; grid-template-columns: 38% 1fr; gap: 0 14px; align-items: start;
  border: 4px solid var(--ink); border-radius: 18px; overflow: hidden;
  background: linear-gradient(var(--strip) 0, var(--strip) 50px, var(--card) 50px);
  padding: 12px 12px 14px;
  font-family: var(--hand); color: var(--ink);
}
.card-location { --strip: var(--where); --strip-text: #fff; }
.card-weapon   { --strip: var(--what);  --strip-text: #000; }
.card-motive   { --strip: var(--why);   --strip-text: #000; }
.card .pic {
  align-self: center;  /* centred in the card when the text runs taller than the picture */
  background: var(--frame);
  border: 2px solid var(--ink); border-radius: 3px;
  box-shadow: 1px 2px 0 var(--ink);
  transform: rotate(-1deg);
  aspect-ratio: 400 / 440; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .num { margin: 2px 0 12px; font-size: 20px; letter-spacing: .14em; color: var(--strip-text); line-height: 1.2; }
.card h3 {
  font-family: var(--hand); font-weight: 400; color: var(--ink);
  font-size: 23px; letter-spacing: .12em; text-transform: uppercase; line-height: 1.15;
  margin: 0 0 8px; padding-bottom: 8px; border-bottom: 2px solid var(--rule);
}
.card .bio { margin: 0; font-size: 19px; line-height: 1.3; }
.card-ico { width: 58%; height: 58%; fill: currentColor; color: var(--strip); }
.heart-green  { color: #1FA34A; }
.heart-orange { color: #F27A1E; }
.heart-red    { color: #E8383D; }
.heart-blue   { color: #1E1AA8; }
.heart-purple { color: #7B2FBF; }
.placeholder {
  width: 100%; height: 100%;
  background: var(--rust); color: #fff;
  font-family: var(--serif); font-weight: 700; font-size: 64px;
  display: flex; align-items: center; justify-content: center;
}
/* ---------- framed box (Canva clue-card frame) ---------- */
.frame {
  margin: 8px 4px; padding: 18px 16px 6px; text-align: center;
  border: 2px solid var(--brown); outline: 1px solid var(--brown); outline-offset: -7px;
  border-radius: 4px; background: var(--card);
}
.starter-clue p { font-family: var(--hand); font-size: clamp(24px, 6.4vw, 32px); line-height: 1.25; margin: 4px 0 14px; }

/* ---------- draft badge ---------- */
.draft {
  display: inline-block; vertical-align: middle;
  margin-left: 10px;
  background: var(--tint); color: var(--brown);
  border: 1px dashed var(--brown); border-radius: 6px;
  font-family: var(--caps); font-size: 12px; letter-spacing: .05em;
  padding: 2px 8px; text-transform: uppercase; line-height: 1.4;
}
.card .bio .draft { display: table; margin: 8px 0 0; }

.footer { color: var(--cream); text-align: center; padding: 8px 16px 24px; }
.footer strong { color: #fff; }
.footer a { color: var(--cream); }
.footer .disclaimer, .footer .credits { font-size: 15px; line-height: 1.45; max-width: 640px; margin: 0 auto 10px; }

/* ---------- wider screens (tablets) ---------- */
@media (max-width: 639px) { :root { --edge: 18px; } }  /* phones: slimmer frame, wider text */
@media (min-width: 640px) {
  body { font-size: 20px; }
  .panel { padding: 18px 36px 30px; }
  .cards { max-width: 560px; margin: 0 auto; }
}

/* ---------- desktop ---------- */
@media (min-width: 1024px) {
  main { max-width: 1160px; }
  .topbar { padding: 8px 28px; }

  .hero { min-height: calc(100vh - 60px); display: flex; flex-direction: column; justify-content: center; padding: 40px 16px; }
  .hero-404 { min-height: 0; }
  .hero .script { font-size: 150px; }
  .hero h1 { font-size: 40px; }
  .jump-panel { max-width: 720px; }
  .jump-list { grid-template-columns: repeat(3, 1fr); }

  .paper { max-width: min(1080px, calc(100% - 2 * var(--edge))); margin-left: auto; margin-right: auto; } /* room for the wavy edges */
  .panel { padding: 36px 56px 40px; }
  .panel > p, .panel > .rats, .lg-intro, .frame { max-width: 68ch; margin-left: auto; margin-right: auto; }
  .lg-layout { display: grid; grid-template-columns: 1fr 420px; gap: 0 36px; align-items: start; }
  .steps { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
  .lg-side { position: sticky; top: 80px; }
  .cards { max-width: none; grid-template-columns: repeat(2, 1fr); gap: 24px; }
}
/* The section links in the top bar only fit on one line from about 1360px; narrower screens use the jump buttons. */
@media (min-width: 1360px) {
  .topnav { display: block; flex: 1; }
  .topnav ul { list-style: none; margin: 0; padding: 0; display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 16px; }
  .topnav a { color: var(--peach-text); text-decoration: none; font-size: 16px; font-weight: 700; padding: 6px 2px; border-bottom: 2px solid transparent; }
  .topnav a:hover { border-bottom-color: var(--peach-text); }
  .topbar .top-btn[href="#top"] { display: none; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

/* ---------- sounds: music button and tappable suspect pictures ---------- */
.topbar-btns { display: flex; gap: 8px; align-items: center; }
.js .music-btn.js-only { display: inline-flex; }
.music-btn { gap: 6px; }
.music-btn .ico { width: 18px; height: 18px; }
.music-btn[aria-pressed="true"] { background: var(--peach-text); color: var(--rust-dark); border-color: var(--peach-text); }
.music-btn[aria-pressed="true"] .ico { animation: bob 1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-3px) rotate(-8deg); } }

.sound-hint { display: none; text-align: center; font-weight: 700; }
.js .sound-hint.js-only { display: block; }
.sound-hint .ico { width: 24px; height: 24px; color: var(--rust); vertical-align: -5px; margin-right: 6px; }

.pic-btn {
  position: relative; display: block; width: 100%; height: 100%;
  padding: 0; border: 0; background: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.pic-btn .speaker {
  position: absolute; right: 4px; bottom: 4px; width: 30px; height: 30px; padding: 5px;
  background: var(--paper); color: var(--ink); border: 2px solid var(--ink); border-radius: 50%;
}
html:not(.js) .pic-btn .speaker { display: none; }
.pic-btn.wiggle img, .pic-btn.wiggle .placeholder { animation: wiggle .6s ease-in-out; }
@keyframes wiggle {
  20% { transform: rotate(-6deg) scale(1.05); } 40% { transform: rotate(5deg) scale(1.05); }
  60% { transform: rotate(-3deg); } 80% { transform: rotate(2deg); }
}
@media (prefers-reduced-motion: reduce) {
  .pic-btn.wiggle img, .music-btn .ico { animation: none !important; }
}
@media (max-width: 380px) {
  .topbar-title { font-size: 20px; }
  .topbar .top-btn { padding: 8px 10px; }
}
.topbar-title, .top-btn { white-space: nowrap; }

/* "Tap anywhere to start the music" prompt, shown only when the browser blocked autoplay. */
.tap-hint {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 20;
  width: fit-content; margin: 0 auto;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; min-height: 48px;
  background: var(--paper); color: var(--brown);
  border: 3px solid var(--ink); border-radius: 999px; box-shadow: 0 4px 14px rgba(0,0,0,.35);
  font-family: var(--serif); font-weight: 700; font-size: 17px; cursor: pointer;
  animation: hint-pulse 1.6s ease-in-out infinite;
}
.tap-hint .ico { width: 20px; height: 20px; flex: none; }
@keyframes hint-pulse { 50% { transform: scale(1.05); } }
@media (prefers-reduced-motion: reduce) { .tap-hint { animation: none; } }
