* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9fe3a0; font-family: "Comic Sans MS", "Chalkboard SE", "Baloo 2", "Segoe UI Rounded", system-ui, sans-serif; color: #4b2c7a; user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#game { position: fixed; inset: 0; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; cursor: pointer; border: none; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; padding: 12px; display: flex; justify-content: space-between; align-items: flex-start; }
.hud-left { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.hud-right { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.pill { background: rgba(255,255,255,.92); border-radius: 999px; padding: 6px 16px; font-size: 26px; font-weight: 800; box-shadow: 0 4px 0 #d8c3f5, 0 6px 16px rgba(80,40,140,.18); }
.pill.stars { color: #e08a00; }
.pill.stars.bump { animation: bump .5s; }
@keyframes bump { 40% { transform: scale(1.3); } }
.crystals { display: flex; gap: 6px; padding: 8px 12px; }
.crystals span { width: 26px; height: 32px; clip-path: polygon(50% 0, 100% 35%, 50% 100%, 0 35%); background: #e3dcef; transition: transform .3s; }
.crystals span.on { transform: scale(1.15); filter: drop-shadow(0 0 6px #fff); }
.objective { background: rgba(75,44,122,.82); color: #fff; padding: 6px 14px; border-radius: 14px; font-size: 16px; max-width: 360px; }
#minimap { width: 180px; height: 135px; border-radius: 16px; border: 4px solid #fff; box-shadow: 0 6px 16px rgba(80,40,140,.25); background: #bdf0bd; }
.hud-btns { display: flex; gap: 6px; pointer-events: auto; }
.icon-btn { width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.92); font-size: 22px; box-shadow: 0 3px 0 #d8c3f5; }
.icon-btn.off { opacity: .45; }

/* Controls */
#controls { position: fixed; left: 0; right: 0; bottom: 0; pointer-events: none; padding: 12px; }
.book-btn { pointer-events: auto; position: absolute; left: 50%; transform: translateX(-50%); bottom: 14px; display: flex; align-items: center; gap: 10px; padding: 8px 22px 8px 8px; border-radius: 999px; font-size: 20px; font-weight: 800; color: #fff; background: linear-gradient(135deg, #ff6fb5, #a66bff); box-shadow: 0 6px 0 #7b3fd0, 0 10px 24px rgba(120,60,200,.4); line-height: 1.05; text-align: left; }
.book-btn img { width: 58px; height: 58px; border-radius: 50%; border: 3px solid #fff; }
.book-btn.pulse { animation: pulse 0.8s 4; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.12); box-shadow: 0 6px 0 #7b3fd0, 0 0 40px #ffe066; } }
.powers { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 10px; align-items: flex-end; pointer-events: auto; }
.power { position: relative; width: 82px; height: 82px; border-radius: 22px; background: rgba(255,255,255,.95); box-shadow: 0 5px 0 #c9b2ef, 0 8px 18px rgba(80,40,140,.25); display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
.power .ico { font-size: 32px; line-height: 1; }
.power .lbl { font-size: 14px; font-weight: 800; }
.power .cost { font-size: 11px; color: #e08a00; font-weight: 700; }
.power .timer { position: absolute; inset: 0; background: conic-gradient(rgba(255,215,0,.45) var(--p, 0%), transparent 0); pointer-events: none; }
.power.active { box-shadow: 0 5px 0 #f0b400, 0 0 24px #ffe066; }
.power.bubble { width: 96px; height: 96px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff, #c8f0ff); }
.power:active { transform: translateY(3px); }
.power.action { width: auto; padding: 0 18px; font-size: 20px; font-weight: 800; background: #ffe066; box-shadow: 0 5px 0 #e0a800; animation: wob 1s infinite; }
@keyframes wob { 50% { transform: scale(1.06); } }
.keys-help { position: absolute; left: 14px; bottom: 14px; font-size: 12px; background: rgba(255,255,255,.75); padding: 4px 10px; border-radius: 10px; }
@media (pointer: coarse) { .keys-help { display: none; } }
@media (max-width: 700px) {
  .power { width: 64px; height: 64px; } .power.bubble { width: 76px; height: 76px; } .power .ico { font-size: 24px; }
  .book-btn { bottom: 96px; left: auto; right: 14px; transform: none; font-size: 15px; } .book-btn img { width: 44px; height: 44px; }
  @keyframes pulse { 50% { transform: scale(1.12); } }
  #minimap { width: 120px; height: 90px; } .pill { font-size: 20px; } .objective { font-size: 13px; max-width: 200px; }
}

/* Dialog */
#dialog { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); width: min(760px, calc(100% - 24px)); background: #fff; border-radius: 26px; padding: 14px; display: flex; gap: 14px; align-items: center; box-shadow: 0 8px 0 #d8c3f5, 0 16px 40px rgba(80,40,140,.35); border: 4px solid #ffb3d9; z-index: 20; cursor: pointer; animation: pop .25s; }
@keyframes pop { from { transform: translateX(-50%) scale(.8); opacity: 0; } }
.portrait { flex: none; width: 96px; height: 96px; border-radius: 50%; background: #f3e9ff; display: flex; align-items: center; justify-content: center; font-size: 60px; overflow: hidden; border: 4px solid #e2cffb; }
.portrait img { width: 100%; height: 100%; object-fit: cover; }
.dname { font-weight: 800; color: #ff5fa2; font-size: 18px; }
.dtext { font-size: 22px; line-height: 1.3; margin-top: 2px; }
.dnext { text-align: right; font-size: 13px; opacity: .6; animation: wob 1s infinite; }

/* Toast */
#toast { position: fixed; top: 76px; left: 50%; transform: translateX(-50%); background: #fff; padding: 10px 18px; border-radius: 18px; font-size: 18px; font-weight: 700; box-shadow: 0 6px 18px rgba(80,40,140,.3); z-index: 15; max-width: calc(100% - 24px); display: flex; gap: 10px; align-items: center; animation: drop .3s; pointer-events: none; }
#toast img { width: 40px; height: 40px; border-radius: 50%; }
@keyframes drop { from { transform: translate(-50%, -20px); opacity: 0; } }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(75,44,122,.45); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 12px; }
.book { background: linear-gradient(#fffaf0, #fff3fb); border-radius: 30px; padding: 18px 22px; width: min(820px, 100%); max-height: 100%; overflow-y: auto; box-shadow: 0 10px 0 #c9a6f5, 0 20px 50px rgba(60,20,120,.4); border: 5px solid #ffcde6; animation: pop2 .3s; }
@keyframes pop2 { from { transform: scale(.85); opacity: 0; } }
.book-head { display: flex; align-items: center; gap: 12px; }
.book-head img { width: 64px; height: 64px; border-radius: 50%; border: 3px solid #ffb3d9; }
.book-title { flex: 1; font-size: 24px; font-weight: 800; }
.book-title small { display: block; font-size: 14px; font-weight: 400; opacity: .75; }
.gate-pips { text-align: center; font-size: 28px; margin-top: 8px; }
.q-text { font-size: 32px; font-weight: 800; text-align: center; margin: 16px 0 6px; line-height: 1.25; }
.q-visual { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px; min-height: 10px; margin: 6px 0; }
.vis-svg { width: 190px; height: 190px; }
.vis-svg.grid { width: 210px; height: 210px; }
.emoji-row { font-size: 30px; letter-spacing: 2px; max-width: 300px; text-align: center; }
.plus { font-size: 34px; font-weight: 800; }
.groups { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.grp { font-size: 26px; background: #fff; border: 3px dashed #ffb3d9; border-radius: 16px; padding: 4px 8px; }
.big-seq { font-size: 38px; font-weight: 800; letter-spacing: 3px; text-align: center; }
.machine { font-size: 34px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.machine .box { background: #8fd3ff; color: #fff; border-radius: 16px; padding: 10px 18px; }
.coins { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.coin { width: 74px; height: 74px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 800; color: #6b4a00; box-shadow: inset 0 -6px 0 rgba(0,0,0,.15), 0 3px 6px rgba(0,0,0,.2); border: 3px solid rgba(0,0,0,.12); }
.coin.c1, .coin.c2 { background: #e8a46a; width: 60px; height: 60px; font-size: 18px; }
.coin.c5, .coin.c10 { background: #dcdcdc; color: #444; }
.coin.c20, .coin.c50 { background: #e6e6e6; color: #444; border-radius: 30%; }
.base10 { display: flex; align-items: flex-end; gap: 5px; }
.base10 .ten { width: 16px; height: 140px; background: repeating-linear-gradient(#7fd0ff 0 12px, #4aa8f0 12px 14px); border-radius: 4px; }
.base10 .one { width: 16px; height: 14px; background: #ff8fc7; border-radius: 3px; }
.base10 .gap { width: 14px; }
.q-opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 12px; }
.q-opts button { font-size: 30px; font-weight: 800; padding: 16px 10px; border-radius: 22px; background: #fff; border: 4px solid #d8c3f5; box-shadow: 0 6px 0 #d8c3f5; min-height: 76px; }
.q-opts button:hover { background: #fff5fb; }
.q-opts button.long { font-size: 20px; }
.q-opts button.right { background: #7fe0b0; border-color: #3fbf83; box-shadow: 0 6px 0 #3fbf83; color: #fff; animation: bump .5s; }
.q-opts button.wrong { background: #ffd0d8; border-color: #ff8fa3; box-shadow: 0 6px 0 #ff8fa3; animation: shake .4s; opacity: .6; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.q-feedback { text-align: center; font-size: 22px; font-weight: 700; min-height: 34px; margin-top: 12px; }
.q-feedback.good { color: #2f9e6a; } .q-feedback.try { color: #e0567a; }
.q-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.big-btn { font-size: 26px; font-weight: 800; color: #fff; padding: 14px 34px; border-radius: 999px; background: linear-gradient(135deg, #ff6fb5, #a66bff); box-shadow: 0 6px 0 #7b3fd0; }
.big-btn:active, .soft-btn:active { transform: translateY(3px); }
.soft-btn { font-size: 18px; font-weight: 700; padding: 12px 20px; border-radius: 999px; background: #fff; border: 3px solid #d8c3f5; box-shadow: 0 4px 0 #d8c3f5; }
.soft-btn.danger { color: #d33; }

/* Title */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 30%, rgba(255,255,255,.55), rgba(190,150,255,.55)); z-index: 40; padding: 12px; }
.title-card { text-align: center; background: rgba(255,255,255,.9); border-radius: 36px; padding: 26px 34px; box-shadow: 0 12px 0 #d2b4fb, 0 24px 60px rgba(80,40,140,.35); max-width: 560px; }
.title-faces { display: flex; justify-content: center; align-items: flex-end; gap: 4px; }
.face { width: 110px; height: 110px; border-radius: 50%; border: 5px solid #fff; box-shadow: 0 6px 18px rgba(80,40,140,.3); }
.face.big { width: 140px; height: 140px; animation: wob 1.6s infinite; }
h1 { margin: 10px 0 0; font-size: 48px; color: #ff5fa2; text-shadow: 0 4px 0 #ffd6ea; }
h2 { margin: 0 0 10px; font-size: 26px; }
.title-card p { font-size: 18px; }
.title-card .big-btn { margin: 8px; }
.ver { font-size: 12px; opacity: .6; margin-top: 10px; }

/* Parents */
.parents-book h3 { margin: 0 0 8px; font-size: 26px; }
.parents-book h4 { margin: 12px 0 6px; }
.parents-book label { display: block; font-size: 17px; margin: 4px 0; }
.p-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .p-cols { grid-template-columns: 1fr; } }
.p-row { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.p-row label { display: inline-block; }
#pGateIn { font-size: 24px; width: 120px; padding: 8px; border-radius: 12px; border: 3px solid #d8c3f5; margin-right: 8px; }
#pStats table { border-collapse: collapse; width: 100%; font-size: 15px; }
#pStats td, #pStats th { padding: 4px 8px; border-bottom: 1px solid #eadff8; text-align: left; }

/* Win */
.win-book { text-align: center; }
.win-rainbow { font-size: 90px; animation: wob 1s infinite; }
.win-book h2 { font-size: 38px; color: #ff5fa2; }
.win-book p { font-size: 20px; }
.next { background: #e6f4ff; padding: 10px; border-radius: 16px; }

/* Level pick */
.level-pick { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 10px; }
.level-card { display: flex; align-items: center; gap: 14px; text-align: left; padding: 12px 18px; border-radius: 22px; color: #fff; box-shadow: 0 6px 0 rgba(0,0,0,.18); }
.level-card.meadow { background: linear-gradient(135deg, #ff7eb6, #a66bff); }
.level-card.snow { background: linear-gradient(135deg, #5fb8ff, #8a7bff); }
.level-card:disabled { filter: grayscale(.8); opacity: .6; cursor: not-allowed; }
.level-card:not(:disabled):active { transform: translateY(3px); }
.lc-ico { font-size: 42px; }
.lc-txt b { display: block; font-size: 22px; }
.lc-txt small { font-size: 14px; opacity: .95; }
#fade { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .6s; z-index: 60; }
#fade.on { opacity: 1; }
body[data-level="snow"] .objective { background: rgba(40,80,150,.82); }

.level-card.toytown { background: linear-gradient(135deg, #ffb020, #ff6b8a); }
body[data-level="toytown"] .objective { background: rgba(180,60,90,.85); }

/* Robot programming */
.rb-wrap { display: flex; gap: 18px; justify-content: center; align-items: flex-start; flex-wrap: wrap; margin-top: 10px; }
.rb-grid { display: grid; grid-template-columns: repeat(5, 58px); grid-template-rows: repeat(5, 58px); gap: 4px; background: #e8ddff; padding: 6px; border-radius: 18px; }
.rb-grid .cell { border-radius: 10px; background: #fffaf0; display: flex; align-items: center; justify-content: center; font-size: 34px; }
.rb-grid .cell.alt { background: #fff0f8; }
.rb-grid .cell.trail { background: #d6f5e6; }
.rb-grid .cell.bump { background: #ffd0d8; animation: shake .4s; }
.rb-side { display: flex; flex-direction: column; gap: 10px; align-items: center; min-width: 230px; }
.rb-label { font-weight: 800; }
.rb-prog { min-height: 56px; width: 240px; background: #fff; border: 3px dashed #d8c3f5; border-radius: 16px; padding: 6px; display: flex; flex-wrap: wrap; gap: 4px; font-size: 26px; }
.rb-prog span { background: #f3e9ff; border-radius: 8px; padding: 0 4px; }
.rb-prog span.now { background: #ffe066; transform: scale(1.15); }
.rb-arrows { display: grid; grid-template-columns: repeat(3, 64px); gap: 6px; }
.rb-arrows button { height: 60px; font-size: 30px; border-radius: 16px; background: #fff; border: 3px solid #d8c3f5; box-shadow: 0 4px 0 #d8c3f5; }
.rb-arrows button:active { transform: translateY(3px); }
.rb-ctrl { display: flex; gap: 8px; }
.rb-ctrl .soft-btn { font-size: 15px; padding: 8px 14px; }
@media (max-width: 600px) { .rb-grid { grid-template-columns: repeat(5, 48px); grid-template-rows: repeat(5, 48px); } }

/* Confetti */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
#confetti i { position: absolute; top: -20px; width: 12px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
