/* Learn to Type with Duffy
   Palette comes from the Blessed Sacrament crest (navy + gold) and Duffy herself.
   Layout is tuned for the Asus Chromebook Flip CM3 (1366 x 912 screen).
   Layout idea: a playroom tabletop fills the stage; Duffy's column sits beside it. */

@font-face { font-family: "Baloo 2"; font-weight: 700; font-style: normal; font-display: swap; src: url("../assets/fonts/baloo-2-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Baloo 2"; font-weight: 800; font-style: normal; font-display: swap; src: url("../assets/fonts/baloo-2-latin-800-normal.woff2") format("woff2"); }
@font-face { font-family: "Andika"; font-weight: 400; font-style: normal; font-display: swap; src: url("../assets/fonts/andika-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Andika"; font-weight: 700; font-style: normal; font-display: swap; src: url("../assets/fonts/andika-latin-700-normal.woff2") format("woff2"); }
/* The letters on the blocks use the same letter shapes as the Chromebook's keys */
@font-face { font-family: "Roboto"; font-weight: 500; font-style: normal; font-display: swap; src: url("../assets/fonts/roboto-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Roboto"; font-weight: 700; font-style: normal; font-display: swap; src: url("../assets/fonts/roboto-latin-700-normal.woff2") format("woff2"); }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
  --ink: #0B1E42;
  --navy: #14356B;
  --gold: #FFC629;
  --gold-deep: #E0A100;
  --go: #62D66F;
  --oops: #FF8A3D;
  --paper: #FFFDF6;

  --sky-top: #6CCBF6;
  --sky-bot: #DDF5FF;
  --hill-back: #7ED467;
  --hill-front: #4DB84A;
  --sun: #FFD84A;
  --cloud: #FFFFFF;
  --on-sky: #0B1E42;

  --font-display: "Baloo 2", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --font-read: "Andika", "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
  --font-keys: "Roboto", Arial, "Helvetica Neue", Helvetica, sans-serif;

  /* Shared layout measures */
  --pad: clamp(8px, 1vw, 16px);      /* page edge */
  --gap: clamp(8px, 1vw, 14px);      /* between the tabletop and Duffy's column */
  --corner-h: 46px;                  /* logo + sound buttons row */

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Night-time playground for dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sky-top: #0C1F47;
    --sky-bot: #2C4F92;
    --hill-back: #2E7A4C;
    --hill-front: #1E5C3A;
    --sun: #F3EFCB;
    --cloud: #5873AC;
    --on-sky: #FFFDF6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --sky-top: #0C1F47;
  --sky-bot: #2C4F92;
  --hill-back: #2E7A4C;
  --hill-front: #1E5C3A;
  --sun: #F3EFCB;
  --cloud: #5873AC;
  --on-sky: #FFFDF6;
}

html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--sky-bot);
  color: var(--ink);
  font-family: var(--font-read);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Playground backdrop ---------- */
.sky {
  position: fixed; inset: 0; z-index: 0; overflow: hidden;
  background: linear-gradient(var(--sky-top), var(--sky-bot) 72%);
}
.sun {
  position: absolute; top: 15%; right: 5%;
  width: clamp(56px, 8vw, 110px); aspect-ratio: 1; border-radius: 50%;
  background: var(--sun);
  box-shadow: 0 0 0 14px color-mix(in srgb, var(--sun) 32%, transparent),
              0 0 0 32px color-mix(in srgb, var(--sun) 15%, transparent);
}
.cloud {
  position: absolute; left: -22%;
  width: clamp(120px, 16vw, 220px); height: clamp(34px, 4.6vw, 62px);
  border-radius: 999px; background: var(--cloud); opacity: .92;
  animation: drift 110s linear infinite;
}
.cloud::before, .cloud::after {
  content: ""; position: absolute; bottom: 30%; border-radius: 50%; background: inherit;
}
.cloud::before { left: 16%; width: 38%; aspect-ratio: 1; }
.cloud::after { right: 14%; width: 48%; aspect-ratio: 1; }
.cloud-1 { top: 12%; animation-delay: -20s; }
.cloud-2 { top: 30%; scale: .7; animation-duration: 150s; animation-delay: -95s; }
.cloud-3 { top: 6%; scale: .55; animation-duration: 130s; animation-delay: -60s; }
@keyframes drift { to { transform: translateX(160vw); } }
.hills { position: absolute; left: 0; bottom: 0; width: 100%; height: 26vh; display: block; }
.hill-back { fill: var(--hill-back); }
.hill-front { fill: var(--hill-front); }

/* ---------- App frame ----------
   Duffy's column sits on one side (data-duffy). The logo and sound buttons ride at the top of it. */
.app {
  --col: clamp(250px, 21vw, 330px);
  position: relative; z-index: 1;
  height: 100%;
}
.app[data-mode="big"] { --col: clamp(270px, 34vw, 470px); }

.corner {
  position: absolute; z-index: 4;
  top: var(--pad); width: var(--col); height: var(--corner-h);
  display: flex; align-items: center; gap: 8px;
  transition: opacity .2s ease;
}
.app[data-duffy="left"] .corner { left: var(--pad); }
.app[data-duffy="right"] .corner { right: var(--pad); }
.brand-logo {
  height: 100%; width: auto; min-width: 0; display: block; margin-right: auto;
  background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 3px 9px;
}

.ctl {
  position: relative; flex: none;
  width: var(--corner-h); height: var(--corner-h); border-radius: 50%;
  display: grid; place-items: center; padding: 0;
  background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); cursor: pointer;
}
.ctl svg { width: 24px; height: 24px; fill: currentColor; }
.ctl[aria-pressed="false"] { background: #D5DBE7; color: #66718C; }
.ctl[aria-pressed="false"]::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 30px; height: 4px; border-radius: 2px; background: #C2452D;
  transform: translate(-50%, -50%) rotate(-45deg);
}

.play {
  position: relative;
  height: 100%;
  display: flex; align-items: stretch;
  gap: var(--gap);
  padding: var(--pad);
}

/* ---------- Stage + screens ---------- */
.stage {
  flex: 1 1 0; min-width: 0; min-height: 0;
  display: flex;
  transition: opacity .2s ease;
}
.app.is-swapping .stage, .app.is-swapping .corner { opacity: 0; }
.screen { display: none; flex: 1 1 0; min-width: 0; min-height: 0; }
.screen.is-active {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(10px, 1.6vh, 18px);
}

/* Title */
.screen-title.is-active { align-items: flex-start; padding-left: clamp(0px, 2vw, 30px); }
.hero-title {
  margin: 0;
  font: 800 clamp(44px, 7.4vw, 104px)/.92 var(--font-display);
  letter-spacing: -.01em;
  color: var(--on-sky);
}
.hero-bricks {
  --u: clamp(.62px, .085vw, 1.2px);
  position: relative; flex: none;
  width: calc(376 * var(--u)); height: calc(96 * var(--u));
}
.hero-sub {
  margin: 0; max-width: 26em;
  font-size: clamp(17px, 1.7vw, 23px); line-height: 1.4;
  color: var(--on-sky);
}
.hero-note { margin: 8px 0 0; font-size: clamp(14px, 1.2vw, 17px); color: var(--on-sky); opacity: .85; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  font: 800 clamp(20px, 2.1vw, 30px)/1 var(--font-display);
  color: var(--ink); background: var(--gold);
  border: 4px solid var(--ink); border-radius: 18px;
  padding: .5em 1.25em .42em;
  box-shadow: 0 6px 0 var(--ink);
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease, filter .12s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.btn svg { width: .8em; height: .8em; fill: currentColor; }
.btn-go { background: var(--go); }
.btn-quiet { background: var(--paper); font-size: clamp(16px, 1.5vw, 22px); }
.btn-play { font-size: clamp(26px, 3vw, 42px); margin-top: 6px; }
.btn.is-calling { animation: call 1.1s ease-in-out infinite; }
@keyframes call { 50% { transform: scale(1.07); } }

:is(.btn, .ctl, .grade, .name-input, .duffy, .refocus):focus-visible {
  outline: 4px solid #fff; outline-offset: 3px;
  box-shadow: 0 0 0 9px var(--ink);
}

/* Cards (name, how to play, the end) */
.card {
  width: min(100%, 560px);
  background: var(--paper);
  border: 4px solid var(--ink); border-radius: 30px;
  padding: clamp(18px, 2.6vw, 34px);
  display: flex; flex-direction: column; align-items: center; gap: clamp(12px, 1.8vh, 20px);
  text-align: center;
}
.card-q {
  margin: 0;
  font: 800 clamp(26px, 3.2vw, 44px)/1.05 var(--font-display);
  color: var(--navy);
  text-wrap: balance;
}
.card-p { margin: 0; font-size: clamp(17px, 1.6vw, 22px); line-height: 1.4; text-wrap: balance; }

.name-input {
  width: 100%;
  font: 700 clamp(24px, 2.8vw, 38px)/1.2 var(--font-read);
  text-align: center; color: var(--ink);
  background: #fff; border: 4px solid var(--ink); border-radius: 18px;
  padding: .35em .5em;
}
.name-input::placeholder { color: #9AA5BD; font-weight: 400; }
.is-shake { animation: shake .36s ease; }
@keyframes shake {
  20% { transform: translateX(-7px); } 40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); } 80% { transform: translateX(3px); }
}

/* Grade buttons, each its own color */
.grades { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: clamp(10px, 1.4vw, 16px); }
.grade {
  font: 800 clamp(28px, 3.4vw, 46px)/1 var(--font-display);
  color: var(--ink);
  border: 4px solid var(--ink); border-radius: 22px;
  padding: .55em .2em .45em;
  box-shadow: 0 6px 0 var(--ink);
  cursor: pointer; white-space: nowrap;
  transition: transform .08s ease, box-shadow .08s ease;
}
.grade:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.grade:nth-child(1) { background: #FFC629; }
.grade:nth-child(2) { background: #7DD3F7; }
.grade:nth-child(3) { background: #62D66F; }
.grade:nth-child(4) { background: #FF9E7A; }

/* How to play: a glowing block, an arrow, and the key to press */
.howto {
  --u: clamp(.8px, .09vw, 1.15px);
  display: flex; align-items: center; justify-content: center; gap: clamp(12px, 1.6vw, 22px);
  padding: calc(30 * var(--u)) calc(34 * var(--u)) calc(22 * var(--u));
  background: #B7DFF8; border: 3px solid var(--ink); border-radius: 20px;
}
.howto-arrow { flex: none; width: calc(62 * var(--u)); height: auto; }
.keycap {
  display: inline-grid; place-items: center;
  min-width: 1.55em; height: 1.55em; padding: 0 .3em;
  border-radius: .3em; background: #1D2027; color: #fff;
  font: 500 .95em/1 var(--font-keys);
  box-shadow: 0 .13em 0 #000;
  vertical-align: -.28em;
}
.keycap-big { flex: none; font-size: calc(46 * var(--u)); }

/* The end */
.medal {
  width: clamp(64px, 7.6vw, 100px); aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--gold); border: 5px solid var(--ink);
  box-shadow: 0 0 0 7px var(--paper), 0 0 0 11px var(--gold-deep);
  color: var(--navy);
  margin: 6px 0 4px;
}
.medal svg { width: 58%; height: 58%; fill: currentColor; }
#screen-finale.is-active { justify-content: safe center; overflow-y: auto; }
#screen-finale .card { width: min(100%, 640px); }
#screen-finale.is-active .medal { animation: medal-in .7s cubic-bezier(.3, 1.5, .6, 1) both; }
@keyframes medal-in { from { transform: scale(.2) rotate(-200deg); opacity: 0; } }
.built {
  list-style: none; margin: 0; padding: 0; width: 100%;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px;
}
.built li {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px;
  font: 700 clamp(14px, 1.3vw, 18px)/1.1 var(--font-read);
  background: #F2EEDD; border-radius: 14px; padding: 12px 6px 9px;
}
#screen-finale.is-active .built li { animation: built-in .4s cubic-bezier(.3, 1.5, .6, 1) both; animation-delay: calc(var(--i) * .3s + .5s); }
@keyframes built-in { from { transform: scale(.4); opacity: 0; } }
.mini { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.mini-row { display: flex; gap: 1px; }
.mini-row i { display: block; width: 11px; height: 8px; border-radius: 2px; background: var(--c); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2); }
.finale-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 14px 18px; }

/* ---------- The tabletop ----------
   The scene is always 1040 x 720 "units". game.js sets --u to the size of one unit in pixels,
   so everything on the table grows and shrinks together. */
.screen-scene.is-active { gap: 8px; }
.scene-wrap {
  flex: 1 1 0; min-height: 0; width: 100%;
  container-type: size;
  display: grid; place-items: center;
}
.scene {
  --u: 1px;
  position: relative; overflow: hidden;
  width: min(100cqw, calc(100cqh * 1040 / 720)); aspect-ratio: 1040 / 720;
  background: #FBE9C6;
  border: 4px solid var(--ink); border-radius: 22px;
  user-select: none; -webkit-user-select: none;
}
.bg-wall {
  position: absolute; left: 0; top: 0; width: 100%; height: calc(440 * var(--u)); display: block;
  filter: blur(calc(2.4 * var(--u))); transform: scale(1.03);
}
.bg-table { position: absolute; left: 0; top: calc(430 * var(--u)); width: 100%; height: calc(100% - 430 * var(--u)); display: block; }

.hud {
  position: absolute; top: calc(14 * var(--u)); z-index: 80;
  display: flex; align-items: center; gap: calc(9 * var(--u));
  font: 800 calc(23 * var(--u))/1 var(--font-display);
  color: var(--ink); background: var(--paper);
  border: calc(3 * var(--u)) solid var(--ink); border-radius: calc(17 * var(--u));
  padding: calc(10 * var(--u)) calc(15 * var(--u)) calc(7 * var(--u));
  font-variant-numeric: tabular-nums;
}
.hud-level { left: calc(14 * var(--u)); }
.hud-count { right: calc(14 * var(--u)); }
.hud-brick {
  position: relative; flex: none; margin-top: calc(-2 * var(--u));
  width: calc(26 * var(--u)); height: calc(17 * var(--u));
  background: #E8413C; border: calc(2.5 * var(--u)) solid var(--ink); border-radius: calc(3 * var(--u));
}
.hud-brick::before, .hud-brick::after {
  content: ""; position: absolute; bottom: 100%; width: 34%; height: calc(5 * var(--u));
  background: #E8413C; border: calc(2.5 * var(--u)) solid var(--ink); border-bottom: 0;
  border-radius: calc(2 * var(--u)) calc(2 * var(--u)) 0 0;
}
.hud-brick::before { left: 6%; }
.hud-brick::after { right: 6%; }

.ground-shadow, .stage-spot {
  position: absolute; z-index: 2; pointer-events: none;
  background: radial-gradient(closest-side, rgba(84, 52, 20, .34), rgba(84, 52, 20, 0));
  opacity: 0; transition: opacity .3s ease;
}
.ground-shadow {
  left: calc((520 - var(--sw, 300) / 2) * var(--u)); top: calc(544 * var(--u));
  width: calc(var(--sw, 300) * var(--u)); height: calc(34 * var(--u));
}
.scene.has-shadow .ground-shadow { opacity: 1; }
.stage-spot {
  left: calc(430 * var(--u)); top: calc(674 * var(--u));
  width: calc(180 * var(--u)); height: calc(34 * var(--u));
}
.scene[data-mode="build"] .stage-spot { opacity: 1; }

/* Dashed outlines show the shape that is being built */
.ghost {
  position: absolute; z-index: 3;
  left: calc(var(--x) * var(--u)); top: calc(var(--y) * var(--u));
  width: calc(86 * var(--u)); height: calc(62 * var(--u));
  border: calc(3 * var(--u)) dashed rgba(11, 30, 66, .24);
  border-radius: calc(8 * var(--u));
}
.ghost.is-next {
  border-color: rgba(11, 30, 66, .8); background: rgba(255, 255, 255, .6);
  animation: ghost-pulse 1.1s ease-in-out infinite;
}
@keyframes ghost-pulse { 50% { background: rgba(255, 255, 255, .15); } }

/* ---------- Blocks ---------- */
.brick {
  position: absolute; z-index: var(--z, 1);
  left: calc(var(--x, 0) * var(--u)); top: calc(var(--y, 0) * var(--u));
  width: calc(86 * var(--u)); height: calc(62 * var(--u));
  rotate: var(--tilt, 0deg);
  pointer-events: none;
}
.brick.is-demo { position: relative; left: auto; top: auto; flex: none; }
.brick-in { position: absolute; inset: 0; }
/* the two studs on top; the block's body covers their feet */
.brick-in::before, .brick-in::after {
  content: ""; position: absolute; top: calc(-9 * var(--u));
  width: calc(32 * var(--u)); height: calc(16 * var(--u));
  background: var(--face);
  border: calc(3 * var(--u)) solid var(--ink);
  border-radius: calc(5 * var(--u)) calc(5 * var(--u)) 0 0;
  box-shadow: inset 0 calc(3 * var(--u)) 0 var(--light);
}
.brick-in::before { left: calc(7 * var(--u)); }
.brick-in::after { right: calc(7 * var(--u)); }
.brick-body {
  position: absolute; inset: 0; z-index: 1;
  display: grid; place-items: center;
  background: var(--face);
  border: calc(3 * var(--u)) solid var(--ink);
  border-radius: calc(8 * var(--u));
  box-shadow: inset 0 calc(-7 * var(--u)) 0 var(--shade), inset 0 calc(4 * var(--u)) 0 var(--light);
}
.brick-letter {
  font: 700 calc(46 * var(--u))/1 var(--font-keys);
  color: var(--letter);
  translate: 0 -5%;
  text-shadow: 0 calc(2 * var(--u)) 0 rgba(11, 30, 66, .3);
}

/* The block to type: white letter, white glow, gentle pulse */
.brick.is-active { z-index: 40; }
.brick.is-active::before {
  content: ""; position: absolute; z-index: -1;
  inset: calc(-17 * var(--u)) calc(-10 * var(--u)) calc(-10 * var(--u));
  border-radius: calc(18 * var(--u));
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 0 calc(14 * var(--u)) calc(10 * var(--u)) rgba(255, 255, 255, .92);
  animation: glow 1.1s ease-in-out infinite;
}
@keyframes glow { 50% { opacity: .55; } }
.brick.is-active .brick-letter {
  --o: calc(2.6 * var(--u)); --d: calc(1.9 * var(--u));
  color: #fff;
  text-shadow: var(--o) 0 var(--ink), calc(-1 * var(--o)) 0 var(--ink), 0 var(--o) var(--ink), 0 calc(-1 * var(--o)) var(--ink),
    var(--d) var(--d) var(--ink), calc(-1 * var(--d)) var(--d) var(--ink), var(--d) calc(-1 * var(--d)) var(--ink), calc(-1 * var(--d)) calc(-1 * var(--d)) var(--ink),
    0 calc(5 * var(--u)) 0 rgba(11, 30, 66, .35);
}
.brick.is-active .brick-in { animation: brick-pulse 1.1s ease-in-out infinite; }
.brick.is-active.is-pop .brick-in { animation: brick-pop .24s cubic-bezier(.3, 1.5, .6, 1), brick-pulse 1.1s ease-in-out .24s infinite; }
@keyframes brick-pulse { 50% { transform: scale(1.07); } }
@keyframes brick-pop { from { transform: scale(.3); opacity: 0; } }

/* Waiting at the front of the table, bigger, until its letter is typed */
.brick.is-staged {
  z-index: 60;
  transform: translate(calc(var(--dx) * var(--u)), calc(var(--dy) * var(--u))) scale(1.45);
}
.brick.is-flying { z-index: 65; }
.brick.is-wobble .brick-in { animation: shake .36s ease; }
.brick.is-snap .brick-in { animation: brick-snap .2s ease-out; }
@keyframes brick-snap { 0% { transform: scale(1.1, .84); } 55% { transform: scale(.97, 1.05); } }
.scene.is-built .brick .brick-in { animation: brick-hop .5s ease-in-out var(--hop, 0s) 2; }
@keyframes brick-hop { 40% { transform: translateY(calc(-16 * var(--u))); } }

/* In K and 1st grade a block can also be clicked or tapped to put it away */
.scene.can-click .brick { pointer-events: auto; }
.scene.can-click .brick.is-active { cursor: pointer; }
.scene.can-click .brick.is-flying { pointer-events: none; }

/* The wrong letter they typed pops up in an orange ring */
.oops-chip {
  position: absolute; z-index: 86; pointer-events: none;
  left: calc(var(--x) * var(--u)); top: calc(var(--y) * var(--u));
  width: calc(52 * var(--u)); height: calc(52 * var(--u));
  display: grid; place-items: center; border-radius: 50%;
  background: var(--paper); border: calc(5 * var(--u)) solid var(--oops);
  font: 700 calc(28 * var(--u))/1 var(--font-keys); color: var(--ink);
  animation: chip .8s ease-out forwards;
}
.oops-chip::after {
  content: ""; position: absolute; left: 8%; right: 8%; top: 50%; height: calc(4 * var(--u)); margin-top: calc(-2 * var(--u));
  background: var(--oops); border-radius: 2px; rotate: -45deg;
}
@keyframes chip {
  0% { transform: scale(.4); opacity: 0; }
  16% { transform: scale(1.12); opacity: 1; }
  28%, 70% { transform: scale(1); opacity: 1; }
  100% { transform: translateY(calc(-30 * var(--u))); opacity: 0; }
}

/* ---------- The bin for cleaning up ---------- */
.bin {
  position: absolute; pointer-events: none;
  left: calc(846 * var(--u)); top: calc(500 * var(--u));
  width: calc(180 * var(--u)); height: calc(190 * var(--u));
  transform: translateX(calc(240 * var(--u)));
  transition: transform .5s cubic-bezier(.3, 1.25, .5, 1);
}
.bin svg { display: block; width: 100%; height: 100%; overflow: visible; }
.bin-back { z-index: 4; }
.bin-pile { z-index: 5; }
.bin-front { z-index: 70; }
.scene.has-bin .bin { transform: none; }
.scene.bin-hit .bin svg { animation: bin-hit .2s ease-out; }
@keyframes bin-hit { 35% { transform: translateY(calc(5 * var(--u))) scale(1.03, .97); } }
.pile-brick {
  position: absolute;
  left: calc(var(--px) * var(--u)); top: calc(var(--py) * var(--u));
  width: calc(48 * var(--u)); height: calc(34 * var(--u));
  rotate: var(--pr, 0deg);
  background: var(--face);
  border: calc(3 * var(--u)) solid var(--ink); border-radius: calc(5 * var(--u));
  box-shadow: inset 0 calc(-5 * var(--u)) 0 var(--shade), inset 0 calc(3 * var(--u)) 0 var(--light);
  animation: brick-pop .25s cubic-bezier(.3, 1.5, .6, 1);
}

/* ---------- Keyboard hint: where the letter lives on the Chromebook ---------- */
.kbd {
  --key: calc(34 * var(--u)); --kg: calc(4 * var(--u));
  position: absolute; z-index: 85; left: calc(14 * var(--u)); bottom: calc(12 * var(--u));
  display: grid; gap: var(--kg);
  padding: calc(var(--key) * .3);
  background: #3A3E49;
  border: max(2px, calc(var(--key) * .09)) solid var(--ink); border-radius: calc(var(--key) * .38);
  opacity: 0; transform: translateY(calc(var(--key) * .7));
  transition: opacity .2s ease, transform .25s cubic-bezier(.3, 1.3, .5, 1);
  pointer-events: none;
}
.kbd.is-on { opacity: 1; transform: none; }
.kbd-row { display: flex; gap: var(--kg); }
.kbd-row:nth-child(2) { margin-left: calc(var(--key) * .3); }
.kbd-row:nth-child(3) { margin-left: calc(var(--key) * .85); }
.key {
  position: relative; flex: none;
  width: var(--key); height: var(--key);
  display: grid; place-items: center;
  border-radius: calc(var(--key) * .18);
  background: #1D2027; color: #fff;
  font: 500 calc(var(--key) * .56)/1 var(--font-keys);
}
/* the little bumps on f and j */
.key.is-home::after {
  content: ""; position: absolute; left: 34%; right: 34%; bottom: 11%; height: max(1px, 5%);
  background: rgba(255, 255, 255, .65); border-radius: 1px;
}
.key.is-target {
  z-index: 2; background: var(--gold); color: var(--ink); font-weight: 700;
  box-shadow: 0 0 0 max(2px, calc(var(--key) * .09)) #fff, 0 0 0 max(4px, calc(var(--key) * .18)) var(--ink);
  animation: key-pulse .9s ease-in-out infinite;
}
@keyframes key-pulse { 0%, 100% { transform: scale(1.18); } 50% { transform: scale(1.45); } }
/* On phones and tablets the keyboard sits under the table and its keys can be tapped */
.kbd.is-touch {
  --key: min(8.3vw, 54px); --kg: min(1vw, 6px);
  position: static; flex: none; opacity: 1; transform: none; pointer-events: auto;
  touch-action: manipulation;
}
.kbd.is-touch .key { cursor: pointer; }

.refocus {
  position: absolute; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 0; border: 0;
  background: rgba(11, 30, 66, .5); cursor: pointer;
}
.refocus span {
  font: 800 calc(34 * var(--u))/1.1 var(--font-display); color: var(--ink);
  background: var(--gold); border: calc(4 * var(--u)) solid var(--ink); border-radius: calc(20 * var(--u));
  padding: calc(16 * var(--u)) calc(28 * var(--u)) calc(12 * var(--u));
  box-shadow: 0 calc(6 * var(--u)) 0 var(--ink);
}

.debug-panel {
  position: fixed; left: 8px; bottom: 8px; z-index: 20;
  display: flex; flex-wrap: wrap; gap: 4px; max-width: 60vw;
  background: rgba(0, 0, 0, .8); border-radius: 8px; padding: 6px;
}
.debug-panel button {
  font: 600 12px/1 ui-monospace, Menlo, monospace; color: #fff;
  background: #333; border: 1px solid #777; border-radius: 5px; padding: 5px 7px; cursor: pointer;
}
.debug-panel button[aria-pressed="true"] { background: #A0A; }

/* ---------- Duffy's column ---------- */
.duffy-zone {
  flex: 0 0 var(--col);
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding-top: calc(var(--corner-h) + 12px);
  --duffy-max-h: 40vh;
}
.app[data-mode="big"] .duffy-zone { --duffy-max-h: 46vh; }
.app[data-duffy="left"] .duffy-zone { order: -1; }

.prompt {
  display: none;
  margin: 0 0 auto; align-self: center; text-align: center;
  font: 800 clamp(17px, 1.55vw, 25px)/1.05 var(--font-display);
  color: var(--ink); background: var(--paper);
  border: 4px solid var(--ink); border-radius: 22px;
  padding: .45em .9em .35em;
  transition: opacity .2s ease;
}
.app[data-screen="scene"] .prompt { display: block; }
.app.is-swapping .prompt { opacity: 0; }
.prompt.is-solved { background: var(--gold); }

.bubble {
  position: relative;
  background: var(--paper);
  border: 4px solid var(--ink); border-radius: 26px;
  padding: 14px 18px 12px;
  margin: 12px 0 20px;
  transition: opacity .2s ease, transform .2s ease;
}
.bubble.is-hidden { opacity: 0; transform: translateY(10px) scale(.96); }
.bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -14px;
  width: 22px; height: 22px;
  background: var(--paper);
  border-right: 4px solid var(--ink); border-bottom: 4px solid var(--ink);
  border-bottom-right-radius: 5px;
  transform: translateX(-50%) rotate(45deg);
}
.bubble-text {
  margin: 0;
  font-size: clamp(17px, 1.6vw, 24px); line-height: 1.38;
}
.bubble-text .w { border-radius: 6px; padding: 0 2px; margin: 0 -2px; }
.bubble-text .w.is-now { background: var(--gold); }
.bubble-actions { display: flex; justify-content: center; }
.bubble-actions:not(:empty) { margin-top: 10px; padding-bottom: 6px; }

.duffy {
  display: block; width: 100%;
  padding: 0; border: 0; background: none; border-radius: 18px;
  cursor: pointer;
}
.duffy-peek { display: flex; justify-content: center; clip-path: inset(-60% -30% 0 -30%); }
.duffy-svg {
  display: block; width: 100%; max-width: 460px; max-height: var(--duffy-max-h);
  overflow: visible;
  transition: transform .3s cubic-bezier(.5, -.2, .5, 1.3);
}
.duffy.is-down .duffy-svg { transform: translateY(108%); }

/* The ledge Duffy peeks over doubles as the progress track: one paw per level */
.duffy-ledge {
  position: relative; z-index: 1;
  height: 38px; margin-top: -8px; padding-top: 6px;
  display: grid; place-items: center;
  background: var(--navy);
  border: 4px solid var(--ink); border-radius: 12px;
  box-shadow: inset 0 6px 0 var(--gold);
}
.progress {
  display: none; align-items: center; justify-content: center; gap: 12px;
  list-style: none; margin: 0; padding: 0 8px; max-width: 100%;
}
.app[data-screen="scene"] .progress, .app[data-screen="finale"] .progress { display: flex; }
.progress li { flex: 0 1 22px; min-width: 0; aspect-ratio: 1; color: #4A6499; }
.progress li svg { width: 100%; height: 100%; display: block; fill: currentColor; }
.progress li.is-current { color: #FFFFFF; animation: paw-pulse 1.2s ease-in-out infinite; }
.progress li.is-done { color: var(--gold); }
@keyframes paw-pulse { 50% { transform: scale(1.2); } }

/* Duffy's moving parts */
.duffy-svg * { transform-box: fill-box; }
.d-head { transform-origin: 50% 92%; animation: d-idle 5.5s ease-in-out infinite; }
@keyframes d-idle {
  0%, 100% { transform: rotate(0); }
  22% { transform: rotate(-3deg) translateY(-2px); }
  50% { transform: rotate(0); }
  72% { transform: rotate(3deg) translateY(-2px); }
}
.d-eye { transform-origin: 50% 60%; animation: d-blink 4.4s infinite; }
@keyframes d-blink { 0%, 91%, 97%, 100% { transform: scaleY(1); } 94% { transform: scaleY(.08); } }
.d-ear-l { transform-origin: 85% 70%; animation: d-ear 7s ease-in-out infinite; }
.d-ear-r { transform-origin: 15% 70%; animation: d-ear 7s ease-in-out -3.2s infinite reverse; }
@keyframes d-ear { 0%, 86%, 100% { transform: rotate(0); } 90% { transform: rotate(-9deg); } 95% { transform: rotate(4deg); } }
.d-tag { transform-origin: 50% 0; animation: d-tag 3s ease-in-out infinite; }
@keyframes d-tag { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
.d-mouth { transform-origin: 50% 0; transform: scaleY(.72); }
.duffy.is-talking .d-mouth { animation: d-talk .24s ease-in-out infinite alternate; }
@keyframes d-talk { from { transform: scaleY(.3); } to { transform: scaleY(1); } }
.d-bursts { opacity: 0; }
.duffy.is-cheer .d-bursts { animation: d-burst .32s ease-in-out 6 alternate; }
@keyframes d-burst { from { opacity: 0; } to { opacity: 1; } }
.duffy.is-cheer .duffy-svg { animation: d-jump .5s ease-in-out 3; }
@keyframes d-jump { 0%, 100% { transform: translateY(0); } 45% { transform: translateY(-8%); } }
.duffy.is-cheer .d-mouth { transform: scaleY(1); }
.duffy.is-oops .d-head { animation: d-oops .6s ease-in-out; }
@keyframes d-oops { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-10deg); } 65% { transform: rotate(7deg); } }
.duffy.is-oops .d-brow-l { transform: rotate(-14deg); }
.duffy.is-oops .d-brow-r { transform: rotate(14deg); }

/* ---------- Confetti ---------- */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 5; pointer-events: none; }

/* ---------- Short windows (a Chromebook with the tab strip and shelf showing) ---------- */
@media (max-height: 640px) {
  :root { --corner-h: 40px; }
  .duffy-zone { --duffy-max-h: 34vh; }
  .app[data-mode="big"] .duffy-zone { --duffy-max-h: 38vh; }
  .bubble { padding: 10px 14px 9px; margin-bottom: 16px; }
  .bubble-text { font-size: clamp(16px, 1.5vw, 21px); }
}

/* ---------- Phones and portrait screens: header on top, Duffy under the stage ---------- */
@media (max-width: 760px), (max-aspect-ratio: 1/1) {
  .corner { position: static; width: auto; margin: var(--pad) var(--pad) 0; }
  .app { display: flex; flex-direction: column; }
  .play { flex: 1 1 0; min-height: 0; height: auto; flex-direction: column; }
  .app .duffy-zone,
  .app[data-mode="big"] .duffy-zone {
    order: 2; flex: 0 0 auto; width: auto;
    padding-top: 0;
    display: grid; grid-template-columns: clamp(110px, 30vw, 200px) 1fr; align-items: end;
    column-gap: 14px;
    --duffy-max-h: 22vh;
  }
  .duffy-zone .prompt { grid-column: 1 / -1; margin: 0 0 10px; }
  .duffy-zone .bubble { grid-column: 2; grid-row: 2 / span 2; margin: 0 0 10px; }
  .duffy-zone .duffy { grid-column: 1; grid-row: 2; }
  .duffy-zone .duffy-ledge { grid-column: 1; grid-row: 3; }
  .bubble::after { display: none; }
  /* the table takes the full width; the keyboard sits right under it */
  .screen-scene.is-active { justify-content: flex-start; }
  .scene-wrap { flex: 0 0 auto; height: min(calc((100vw - 2 * var(--pad)) * 720 / 1040), 56vh); }
  .scene { border-width: 3px; border-radius: 14px; }
  .screen-title.is-active { align-items: center; text-align: center; padding-left: 0; }
  #screen-finale .medal { display: none; }
  #screen-finale .card { gap: 10px; padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .cloud, .d-head, .d-ear-l, .d-ear-r, .d-tag, .progress li.is-current, .btn.is-calling,
  .ghost.is-next, .brick.is-active::before, .brick.is-active .brick-in, .key.is-target,
  .scene.is-built .brick .brick-in, #screen-finale.is-active .medal, #screen-finale.is-active .built li { animation: none; }
  .key.is-target { transform: scale(1.3); }
  .duffy.is-cheer .duffy-svg { animation: none; }
  .duffy-svg, .stage, .bubble, .corner, .prompt, .bin, .kbd { transition: none; }
}
