/* PCB PAL: flat bright kid aesthetic, touch-first, full screen like the other games. The WebGL canvas is transparent: the deep teal
   gradient behind the board is this CSS. */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: "Trebuchet MS", "Comic Sans MS", Verdana, sans-serif;
  background: linear-gradient(180deg, #0d2b2b 0%, #12423f 35%, #1a5c52 70%, #2a7a66 100%);
  touch-action: none; -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
#game3d { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#topbar { position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 14px; z-index: 8; display: flex; gap: 10px; }
#modebar { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 14px; z-index: 8; display: flex; gap: 10px; }
.pillBtn { width: 56px; height: 56px; border: 0; border-radius: 50%; background: rgba(255,255,255,.88); color: #0e5b4a; font-size: 26px; cursor: pointer; box-shadow: 0 4px 0 rgba(0,0,0,.2); }
.pillBtn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.2); }
.pillBtn.off { opacity: .45; }
.modeBtn.active { background: #ffe066; box-shadow: 0 4px 0 rgba(0,0,0,.25), 0 0 0 4px rgba(255,224,102,.45); }
.modeBtn.nudge { animation: modeNudge 1s ease-in-out infinite; }
@keyframes modeNudge { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); background: #fff3b0; } }

#wordLabel {
  position: fixed; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 7; pointer-events: none;
  width: max-content; max-width: 74vw; padding: 14px 34px; border-radius: 30px; background: #fff; color: #0e5b4a;
  font-size: clamp(26px, 5vmin, 52px); font-weight: 900; text-align: center; min-height: 1em;
  box-shadow: 0 5px 0 rgba(0,0,0,.25), 0 0 26px rgba(0,0,0,.35);
}
#wordLabel:empty { display: none; }
#wordLabel[data-link="power"] { background: #fff3bf; color: #8a5a00; }
#wordLabel[data-link="nudge"] { background: #e7f5ff; color: #1864ab; font-size: clamp(20px, 3.6vmin, 36px); }
#wordLabel.pop { animation: labelPop .5s ease-out; }
@keyframes labelPop { 0% { transform: translateX(-50%) scale(.5); opacity: 0; } 60% { transform: translateX(-50%) scale(1.12); opacity: 1; } 100% { transform: translateX(-50%) scale(1); } }


#handHint {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(118px + env(safe-area-inset-bottom)); z-index: 7; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px); text-align: center; padding: 10px 24px; border-radius: 26px;
  background: rgba(255,255,255,.9); color: #0e5b4a; font-size: clamp(17px, 3.2vmin, 28px); font-weight: 900; box-shadow: 0 4px 0 rgba(0,0,0,.18);
  transition: opacity .5s ease;
}
#handHint.gone { opacity: 0; }

/* the shelf: a scrolling row of parts */
#shelf {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; height: calc(106px + env(safe-area-inset-bottom)); padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; touch-action: pan-x; -webkit-overflow-scrolling: touch;
  background: rgba(8, 30, 28, .72); border-top: 3px solid rgba(255,255,255,.25); scrollbar-width: none;
  transition: bottom .25s ease;
}
#shelf::-webkit-scrollbar { display: none; }
.part {
  flex: 0 0 auto; width: 86px; height: 88px; border: 0; border-radius: 18px; background: rgba(255,255,255,.92); color: #0e5b4a; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; box-shadow: 0 4px 0 rgba(0,0,0,.22); font-family: inherit;
}
.part img { width: 58px; height: 58px; pointer-events: none; }
.part span { font-size: 12px; font-weight: 900; line-height: 1.05; text-align: center; max-width: 80px; }
.part:active { transform: translateY(3px); }
.part.sel { background: #ffe066; box-shadow: 0 4px 0 rgba(0,0,0,.25), 0 0 0 4px rgba(255,224,102,.55); }
.part.need { background: #d3f9d8; animation: need 1s ease-in-out infinite; }
@keyframes need { 0%,100% { transform: translateY(0); box-shadow: 0 4px 0 rgba(0,0,0,.22), 0 0 0 3px rgba(105,219,124,.6); } 50% { transform: translateY(-6px); box-shadow: 0 10px 0 rgba(0,0,0,.14), 0 0 0 6px rgba(105,219,124,.9); } }
@media (min-width: 900px) { .part { width: 104px; height: 96px; } .part img { width: 66px; height: 66px; } }
/* centre the row when it fits, but never clip the first item when it scrolls (justify-content:center would) */
.part:first-child { margin-left: auto; } .part:last-child { margin-right: auto; }

/* phones: the mode buttons (left) and read/bulb/lessons/mute (right) share one row — shrink them so they never collide */
@media (max-width: 420px) {
  #topbar { right: 10px; gap: 4px; } #modebar { left: 10px; gap: 4px; }
  .pillBtn { width: 44px; height: 44px; font-size: 21px; }
}

@media (min-width: 561px) and (max-width: 900px) { #wordLabel { top: calc(78px + env(safe-area-inset-top)); } }  /* tablet portrait: one shared row, label below the six top buttons */

/* phones: six build pills no longer share row 1 with the tool buttons — topbar stacks to a second row on the right (never shrink the 44px touch targets) */
@media (max-width: 560px) {
  #topbar { top: calc(62px + env(safe-area-inset-top)); }
  #wordLabel { top: calc(118px + env(safe-area-inset-top)); }
  /* lesson book open: the lesson bar (max ~240px tall incl. recap) covers the shelf on phones — lift the shelf clear above it */
  body:has(#lessonBar.show) #shelf { bottom: calc(250px + env(safe-area-inset-bottom)); }
}

/* part helper card: first-time safety card, top-center under the word label; non-modal (pointer-events only on the card itself) */
#partCard {
  position: fixed; left: 50%; top: calc(96px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 9;
  display: none; align-items: center; gap: 12px; width: max-content; max-width: 260px; padding: 12px 16px; border-radius: 20px;
  background: rgba(8, 30, 28, .92); color: #eafff5; border: 2px solid rgba(255,255,255,.22); box-shadow: 0 5px 0 rgba(0,0,0,.3), 0 0 24px rgba(0,0,0,.35);
  text-align: left;
}
#partCard.in { display: flex; cursor: pointer; animation: cardIn .35s ease-out; }
#partCard.fade { animation: cardOut .4s ease-in forwards; }
@keyframes cardIn { 0% { opacity: 0; transform: translate(-50%, -14px); } 100% { opacity: 1; transform: translate(-50%, 0); } }
@keyframes cardOut { 0% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -14px); } }
#partCard img { width: 64px; height: 64px; flex: 0 0 auto; pointer-events: none; }
#partCard div { display: flex; flex-direction: column; gap: 3px; }
#partCard b { font-size: 17px; color: #ffe066; }
#partCard span { font-size: 14px; line-height: 1.25; font-weight: 700; }
@media (max-width: 520px) { #partCard { top: calc(190px + env(safe-area-inset-top)); max-width: 240px; } }  /* phones: below both stacked button rows and the word label, clear of the board centre */
