/* ============================================================
   Simon's Hangman — the sketchbook
   One warm paper page. Every mark is graphite; red pencil only
   for wrong guesses, focus, and the final stamp.
   ============================================================ */

@font-face {
  font-family: "Caveat";
  src: url("assets/fonts/caveat-400.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "Architects Daughter";
  src: url("assets/fonts/architectsdaughter-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --paper: #f4e9d9;
  --graphite-6b: #3b3833;
  --graphite-4b: #55514b;
  --graphite-hb: #8a857b;
  --graphite-faint: #c9c3b6;
  --red-pencil: #b23a2e;
  --red-deep: #9c3226;
  --hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  --print: "Architects Daughter", "Segoe Print", "Comic Sans MS", cursive;
}

* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; }

body {
  background: var(--paper) url("assets/plates/paper.png");
  background-size: 620px auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-family: var(--print);
  color: var(--graphite-4b);
  container-type: size;
}

/* The open sketchbook: one sheet with a two-page spread.
   All regions are placed as % of this frame, so the whole
   spread scales like one drawing. */
.book {
  position: relative;
  width: min(100cqw, 150cqh);
  aspect-ratio: 1536 / 1024;
  container-type: size;
}

/* --- The gutter: spiral binding between the pages --- */
.spine {
  position: absolute;
  left: 40%; top: 0; width: 20%; height: 100%;
  background: url("assets/plates/spine.png") center / cover no-repeat;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16%, #000 84%, transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 16%, #000 84%, transparent 100%);
  pointer-events: none;
}

/* --- Region boxes: measured from the approved comp --- */
.r-title   { position: absolute; left: 6%;  top: 2%;  width: 30%; height: 9%; }
.r-drawing { position: absolute; left: 4.56%; top: 11.23%; width: 32.94%; height: 78.71%; }
.r-tally   { position: absolute; left: 6.25%; top: 81%; width: 13.74%; height: 5.86%; }
.r-word    { position: absolute; left: 55%; top: 19%; width: 44%; height: 11%; }
.r-status  { position: absolute; left: 60%; top: 31%; width: 26%; height: 7%; }
.r-rail    { position: absolute; left: 53%; top: 40%; width: 46%; height: 36%; }
.r-newword { position: absolute; left: 80%; top: 82%; width: 17%; height: 14%; }

/* --- Title --- */
.r-title h1 {
  font-family: var(--hand);
  font-weight: 700;
  font-size: 3.6cqw;
  color: var(--graphite-6b);
  transform: rotate(-1.2deg);
  letter-spacing: 0.01em;
}

/* --- The drawing --- */
#drawing { width: 100%; height: 100%; display: block; }

/* --- The word row --- */
.r-word {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0.4em;
  font-family: var(--hand);
  font-weight: 700;
  font-size: 4.2cqw;
  line-height: 1;
  color: var(--graphite-6b);
  transform: rotate(-0.4deg);
}
.r-word .slot {
  position: relative;
  width: 0.68em;
  height: 1.25em;
}
.r-word .slot::after {
  content: "";
  position: absolute;
  left: -4%; right: -4%; bottom: 0.08em;
  height: 0.09em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='6'%3E%3Cpath d='M2 4 Q 16 2 30 4 T 58 3' fill='none' stroke='%233b3833' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}
.r-word .slot .letter { position: absolute; inset: 0; text-align: center; }
.r-word .slot .letter.missed { color: var(--red-deep); }

/* --- Status line --- */
.r-status {
  text-align: center;
  font-size: 1.9cqw;
  color: var(--graphite-4b);
  transform: rotate(-0.4deg);
}
.r-status.bad { color: var(--red-deep); }

/* --- The letter rail --- */
.r-rail {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.6cqh 0.4cqw;
  align-content: center;
}
.r-rail button {
  position: relative;
  border: 0;
  background: none;
  padding: 0.35cqh 0 0.75cqh;
  font-family: var(--print);
  font-size: 2.05cqw;
  line-height: 1;
  color: var(--graphite-4b);
  cursor: pointer;
  transition: transform 0.15s ease-out, color 0.15s ease-out;
}
.r-rail button::after {
  content: "";
  position: absolute;
  left: 12%; right: 12%; bottom: 0;
  height: 0.28cqh;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='6'%3E%3Cpath d='M2 4 Q 16 2 30 4 T 58 3' fill='none' stroke='%238a857b' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}
.r-rail button:hover { transform: translateY(-0.3cqh); }
.r-rail button:focus-visible {
  outline: none;
  border-radius: 50%;
  box-shadow: 0 0 0 0.22cqw var(--red-pencil);
  color: var(--graphite-6b);
}
/* Guessed right: pressed in darker */
.r-rail button.hit {
  color: var(--graphite-6b);
  font-weight: 700;
}
.r-rail button.hit::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='6'%3E%3Cpath d='M2 4 Q 16 2 30 4 T 58 3' fill='none' stroke='%233b3833' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
}
/* Guessed wrong: crossed out with the red pencil */
.r-rail button.miss {
  color: var(--graphite-hb);
  opacity: 0.55;
}
.r-rail button.miss::before {
  content: "";
  position: absolute;
  left: 4%; right: 4%; top: 42%;
  height: 0.3cqh;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='6'%3E%3Cpath d='M2 5 Q 20 2 58 2' fill='none' stroke='%23b23a2e' stroke-width='2.6' stroke-linecap='round'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
  transform: rotate(-8deg);
}
/* Round over: the whole rail rests */
.r-rail.done button { cursor: default; }
.r-rail.done button:hover { transform: none; }

/* --- New word button: a drawn rounded box --- */
.r-newword {
  border: 0.2cqw solid var(--graphite-4b);
  background: none;
  border-radius: 0.9cqw 1.4cqw 1cqw 1.5cqw / 1.4cqw 0.9cqw 1.5cqw 1cqw;
  padding: 0.9cqh 1cqw;
  font-family: var(--print);
  font-size: 1.85cqw;
  color: var(--graphite-4b);
  transform: rotate(-1deg);
  cursor: pointer;
  transition: transform 0.15s ease-out, color 0.15s ease-out, border-color 0.15s ease-out;
}
.r-newword:hover {
  transform: rotate(-1deg) translateY(-0.25cqh);
  color: var(--graphite-6b);
  border-color: var(--graphite-6b);
}
.r-newword:focus-visible {
  outline: none;
  border-color: var(--red-pencil);
  box-shadow: 0 0 0 0.2cqw var(--red-pencil);
}

/* --- The stamps --- */
.stamp {
  position: absolute;
  font-family: var(--hand);
  font-weight: 700;
  color: var(--red-deep);
  border: 0.22cqw solid var(--red-deep);
  padding: 0.2cqh 0.7cqw;
  border-radius: 1cqw 1.6cqw 1.1cqw 1.7cqw / 1.6cqw 1.1cqw 1.7cqw 1.1cqw;
  transform: rotate(-7deg);
  opacity: 0.9;
}
.stamp-lose {
  left: 12%; top: 14%;
  font-size: 3.6cqw;
  background: color-mix(in srgb, var(--paper) 72%, transparent);
}
.stamp-win {
  left: 62%; top: 6%;
  font-size: 2.6cqw;
}

/* --- Tally strokes --- */
#tally { width: 100%; height: 100%; }
#tally path {
  fill: none;
  stroke: var(--red-pencil);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 1 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 0.5s ease-out;
}
#tally path.drawn { stroke-dashoffset: 0; }

/* --- Reduced motion: every stroke is simply there --- */
@media (prefers-reduced-motion: reduce) {
  #tally path { transition: none; stroke-dashoffset: 0; }
  .r-rail button, .r-newword { transition: none; }
}
/* The hangman is intentionally SVG: each visible group is a game-state stroke. */
.r-drawing svg { width: 100%; height: 100%; display: block; overflow: visible; }
.stroke {
  fill: none;
  stroke: var(--graphite-4b);
  stroke-dasharray: 1000;
  stroke-dashoffset: 1000;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: stroke-dashoffset 0.9s cubic-bezier(0.22, 0.9, 0.3, 1);
}
.stroke.heavy { stroke: var(--graphite-6b); stroke-width: 5.5; }
.drawn .stroke { stroke-dashoffset: 0; }
.guides circle, .guides line { fill: none; stroke: var(--graphite-faint); stroke-width: 1.6; stroke-dasharray: 2 7; opacity: .55; }
.smudges ellipse { fill: var(--graphite-hb); opacity: .1; }
@media (prefers-reduced-motion: reduce) { .stroke, #tally path { transition: none; stroke-dashoffset: 0; } }
@media (max-width: 720px) {
  body { overflow: auto; display: block; }
  .book {
    width: 100%;
    min-height: 100vh;
    aspect-ratio: auto;
    padding: 8vw 7vw 12vw;
    display: grid;
    grid-template-columns: 1fr;
    gap: 5vw;
    align-content: start;
  }
  .spine { display: none; }
  .r-title, .r-drawing, .r-tally, .r-word, .r-status, .r-rail, .r-newword {
    position: static;
    width: auto;
    height: auto;
  }
  .r-title { order: 1; }
  .r-title h1 { font-size: 11cqw; }
  .r-drawing { order: 2; height: 72vw; min-height: 260px; }
  .r-tally { order: 3; height: 9vw; width: 34vw; justify-self: end; margin-top: -4vw; }
  .r-word { order: 4; min-height: 16vw; font-size: 10cqw; }
  .r-status { order: 5; font-size: 5cqw; min-height: 7vw; }
  .r-rail { order: 6; min-height: 48vw; gap: 2vw 1vw; }
  .r-rail button { font-size: 6cqw; padding: 1vw 0 2vw; }
  .r-newword { order: 7; justify-self: end; font-size: 5cqw; padding: 2vw 4vw; }
  .stamp-lose { left: 12vw; top: 56vw; font-size: 9cqw; }
  .stamp-win { left: 46vw; top: 44vw; font-size: 6cqw; }
}
