:root {
  --ink: #23324a; --ink2: #4c5d78; --teal: #16a39a; --teal-d: #0d7a73; --teal-l: #5fd0c6;
  --sun: #ffcc3d; --sun-d: #e0a417; --cream: #fffaf0; --paper: #ffffff; --coral: #ff6b5a; --coral-d: #d94a3b;
  --ok: #33b864; --ok-d: #23864a; --bad: #ef5a4c; --muted: #9aa7ba;
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --tile: 46px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  position: fixed; inset: 0; overscroll-behavior: none; touch-action: none; color: var(--ink); font-family: var(--font);
  background-color: #1bb3a8;
  background-image:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, .22) 0 2px, transparent 3px),
    radial-gradient(circle at 70% 60%, rgba(255, 255, 255, .16) 0 2px, transparent 3px),
    linear-gradient(170deg, #2cc6b9 0%, #16a39a 55%, #0f8c84 100%);
  background-size: 46px 46px, 46px 46px, 100% 100%;
  user-select: none; -webkit-user-select: none;
}
button { font-family: inherit; cursor: pointer; color: inherit; }
.hidden { display: none !important; }
#app { position: relative; height: 100%; display: flex; flex-direction: column; max-width: 640px; margin: 0 auto; padding: 10px 14px 12px; }

/* header */
#top { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.ib { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 14px; border: 3px solid var(--ink); background: var(--cream); padding: 7px; box-shadow: 0 3px 0 var(--ink); }
.ib svg { width: 100%; height: 100%; display: block; }
.ib:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
#back.off { visibility: hidden; }
#where { flex: 1 1 auto; min-width: 0; color: #fff; line-height: 1.1; text-shadow: 0 2px 0 rgba(0, 0, 0, .18); }
#where b { display: block; font-size: 20px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#where span { display: block; font-size: 13px; font-weight: 700; opacity: .92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#coins { display: flex; align-items: center; gap: 6px; background: var(--ink); color: #fff; border-radius: 22px; padding: 5px 12px 5px 6px; font-weight: 900; font-size: 18px; }
#coins.bump { animation: bump .35s; }
@keyframes bump { 40% { transform: scale(1.2); } }
.coin { display: inline-block; width: 22px; height: 22px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff3a8 0 18%, #ffd23f 20% 60%, #e39b12 62%); border: 2px solid #9a6400; vertical-align: middle; flex: 0 0 auto; }

#main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; margin-top: 10px; }
.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.vh { margin: 2px 0 10px; color: #fff; font-size: 22px; font-weight: 900; text-align: center; text-shadow: 0 2px 0 rgba(0, 0, 0, .18); }
.note { text-align: center; color: #eafffb; font-size: 13px; font-weight: 700; margin: 8px 0 0; }

/* packs */
#packs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; overflow-y: auto; padding: 2px 2px 8px; touch-action: pan-y; }
.pack { position: relative; display: flex; align-items: center; gap: 10px; text-align: left; border: 3px solid var(--ink); border-radius: 18px; background: var(--cream); padding: 10px; box-shadow: 0 4px 0 var(--ink); min-height: 92px; }
.pack:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.pack .pi { width: 64px; height: 64px; flex: 0 0 auto; border-radius: 14px; background-color: #fff; border: 2px solid #d9e2ee; overflow: hidden; }
.pack .pt { min-width: 0; flex: 1 1 auto; }
.pack b { display: block; font-size: 16px; font-weight: 900; line-height: 1.15; }
.pack small { display: block; font-size: 12px; color: var(--ink2); font-weight: 700; margin: 2px 0 6px; }
.bar { height: 9px; border-radius: 6px; background: #dfe6ef; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--ok), #7ad957); border-radius: 6px; }
.pack .cnt { font-size: 12px; font-weight: 800; color: var(--ink2); margin-top: 3px; display: block; }
.pack.done::after { content: "\2713"; position: absolute; top: -9px; right: -7px; width: 28px; height: 28px; border-radius: 50%; background: var(--ok); color: #fff; border: 3px solid var(--ink); font-weight: 900; display: grid; place-items: center; font-size: 15px; }

/* levels */
#levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; overflow-y: auto; padding: 2px 2px 10px; touch-action: pan-y; align-content: start; }
.lv { aspect-ratio: 1; border: 3px solid var(--ink); border-radius: 14px; background: var(--cream); font-size: 20px; font-weight: 900; box-shadow: 0 3px 0 var(--ink); position: relative; }
.lv.solved { background: var(--ok); color: #fff; }
.lv.solved::after { content: "\2605"; position: absolute; right: 3px; bottom: 0; font-size: 12px; color: var(--sun); }
.lv.cur { background: var(--sun); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 3px 0 var(--ink), 0 0 0 5px rgba(255, 204, 61, .5); } }
.lv.lock { background: #c9d4e2; color: #8796ab; box-shadow: 0 3px 0 #7d8ca3; border-color: #7d8ca3; }
.lv.lock::before { content: ""; position: absolute; inset: 0; background: center / 40% no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='5' y='10' width='14' height='10' rx='2' fill='%237d8ca3'/%3E%3Cpath d='M8 10V7a4 4 0 018 0v3' fill='none' stroke='%237d8ca3' stroke-width='2.5'/%3E%3C/svg%3E"); }
.lv.lock span { visibility: hidden; }

/* play */
#ask { display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 52px; }
#kikoMini { width: 56px; height: 56px; object-fit: contain; flex: 0 0 auto; }
#kikoMini.hop { animation: kh .5s; }
@keyframes kh { 40% { transform: translateY(-10px) rotate(-6deg); } }
#askTxt { position: relative; display: inline-block; background: #fff; color: var(--ink); border: 3px solid var(--ink); font-weight: 800; font-size: 15px; padding: 6px 14px; border-radius: 16px; box-shadow: 0 3px 0 rgba(0, 0, 0, .18); max-width: calc(100% - 70px); }
#askTxt::before { content: ""; position: absolute; left: -10px; top: 50%; margin-top: -7px; border: 7px solid transparent; border-right-color: var(--ink); border-left: 0; }
#askTxt.talk { background: var(--sun); }
#pics { flex: 1 1 auto; min-height: 120px; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 0; }
.card { position: relative; background: var(--paper); border: 4px solid var(--ink); border-radius: 20px; box-shadow: 0 5px 0 var(--ink), 0 12px 24px rgba(0, 40, 40, .25); padding: 6px; aspect-ratio: 1; height: 100%; max-height: 260px; max-width: 46%; animation: cardIn .35s backwards; }
#pics.n1 .card { max-width: 78%; max-height: 300px; }
#pics.n3 .card { max-width: 30%; }
.card:nth-child(3) { animation-delay: .08s; } .card:nth-child(5) { animation-delay: .16s; }
@keyframes cardIn { from { transform: scale(.7) rotate(-4deg); opacity: 0; } }
.sp { width: 100%; height: 100%; background-repeat: no-repeat; border-radius: 12px; }
.pi svg { width: 100%; height: 100%; display: block; }
.card svg { width: 100%; height: 100%; display: block; }
.plus { color: #fff; font-size: 34px; font-weight: 900; text-shadow: 0 3px 0 rgba(0, 0, 0, .2); flex: 0 0 auto; }
#pics.n3 .plus { font-size: 26px; }

#slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; padding: 6px 0 12px; }
.word { display: flex; gap: 4px; }
.slot { width: var(--tile); height: calc(var(--tile) * 1.1); border-radius: 10px; border: 3px solid var(--ink); background: rgba(255, 255, 255, .55); display: grid; place-items: center; font-size: calc(var(--tile) * .55); font-weight: 900; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .08); }
.slot.f { background: var(--paper); animation: drop .18s; }
.slot.rv { background: #c9f2d6; color: var(--ok-d); border-color: var(--ok-d); }
.slot.bad { background: #ffd9d4; color: var(--coral-d); border-color: var(--coral-d); }
.slot.good { background: var(--ok); color: #fff; animation: hop .4s backwards; }
.slot.fix { border: 0; background: none; box-shadow: none; width: auto; color: #fff; font-size: calc(var(--tile) * .6); }
@keyframes drop { from { transform: scale(.6); } }
@keyframes hop { 40% { transform: translateY(-10px); } }
#slots.shake { animation: shake .35s; }
@keyframes shake { 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }

#bank { display: grid; grid-template-columns: repeat(var(--cols, 7), var(--tile)); justify-content: center; gap: 7px; padding-bottom: 10px; }
.tile { width: var(--tile); height: var(--tile); border-radius: 11px; border: 3px solid var(--ink); background: var(--sun); font-size: calc(var(--tile) * .52); font-weight: 900; color: var(--ink); box-shadow: 0 4px 0 var(--ink); padding: 0; transition: transform .08s; }
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.tile.used { visibility: hidden; }
.tile.gone { visibility: hidden; }
.tile.press { transform: translateY(3px) scale(.95); box-shadow: 0 1px 0 var(--ink); }

#tools { display: flex; justify-content: center; gap: 8px; }
.tool { display: flex; align-items: center; gap: 6px; border: 3px solid var(--ink); border-radius: 14px; background: var(--cream); padding: 6px 10px; font-weight: 900; font-size: 14px; box-shadow: 0 3px 0 var(--ink); min-height: 46px; }
.tool svg { width: 22px; height: 22px; flex: 0 0 auto; }
.tool em { font-style: normal; display: flex; align-items: center; gap: 3px; background: var(--ink); color: #fff; border-radius: 10px; padding: 2px 7px 2px 3px; font-size: 13px; }
.tool em .coin { width: 16px; height: 16px; border-width: 1.5px; }
.tool.small { padding: 6px 9px; }
.tool:disabled { opacity: .45; cursor: default; }
.tool:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }


/* overlays */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10, 50, 55, .55); z-index: 10; padding: 16px; touch-action: none; }
.panel { position: relative; width: min(420px, 100%); background: var(--cream); border: 4px solid var(--ink); border-radius: 26px; box-shadow: 0 7px 0 var(--ink), 0 20px 40px rgba(0, 0, 0, .3); text-align: center; padding: 70px 22px 20px; animation: pop .3s; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.kikoBig { position: absolute; left: 50%; top: -78px; width: 140px; height: 140px; object-fit: contain; transform: translateX(-50%); }
.panel h1 { margin: 0; font-size: 44px; font-weight: 900; line-height: 1; color: var(--teal-d); letter-spacing: .5px; }
.panel h1 span { color: var(--coral); }
.panel .tag { margin: 4px 0 8px; font-weight: 900; color: var(--ink2); font-size: 16px; }
.panel .intro { margin: 0 0 14px; font-size: 15px; line-height: 1.4; color: var(--ink); }
.panel h2 { margin: 0 0 4px; font-size: 36px; font-weight: 900; color: var(--ok-d); }
.btn { display: block; width: 100%; border: 3px solid var(--ink); border-radius: 18px; background: var(--coral); color: #fff; font-weight: 900; font-size: 20px; padding: 10px; box-shadow: 0 5px 0 var(--ink); margin-top: 8px; }
.btn.big { font-size: 26px; padding: 14px; }
.btn.ghost { background: var(--cream); color: var(--ink); font-size: 16px; padding: 8px; box-shadow: 0 3px 0 var(--ink); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.ctl { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin-top: 12px; font-size: 13px; font-weight: 700; color: var(--ink2); }
kbd { display: inline-block; min-width: 22px; padding: 1px 5px; border: 2px solid var(--ink2); border-bottom-width: 3px; border-radius: 6px; background: #fff; font-family: inherit; font-weight: 900; font-size: 12px; margin-right: 2px; color: var(--ink); }
.small { font-size: 13px; color: var(--ink2); font-weight: 700; margin: 8px 0 0; }
#winAnswer { margin: 6px 0 8px; font-size: 30px; font-weight: 900; color: var(--ink); letter-spacing: 2px; word-break: break-word; }
#winCoins { display: inline-flex; align-items: center; gap: 6px; background: var(--ink); color: #fff; border-radius: 20px; padding: 4px 14px 4px 6px; font-size: 20px; font-weight: 900; }
#winCoins.zero { display: none; }

#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }

@media (pointer: fine) { .touchOnly { display: none; } }
@media (max-height: 700px) {
  #where span { display: none; }
  .vh { font-size: 19px; margin-bottom: 6px; }
  #keysHint { display: none; }
}
@media (max-width: 420px) {
  #app { padding: 8px 10px 10px; }
  .pack { min-height: 80px; padding: 8px; gap: 8px; }
  .pack .pi { width: 50px; height: 50px; }
  .pack b { font-size: 14px; }
  .tool span { display: none; }
  .panel h1 { font-size: 38px; }
}
.lv.nope { animation: shake .3s; }
