:root {
  --lego-yellow: #FFCF00; --lego-red: #D01012; --lego-blue: #0055BF;
  --lego-green: #00852B; --cream: #FFF9E8; --ink: #1b1b1f;
  --panel: #ffffff; --line: #e3d9b8;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; color: var(--ink);
  font-family: "Baloo 2", "Comic Sans MS", "Segoe UI", system-ui, sans-serif;
  touch-action: none; user-select: none; font-weight: 700; }
canvas#game { position: fixed; inset: 0; display: block; }
.hidden { display: none !important; }

/* ---------- topbar: big friendly LEGO buttons ---------- */
#topbar { position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 30; display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  background: var(--lego-yellow); border: 3px solid #d9a800; border-radius: 18px;
  box-shadow: 0 6px 0 #c69a00, 0 10px 24px #0006; max-width: calc(100vw - 16px); }
.logo { font-weight: 900; font-size: 17px; color: var(--lego-red); letter-spacing: .5px;
  margin-right: 4px; text-shadow: 0 1px 0 #fff8; white-space: nowrap; }
.tb-group { display: flex; gap: 5px; }
.lego-btn { min-width: 38px; height: 36px; padding: 0 10px; font: inherit; font-size: 15px;
  background: var(--lego-red); color: #fff; border: 2px solid #a30c0e; border-radius: 12px;
  cursor: pointer; box-shadow: 0 3px 0 #a30c0e; transition: transform .08s, box-shadow .08s; }
.lego-btn:hover { transform: translateY(-2px); box-shadow: 0 5px 0 #a30c0e; }
.lego-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #a30c0e; }
.lego-btn.blue { background: var(--lego-blue); border-color: #003d8a; box-shadow: 0 3px 0 #003d8a; }
.lego-btn.blue:hover { box-shadow: 0 5px 0 #003d8a; } .lego-btn.blue:active { box-shadow: 0 1px 0 #003d8a; }
.lego-btn.green { background: var(--lego-green); border-color: #006020; box-shadow: 0 3px 0 #006020; }
.lego-btn.green:hover { box-shadow: 0 5px 0 #006020; } .lego-btn.green:active { box-shadow: 0 1px 0 #006020; }
select { height: 36px; font: inherit; font-size: 13px; background: #fff; color: var(--ink);
  border: 2px solid #d9a800; border-radius: 12px; padding: 0 8px; outline: none; cursor: pointer; }
#stats { margin-left: 4px; color: #6b4d00; font-size: 13px; white-space: nowrap; }
#stats span { color: var(--lego-red); font-size: 15px; }

/* ---------- left palette: white friendly panel ---------- */
#palette { position: fixed; top: 72px; left: 10px; width: 138px; z-index: 30;
  background: var(--cream); border: 3px solid var(--line); border-radius: 18px;
  padding: 10px; max-height: calc(100vh - 96px); overflow-y: auto;
  box-shadow: 0 8px 22px #0004; }
#palette::-webkit-scrollbar { width: 8px; } #palette::-webkit-scrollbar-thumb { background: #d9a800; border-radius: 4px; }
.p-title { font-size: 11px; color: #9a7d1a; letter-spacing: 1px; margin: 9px 0 6px; font-weight: 900; }
.p-title:first-child { margin-top: 0; }
.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.tool { height: 34px; font-size: 16px; background: #fff; border: 2px solid var(--line);
  border-radius: 10px; cursor: pointer; transition: transform .08s; }
.tool:hover { transform: scale(1.08); }
.tool.sel { border-color: var(--lego-red); background: #ffe9e9; box-shadow: 0 0 0 2px #f5baba; }
#brick-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.bshape { position: relative; height: 36px; background: #fff; border: 2px solid var(--line);
  border-radius: 10px; cursor: pointer; transition: transform .08s; }
.bshape:hover { transform: scale(1.08); }
.bshape.sel { border-color: var(--lego-blue); box-shadow: 0 0 0 2px #bcd7f7; }
.bshape canvas { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 8px; }
.inv-count { position: absolute; top: -7px; right: -5px; background: var(--lego-red); color: #fff;
  border-radius: 9px; padding: 1px 6px; font-size: 10px; font-weight: 900; z-index: 2;
  box-shadow: 0 2px 0 #a30c0e; }
#color-list { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.swatch { aspect-ratio: 1; border-radius: 8px; cursor: pointer; border: 2px solid #0003;
  box-shadow: inset 0 -3px 0 #0002; transition: transform .08s; }
.swatch:hover { transform: scale(1.15); }
.swatch.sel { border-color: var(--ink); box-shadow: 0 0 0 3px #ffcf00, inset 0 -3px 0 #0002; }
.layers { display: flex; gap: 5px; }
.layers button { flex: 1; height: 30px; font: inherit; background: #fff;
  border: 2px solid var(--line); border-radius: 10px; cursor: pointer; }
.layers button.sel { border-color: var(--lego-red); color: var(--lego-red); }
.hint { margin-top: 10px; font-size: 10px; color: #9a7d1a; line-height: 1.6; font-weight: 600; }
#rank { margin-top: 8px; text-align: center; background: #fff; border: 2px solid var(--line);
  border-radius: 12px; padding: 6px 4px; font-size: 11px; }
#rank b { color: var(--lego-red); font-size: 13px; display: block; }

/* ---------- tips / toasts ---------- */
#tipbar { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 3px solid var(--lego-yellow); border-radius: 16px;
  padding: 8px 18px; font-size: 13px; z-index: 25; box-shadow: 0 6px 18px #0004;
  max-width: min(92vw, 560px); text-align: center; }
#tipbar b { color: var(--lego-blue); }
#toast-wrap { position: fixed; top: 66px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: var(--lego-yellow); border: 3px solid #d9a800; color: #5a3d00;
  padding: 8px 18px; border-radius: 14px; font-size: 14px; box-shadow: 0 5px 0 #c69a00;
  animation: bounceIn .35s, toast 2.8s .2s forwards; }
@keyframes bounceIn { 0% { transform: scale(.6); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes toast { 0% {opacity:1;} 80% {opacity:1;} 100% {opacity:0;} }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; background: #1b2a3488; z-index: 70;
  display: flex; align-items: center; justify-content: center; }
.modal-box { background: var(--cream); border: 3px solid var(--lego-yellow); border-radius: 20px;
  padding: 20px; width: 400px; max-width: 92vw; box-shadow: 0 14px 40px #0007; }
.modal-box h2 { color: var(--lego-red); margin-bottom: 12px; font-size: 20px; }
.savecard { display: flex; align-items: center; gap: 10px; background: #fff;
  border: 2px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.savecard b { flex: 1; } .savecard small { color: #9a7d1a; font-weight: 600; }
.savecard button { min-width: 36px; height: 32px; background: var(--lego-yellow);
  border: 2px solid #d9a800; border-radius: 10px; cursor: pointer; font-size: 14px; }
.modal-box .btn { margin-top: 10px; width: 100%; height: 40px; font: inherit; font-size: 15px;
  background: var(--lego-blue); color: #fff; border: 2px solid #003d8a; border-radius: 12px;
  cursor: pointer; box-shadow: 0 3px 0 #003d8a; }

#mobile-hint { display: none; }

/* ---------- puzzle HUD ---------- */
#puzzle-hud { position: fixed; top: 66px; left: 50%; transform: translateX(-50%);
  z-index: 28; display: flex; align-items: center; gap: 10px;
  background: var(--cream); border: 3px solid var(--lego-yellow); border-radius: 16px;
  padding: 7px 12px; box-shadow: 0 6px 18px #0004; }
.ph-info { font-size: 13px; color: #6b4d00; white-space: nowrap; }
.ph-info span:first-child { color: var(--lego-red); font-size: 14px; }
.ph-buttons { display: flex; gap: 5px; }
.ph-buttons .lego-btn { height: 30px; min-width: 0; font-size: 12px; padding: 0 9px; }

/* ---------- menu ---------- */
#menu { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center;
  justify-content: center; background: linear-gradient(180deg, #63b8f2, #a8dcff); }
.menu-box { background: var(--cream); border: 4px solid var(--lego-yellow); border-radius: 26px;
  padding: 28px; width: 560px; max-width: 94vw; max-height: 90vh; overflow: auto;
  box-shadow: 0 16px 44px #0007; text-align: center; }
.menu-box h1 { color: var(--lego-red); font-size: 34px; }
.menu-box .tag { color: #9a7d1a; margin: 4px 0 18px; font-size: 15px; }
.mode-cards { display: flex; gap: 12px; justify-content: center; margin-bottom: 16px; }
.mode-card { flex: 1; max-width: 240px; padding: 18px 12px; background: #fff;
  border: 3px solid var(--line); border-radius: 18px; cursor: pointer;
  transition: transform .1s, border-color .1s; font: inherit; }
.mode-card:hover { transform: translateY(-3px); border-color: var(--lego-red); }
.mode-card .mc-icon { font-size: 42px; display: block; margin-bottom: 6px; }
.mode-card b { color: var(--lego-blue); font-size: 16px; display: block; }
.mode-card small { color: #9a7d1a; font-weight: 600; }
#level-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 10px 0; }
.level-card { aspect-ratio: 1; background: #fff; border: 3px solid var(--line); border-radius: 14px;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font: inherit; transition: transform .1s; }
.level-card:hover { transform: scale(1.06); border-color: var(--lego-yellow); }
.level-card .lc-num { font-size: 22px; font-weight: 900; color: var(--lego-red); }
.level-card .lc-emoji { font-size: 18px; }
.level-card .lc-stars { font-size: 10px; color: #d9a800; }
.level-card.locked { opacity: .45; cursor: not-allowed; }

/* ---------- victory ---------- */
#victory { position: fixed; inset: 0; z-index: 90; background: #1b2a3499;
  display: flex; align-items: center; justify-content: center; }
.victory-box { background: var(--cream); border: 4px solid var(--lego-yellow); border-radius: 24px;
  padding: 28px 40px; text-align: center; box-shadow: 0 16px 44px #0008;
  animation: bounceIn .4s; }
.victory-box .stars { font-size: 42px; letter-spacing: 4px; }
.victory-box h2 { color: var(--lego-red); font-size: 26px; margin: 8px 0 4px; }
.victory-box p { color: #6b4d00; margin-bottom: 16px; font-size: 14px; }
.v-buttons { display: flex; gap: 8px; justify-content: center; }

@media (max-width: 760px) {
  #palette { width: 112px; padding: 8px; }
  .logo { font-size: 14px; }
  #topbar { gap: 5px; padding: 6px 8px; overflow-x: auto; }
  .lego-btn { min-width: 34px; height: 32px; padding: 0 8px; }
  #tipbar { font-size: 11px; padding: 6px 12px; bottom: 6px; }
  #stats { font-size: 11px; }
}
