/* ============ Brick Studio — kid-friendly theme ============ */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Comic Sans MS", system-ui, sans-serif;
  /* modern soft-white with aurora color blobs in the brand colors */
  background:
    radial-gradient(50rem 34rem at 88% -12%, rgba(42, 168, 224, 0.16), transparent 62%),
    radial-gradient(44rem 30rem at -12% 22%, rgba(255, 90, 95, 0.12), transparent 60%),
    radial-gradient(46rem 32rem at 52% 115%, rgba(88, 193, 92, 0.14), transparent 60%),
    radial-gradient(34rem 24rem at 68% 45%, rgba(255, 210, 62, 0.09), transparent 60%),
    #f7f8fc;
  background-attachment: fixed;
  min-height: 100vh;
  color: #2b3445;
}

.app-header {
  text-align: center;
  padding: 18px 10px 6px;
  position: relative;
}
.header-actions {
  position: absolute;
  top: 12px; right: 14px;
  display: flex; align-items: center; gap: 4px;
}
.save-indicator {
  font-weight: 800;
  font-size: .85rem;
  color: #2e7d32;
  opacity: 0;
  transition: opacity .35s;
  margin-right: 6px;
}
.save-indicator.show { opacity: 1; }
.save-indicator.warn { color: #c62828; }
/* below ~1080px the absolutely-positioned actions would overlap the centered title */
@media (max-width: 1080px) {
  .header-actions { position: static; justify-content: center; margin-top: 8px; flex-wrap: wrap; }
}
.app-header h1 {
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.logo-mark { filter: drop-shadow(0 3px 4px rgba(43, 52, 69, 0.18)); flex: 0 0 auto; }
.logo-mark .spark {
  animation: sparkle 2.6s ease-in-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}
.logo-mark .spark2 { animation-delay: 1.3s; }
@keyframes sparkle {
  0%, 100% { opacity: 0.35; transform: scale(0.7) rotate(0deg); }
  50%      { opacity: 1;    transform: scale(1.15) rotate(20deg); }
}
.logo-text { font-weight: 900; color: #2b3445; }
.logo-accent {
  background: linear-gradient(100deg, #ff5a5f 0%, #2aa8e0 55%, #58c15c 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { margin: 6px 0 0; font-weight: 800; font-size: 1.02rem; letter-spacing: 0.2px; }
.tagline .t-draw  { color: #ff5a5f; }
.tagline .t-build { color: #2aa8e0; }
.tagline .t-life  { color: #58c15c; }

/* ---- Tabs ---- */
.tabs {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 14px 10px;
  flex-wrap: wrap;
}
.tab {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 10px 22px;
  border-radius: 999px;
  border: 3px solid #2b3445;
  background: #ffffff;
  cursor: pointer;
  box-shadow: 0 4px 0 #2b3445;
  transition: transform .08s;
}
.tab:hover { transform: translateY(-2px); }
.tab.active {
  background: #ffd23e;
  transform: translateY(2px);
  box-shadow: 0 2px 0 #2b3445;
}

.tab-panel { display: none; padding: 0 16px 40px; max-width: 1200px; margin: 0 auto; }
.tab-panel.active { display: block; animation: panelIn 0.22s ease; }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.panel-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  align-items: start;
}
#tab-animate .panel-grid { grid-template-columns: 1fr 1fr; }
#tab-build .panel-grid, #tab-three .panel-grid { grid-template-columns: 1fr 340px; }
@media (max-width: 860px) {
  .panel-grid, #tab-animate .panel-grid, #tab-build .panel-grid, #tab-three .panel-grid { grid-template-columns: 1fr; }
}
.mode-tabs { flex-wrap: wrap; margin-bottom: 0; }
.mode-tabs .sub-tab { flex: 0 1 auto; padding: 8px 14px; }
#threeCanvas { cursor: grab; touch-action: none; background: #eaf3fb; border: 2px solid #c6cdd8; }
#threeCanvas:active { cursor: grabbing; }

/* ---- Cards ---- */
.card {
  background: #ffffff;
  border: 3px solid #2b3445;
  border-radius: 18px;
  padding: 14px;
  box-shadow: 0 6px 0 rgba(43,52,69,0.25);
  margin-bottom: 16px;
}
.card h3 { margin: 10px 0 6px; font-size: 1rem; }
.card h3:first-child { margin-top: 0; }

.canvas-card { text-align: center; }
canvas { max-width: 100%; height: auto; border-radius: 8px; }
#drawCanvas, #mosaicCanvas {
  border: 2px solid #c6cdd8;
  touch-action: none;
  cursor: crosshair;
  background: #fff;
}
#playCanvas { border: 2px solid #c6cdd8; background: #fff; width: 100%; }

/* ---- Buttons ---- */
.big-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  font-family: inherit;
  font-size: 1.3rem;
  font-weight: 800;
  padding: 12px;
  border-radius: 14px;
  border: 3px solid #2b3445;
  background: #ff6b6b;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 #2b3445;
  transition: transform .08s;
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #2b3445; }
.big-btn:disabled { opacity: .45; cursor: not-allowed; }
.big-btn.play { background: #2aa8e0; margin-top: 8px; font-size: 1.15rem; }   /* the movie's hero action */

.mini-btn {
  font-family: inherit;
  font-size: .92rem;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 10px;
  border: 2px solid #2b3445;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(43,52,69,.35);
  margin: 3px 2px;
}
.mini-btn:hover { background: #fff3c4; }
.mini-btn:active { transform: translateY(2px); box-shadow: none; }
.mini-btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: 0 3px 0 rgba(43,52,69,.2); }
.mini-btn:disabled:hover { background: #fff; transform: none; }
/* one recommended next step per dense toolbar stands out */
.mini-btn.primary { background: #ffd23e; }
.mini-btn.primary:hover { background: #ffdb5a; }
/* destructive actions read as dangerous and never blend into Save/Export */
.mini-btn.danger { background: #fff1f0; border-color: #c1291f; color: #c1291f; }
.mini-btn.danger:hover { background: #ffe3e0; }

/* progressive disclosure: tuck rarely-used controls behind a friendly toggle */
.more-group { border: 2px dashed #c6cdd8; border-radius: 12px; padding: 4px 10px; margin: 8px 0; }
/* author rule needed: our .tool-row { display:flex } would otherwise override
   the UA's collapse and leave a closed group's content on screen */
.more-group:not([open]) > :not(summary) { display: none !important; }
.more-group > summary {
  cursor: pointer; font-weight: 700; font-size: .95rem; color: #5b6577;
  list-style: none; padding: 6px 2px; user-select: none;
}
.more-group > summary::-webkit-details-marker { display: none; }
.more-group > summary::before { content: '▸ '; }
.more-group[open] > summary::before { content: '▾ '; }
.more-group[open] > summary { color: #2b3445; }

/* ---- magic scissors: tap-to-cutout stage ---- */
.cutout-stage { text-align: center; }
#cutoutCanvas {
  max-width: 100%; max-height: 46vh; border-radius: 10px; cursor: crosshair;
  touch-action: none; border: 2px solid #c6cdd8;
  /* checkerboard so the snipped-out transparency reads clearly */
  background: repeating-conic-gradient(#e9edf3 0% 25%, #f8fafc 0% 50%) 0 0 / 20px 20px;
}

/* ---- Little Kids mode: full-screen toddler brick stamper ---- */
#littleOverlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center;
  background: linear-gradient(160deg, #fdf3d0, #d9eefb 60%, #e7f7e2);
  padding: 12px; gap: 10px; touch-action: none;
}
#littleOverlay[hidden] { display: none !important; }
.little-board {
  flex: 1; width: 100%; display: flex; align-items: center; justify-content: center;
  min-height: 0;
}
#littleCanvas {
  border: 6px solid #fff; border-radius: 20px;
  box-shadow: 0 10px 0 rgba(43,52,69,.18); background: #eef2f7;
  touch-action: none; cursor: pointer;
}
.little-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  justify-content: center; width: 100%;
}
.little-palette { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.little-swatch {
  width: 62px; height: 62px; border-radius: 50%; padding: 0;
  border: 5px solid #fff; box-shadow: 0 5px 0 rgba(43,52,69,.22);
  cursor: pointer; transition: transform .1s;
}
.little-swatch.active { transform: scale(1.15); border-color: #2b3445; }
.little-swatch:active { transform: scale(.92); }
#littleCheerBtn {
  width: 68px; height: 68px; border-radius: 50%; border: 5px solid #fff;
  background: #ffd23e; font-size: 2rem; cursor: pointer;
  box-shadow: 0 5px 0 rgba(43,52,69,.22);
}
#littleCheerBtn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(43,52,69,.22); }
#littleExitBtn {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 52px; height: 52px; border-radius: 50%;
  border: 3px solid #c6cdd8; background: rgba(255,255,255,.85);
  font-size: 1.2rem; color: #8a94a6; cursor: pointer; overflow: hidden;
}
#littleExitBtn .hold-ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(#ff6b6b var(--p, 0%), transparent 0);
  opacity: 0; transition: opacity .1s;
}
#littleExitBtn.holding .hold-ring { opacity: .5; animation: holdFill 1.2s linear forwards; }
@keyframes holdFill { from { --p: 0%; } to { --p: 100%; } }
@property --p { syntax: '<percentage>'; inherits: false; initial-value: 0%; }

/* ---- Film it: the 3D stage as a stop-motion set ---- */
.film-stack { position: relative; display: inline-block; max-width: 100%; }
.film-stack canvas { max-width: 100%; display: block; }   /* no baseline gap — overlay must match exactly */
#filmOverlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;   /* effects are dragged through the 3D canvas's own handlers */
}
.fx-chip.active { background: #ffd23e; }
#filmBar { text-align: left; }

/* ---- filming plan: storyboard scenes as tappable chips in Stop Frame ---- */
.plan-strip { display: flex; gap: 6px; overflow-x: auto; max-width: 50vw; padding: 2px; }
.plan-chip {
  position: relative; flex: 0 0 auto; padding: 0; cursor: pointer;
  width: 64px; height: 44px; border: 3px solid #c6cdd8; border-radius: 8px;
  overflow: hidden; background: #f6f8fb; font-family: inherit;
}
.plan-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.plan-chip .num {
  position: absolute; left: 2px; top: 1px;
  background: rgba(43,52,69,.8); color: #fff;
  font-size: .68rem; font-weight: 700; border-radius: 5px; padding: 0 4px;
}
.plan-chip.active { border-color: #ff6b6b; }
.plan-chip:focus-visible { outline: 3px solid #2aa8e0; outline-offset: 2px; }

/* ---- tutorial coach marks: dim + spotlight + card ---- */
.tour-dim { position: fixed; inset: 0; z-index: 900; }
.tour-spot {
  position: fixed; z-index: 901; pointer-events: none;
  border: 3px solid #ffd23e; border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(27, 42, 52, 0.55);
  transition: left .25s ease, top .25s ease, width .25s ease, height .25s ease;
}
.tour-card {
  position: fixed; z-index: 902; left: 50%; transform: translateX(-50%);
  width: min(440px, calc(100vw - 32px));
  background: #fff; border: 3px solid #2b3445; border-radius: 16px;
  box-shadow: 0 8px 0 rgba(43, 52, 69, 0.35);
  padding: 14px 16px;
}
.tour-card p { margin: 0 0 10px; font-weight: 700; line-height: 1.45; }

/* a friendly welcome nudge on first run, shown once */
.welcome-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff7d6; border: 2px solid #ffd23e; border-radius: 14px;
  padding: 10px 14px; margin-bottom: 14px; font-weight: 700; color: #2b3445;
}
.welcome-banner .spacer { flex: 1; }
.welcome-banner .dismiss {
  border: none; background: transparent; font-size: 1.2rem; cursor: pointer; color: #5b6577;
}

/* bigger, comfier tap targets on touch devices without bulking up the desktop */
@media (pointer: coarse) {
  .mini-btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 10px 14px; }
  .segmented .seg-btn { min-height: 44px; padding: 10px 14px; }
  .pen-swatch { width: 44px; height: 44px; }
  .scene-head button { width: 40px; height: 40px; }
  .tool-row, .options-bar { gap: 10px; }
}

/* the hidden attribute must ALWAYS win — author display rules (flex on
   .tool-row/.options-bar) otherwise beat the UA's [hidden]{display:none} */
[hidden] { display: none !important; }

.tool-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.tool-row .spacer { flex: 1; }

/* touch devices should never leave a button looking "stuck" after a tap:
   neutralise every hover effect where there is no real hover */
@media (hover: none) {
  .tab:hover, .big-btn:hover, .size-options button:hover, .example-card:hover,
  .plan-chip:hover, .little-swatch:hover { transform: none; }
  .mini-btn:hover { background: #fff; }
  .mini-btn.primary:hover { background: #ffd23e; }
  .mini-btn.danger:hover { background: #fff1f0; }
  .tool-btn:hover, .add-scene:hover, .size-options button:hover { background: #fff; }
  .example-card:hover { border-color: #c6cdd8; background: #fff; }
}

/* one consistent, on-brand focus ring for every interactive control */
.tab:focus-visible, .big-btn:focus-visible, .mini-btn:focus-visible,
.tool-btn:focus-visible, .size-options button:focus-visible, .add-scene:focus-visible,
.badge-card:focus-visible, .seg-btn:focus-visible, .little-swatch:focus-visible {
  outline: 3px solid #2aa8e0; outline-offset: 2px;
}

/* the My Stuff empty state should be centered across the whole grid */
.creations-grid .empty-msg { grid-column: 1 / -1; text-align: center; }

/* a freshly-earned badge does a proud little pop + gold glow, once */
.badge-card.just-earned { animation: badgePop 0.7s ease; }
@keyframes badgePop {
  0% { transform: scale(0.8); box-shadow: 0 0 0 0 rgba(255,210,62,0); }
  40% { transform: scale(1.15); box-shadow: 0 0 0 10px rgba(255,210,62,0.5); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,210,62,0); }
}
@media (prefers-reduced-motion: reduce) { .badge-card.just-earned { animation: none; } }
.tool-label { font-weight: 700; font-size: .9rem; }
.tool-btn {
  font-size: 1.15rem;
  width: 44px; height: 44px;
  border-radius: 10px;
  border: 2px solid #2b3445;
  background: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(43,52,69,.35);
}
.tool-btn:hover { background: #fff3c4; }
.tool-btn.active { background: #ffd23e; box-shadow: none; transform: translateY(2px); }

.nice-select {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 8px;
  border-radius: 10px;
  border: 2px solid #2b3445;
  width: 100%;
  background: #fff;
}

/* ---- Palette ---- */
.palette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid rgba(0,0,0,0.25);
  cursor: pointer;
  padding: 0;
}
.swatch.active {
  outline: 3px solid #2b3445;
  outline-offset: 2px;
}

/* ---- Upload ---- */
.upload-zone {
  display: block;
  border: 3px dashed #8a94a6;
  border-radius: 12px;
  padding: 18px 10px;
  text-align: center;
  font-weight: 700;
  color: #5b6577;
  cursor: pointer;
  background: #f6f8fb;
  margin-bottom: 8px;
}
.upload-zone.dragover { background: #fff3c4; border-color: #2b3445; }

/* ---- Build tab ---- */
.options-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.options-bar .spacer { flex: 1; }
.check-label { font-weight: 700; font-size: .95rem; display: inline-flex; align-items: center; gap: 6px; }
.check-label input { width: 18px; height: 18px; }
.empty-msg {
  padding: 30px 10px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #8a94a6;
}

.shopping-card table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.shopping-card td, .shopping-card th { padding: 5px 6px; border-bottom: 1px solid #e3e8ef; text-align: left; vertical-align: top; }
.color-dot {
  display: inline-block;
  width: 18px; height: 18px;
  border-radius: 5px;
  border: 1px solid rgba(0,0,0,.3);
  vertical-align: -4px;
  margin-right: 4px;
}
.piece-chip {
  display: inline-block;
  background: #eef2f7;
  border-radius: 6px;
  padding: 1px 6px;
  margin: 1px;
  font-weight: 600;
  white-space: nowrap;
}
.totals-box {
  margin-top: 10px;
  background: #fff8dd;
  border: 2px solid #ecd57a;
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 600;
  line-height: 1.5;
}
.hint { color: #8a94a6; font-size: .88rem; font-weight: 600; }

/* ---- Animate tab ---- */
.sub-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.sub-tab {
  flex: 1;
  font-family: inherit; font-weight: 700; font-size: 1rem;
  padding: 8px; border-radius: 10px;
  border: 2px solid #2b3445; background: #fff; cursor: pointer;
}
.sub-tab.active { background: #7ed6a5; }

.sketch-stack { position: relative; width: 100%; max-width: 480px; margin: 0 auto; }
.sketch-stack canvas, .sketch-stack video {
  display: block; width: 100%; border-radius: 8px; border: 2px solid #c6cdd8;
}
#sketchCanvas { position: absolute; inset: 0; touch-action: none; cursor: crosshair; background: transparent; border-color: transparent; }
#puppetLayer { position: absolute; inset: 0; pointer-events: none; background: transparent; border-color: transparent; }
.tool-btn.danger { background: #fff1f0; border-color: #c1291f; color: #c1291f; }
#sketchOnion { background: #fff; }
#camOnion { position: absolute; inset: 0; pointer-events: none; border-color: transparent; }
#camVideo { background: #1b2a34; object-fit: cover; }

.pen-swatch {
  width: 34px; height: 34px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,.3); cursor: pointer; padding: 0;
}
.pen-swatch.active { outline: 3px solid #2b3445; outline-offset: 2px; }

.frames-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px; min-height: 86px; align-items: center;
  /* fade the right edge so it's obvious more frames scroll off-screen */
  -webkit-mask-image: linear-gradient(to right, #000 92%, transparent);
  mask-image: linear-gradient(to right, #000 92%, transparent);
}
.frames-strip:only-child, .frames-strip { scrollbar-width: thin; }
.frame-thumb {
  position: relative; flex: 0 0 auto; cursor: pointer;
  border: 3px solid #c6cdd8; border-radius: 8px; overflow: hidden;
  padding: 0; background: #fff; font-family: inherit;   /* it's a <button> now */
}
.frame-thumb img { display: block; width: 96px; height: 72px; object-fit: cover; }
.frame-thumb.selected { border-color: #ff6b6b; }
.frame-thumb { touch-action: pan-x; }            /* flick scrolls; hold picks up to reorder */
.frame-thumb.dragging { opacity: .5; }
.frame-thumb.drop-before { box-shadow: -4px 0 0 0 #ff6b6b; }
.frame-thumb .num {
  position: absolute; left: 3px; top: 2px;
  background: rgba(43,52,69,.8); color: #fff;
  font-size: .7rem; font-weight: 700; border-radius: 5px; padding: 0 5px;
}
.frame-thumb .hold-badge {
  position: absolute; right: 3px; top: 2px;
  background: #ffb01f; color: #2b3445;
  font-size: .7rem; font-weight: 800; border-radius: 5px; padding: 0 5px;
}
input[type="range"] { accent-color: #ff6b6b; }
.scrubber { display: block; width: 100%; max-width: 480px; margin: 8px auto 2px; }

/* segmented control: a compact row of exclusive options (ghosts, playback, timer) */
.segmented { display: inline-flex; border: 2px solid #2b3445; border-radius: 10px; overflow: hidden; }
.segmented .seg-btn {
  font-family: inherit; font-weight: 700; font-size: .85rem;
  padding: 6px 11px; border: none; border-right: 2px solid #2b3445;
  background: #fff; cursor: pointer; color: #2b3445;
}
.segmented .seg-btn:last-child { border-right: none; }
.segmented .seg-btn.active { background: #7ed6a5; }
.segmented .seg-btn:focus-visible { outline: 3px solid #2aa8e0; outline-offset: -3px; }

/* ---- Storyboard ---- */
.scenes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.scene-card { margin-bottom: 0; }
.scene-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.scene-head .scene-num { font-weight: 800; font-size: 1.05rem; flex: 1; }
.scene-head button {
  border: 2px solid #2b3445; background: #fff; border-radius: 8px;
  cursor: pointer; font-size: .9rem; width: 30px; height: 30px;
}
.scene-title {
  width: 100%; font-family: inherit; font-weight: 700; font-size: 1rem;
  border: 2px solid #c6cdd8; border-radius: 8px; padding: 6px 8px; margin-bottom: 6px;
}
.scene-card canvas {
  display: block; width: 100%; border: 2px solid #c6cdd8; border-radius: 8px;
  background: #fff; touch-action: none; cursor: crosshair;
}
.scene-notes {
  width: 100%; font-family: inherit; font-size: .92rem;
  border: 2px solid #c6cdd8; border-radius: 8px; padding: 6px 8px;
  margin-top: 6px; resize: vertical; min-height: 56px;
}
.add-scene {
  border: 3px dashed #8a94a6; border-radius: 18px; background: #f6f8fb;
  min-height: 220px; display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; font-weight: 800; color: #5b6577; cursor: pointer;
  font-family: inherit;   /* it's a <button> now */
}
.modal-box:focus { outline: 3px solid rgba(42, 168, 224, 0.35); outline-offset: 2px; }
.frame-thumb:focus-visible, .swatch:focus-visible, .example-card:focus-visible {
  outline: 3px solid #2aa8e0; outline-offset: 2px;
}
.add-scene:hover { background: #fff3c4; }
.mini-tools { display: flex; gap: 6px; margin-top: 6px; }

/* ---- Modal (image-import size picker) ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(43,52,69,.55);
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay[hidden] { display: none; }
.modal-overlay:not([hidden]) .modal-box { animation: popIn 0.18s ease; }
@keyframes popIn {
  from { opacity: 0; transform: scale(0.93); }
  to   { opacity: 1; transform: scale(1); }
}
#confettiCanvas {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 300;
}
/* respect users (and parents) who turn motion off */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    transition-duration: 0.001s !important;
  }
}
.modal-box {
  background: #fff;
  border: 3px solid #2b3445;
  border-radius: 18px;
  padding: 18px 20px;
  max-width: 420px; width: 92%;
  text-align: center;
  box-shadow: 0 8px 0 rgba(43,52,69,.3);
}
.modal-box h3 { margin: 0 0 6px; }
#sizeModalPreview {
  max-width: 140px; max-height: 140px;
  border-radius: 10px; border: 2px solid #c6cdd8;
  margin: 6px auto; display: block; object-fit: cover;
}
.size-options {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 10px; margin: 12px 0;
}
.size-options button {
  font-family: inherit; font-weight: 800; font-size: 1.05rem;
  padding: 13px 8px; border-radius: 12px;
  border: 3px solid #2b3445; background: #fff; cursor: pointer;
  box-shadow: 0 4px 0 rgba(43,52,69,.3);
  transition: transform .08s;
}
.size-options button:hover { background: #fff3c4; transform: translateY(-2px); }
.size-options button:active { transform: translateY(2px); box-shadow: none; }
.size-options button span { font-weight: 600; font-size: .85rem; color: #5b6577; }
.size-options button.current { background: #ffd23e; }

/* ---- camera snap (Draw page) ---- */
#drawCamVideo {
  width: 100%; max-width: 400px;
  border-radius: 10px; border: 2px solid #c6cdd8;
  background: #1b2a34;
  transform: scaleX(-1);   /* mirror, like looking in a mirror */
}
#scanVideo {
  width: 100%; max-width: 400px;
  border-radius: 10px; border: 2px solid #c6cdd8;
  background: #1b2a34;     /* NOT mirrored — the toy spins, orientation matters */
}
.snap-btn { width: auto; margin-top: 0; padding: 10px 28px; font-size: 1.1rem; }

/* ---- my bricks ---- */
.swatch.locked { opacity: 0.18; pointer-events: none; }
.owned-palette { grid-template-columns: repeat(7, 1fr); }
.owned-palette .swatch { font-weight: 900; font-size: 1rem; }
.owned-palette .swatch.unowned { opacity: 0.3; }
.owned-palette .swatch.owned { outline: 2px solid #2b3445; outline-offset: 1px; }

/* ---- examples gallery ---- */
.examples-box { max-width: 640px; max-height: 86vh; overflow-y: auto; }
.examples-box h4 { margin: 12px 0 8px; text-align: left; }
.examples-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
}
.example-card {
  font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px;
  border: 2px solid #c6cdd8; border-radius: 12px;
  background: #fff; cursor: pointer;
  font-weight: 700; font-size: 0.85rem; color: #2b3445;
  transition: transform .08s;
}
.example-card:hover { border-color: #2b3445; transform: translateY(-2px); background: #fff9e3; }
.example-card canvas, .example-card img {
  width: 64px; height: 64px;
  border-radius: 8px;
  image-rendering: pixelated;
  object-fit: cover;
  background: #f2f5f9;
}

/* ---- guided build ---- */
.guided-box { max-width: 660px; }
.guided-head { display: flex; align-items: center; gap: 10px; }
.guided-head h3 { flex: 1; text-align: left; margin: 0; }
#guidedCanvas { max-height: 55vh; width: auto; max-width: 100%; border: 2px solid #c6cdd8; }
.guided-pieces { min-height: 40px; margin: 8px 0; text-align: left; }
.guided-pieces .piece-chip { font-size: 0.95rem; padding: 4px 8px; }
.guided-done { font-size: 1.3rem; font-weight: 800; text-align: center; margin: 8px 0; }
.guided-nav { justify-content: center; gap: 12px; }
.guided-nav .big-btn { width: auto; margin-top: 0; padding: 10px 26px; font-size: 1.05rem; }
.guided-nav .mini-btn:disabled { opacity: 0.4; cursor: default; }

/* ---- My Stuff: badges + creations + toast ---- */
.section-title { margin: 18px 4px 10px; }
.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.badge-card {
  text-align: center;
  border: 2px solid #e3e8ef;
  border-radius: 12px;
  padding: 12px 6px;
  opacity: 0.4;
  background: #fafbfd;
}
.badge-card.earned {
  opacity: 1;
  border-color: #ffd23e;
  background: #fffaf0;
  box-shadow: 0 3px 0 rgba(236, 213, 122, 0.6);
}
.badge-emoji { font-size: 2rem; }
.badge-name { font-weight: 800; font-size: 0.9rem; margin-top: 4px; }
.badge-desc { font-size: 0.78rem; color: #5b6577; font-weight: 600; }
.creations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}
.creation-card { margin-bottom: 0; text-align: center; }
.creation-card img {
  width: 100%;
  border-radius: 10px;
  border: 2px solid #e3e8ef;
  background: #fff;
  image-rendering: pixelated;
}
.creation-title { font-weight: 800; font-size: 0.9rem; margin-top: 6px; }
.creation-date { font-size: 0.78rem; color: #8a94a6; font-weight: 600; margin-bottom: 4px; }
.creation-card .tool-row { justify-content: center; }
#toast {
  position: fixed;
  left: 50%; top: 18px; transform: translateX(-50%) translateY(-80px);
  z-index: 250;
  background: #2b3445;
  color: #fff;
  font-weight: 800;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(43, 52, 69, 0.35);
  transition: transform 0.3s ease;
  pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ---- pro ---- */
.pro-perks { text-align: left; margin: 10px 0; }
.pro-perks p { margin: 6px 0; font-size: 0.95rem; }

/* ---- footer + error banner ---- */
.app-footer {
  text-align: center;
  padding: 18px 12px 26px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #8a94a6;
}
.app-footer a { color: #5b6577; }
#errorBanner {
  position: fixed;
  left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 200;
  max-width: 520px; width: 92%;
  background: #fff;
  border: 3px solid #e4453c;
  border-radius: 14px;
  box-shadow: 0 6px 0 rgba(43, 52, 69, 0.25);
  padding: 12px 14px;
  font-weight: 700;
  color: #2b3445;
  animation: bannerIn 0.28s ease;   /* arrive with the same soft feel as every other overlay */
}
@keyframes bannerIn {
  from { opacity: 0; transform: translateX(-50%) translateY(16px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@media (prefers-reduced-motion: reduce) { #errorBanner { animation: none; } }
#errorBanner code {
  display: block;
  margin: 8px 0;
  padding: 6px 8px;
  background: #f4f6f8;
  border-radius: 8px;
  font-weight: 400;
  font-size: 0.82rem;
  word-break: break-all;
}
.error-banner-row { display: flex; gap: 8px; }
.error-banner-row button {
  font-family: inherit; font-weight: 700; font-size: 0.88rem;
  padding: 6px 10px; border-radius: 8px;
  border: 2px solid #2b3445; background: #fff; cursor: pointer;
}

/* ---- Print ---- */
#printArea { display: none; }
@media print {
  body.print-mode > *:not(#printArea) { display: none !important; }
  body.print-mode #printArea { display: block !important; }
  #printArea img { max-width: 100%; }
  #printArea h2 { font-size: 1.3rem; }
  #printArea table { width: 100%; border-collapse: collapse; font-size: 11pt; }
  #printArea td, #printArea th { border: 1px solid #999; padding: 4px 6px; text-align: left; }
  .print-scene { break-inside: avoid; border: 1px solid #999; border-radius: 8px; padding: 8px; margin-bottom: 10px; }
  .print-scene img { width: 260px; float: left; margin-right: 10px; border: 1px solid #ccc; }
  .print-scene::after { content: ""; display: block; clear: both; }
}
