/* The puzzle card. Class prefix pz-. Uses only variables from tokens.css. */

.pz-root, .pz-root * { box-sizing: border-box; }
.pz-root [hidden] { display: none !important; }

.pz-root {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: clamp(8px, 2vh, 26px) clamp(10px, 2.4vw, 36px);
  overflow: hidden;
  font-family: var(--font);
  font-size: var(--size-body);
  color: var(--ink);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.pz-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(42, 27, 94, 0.45);
  background: color-mix(in srgb, var(--night) 45%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: pz-fade 0.3s ease-out both;
}

.pz-card {
  position: relative;
  width: min(1180px, 100%);
  height: min(100%, 800px);
  display: flex;
  flex-direction: column;
  gap: clamp(6px, 1.2vh, 14px);
  padding: clamp(10px, 1.8vh, 22px) clamp(12px, 1.8vw, 26px);
  background: var(--cream);
  border: var(--outline);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-sticker), var(--shadow-soft);
  animation: pz-rise 0.5s var(--pop) both;
}

/* header */
.pz-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; }
.pz-badge {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 4px 18px 4px 10px;
  background: var(--lilac); border: 3px solid var(--ink); border-radius: 999px;
  font-weight: 800; font-size: var(--size-body); line-height: 1.2;
}
.pz-badge-icon { font-size: 28px; line-height: 1; }

/* layout */
.pz-main {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 58fr) minmax(0, 42fr);
  gap: clamp(10px, 1.8vw, 26px);
}
.pz-left {
  position: relative; min-height: 0; min-width: 0;
  display: flex; flex-direction: column; gap: clamp(6px, 1.1vh, 12px);
}
.pz-right {
  min-height: 0; min-width: 0;
  display: flex; flex-direction: column; justify-content: center; gap: clamp(8px, 1.4vh, 16px);
}

.pz-story {
  margin: 0; flex: 0 0 auto;
  padding: 8px 14px; background: var(--blush); border-radius: var(--radius-m);
  font-size: clamp(20px, 2.7vh, 26px); line-height: 1.3; font-weight: 700;
}
.pz-sum {
  flex: 0 0 auto; text-align: center; font-family: var(--font-num); font-weight: 900;
  font-size: clamp(64px, min(11vh, 7.2vw), 108px); line-height: 1.05;
  color: var(--ink); overflow-wrap: anywhere;
}
.pz-working {
  flex: 0 3 auto; min-height: 0; max-height: 28vh; overflow: auto;
  padding: 6px 10px; background: var(--paper); border: 3px solid var(--lilac); border-radius: var(--radius-m);
  font-size: clamp(20px, 3vh, 30px); text-align: center;
}

/* answer boxes */
.pz-answers {
  position: relative; z-index: 6; flex: 0 0 auto;
  display: flex; align-items: flex-end; justify-content: center; gap: clamp(8px, 1.4vw, 18px);
  pointer-events: none;
}
.pz-box-wrap { display: flex; flex-direction: column; align-items: flex-start; flex: 1 1 0; max-width: 380px; min-width: 0; pointer-events: auto; }
.pz-box-wrap-rem { flex: 0 1 190px; flex-direction: row; align-items: flex-end; gap: 8px; max-width: 200px; }
.pz-box-label { font-weight: 800; font-size: 18px; color: var(--ink-soft); padding-left: 10px; }
.pz-box-wrap-rem .pz-box-label {
  font-size: clamp(40px, 6vh, 56px); line-height: 1; padding: 0 0 8px; color: var(--ink);
  font-family: var(--font-num); font-weight: 900;
}
.pz-box {
  position: relative; width: 100%; min-height: clamp(68px, 10vh, 92px);
  display: flex; align-items: center; justify-content: center; gap: 2px;
  padding: 4px 14px; background: var(--paper); border: var(--outline); border-radius: var(--radius-m);
  box-shadow: 0 4px 0 var(--ink);
  font-family: var(--font-num); font-weight: 900; font-size: clamp(40px, 6.6vh, 58px); line-height: 1;
  cursor: pointer; outline: none; overflow: hidden;
  transition: background 0.2s, transform 0.2s var(--pop), border-color 0.2s;
}
.pz-box.pz-small { font-size: clamp(32px, 5vh, 44px); }
.pz-box.pz-xsmall { font-size: clamp(24px, 4vh, 34px); }
.pz-box.pz-active {
  border-color: var(--orchid-deep);
  box-shadow: 0 4px 0 var(--orchid-deep), 0 0 0 6px var(--gold);
  background: var(--paper);
  transform: translateY(-2px);
}
.pz-box:focus-visible { box-shadow: 0 4px 0 var(--ink), 0 0 0 6px var(--turquoise); }
.pz-caret { display: none; width: 4px; height: 1em; border-radius: 2px; background: var(--orchid); }
.pz-box.pz-active .pz-caret { display: inline-block; animation: pz-blink 1s steps(2, start) infinite; }
.pz-box.pz-oops { background: var(--butter); }
.pz-box.pz-good { background: var(--mint); }
.pz-box.pz-shake { animation: pz-shake 0.5s ease-in-out; }

/* feedback */
.pz-feedback {
  position: relative; z-index: 6; flex: 0 0 auto; pointer-events: none;
  min-height: 3.2em; display: flex; align-items: center;
  padding: 8px 14px; border-radius: var(--radius-m); border: 3px solid transparent;
  font-weight: 800; font-size: var(--size-body); line-height: 1.3;
}
.pz-feedback:empty { visibility: hidden; }
.pz-feedback[data-kind="try"], .pz-feedback[data-kind="gentle"] { background: var(--butter); border-color: var(--gold-deep); }
.pz-feedback[data-kind="right"] { background: var(--mint); border-color: var(--turquoise-deep); }
.pz-feedback.pz-pop { animation: pz-pop 0.45s var(--pop) both; }

/* hints */
.pz-hints {
  flex: 1 1 auto; min-height: 96px; display: flex; flex-direction: column; gap: 8px;
  padding: 8px; background: var(--lilac); border-radius: var(--radius-m);
}
.pz-hints-body { position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-right: 4px; outline: none; }
.pz-nudge { display: flex; gap: 10px; align-items: flex-start; font-weight: 700; line-height: 1.3; }
.pz-nudge p { margin: 0; }
.pz-nudge-icon { font-size: 28px; }
.pz-step { display: flex; gap: 10px; margin-top: 8px; padding: 8px 10px; background: var(--paper); border-radius: var(--radius-s); animation: pz-pop 0.45s var(--pop) both; }
.pz-step-num {
  flex: 0 0 auto; width: 34px; height: 34px; display: grid; place-items: center;
  background: var(--gold); border: 3px solid var(--ink); border-radius: 50%; font-weight: 900;
}
.pz-step-body { min-width: 0; flex: 1 1 auto; }
.pz-step-title { font-weight: 900; }
.pz-step-text { margin: 2px 0 0; line-height: 1.3; }
.pz-step-html { margin-top: 6px; overflow-x: auto; }
.pz-hint-done { margin: 10px 0 0; font-weight: 800; text-align: center; }
.pz-hint-actions { flex: 0 0 auto; display: flex; flex-wrap: wrap; gap: 8px; }

/* buttons */
.pz-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 8px 18px;
  background: var(--paper); color: var(--ink); border: var(--outline); border-radius: var(--radius-m);
  box-shadow: var(--shadow-sticker);
  font: inherit; font-weight: 900; font-size: var(--size-body); line-height: 1.1; cursor: pointer;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
  transition: transform 0.12s var(--pop), box-shadow 0.12s;
}
.pz-btn:active:not(:disabled), .pz-key:active:not(:disabled), .pz-tool:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.pz-btn:disabled, .pz-key:disabled { opacity: 0.55; cursor: default; }
.pz-btn:focus-visible, .pz-key:focus-visible, .pz-tool:focus-visible { outline: 4px solid var(--turquoise); outline-offset: 2px; }
.pz-btn-small { min-height: 48px; padding: 4px 16px; box-shadow: 0 4px 0 var(--ink); }
.pz-btn-hint, .pz-btn-hint-all { flex: 1 1 auto; min-height: 56px; background: var(--gold); }
.pz-btn-hint-all { background: var(--peach); }

.pz-actions { display: flex; flex-direction: column; gap: clamp(8px, 1.4vh, 14px); }
.pz-btn-check { min-height: clamp(64px, 10vh, 84px); background: var(--turquoise); font-size: clamp(26px, 4vh, 34px); }
.pz-action-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pz-btn-hintmain { min-height: clamp(64px, 8.5vh, 76px); background: var(--gold); padding: 6px 8px; }
.pz-btn-padtoggle { min-height: clamp(64px, 8.5vh, 76px); background: var(--lilac); padding: 6px 8px; }
.pz-btn-padtoggle.pz-on { background: var(--orchid); color: var(--paper); }
.pz-btn-skip { background: var(--blush); min-height: 56px; }
.pz-pulse { animation: pz-pulse 1.1s ease-in-out infinite; }

/* keypad */
.pz-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: clamp(8px, 1.3vh, 12px); }
.pz-key {
  min-height: clamp(64px, 9vh, 92px); padding: 0;
  background: var(--paper); color: var(--ink); border: var(--outline); border-radius: var(--radius-m);
  box-shadow: var(--shadow-sticker);
  font-family: var(--font-num); font-weight: 900; font-size: clamp(30px, 4.6vh, 42px); cursor: pointer;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
  transition: transform 0.12s var(--pop), box-shadow 0.12s;
}
.pz-key-back { background: var(--blush); }
.pz-key-clear { background: var(--peach); }

/* scratchpad */
.pz-pad { position: absolute; inset: 0; z-index: 4; border-radius: var(--radius-m); }
.pz-pad-canvas {
  display: block; width: 100%; height: 100%;
  background-color: rgba(255, 255, 255, 0.5);
  background-image: radial-gradient(circle, var(--lilac) 2px, transparent 2.5px);
  background-size: 28px 28px;
  border: 3px dashed var(--orchid); border-radius: var(--radius-m);
  touch-action: none; cursor: crosshair; animation: pz-fade 0.2s ease-out both;
}
.pz-pad-tools { position: absolute; top: 8px; right: 8px; z-index: 7; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pz-tool {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); min-width: var(--tap); padding: 4px 12px;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: var(--radius-m);
  box-shadow: 0 4px 0 var(--ink); font: inherit; font-weight: 900; font-size: 18px; cursor: pointer;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.pz-tool.pz-on { background: var(--gold); }
.pz-tool-done { background: var(--turquoise); }
.pz-tool-icon { font-size: 22px; }

/* celebration */
.pz-burst { position: absolute; left: 50%; top: 50%; width: 0; height: 0; z-index: 9; pointer-events: none; }
.pz-spark {
  position: absolute; left: 0; top: 0; width: var(--sz, 20px); height: var(--sz, 20px); background: var(--c, var(--gold));
  clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
  opacity: 0; animation: pz-fly 1.2s ease-out both;
}
.pz-praise {
  position: absolute; left: 50%; top: 34%; z-index: 8; pointer-events: none; white-space: nowrap;
  padding: 6px 30px; background: var(--gold); border: var(--outline); border-radius: 999px; box-shadow: var(--shadow-sticker);
  font-family: var(--font-num); font-weight: 900; font-size: clamp(40px, 7vh, 64px); line-height: 1.2;
  transform: translate(-50%, -50%) rotate(-3deg); animation: pz-praise 0.6s var(--pop) both;
}
.pz-won .pz-card { cursor: pointer; }

/* motion */
@keyframes pz-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pz-rise { from { opacity: 0; transform: translateY(26px) scale(0.93); } to { opacity: 1; transform: none; } }
@keyframes pz-pop { 0% { opacity: 0; transform: scale(0.85); } 100% { opacity: 1; transform: none; } }
@keyframes pz-praise {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-3deg) scale(0.3); }
  100% { opacity: 1; transform: translate(-50%, -50%) rotate(-3deg) scale(1); }
}
@keyframes pz-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}
@keyframes pz-blink { 0% { opacity: 1; } 50% { opacity: 0; } }
@keyframes pz-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); box-shadow: 0 6px 0 var(--ink), 0 0 0 7px var(--butter); } }
@keyframes pz-fly {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(0) rotate(0deg); }
  35% { opacity: 1; transform: translate(calc(-50% + var(--dx) * 0.7), calc(-50% + var(--dy) * 0.7)) scale(1.2) rotate(var(--rot)); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy) + 24px)) scale(0.6) rotate(var(--rot)); }
}

@media (prefers-reduced-motion: reduce) {
  .pz-root *, .pz-root *::before, .pz-root *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important;
  }
  .pz-box.pz-active .pz-caret { animation: none; }
  .pz-pulse { animation: none; outline: 4px solid var(--gold); }
}

/* short landscape screens */
@media (max-height: 640px) {
  .pz-badge { min-height: 38px; font-size: 18px; }
  .pz-working { max-height: 22vh; }
}

/* lead: fixes from the first browser run */
.pz-head { padding-left: 56px; }                 /* room for the shell's pause button */
.pz-box-label { line-height: 1.2; margin-bottom: 4px; }
.pz-praise { top: 13%; }                          /* keep the check sentence readable */
.pz-root, .pz-card { overflow: hidden; }
.pz-main { grid-template-rows: minmax(0, 1fr); }   /* the row must not grow with the hints */
.pz-left:has(.pz-step) .pz-working { display: none; }   /* the hint steps show the layout themselves */
.pz-step-html { overflow-x: auto; }
/* while the step-by-step hints are open, give them the room */
.pz-left:has(.pz-step) .pz-story { display: none; }
.pz-left:has(.pz-step) .pz-sum { font-size: clamp(40px, 6vh, 64px); }
.pz-left:has(.pz-step) .pz-feedback:empty { display: none; }
.pz-left:has(.pz-step) .pz-box { min-height: 0; height: clamp(52px, 8vh, 72px); }
.pz-left:has(.pz-step) .pz-box-wrap:not(.pz-box-wrap-rem) .pz-box-label { display: none; }

/* ---------- new answer kinds (decimal, fraction, mixed, choice), prompt and sumHtml ---------- */
.pz-story-long { font-size: clamp(20px, 2.4vh, 23px); line-height: 1.28; padding: 6px 12px; }

/* a question sentence replaces the big sum */
.pz-sum.pz-prompt {
  font-family: var(--font); font-weight: 800; line-height: 1.25;
  font-size: clamp(30px, min(5vh, 3.6vw), 46px);
  max-height: calc(1.25em * 3 + 4px); overflow: hidden; overflow-wrap: break-word;
}
/* the sum as HTML: stacked fractions scale with the sum's font size (working.css uses em) */
.pz-sum.pz-sum-html { line-height: 1.35; }
.pz-sum-html .wk-frac { margin: 0 0.18em; }
.pz-sum-html .wk-frac-n { border-bottom-width: 0.075em; }
.pz-left:has(.pz-step) .pz-sum.pz-prompt { font-size: 30px; }
.pz-left:has(.pz-step) .pz-sum.pz-sum-html { line-height: 1.3; }

/* unit after the answer */
.pz-unit {
  flex: 0 0 auto; align-self: flex-end; padding: 0 4px 16px;
  font-weight: 800; font-size: clamp(22px, 3.2vh, 30px); line-height: 1.1; color: var(--ink);
}
.pz-answers[data-kind="fraction"] .pz-unit, .pz-answers[data-kind="mixed"] .pz-unit { align-self: center; padding-bottom: 0; }
.pz-answers[data-kind="choice"] { min-height: 4px; }

/* stacked fraction: numerator, bar, denominator */
.pz-answers[data-kind="fraction"], .pz-answers[data-kind="mixed"] { align-items: center; }
.pz-fracrow { display: flex; align-items: center; justify-content: center; gap: clamp(10px, 1.6vw, 22px); pointer-events: auto; }
.pz-stack { display: flex; flex-direction: column; align-items: stretch; width: clamp(120px, 16vw, 180px); }
.pz-bar { height: 8px; margin: 8px 4px; border-radius: 4px; background: var(--ink); }
.pz-box-frac {
  min-height: clamp(56px, 8.4vh, 76px); font-size: clamp(34px, 5.4vh, 48px); padding: 2px 8px;
}
.pz-box-frac.pz-small { font-size: clamp(28px, 4.4vh, 38px); }
.pz-box-frac.pz-xsmall { font-size: clamp(22px, 3.4vh, 30px); }
.pz-box-whole { width: clamp(100px, 13vw, 150px); min-height: clamp(76px, 12vh, 112px); font-size: clamp(40px, 6.4vh, 56px); }
.pz-left:has(.pz-step) .pz-box-whole { height: clamp(64px, 9vh, 84px); }

/* keypad with a decimal point: bottom row of four */
.pz-keypad-point { grid-template-columns: repeat(12, 1fr); }
.pz-keypad-point .pz-key { grid-column: span 4; }
.pz-keypad-point .pz-key-q { grid-column: span 3; }
.pz-key-point { background: var(--butter); }

/* multiple choice: one big button each */
.pz-choices { display: flex; flex-direction: column; gap: clamp(8px, 1.4vh, 14px); }
.pz-choice {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: clamp(64px, 10.5vh, 96px); padding: 6px 18px;
  background: var(--paper); color: var(--ink); border: var(--outline); border-radius: var(--radius-m);
  box-shadow: var(--shadow-sticker);
  font-family: var(--font-num); font-weight: 900; font-size: clamp(26px, 4.2vh, 38px); line-height: 1.15; text-align: left;
  cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none;
  transition: transform 0.12s var(--pop), box-shadow 0.12s, background 0.2s;
}
.pz-choice-n {
  flex: 0 0 auto; width: 38px; height: 38px; display: grid; place-items: center;
  background: var(--lilac); border: 3px solid var(--ink); border-radius: 50%; font-size: 20px;
}
.pz-choice-text { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.pz-choice:active:not(:disabled) { transform: translateY(5px); box-shadow: 0 1px 0 var(--ink); }
.pz-choice:focus-visible { outline: 4px solid var(--turquoise); outline-offset: 2px; }
.pz-choice.pz-chosen { background: var(--gold); box-shadow: var(--shadow-sticker), 0 0 0 5px var(--gold-deep); }
.pz-choice.pz-chosen .pz-choice-n { background: var(--paper); }
.pz-choice.pz-oops { background: var(--butter); box-shadow: var(--shadow-sticker); }
.pz-choice.pz-good { background: var(--mint); box-shadow: var(--shadow-sticker); }
.pz-choice.pz-shake { animation: pz-shake 0.5s ease-in-out; }
.pz-choice:disabled { cursor: default; }
.pz-choice:disabled:not(.pz-good) { opacity: 0.55; }
