/* ==========================================================================
   Bradul nostru de Crăciun — styles
   Mobile/tablet/interactive-whiteboard friendly: big touch targets,
   strong contrast, playful but calm colours.
   ========================================================================== */

:root {
  --green-900: #0f3d2e;
  --green-700: #1b6b45;
  --green-500: #2e9d5b;
  --red-600: #d62f3a;
  --red-500: #e84a4a;
  --gold-400: #ffcf3f;
  --gold-300: #ffe08a;
  --cream: #fff9ef;
  --ink: #1f2a37;
  --ink-soft: #4b5a6b;

  --panel: rgba(255, 255, 255, 0.86);
  --panel-border: rgba(15, 61, 46, 0.12);
  --panel-ink: var(--ink);
  --chip: #ffffff;
  --selected: #ffcf3f;

  --radius: 22px;
  --shadow: 0 6px 18px rgba(15, 40, 30, 0.14);
  --shadow-press: 0 2px 6px rgba(15, 40, 30, 0.18);
  --font: "Baloo 2", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --t-dark: 1.2s;
}

/* "Room lights off": panels become dark too, so the tree is the star. */
body.is-dark {
  --panel: rgba(16, 24, 48, 0.88);
  --panel-border: rgba(255, 255, 255, 0.08);
  --panel-ink: #e9eefc;
  --chip: #1d2a4d;
  --ink-soft: #b7c3e0;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--panel-ink);
  background: #dff1ff;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  transition: background-color var(--t-dark), color var(--t-dark);
}
body.is-dark { background: #050a1f; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus-visible { outline: 4px solid #3b8bff; outline-offset: 3px; }
button:disabled { opacity: 0.4; cursor: default; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ==========================================================================
   Layout
   Landscape (whiteboard, laptop, tablet): the tree uses the whole height
   of the screen in the middle column.
   ========================================================================== */
.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-areas:
    "tabs stage top"
    "tabs stage palette";
  grid-template-columns: 112px minmax(0, 1fr) minmax(290px, 340px);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

.topbar  { grid-area: top; }
.tabs    { grid-area: tabs; }
.stage   { grid-area: stage; }
.palette { grid-area: palette; }

.topbar, .tabs, .palette {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  transition: background-color var(--t-dark), border-color var(--t-dark);
}

/* ---------- global actions ---------- */
.topbar { padding: 8px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 56px; padding: 4px 2px;
  border: 0; border-radius: 14px;
  background: var(--chip);
  box-shadow: var(--shadow-press);
  transition: transform .12s, background-color var(--t-dark);
}
.action:active { transform: scale(.94); }
.action .ico { font-size: 1.35rem; line-height: 1.1; }
.action .lbl { font-size: .72rem; font-weight: 700; color: var(--ink-soft); white-space: nowrap; }
.action[aria-pressed="false"] .ico { filter: grayscale(1); opacity: .6; }
.action--danger .lbl { color: var(--red-600); }

/* ---------- category tabs ---------- */
.tabs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 8px;
  overflow-y: auto;
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  min-height: 92px;
  padding: 8px 4px;
  border: 3px solid transparent;
  border-radius: 20px;
  background: var(--chip);
  box-shadow: var(--shadow-press);
  transition: transform .15s, border-color .15s, background-color var(--t-dark);
}
.tab:active { transform: scale(.95); }
.tab-ico { font-size: 2.3rem; line-height: 1; display: grid; place-items: center; height: 44px; }
.tab-ico img { width: 44px; height: 44px; object-fit: contain; }
.tab-lbl { font-size: .95rem; font-weight: 800; }
.tab.is-active {
  border-color: var(--gold-400);
  background: linear-gradient(180deg, #fff6d6, #ffe7a3);
  color: var(--ink);
}
body.is-dark .tab.is-active { background: linear-gradient(180deg, #3b3a1d, #5a4a12); color: #fff4c2; }
.tab--surprise .tab-ico { animation: giftWiggle 2.2s ease-in-out infinite; }
.tab--surprise::after {
  content: "";
  position: absolute; inset: -3px;
  border-radius: 20px;
  box-shadow: 0 0 0 0 rgba(255, 207, 63, .8);
  animation: ring 2.2s infinite;
  pointer-events: none;
}

/* ---------- stage (tree) ---------- */
.stage {
  position: relative;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    radial-gradient(120% 40% at 50% 104%, #ffffff 0 55%, transparent 56%),
    linear-gradient(180deg, #a9dbff 0%, #d7efff 60%, #f1f9ff 100%);
  box-shadow: inset 0 0 0 1px rgba(15, 61, 46, .08), var(--shadow);
}
/* Night sky layer: fades in when the room lights are switched off. */
.stage::before {
  content: "";
  position: absolute; inset: 0;
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 28% 8%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 44% 22%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 66% 12%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 82% 26%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 90% 6%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 6% 40%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 94% 44%, #fff 50%, transparent 51%),
    linear-gradient(180deg, #030716 0%, #0a1433 70%, #101c40 100%);
  opacity: 0;
  transition: opacity var(--t-dark);
  pointer-events: none;
}
.is-dark .stage::before { opacity: 1; }

.tree-svg {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  overflow: visible;
  touch-action: none;
  z-index: 1;
}
.snow {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity .6s;
}
.snow.is-on { opacity: .9; }

/* Cursor hints per tool */
[data-tool="balls"] .tree-svg, [data-tool="bubu"] .tree-svg { cursor: copy; }
[data-tool="lights"] .tree-svg { cursor: crosshair; }
[data-tool="eraser"] .tree-svg { cursor: not-allowed; }
[data-tool="eraser"] .tree-svg .ornament,
[data-tool="eraser"] .tree-svg .bulb,
[data-tool="eraser"] .tree-svg .topper { cursor: pointer; }
.tree-svg .ornament { cursor: grab; }

.toast {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 4;
  transform: translateY(-20px);
  padding: 8px 20px;
  border-radius: 999px;
  background: rgba(15, 30, 40, .88);
  color: #fff;
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .25s;
}
.toast.is-on { opacity: 1; transform: none; }

/* ---------- palette ---------- */
.palette {
  padding: 12px 14px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.pal-section + .pal-section { margin-top: 14px; }
.pal-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--green-700);
  transition: color var(--t-dark);
}
body.is-dark .pal-title { color: var(--gold-300); }

.grid { display: grid; gap: 8px; }
.grid--balls { grid-template-columns: repeat(4, 1fr); }
.grid--bubu { grid-template-columns: repeat(3, 1fr); }
.grid--toppers { grid-template-columns: repeat(3, 1fr); }

.swatch {
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 2px 4px;
  border: 3px solid transparent;
  border-radius: 18px;
  background: var(--chip);
  box-shadow: var(--shadow-press);
  transition: transform .12s, border-color .12s, background-color var(--t-dark);
}
.swatch:active { transform: scale(.92); }
.swatch svg { width: 100%; max-width: 58px; aspect-ratio: 56 / 60; }
.grid--bubu .swatch svg { max-width: 72px; aspect-ratio: 64 / 70; }
.swatch-lbl { font-size: .72rem; font-weight: 700; line-height: 1.1; text-align: center; color: var(--ink-soft); min-height: 1.6em; }
.swatch.is-selected { border-color: var(--selected); background: #fff6d6; transform: scale(1.04); }
body.is-dark .swatch.is-selected { background: #3b3a1d; }

.combos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.combo {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px 6px;
  border: 3px solid transparent;
  border-radius: 16px;
  background: var(--chip);
  box-shadow: var(--shadow-press);
  transition: transform .12s, border-color .12s;
}
.combo:active { transform: scale(.95); }
.combo.is-selected { border-color: var(--selected); }
.combo-name { font-size: .85rem; font-weight: 700; }
.combos--big .combo { min-height: 84px; justify-content: center; gap: 6px; }
.combos--big .pattern .dot { width: 20px; height: 26px; }
.combos--big .combo-name { font-size: 1rem; }
.pal-btn--hero { width: 100%; min-height: 72px; margin-top: 14px; font-size: 1.35rem; border-radius: 20px; }

.pattern { display: inline-flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: center; }
.pattern .dot {
  width: 14px; height: 18px;
  border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%;
  background: radial-gradient(circle at 38% 32%, #fff 0 15%, var(--c) 60%);
  box-shadow: 0 0 8px var(--c);
}
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode {
  display: flex; align-items: center; gap: 8px;
  min-height: 52px;
  padding: 6px 10px;
  border: 3px solid transparent;
  border-radius: 14px;
  background: var(--chip);
  box-shadow: var(--shadow-press);
  font-weight: 700;
}
.mode.is-selected { border-color: var(--selected); }
.mode-ico { font-size: 1.3rem; width: 1.4em; text-align: center; color: #f2a900; }
.mode-ico--blink, .mode-ico--flash { animation: blinkIcon 1s steps(1) infinite; }
.mode-ico--sequence { animation: chaseIcon 1.2s linear infinite; }
.mode-ico--breathe { animation: twinkleIcon 2.4s ease-in-out infinite; }
.mode-ico--chase { animation: chaseIcon 1s ease-in-out infinite; }
.mode-ico--twinkle { animation: twinkleIcon 1.4s ease-in-out infinite; }

.pal-actions { display: grid; gap: 8px; margin-top: 14px; }
.pal-btn {
  min-height: 56px;
  padding: 8px 12px;
  border: 0; border-radius: 16px;
  background: var(--chip);
  box-shadow: var(--shadow-press);
  font-size: 1.05rem; font-weight: 800;
  transition: transform .12s;
}
.pal-btn:active { transform: scale(.96); }
.pal-btn--magic {
  background: linear-gradient(90deg, #ff6b6b, #ffcf3f, #4cd97b, #4ba3ff, #b45cff);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

.hint {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 207, 63, .2);
  font-size: .98rem; font-weight: 700;
  line-height: 1.3;
}

.topper-tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 120px;
  padding: 8px 4px;
  border: 3px solid transparent;
  border-radius: 18px;
  background: var(--chip);
  box-shadow: var(--shadow-press);
  font-size: .9rem; font-weight: 800; line-height: 1.1; text-align: center;
}
.topper-tile svg { width: 72px; height: 72px; filter: drop-shadow(0 0 8px rgba(255, 210, 63, .8)); }
.topper-tile.is-selected { border-color: var(--selected); }
.topper-bubu { display: grid; place-items: center; width: 80px; height: 80px; }
.topper-bubu img { width: 80px; height: 80px; object-fit: contain; filter: drop-shadow(0 0 6px #ff2020) drop-shadow(0 0 10px rgba(255, 32, 32, .6)); }
.topper-locked { font-size: 2.6rem; line-height: 72px; }
.topper-tile--locked .topper-locked { animation: giftWiggle 2.2s ease-in-out infinite; display: inline-block; }

.eraser-info { display: flex; align-items: center; gap: 12px; }
.eraser-ico { font-size: 3rem; }
.eraser-info p { margin: 0; font-weight: 700; font-size: 1.05rem; line-height: 1.3; }

/* ---------- big buttons ---------- */


/* ---------- counters (on the stage, top-left corner) ---------- */
.counters {
  position: absolute; top: 12px; left: 12px;
  z-index: 3;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.counter {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 46px;
  padding: 2px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .85);
  color: var(--ink);
  box-shadow: var(--shadow-press);
  font-size: 1.3rem;
  transition: background-color var(--t-dark), color var(--t-dark);
}
body.is-dark .counter { background: rgba(20, 30, 60, .8); color: #e9eefc; }
.counter[hidden] { display: none; }
.counter b { font-size: 1.55rem; min-width: 1.2em; text-align: center; display: inline-block; }
.counter img { width: 30px; height: 30px; object-fit: contain; }
.counter b.bump { animation: bump .35s ease-out; }

/* "Gata!" among the small action buttons, slightly highlighted */
.action--done { background: linear-gradient(180deg, #ff6a6a, var(--red-600)); }
.action--done .lbl { color: #fff; }

/* Special "room lights" button at the bottom of the left column */
.tablist { display: contents; }
.tab--lights {
  margin-top: auto;
  background: linear-gradient(180deg, #2a3557, #141c36);
  color: #fff4c2;
}
.tab--lights .tab-lbl { line-height: 1.1; text-align: center; }
.tab--lights[aria-pressed="true"] {
  background: linear-gradient(180deg, #fff1a8, #ffcf3f);
  color: #3a2a00;
  box-shadow: 0 0 22px rgba(255, 207, 63, .6);
}

/* ==========================================================================
   SVG scene
   ========================================================================== */
.darkness {
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-dark) ease;
}
.is-dark .darkness { opacity: .84; }

.wire { fill: none; stroke: #1b3a20; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }

/* Ornaments: pop in, then swing gently around the hook (local 0,0). */
.ornament .swing { animation: swing 3.2s ease-in-out infinite; transform-origin: 0 0; }
.ornament .pop { animation: popIn .45s cubic-bezier(.34, 1.56, .64, 1) both; transform-origin: 0 30px; }
.ornament.no-pop .pop { animation: none; }
.ornament.wiggle .pop { animation: wiggle .5s ease-in-out; transform-origin: 0 0; }
.ornament.is-dragging { filter: drop-shadow(0 8px 6px rgba(0, 0, 0, .35)); cursor: grabbing; }
.ornament.is-dragging .swing { animation: none; }
.ornament.is-off-tree { opacity: .5; }
.ornament.is-returning { transition: transform .35s cubic-bezier(.34, 1.56, .64, 1); }
.ornament.is-leaving .pop { animation: popOut .25s ease-in both; }

/* Bulbs */
.bulb .glow { opacity: .4; transition: opacity var(--t-dark); }
.is-dark .bulb .glow { opacity: 1; }
.bulb .glow, .bulb .bulb-body { transform-box: fill-box; transform-origin: center; }
.bulb.is-new .bulb-body,
.bulb.is-new .glow { animation: bulbIn .4s cubic-bezier(.34, 1.56, .64, 1) both; animation-delay: inherit; }

.mode-blink .bulb { --dur: 1.2s; --delay: 0s; }
.mode-blink .bulb:nth-child(even) { --delay: -.6s; }
.mode-chase .bulb { --dur: 1.5s; --delay: calc(var(--i) * -.12s); }
.mode-twinkle .bulb { --dur: 1.9s; --delay: calc(var(--r) * -1); }

.mode-blink .bulb:not(.is-new) .glow { animation: glowBlink var(--dur) var(--delay) steps(1) infinite; }
.mode-blink .bulb:not(.is-new) .glass { animation: glassBlink var(--dur) var(--delay) steps(1) infinite; }
.mode-chase .bulb:not(.is-new) .glow,
.mode-twinkle .bulb:not(.is-new) .glow { animation: glowWave var(--dur) var(--delay) ease-in-out infinite; }
.mode-chase .bulb:not(.is-new) .glass,
.mode-twinkle .bulb:not(.is-new) .glass { animation: glassWave var(--dur) var(--delay) ease-in-out infinite; }

.mode-flash .bulb { --dur: 1.1s; --delay: 0s; }
/* Negative base delay (a whole number of periods) keeps the bulbs in order from the very start. */
.mode-sequence .bulb { --dur: 3.2s; --delay: calc(var(--i) * .2s - 320s); }
.mode-breathe .bulb { --dur: 3.4s; --delay: 0s; }

.mode-flash .bulb:not(.is-new) .glow { animation: glowBlink var(--dur) var(--delay) steps(1) infinite; }
.mode-flash .bulb:not(.is-new) .glass { animation: glassBlink var(--dur) var(--delay) steps(1) infinite; }
.mode-sequence .bulb:not(.is-new) .glow { animation: glowSeq var(--dur) var(--delay) linear infinite; }
.mode-sequence .bulb:not(.is-new) .glass { animation: glassSeq var(--dur) var(--delay) linear infinite; }
.mode-breathe .bulb:not(.is-new) .glow { animation: glowWave var(--dur) ease-in-out infinite; }
.mode-breathe .bulb:not(.is-new) .glass { animation: glassWave var(--dur) ease-in-out infinite; }
.mode-rainbow .strand { animation: hue 4s linear infinite; }

/* A star twinkling on an ornament while the room is dark */
.shimmer .twinkle { transform-box: fill-box; transform-origin: center; animation: twinkleStar 1.6s ease-in-out both; }

/* Topper */
.topper-glow { opacity: .6; transform-box: fill-box; transform-origin: center; animation: pulse 2.6s ease-in-out infinite; transition: opacity var(--t-dark); }
.is-dark .topper-glow { opacity: 1; }
.topper-body { transform-box: fill-box; transform-origin: center; }
.topper-body.pop-big { animation: popBig .6s cubic-bezier(.34, 1.56, .64, 1) both; }
.topper { cursor: pointer; }

/* Surprise gift under the tree */
.surprise-gift { cursor: pointer; }
.surprise-gift:focus { outline: none; }
.surprise-gift:focus-visible .gift-wiggle { filter: drop-shadow(0 0 6px #3b8bff); }
.gift-wiggle { transform-box: fill-box; transform-origin: 50% 100%; animation: giftWiggle 2.2s ease-in-out infinite; filter: drop-shadow(0 0 10px rgba(255, 207, 63, .9)); }
.gift-glow { animation: giftGlow 1.8s ease-in-out infinite; }

/* Sparkles */
.spark { animation: spark .65s ease-out forwards; }

/* ==========================================================================
   Overlays (start, surprise, celebration, confirm)
   ========================================================================== */
.overlay {
  position: fixed; inset: 0;
  z-index: 50;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(8, 20, 30, .55);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s, visibility .25s;
}
.overlay.is-open { opacity: 1; visibility: visible; }
.overlay--start { background: linear-gradient(180deg, rgba(15, 61, 46, .92), rgba(10, 30, 50, .92)); }

.card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 28px 28px 24px;
  border-radius: 30px;
  --ink-soft: #4b5a6b;
  background: var(--cream);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
  transform: scale(.9) translateY(10px);
  transition: transform .35s cubic-bezier(.34, 1.56, .64, 1);
}
.overlay.is-open .card { transform: none; }
.card h2 { margin: 6px 0 6px; font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.1; color: var(--green-900); }
.lead { margin: 0 0 14px; font-size: 1.25rem; font-weight: 600; color: var(--ink-soft); }
.big-emoji { font-size: 3.6rem; }

.btn-big {
  min-height: 64px;
  padding: 8px 32px;
  border: 0; border-radius: 999px;
  background: linear-gradient(180deg, #46c06f, var(--green-700));
  color: #fff;
  font-size: 1.5rem; font-weight: 800;
  box-shadow: 0 5px 0 #0f4a2d, 0 8px 18px rgba(0, 0, 0, .2);
  transition: transform .12s, box-shadow .12s;
}
.btn-big:active { transform: translateY(4px); box-shadow: 0 1px 0 #0f4a2d; }
.btn-big--ghost { background: #fff; color: var(--green-900); box-shadow: 0 5px 0 #c9d6cf, 0 8px 18px rgba(0, 0, 0, .12); }
.btn-big--danger { background: linear-gradient(180deg, #ff6a6a, var(--red-600)); box-shadow: 0 5px 0 #9e1f28, 0 8px 18px rgba(0, 0, 0, .2); }
.card-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

/* start */
.start-tree { font-size: 5rem; line-height: 1; animation: bob 2.4s ease-in-out infinite; }
.steps { list-style: none; margin: 8px 0 22px; padding: 0; display: grid; gap: 10px; text-align: left; }
.steps li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  background: #fff;
  font-size: 1.2rem; font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .06);
}
.step-ico { font-size: 1.8rem; }

/* surprise: gift box that opens and Bubu jumps out */
.gift { position: relative; width: 240px; height: 250px; margin: 6px auto 4px; }
.gift-body {
  position: absolute; left: 30px; bottom: 0;
  width: 180px; height: 120px;
  border-radius: 10px;
  background:
    linear-gradient(90deg, transparent 78px, var(--gold-400) 78px 102px, transparent 102px),
    linear-gradient(180deg, #ff5a5a, #c62832);
  z-index: 2;
}
.gift-lid {
  position: absolute; left: 20px; bottom: 112px;
  width: 200px; height: 36px;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 88px, var(--gold-400) 88px 112px, transparent 112px),
    linear-gradient(180deg, #ff7272, #d93441);
  z-index: 3;
  transform-origin: 0% 100%;
  transition: transform .5s cubic-bezier(.34, 1.56, .64, 1);
  animation: giftShake .5s ease-in-out infinite;
}
.gift-lid::before, .gift-lid::after {
  content: "";
  position: absolute; top: -26px;
  width: 44px; height: 30px;
  border: 7px solid var(--gold-400);
  border-radius: 50% 50% 0 50%;
}
.gift-lid::before { left: 54px; transform: rotate(-12deg); }
.gift-lid::after { right: 54px; transform: scaleX(-1) rotate(-12deg); }
.gift-bubu {
  position: absolute; left: 50%; bottom: 20px;
  width: 190px; height: 190px;
  margin-left: -95px;
  object-fit: contain;
  z-index: 1;
  transform: translateY(40px) scale(.3);
  opacity: 0;
  transition: transform .7s cubic-bezier(.34, 1.7, .64, 1) .15s, opacity .2s .15s;
}
.gift.is-open .gift-lid { transform: translate(-26px, -18px) rotate(-30deg); animation: none; }
.gift.is-open .gift-bubu { transform: translateY(-18px) scale(1); opacity: 1; z-index: 4; }
.gift.is-open .gift-body { opacity: .95; }

/* celebration */
.celebrate-bubu { width: 150px; height: 150px; object-fit: contain; animation: hop 1s ease-in-out infinite; }
.tally {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
}
.tally-item {
  display: flex; flex-direction: column; align-items: center;
  min-width: 78px;
  padding: 8px 10px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .08);
  animation: popInFlat .4s cubic-bezier(.34, 1.56, .64, 1) both;
}
.tally-item:nth-child(2) { animation-delay: .08s; }
.tally-item:nth-child(3) { animation-delay: .16s; }
.tally-item:nth-child(4) { animation-delay: .24s; }
.tally-item:nth-child(5) { animation-delay: .32s; }
.tally-item:nth-child(n+6) { animation-delay: .4s; }
.tally-item svg { width: 48px; height: 52px; }
.tally-item img { width: 48px; height: 48px; object-fit: contain; }
.tally-item b { font-size: 1.8rem; line-height: 1; color: var(--green-900); }
.tally-bulb, .tally-item--topper span { font-size: 2.3rem; line-height: 52px; }
.tally-empty { font-size: 1.2rem; font-weight: 700; }

/* confetti */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i {
  position: absolute; top: -20px;
  width: 10px; height: 16px;
  border-radius: 2px;
  animation: fall 3s cubic-bezier(.25, .6, .4, 1) forwards;
}

.noscript { position: fixed; inset: auto 0 0; margin: 0; padding: 16px; background: #fff3cd; text-align: center; font-weight: 700; z-index: 99; }

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes swing { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes popIn { 0% { transform: scale(0); } 100% { transform: scale(1); } }
@keyframes popOut { to { transform: scale(0); opacity: 0; } }
@keyframes popBig { 0% { transform: scale(0) rotate(-90deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes popInFlat { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bulbIn { 0% { transform: scale(0); } 100% { transform: scale(1); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-14deg); } 75% { transform: rotate(14deg); } }
@keyframes glowBlink { 0% { opacity: 1; } 50% { opacity: .05; } }
@keyframes glassBlink { 0% { opacity: 1; } 50% { opacity: .45; } }
@keyframes glowWave { 0%, 100% { opacity: 1; } 50% { opacity: .08; } }
@keyframes glassWave { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
@keyframes glowSeq { 0%, 16% { opacity: 1; } 24%, 100% { opacity: .06; } }
@keyframes glassSeq { 0%, 16% { opacity: 1; } 24%, 100% { opacity: .4; } }
@keyframes twinkleStar { 0% { transform: scale(0) rotate(0); opacity: 0; } 45% { transform: scale(1.15) rotate(45deg); opacity: 1; } 100% { transform: scale(0) rotate(90deg); opacity: 0; } }
@keyframes giftGlow { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }
@keyframes pulse { 0%, 100% { transform: scale(.9); } 50% { transform: scale(1.12); } }
@keyframes spark { from { transform: translate(0, 0) scale(1); opacity: 1; } to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; } }
@keyframes giftWiggle { 0%, 70%, 100% { transform: rotate(0); } 76% { transform: rotate(-9deg); } 82% { transform: rotate(9deg); } 88% { transform: rotate(-6deg); } 94% { transform: rotate(4deg); } }
@keyframes giftShake { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-3deg) translateY(-3px); } }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(255, 207, 63, .8); } 70%, 100% { box-shadow: 0 0 0 12px rgba(255, 207, 63, 0); } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.5); color: var(--red-600); } 100% { transform: scale(1); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes hop { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-16px) rotate(3deg); } }
@keyframes fall { to { transform: translate(var(--x), 105vh) rotate(var(--rot)); } }
@keyframes hue { to { filter: hue-rotate(360deg); } }
@keyframes blinkIcon { 50% { opacity: .2; } }
@keyframes chaseIcon { 0%, 100% { transform: translateX(-3px); } 50% { transform: translateX(3px); } }
@keyframes twinkleIcon { 0%, 100% { transform: scale(.8); opacity: .6; } 50% { transform: scale(1.2); opacity: 1; } }

/* ==========================================================================
   Responsive: tablets in portrait, phones
   ========================================================================== */
@media (orientation: portrait), (max-width: 760px) {
  .app {
    grid-template-areas:
      "top"
      "tabs"
      "stage"
      "palette";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 8px;
  }
  .actions { grid-template-columns: repeat(6, 1fr); }
  .tab--lights { margin-top: 0; }
  .action .lbl { display: none; }
  .action { min-height: 46px; }
  .tabs { flex-direction: row; padding: 6px; overflow-x: auto; }
  .tab { flex: 1 0 84px; min-height: 70px; padding: 4px; }
  .tab-ico { font-size: 1.8rem; height: 34px; }
  .tab-ico img { width: 34px; height: 34px; }
  .tab-lbl { font-size: .85rem; }
  .stage { min-height: 300px; }
  .palette { max-height: 30dvh; padding: 10px; }
  .grid--balls { grid-template-columns: repeat(6, 1fr); }
  .grid--bubu { grid-template-columns: repeat(5, 1fr); }
  .combos { grid-template-columns: repeat(3, 1fr); }
  .modes { grid-template-columns: repeat(4, 1fr); }
  .pal-actions { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .grid--balls { grid-template-columns: repeat(4, 1fr); }
  .grid--bubu { grid-template-columns: repeat(3, 1fr); }
  .combos { grid-template-columns: repeat(2, 1fr); }
  .modes { grid-template-columns: repeat(2, 1fr); }
  .pal-actions { grid-template-columns: 1fr; }
  .counter { min-height: 36px; padding: 2px 10px; font-size: 1rem; }
  .counter b { font-size: 1.2rem; }
  .counter img { width: 24px; height: 24px; }
  .card { padding: 22px 18px 18px; }
}

@media (max-height: 640px) and (orientation: landscape) {
  .tab { min-height: 60px; }
  .tab-ico { font-size: 1.6rem; height: 30px; }
  .tab-ico img { width: 30px; height: 30px; }
  .action { min-height: 44px; }
  .action .lbl { display: none; }
}

/* Calmer motion for users who ask for it; the tree lights keep blinking
   because changing them is the point of the activity. */
@media (prefers-reduced-motion: reduce) {
  .ornament .swing, .gift-wiggle, .gift-glow, .start-tree, .celebrate-bubu,
  .tab--surprise .tab-ico, .tab--surprise::after, .gift-lid { animation: none !important; }
  .confetti { display: none; }
}
