/* ============================================================
   MILLER THE FARMER — chores3d.css
   Fullscreen overlay for Chore Day, the free-roam 3D farm game
   (js/chores3d.js). DOM is built entirely by the script.
   Book look: wooden header sign, the book's cream narration boxes
   in hand-lettered capitals, speech bubbles with the animals' own
   lines from the book, chunky outlined buttons, and an ending card
   where Miller comes home. Colors/type from css/tokens.css (every var
   carries the book value as a fallback).
   z-index 58: above nav (40) and storybook chrome, BELOW the
   #confetti layer (60) so celebrations still rain on top.
   ============================================================ */
@font-face { font-family: "Patrick Hand"; src: url("../assets/fonts/patrickhand.woff") format("woff"); font-weight: 400; font-style: normal; font-display: swap; }

.ch3d-overlay {
  --c-ink: var(--outline, #2b1a10);
  --c-cream: var(--cream, #f8f2d6);
  --c-cream-edge: var(--cream-edge, #e9dfb4);
  --c-red: var(--barn-red, #d9332b);
  --c-green: var(--tractor-green, #2f9e3f);
  --c-yellow: var(--tractor-yellow, #f5c400);
  --c-orange: var(--wheel-orange, #f6a21a);
  --c-wood: var(--wood, #b5814f);
  --c-book: var(--font-book, "Patrick Hand", "Comic Sans MS", cursive);
  --c-display: var(--font-display, "Fredoka", system-ui, sans-serif);
  --c-body: var(--font-body, "Nunito", system-ui, sans-serif);
  --c-spring: var(--ease-spring, cubic-bezier(.34, 1.56, .64, 1));
  position: fixed; inset: 0; z-index: 58;
  display: flex; flex-direction: column;
  font-family: var(--c-body); color: var(--c-ink);
  background: linear-gradient(180deg, var(--sky-top, #8ee7ee) 0%, var(--sky-low, #dffafa) 100%);
}

body.ch3d-lock { overflow: hidden !important; }

/* ---------- head bar: a wooden sign ---------- */
.ch3d-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; position: relative; z-index: 7;
  background: linear-gradient(180deg, #c98a4f, var(--c-wood));
  border-bottom: 4px solid var(--c-ink);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .12), 0 4px 0 rgba(43, 26, 16, .18);
}
.ch3d-title {
  font-family: var(--c-display); font-size: 26px; font-weight: 700; margin-right: auto; color: #fff; letter-spacing: .4px;
  text-shadow: 0 3px 0 var(--c-ink), 2px 0 0 var(--c-ink), -2px 0 0 var(--c-ink), 0 -2px 0 var(--c-ink), 2px 2px 0 var(--c-ink), -2px 2px 0 var(--c-ink), 2px -2px 0 var(--c-ink), -2px -2px 0 var(--c-ink);
}

.ch3d-chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.ch3d-chip, .ch3d-back, .ch3d-chores-chip, .ch3d-btn {
  border: 3px solid var(--c-ink); box-shadow: 0 4px 0 var(--c-ink);
  transition: transform var(--t-fast, .14s) ease, box-shadow var(--t-fast, .14s) ease;
  touch-action: manipulation;
}
.ch3d-chip {
  min-height: 52px; background: #fff; color: var(--c-ink);
  font-family: var(--c-display); font-weight: 600; font-size: 14px;
  padding: 4px 13px; border-radius: 999px; cursor: pointer;
}
.ch3d-chip small { display: block; font-size: 11px; font-weight: 600; opacity: .82; line-height: 1.15; }
.ch3d-chip.active { background: var(--c-red); color: #fff; }
.ch3d-chip:active, .ch3d-back:active, .ch3d-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--c-ink); }
.ch3d-chip:focus-visible, .ch3d-back:focus-visible, .ch3d-btn:focus-visible { outline: 4px solid var(--focus, #1f6fa8); outline-offset: 3px; }

.ch3d-chores-chip {
  display: inline-flex; align-items: center; min-height: 48px;
  font-family: var(--c-display); font-weight: 700; font-size: 15px;
  background: var(--c-yellow); color: var(--c-ink);
  padding: 6px 16px; border-radius: 999px;
}

.ch3d-back {
  min-height: 52px; cursor: pointer; background: var(--c-cream); color: var(--c-ink);
  font-family: var(--c-display); font-weight: 700; font-size: 16px;
  padding: 8px 20px; border-radius: 999px;
}

/* ---------- stage ---------- */
.ch3d-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.ch3d-stage canvas.ch3d-canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.ch3d-loading {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-family: var(--c-book); text-transform: uppercase; font-size: 24px; color: var(--c-ink);
  background: var(--c-cream); padding: 12px 26px; border-radius: 22px;
  box-shadow: 0 10px 24px rgba(43, 26, 16, .18); z-index: 6;
}

/* HUD floats over the canvas and never steals taps */
.ch3d-hud { position: absolute; inset: 0; pointer-events: none; z-index: 4; }

/* narration: the book's cream box, hand-lettered capitals */
.ch3d-fb {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  max-width: min(86%, 660px); width: max-content; text-align: center;
  font-family: var(--c-book); text-transform: uppercase; letter-spacing: .03em; line-height: 1.22;
  font-weight: 400; font-size: 21px; color: var(--c-ink);
  background: var(--c-cream); border-radius: 22px;
  padding: 8px 20px; min-height: 40px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 0 var(--c-cream-edge), 0 10px 24px rgba(43, 26, 16, .18);
}

.ch3d-timerchip {
  position: absolute; top: 12px; right: 14px;
  font-family: var(--c-display); font-weight: 700; font-size: 16px; color: #fff;
  text-shadow: 0 2px 0 rgba(43, 26, 16, .55);
  background: var(--c-wood); border: 3px solid var(--c-ink); padding: 6px 14px; border-radius: 14px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .15), 0 4px 0 rgba(43, 26, 16, .3);
}
.ch3d-timerchip.low { background: var(--c-orange); animation: ch3dPulse 1s ease infinite; }
@keyframes ch3dPulse { 50% { transform: scale(1.06); } }

/* action prompt (bottom center): a chunky yellow button-look pill */
.ch3d-prompt {
  position: absolute; bottom: calc(18px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%);
  font-family: var(--c-display); font-weight: 700; font-size: 20px; color: var(--c-ink);
  background: var(--c-yellow); border: 3px solid var(--c-ink); border-radius: 999px;
  padding: 10px 26px; box-shadow: 0 5px 0 var(--c-ink);
  max-width: min(88vw, 560px); text-align: center; z-index: 5;
  pointer-events: none;
}

/* ---------- speech bubbles: the animals' lines from the book ---------- */
.ch3d-bubbles { position: absolute; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.ch3d-bubble {
  position: absolute; transform: translate(-50%, -100%);
  background: #fff; color: var(--c-ink);
  border: 3px solid var(--c-ink); border-radius: 18px;
  font-family: var(--c-book); text-transform: uppercase; letter-spacing: .02em;
  font-weight: 400; font-size: 16px; line-height: 1.15;
  padding: 6px 12px; max-width: 220px; text-align: center;
  box-shadow: 0 4px 0 rgba(43, 26, 16, .25);
}
.ch3d-bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -9px;
  width: 13px; height: 13px; transform: translateX(-50%) rotate(45deg);
  background: #fff;
  border-right: 3px solid var(--c-ink); border-bottom: 3px solid var(--c-ink);
}
.ch3d-bubble b { color: var(--c-red); font-family: var(--c-display); }
.ch3d-bubble.next { background: var(--c-cream); animation: ch3dBounce 1.2s ease infinite; }
.ch3d-bubble.next::after { background: var(--c-cream); }
@keyframes ch3dBounce { 0%, 100% { transform: translate(-50%, -100%); } 50% { transform: translate(-50%, calc(-100% - 6px)); } }
.ch3d-bubble .ch3d-check { color: var(--c-green); font-family: var(--c-display); font-weight: 800; font-size: 20px; }
.ch3d-bubble-meter {
  display: block; height: 11px; margin-top: 5px;
  background: rgba(43, 26, 16, .12); border: 2px solid var(--c-ink); border-radius: 999px; overflow: hidden;
}
.ch3d-bubble-meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--c-green), var(--c-yellow)); }

/* bigger, bolder clues for the smallest farmers */
.ch3d-band-1 .ch3d-bubble { font-size: 18px; max-width: 250px; }
.ch3d-band-1 .ch3d-fb { font-size: 23px; }
.ch3d-band-1 .ch3d-prompt { font-size: 23px; }

/* ---------- the ending: Miller comes home ---------- */
.ch3d-done {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(43, 26, 16, .3);
  display: grid; place-items: center; padding: 18px;
}
.ch3d-done-card {
  position: relative; background: var(--c-cream);
  border: 4px solid var(--c-ink); border-radius: 30px;
  box-shadow: 0 8px 0 rgba(43, 26, 16, .3), 0 24px 56px rgba(43, 26, 16, .3);
  padding: 56px 26px 22px 26px; width: min(92vw, 560px); max-height: 92%; overflow: auto; text-align: center;
  animation: ch3dCard .55s var(--c-spring);
}
@keyframes ch3dCard { from { transform: scale(.86) translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.ch3d-done-card::before {   /* bunting from the party page */
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 44px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 216 44'%3E%3Cpath d='M0 4Q108 18 216 4' stroke='%232b1a10' stroke-width='2' fill='none'/%3E%3Cpath d='M4 5h28L18 36z' fill='%23f5c400' stroke='%232b1a10' stroke-width='2'/%3E%3Cpath d='M40 8h28L54 39z' fill='%23d9332b' stroke='%232b1a10' stroke-width='2'/%3E%3Cpath d='M76 10h28L90 41z' fill='%23ff7aa8' stroke='%232b1a10' stroke-width='2'/%3E%3Cpath d='M112 10h28l-14 31z' fill='%233db8f5' stroke='%232b1a10' stroke-width='2'/%3E%3Cpath d='M148 8h28l-14 31z' fill='%23b9e441' stroke='%232b1a10' stroke-width='2'/%3E%3Cpath d='M184 5h28l-14 31z' fill='%23ffa53a' stroke='%232b1a10' stroke-width='2'/%3E%3C/svg%3E") 0 0 / 216px 44px repeat-x;
}
.ch3d-done-miller { float: right; height: 150px; width: auto; margin: -6px -6px 0 8px; filter: drop-shadow(0 4px 0 rgba(43, 26, 16, .2)); }
.ch3d-done-title {
  font-family: var(--c-display); font-size: 36px; font-weight: 700; line-height: 1.05; margin: 0 0 8px;
  color: var(--logo-yellow, #fff200); -webkit-text-stroke: 6px var(--c-ink); paint-order: stroke fill; text-shadow: 0 4px 0 var(--c-ink);
}
.ch3d-done-msg { font-family: var(--c-book); text-transform: uppercase; letter-spacing: .03em; font-size: 20px; line-height: 1.25; color: var(--c-ink); margin: 0 0 12px; }
.ch3d-done-list {
  clear: both; list-style: none; margin: 0 0 12px; padding: 10px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left;
  background: #33405a; border: 3px solid var(--c-ink); border-radius: 18px;   /* the camera monitors (page 33) */
}
.ch3d-done-list li {
  display: flex; align-items: center; gap: 8px; background: linear-gradient(180deg, #c7ec52, #9ed426);
  border: 2px solid #1d2638; border-radius: 10px; padding: 4px 8px 4px 4px; min-height: 52px;
  font-family: var(--c-body); font-size: 14px; line-height: 1.2; color: var(--c-ink);
}
.ch3d-done-list li img { width: 44px; height: 44px; object-fit: contain; flex: none; }
.ch3d-done-list li b { font-family: var(--c-display); }
.ch3d-done-check { margin-left: auto; color: var(--c-green); font-weight: 900; font-size: 18px; text-shadow: 0 1px 0 #fff; }
.ch3d-stars { font-size: 50px; letter-spacing: 6px; color: var(--c-yellow); -webkit-text-stroke: 3px var(--c-ink); paint-order: stroke fill; margin: 2px 0 14px; }
.ch3d-stars span { display: inline-block; animation: ch3dStar .7s var(--c-spring) both; }
.ch3d-stars span:nth-child(2) { animation-delay: .22s; }
.ch3d-stars span:nth-child(3) { animation-delay: .44s; }
.ch3d-stars .off { opacity: .35; color: #fff; }
@keyframes ch3dStar { from { transform: scale(0) rotate(-90deg); } to { transform: none; } }

.ch3d-done-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.ch3d-btn {
  min-height: 54px; cursor: pointer;
  background: var(--c-green); color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, .2);
  font-family: var(--c-display); font-weight: 600; font-size: 18px;
  padding: 10px 24px; border-radius: 999px; box-shadow: 0 6px 0 var(--c-ink);
}
.ch3d-btn.ghost { background: #fff; color: var(--c-ink); text-shadow: none; }
.ch3d-btn.hay { background: var(--c-yellow); color: var(--c-ink); text-shadow: none; }

/* load-error card + logbook card */
.ch3d-card {
  background: var(--c-cream); border: 4px solid var(--c-ink); border-radius: 26px;
  box-shadow: 0 8px 0 rgba(43, 26, 16, .3), 0 24px 56px rgba(43, 26, 16, .25); padding: 22px 26px; text-align: center;
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  max-width: min(90vw, 420px); z-index: 6;
}
.ch3d-card h4 { font-family: var(--c-display); font-weight: 700; margin: 0 0 8px; font-size: 23px; color: var(--c-ink); }

/* ---------- Stewards (ages 11–14): science notes + ranch logbook ---------- */
.ch3d-band-4 .ch3d-fb { font-size: 18px; line-height: 1.25; max-width: min(92%, 700px); }
.ch3d-logbook { width: min(92vw, 540px); max-height: 88%; overflow: auto; z-index: 9; }
.ch3d-logbook p { font-weight: 700; font-size: 17px; line-height: 1.35; margin: 0 0 10px; }
.ch3d-log-opts { display: grid; gap: 10px; margin: 6px 0 8px; }
.ch3d-log-btn { width: 100%; min-height: 52px; background: #fff; color: var(--c-ink); text-shadow: none; border-radius: 18px; text-align: left; font-size: 16px; line-height: 1.25; }
.ch3d-log-btn.right { background: var(--c-green); color: #fff; }
.ch3d-log-btn.wrong, .ch3d-log-btn:disabled { background: #fff0d4; border-color: var(--c-orange); box-shadow: 0 4px 0 var(--c-orange); color: #8a3a06; opacity: .8; cursor: default; }
.ch3d-log-note { font-family: var(--c-book); text-transform: uppercase; letter-spacing: .03em; font-size: 18px; min-height: 1.3em; }

/* ---------- small screens (375px and friends) ---------- */
@media (max-width: 640px) {
  .ch3d-title { font-size: 21px; }
  .ch3d-head { padding: 8px 10px; gap: 6px; }
  .ch3d-chip-row { order: 3; width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .ch3d-chip { min-height: 48px; font-size: 12.5px; padding: 3px 2px; }
  .ch3d-chip small { font-size: 9.5px; }
  .ch3d-back { min-height: 48px; font-size: 15px; padding: 6px 14px; }
  .ch3d-chores-chip { font-size: 13px; padding: 4px 10px; min-height: 44px; }
  .ch3d-fb { font-size: 16px; padding: 6px 12px; top: 8px; max-width: 94%; }
  .ch3d-timerchip { font-size: 14px; padding: 4px 10px; top: auto; bottom: 74px; right: 10px; }
  .ch3d-prompt { font-size: 17px; padding: 8px 18px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .ch3d-band-1 .ch3d-fb { font-size: 18px; }
  .ch3d-band-1 .ch3d-prompt { font-size: 18px; }
  .ch3d-bubble { font-size: 13.5px; max-width: 150px; padding: 4px 8px; }
  .ch3d-band-1 .ch3d-bubble { font-size: 15px; max-width: 170px; }
  .ch3d-band-4 .ch3d-fb { font-size: 14.5px; }
  .ch3d-done-list { grid-template-columns: minmax(0, 1fr); }
  .ch3d-done-card { padding: 50px 16px 18px; }
  .ch3d-done-miller { height: 110px; }
  .ch3d-done-title { font-size: 28px; }
  .ch3d-done-msg { font-size: 17px; }
  .ch3d-stars { font-size: 40px; }
  .ch3d-logbook { padding: 16px; }
  .ch3d-logbook p { font-size: 15.5px; }
}
@media (prefers-reduced-motion: reduce) {
  .ch3d-bubble.next, .ch3d-timerchip.low, .ch3d-done-card, .ch3d-stars span { animation: none; }
}
