/* ---------- sketch minigame ---------- */
.card.mg-sketch {
  width: min(960px, 100%);
  padding: 12px;
  background: #e9d8c2;
  overflow: hidden;
}
.mg-sketch .sk-book {
  /* The photo is zoomed to 115% so the book fills the card; these are the clear
     (doodle-free) page areas as fractions of the visible box. */
  --l-x: 17.5%; --l-y: 10%; --l-w: 30%; --l-h: 78%;
  --r-x: 51.8%; --r-y: 8%; --r-w: 32%; --r-h: 83%;
  position: relative;
  aspect-ratio: 3 / 2;
  max-height: calc(100vh - 60px);
  margin: 0 auto;
  border-radius: 16px;
  overflow: hidden;
  background:
    url(img/sketchbook.webp) center / 115% 115% no-repeat,
    /* Fallback until the photo exists: two cream pages and a ribbon on a wooden desk. */
    linear-gradient(90deg, transparent 49.2%, #d77f8f 49.2% 50.8%, transparent 50.8%) 0 0 / 100% 100% no-repeat,
    radial-gradient(ellipse at 50% 50%, rgba(94, 70, 63, 0.18), transparent 3%) 0 0 / 100% 100% no-repeat,
    linear-gradient(90deg, transparent 5%, #fdf8ee 5% 49%, #f3ead9 49.6% 50.4%, #fdf8ee 51% 95%, transparent 95%) 0 4% / 100% 92% no-repeat,
    repeating-linear-gradient(90deg, #b88b62 0 42px, #b08257 42px 44px, #bd9068 44px 90px);
  user-select: none;
  -webkit-user-select: none;
}
.mg-sketch .sk-page { position: absolute; }
.mg-sketch .sk-left {
  left: var(--l-x); top: var(--l-y); width: var(--l-w); height: var(--l-h);
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  padding: 0 4% 0 6%; text-align: left;
}
.mg-sketch .sk-right {
  left: var(--r-x); top: var(--r-y); width: var(--r-w); height: var(--r-h);
  display: grid; place-items: center;
}
.mg-sketch h2 {
  font-size: clamp(22px, 3.1vw, 32px); margin: 10px 0 8px; line-height: 1.05;
  color: #5e463f; transform: rotate(-1.5deg);
}
.mg-sketch .sk-line { margin: 0 0 18px; font-size: 15.5px; line-height: 1.45; color: #7d655c; max-width: 26ch; }

/* pencil doodles on the brief page */
.mg-sketch .sk-doodles { position: relative; width: 100%; height: 70px; }
.mg-sketch .sk-doodles i { position: absolute; display: block; }
.mg-sketch .d-flower {
  left: 4px; top: 8px; width: 40px; height: 40px; border-radius: 50%;
  background:
    radial-gradient(circle, #f5d98a 0 5px, transparent 5.5px),
    radial-gradient(circle at 50% 18%, transparent 6px, rgba(94, 70, 63, .55) 6.5px 7.5px, transparent 8px),
    radial-gradient(circle at 50% 82%, transparent 6px, rgba(94, 70, 63, .55) 6.5px 7.5px, transparent 8px),
    radial-gradient(circle at 18% 50%, transparent 6px, rgba(94, 70, 63, .55) 6.5px 7.5px, transparent 8px),
    radial-gradient(circle at 82% 50%, transparent 6px, rgba(94, 70, 63, .55) 6.5px 7.5px, transparent 8px);
  transform: rotate(14deg); opacity: .8;
}
.mg-sketch .d-swatch {
  left: 70px; top: 14px; width: 30px; height: 30px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f9d2d9, #e7a0ab);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .5), 0 1px 0 rgba(94, 70, 63, .15);
}
.mg-sketch .d-swatch.b { left: 92px; top: 30px; width: 24px; height: 24px; background: radial-gradient(circle at 35% 30%, #d7e6cf, #9fb79a); }
.mg-sketch .sk-progress { display: flex; flex-direction: column; gap: 6px; width: min(230px, 100%); margin-bottom: 14px; }
.mg-sketch .sk-pct { font-weight: 800; font-size: 14px; color: #6b5850; }
.mg-sketch .sk-bar {
  display: block; height: 8px; border-radius: 99px; overflow: hidden;
  background: rgba(94, 70, 63, .1); box-shadow: inset 0 1px 1px rgba(94, 70, 63, .12);
}
.mg-sketch .sk-bar i {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: repeating-linear-gradient(115deg, #6d6670 0 3px, #57515a 3px 6px);
  transition: width .25s ease;
}
.mg-sketch.sk-done .sk-bar i { background: linear-gradient(90deg, var(--sage), var(--sage-deep)); }
.mg-sketch .sk-buttons { display: flex; gap: 10px; }
.mg-sketch .sk-go { animation: pop .35s cubic-bezier(.2, 1.4, .4, 1); }

/* drawing area */
/* The drawing fills the page box; the SVGs letterbox the dress inside it. */
.mg-sketch .sk-canvas { position: absolute; inset: 0; }
.mg-sketch .sk-canvas > svg, .mg-sketch .sk-final, .mg-sketch .sk-final svg {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
}
.mg-sketch .sk-draw { touch-action: none; cursor: crosshair; overflow: visible; }
@media (pointer: fine) { .mg-sketch .sk-draw { cursor: none; } }
.mg-sketch .sk-dot { fill: #8e7f79; opacity: .5; }
.mg-sketch .sk-dot.on {
  fill: #4d4852; opacity: .95;
  transform-box: fill-box; transform-origin: center;
  animation: sk-pop .32s cubic-bezier(.2, 1.6, .4, 1);
}
.mg-sketch .sk-ring {
  fill: none; stroke: #6d6670; stroke-width: .5;
  transform-box: fill-box; transform-origin: center;
  animation: sk-ring .45s ease-out forwards;
}
.mg-sketch .sk-stroke {
  fill: none; stroke: #4f4a55; stroke-width: 1.15; stroke-linecap: round; stroke-linejoin: round; opacity: .85;
}
.mg-sketch .sk-guide, .mg-sketch .sk-strokes { transition: opacity .7s ease; }
.mg-sketch.sk-done .sk-guide { opacity: 0; transition-delay: .4s; }
.mg-sketch.sk-done .sk-strokes { opacity: .3; }

/* the finished sketch: pencil lines melting into the paper */
.mg-sketch .sk-final { opacity: 0; mix-blend-mode: multiply; filter: saturate(.55); transition: opacity .3s; pointer-events: none; }
.mg-sketch .sk-final.in { opacity: 1; }
.mg-sketch .sk-final .sk-outline { fill: #fffcf6; stroke: #6f5d57; }
.mg-sketch .sk-final path[fill="none"][stroke^="rgba"] { stroke: rgba(90, 75, 70, .4); stroke-width: .7; }
.mg-sketch .sk-final .sk-form { fill: none; stroke: #a59690; stroke-width: .7; stroke-dasharray: 2.5 2; }
.mg-sketch .sk-final .sk-form[opacity], .mg-sketch .sk-final rect.sk-form, .mg-sketch .sk-final ellipse.sk-form { display: none; }

.mg-sketch .sk-pencil {
  position: absolute; left: 0; top: 0; width: 46px; height: 46px; margin: -44px 0 0 -2px;
  pointer-events: none; opacity: 0; transition: opacity .15s;
  filter: drop-shadow(3px 5px 3px rgba(60, 40, 30, .25));
}
.mg-sketch .sk-pencil svg { width: 100%; height: 100%; display: block; transform-origin: 4% 96%; transition: transform .12s; }
.mg-sketch .sk-pencil.show { opacity: 1; }
.mg-sketch .sk-pencil.down svg { transform: rotate(4deg) scale(.96); }

.mg-sketch .sk-note {
  position: absolute; right: 6%; bottom: 3%;
  padding: 8px 14px 6px; border-radius: 4px;
  background: #fff7c9; box-shadow: 0 6px 14px rgba(94, 70, 63, .18);
  font-family: "Fraunces", Georgia, serif; font-style: italic; font-weight: 700; font-size: 19px; color: #5e463f;
  transform: rotate(-4deg);
  animation: sk-note .5s cubic-bezier(.2, 1.4, .4, 1);
}
.mg-sketch .sk-note::before {
  content: ""; position: absolute; left: 50%; top: -8px; width: 38px; height: 14px; margin-left: -19px;
  background: rgba(231, 160, 171, .55); transform: rotate(3deg);
}
.mg-sketch .sk-note svg { display: block; width: 100%; height: 12px; margin-top: 1px; }
.mg-sketch .sk-note path {
  fill: none; stroke: #c96f80; stroke-width: 2.2; stroke-linecap: round;
  stroke-dasharray: 130; stroke-dashoffset: 130; animation: sk-swash .6s .25s ease-out forwards;
}

@keyframes sk-pop { 0% { transform: scale(.3); } 60% { transform: scale(1.9); } 100% { transform: scale(1); } }
@keyframes sk-ring { from { transform: scale(.5); opacity: .8; } to { transform: scale(2.4); opacity: 0; } }
@keyframes sk-note { from { transform: rotate(-12deg) scale(.6); opacity: 0; } }
@keyframes sk-swash { to { stroke-dashoffset: 0; } }
.reduce-motion .mg-sketch .sk-note path { stroke-dashoffset: 0; }

/* phones: the brief becomes a header and the drawing page fills the card */
@media (max-width: 760px) {
  .card.mg-sketch { padding: 8px; }
  .mg-sketch .sk-book {
    aspect-ratio: auto; max-height: none;
    display: flex; flex-direction: column;
    background: #f3e7d6;
  }
  .mg-sketch .sk-page { position: relative; left: auto; top: auto; width: auto; height: auto; }
  .mg-sketch .sk-left {
    display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px;
    padding: 12px 14px 8px 20px;
  }
  .mg-sketch .sk-doodles { display: none; }
  .mg-sketch h2 { grid-column: 1 / -1; font-size: 23px; margin: 0; }
  .mg-sketch .sk-line { grid-column: 1 / -1; font-size: 14px; margin: 2px 0 6px; max-width: none; }
  .mg-sketch .sk-progress { margin: 0; width: auto; grid-column: 1; grid-row: 3; }
  .mg-sketch .sk-buttons { grid-column: 2; grid-row: 3; }
  .mg-sketch .sk-right {
    /* Crop the photo to the clear part of the right-hand page. */
    width: min(100% - 12px, 62vh * 455 / 700); aspect-ratio: 455 / 700; margin: 0 auto 8px;
    background: url(img/sketchbook.webp) 72.6% 38.6% / 337.6% auto no-repeat, #fdf8ee;
    border-radius: 6px; box-shadow: 0 2px 8px rgba(94, 70, 63, .15);
  }
  .mg-sketch .sk-canvas { inset: 3%; }
  .mg-sketch .sk-note { position: relative; right: auto; bottom: auto; grid-column: 1; grid-row: 3; justify-self: start; margin: 10px 0 4px; font-size: 17px; }
  .mg-sketch.sk-done .sk-line, .mg-sketch.sk-done .sk-progress { display: none; }
}

/* short landscape phones: the open book fits under the step bar, with a smaller brief */
@media (max-height: 500px) and (min-width: 761px) {
  .card.mg-sketch { padding: 8px; }
  .mg-sketch .sk-book { max-height: calc(100dvh - 84px - 16px - env(safe-area-inset-top)); }
  .mg-sketch .sk-doodles { display: none; }
  .mg-sketch h2 { font-size: 19px; margin: 0 0 4px; }
  .mg-sketch .sk-line { font-size: 12.5px; line-height: 1.35; margin-bottom: 8px; }
  .mg-sketch .sk-pct { font-size: 12px; }
  .mg-sketch .sk-progress { margin-bottom: 8px; gap: 4px; }
  .mg-sketch .sk-note { font-size: 15px; padding: 6px 10px 4px; }
}

/* The "Lovely lines!" note never blocks the Continue button underneath it. */
.mg-sketch .sk-note { pointer-events: none; }
/* Narrow two-page books (portrait tablets): pin the note at the top of the brief page,
   clear of the buttons. */
@media (min-width: 761px) and (max-width: 1100px) and (min-height: 501px) {
  .mg-sketch .sk-note { top: 4%; bottom: auto; right: 5%; font-size: 17px; }
}
