:root {
  --ink: #1b1240; --ink2: #5a4f86; --night: #2a1460; --night2: #170a3d; --violet: #6b3fd6; --violet-d: #4a25a6;
  --gold: #ffc93c; --gold-d: #e39a12; --gold-l: #fff1b0; --cream: #fff8ec; --pink: #ff4f8b; --pink-d: #c82763;
  --led: #10265e; --led-l: #2f63d6; --ok: #2fcf74; --ok-d: #168a48; --bad: #ff5f5f;
  --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: var(--night);
  background-image:
    conic-gradient(from 180deg at 50% -10%, rgba(255, 255, 255, .07) 0 6deg, transparent 6deg 18deg, rgba(255, 255, 255, .06) 18deg 24deg, transparent 24deg 36deg, rgba(255, 255, 255, .07) 36deg 42deg, transparent 42deg 318deg, rgba(255, 255, 255, .06) 318deg 324deg, transparent 324deg 336deg, rgba(255, 255, 255, .07) 336deg 342deg, transparent 342deg 354deg, rgba(255, 255, 255, .06) 354deg 360deg),
    radial-gradient(ellipse at 50% 0%, #5b2bc4 0%, #3a1a8a 40%, var(--night2) 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: 660px; margin: 0 auto; padding: 10px 14px 12px; }

#top { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.ib { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 50%; border: 3px solid var(--gold); background: var(--violet-d); color: #fff; padding: 8px; box-shadow: 0 3px 0 #120830; }
.ib svg { width: 100%; height: 100%; display: block; }
.ib:active { transform: translateY(2px); box-shadow: 0 1px 0 #120830; }
#back.off { visibility: hidden; }
#where { flex: 1 1 auto; min-width: 0; color: #fff; line-height: 1.1; }
#where b { display: block; font-size: 20px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--gold); text-shadow: 0 2px 0 #120830; }
#where span { display: block; font-size: 13px; font-weight: 700; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#coins { display: flex; align-items: center; gap: 6px; background: #120830; color: var(--gold); border: 2px solid var(--gold-d); border-radius: 22px; padding: 4px 12px 4px 5px; 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%, #fff6c2 0 18%, #ffd23f 20% 60%, #e39b12 62%); border: 2px solid #8a5600; 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: var(--gold); font-size: 22px; font-weight: 900; text-align: center; text-shadow: 0 2px 0 #120830; }
.note { text-align: center; color: #d9cfff; font-size: 13px; font-weight: 700; margin: 8px 0 0; }

#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(--gold); border-radius: 18px; background: linear-gradient(180deg, #fffaf0, #f3e6ff); padding: 10px; box-shadow: 0 4px 0 var(--gold-d), 0 10px 20px rgba(0, 0, 0, .3); min-height: 92px; }
.pack:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--gold-d); }
.pack .pi { width: 64px; height: 64px; flex: 0 0 auto; border-radius: 14px; background: #fff; border: 2px solid #e0d2ff; 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; color: var(--ink); }
.pack small { display: block; font-size: 12px; color: var(--ink2); font-weight: 700; margin: 2px 0 6px; }
.bar { height: 9px; border-radius: 6px; background: #e3dbf5; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--pink), var(--gold)); border-radius: 6px; }
.pack .cnt { font-size: 12px; font-weight: 800; color: var(--ink2); margin-top: 3px; display: block; }
.pack.done::after { content: "\2605"; position: absolute; top: -10px; right: -8px; width: 30px; height: 30px; border-radius: 50%; background: var(--gold); color: var(--ink); border: 3px solid var(--ink); font-weight: 900; display: grid; place-items: center; font-size: 16px; }
.sp { width: 100%; height: 100%; background-repeat: no-repeat; }

#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(--gold); border-radius: 50%; background: var(--violet-d); color: #fff; font-size: 20px; font-weight: 900; box-shadow: 0 3px 0 #120830; position: relative; }
.lv.solved { background: var(--gold); color: var(--ink); }
.lv.solved::after { content: "\2605"; position: absolute; right: 2px; bottom: -2px; font-size: 13px; color: var(--pink); }
.lv.cur { background: var(--pink); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { box-shadow: 0 3px 0 #120830, 0 0 0 6px rgba(255, 79, 139, .4); } }
.lv.lock { background: #3b2a6e; color: #7d6db0; border-color: #6a5a9e; }
.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='%238d7dc0'/%3E%3Cpath d='M8 10V7a4 4 0 018 0v3' fill='none' stroke='%238d7dc0' stroke-width='2.5'/%3E%3C/svg%3E"); }
.lv.lock span { visibility: hidden; }
.lv.nope { animation: shake .3s; }

#ask { display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 50px; }
#mcMini { width: 56px; height: 56px; object-fit: contain; flex: 0 0 auto; }
#mcMini.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(--gold); font-weight: 800; font-size: 15px; padding: 6px 14px; border-radius: 16px; 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(--gold); border-left: 0; }
#askTxt.talk { background: var(--gold-l); }

#stage { flex: 1 1 auto; min-height: 120px; display: flex; align-items: center; justify-content: center; padding: 6px 0 8px; }
#screen {
  position: relative; padding: 16px; border-radius: 22px;
  background: radial-gradient(circle, #fffbe0 0 2.6px, rgba(255, 251, 224, 0) 3.4px) 1px 1px / 16px 16px, linear-gradient(180deg, #ffd85e, #e39a12);
  box-shadow: 0 6px 0 #8a5600, 0 0 40px rgba(255, 201, 60, .35), 0 14px 30px rgba(0, 0, 0, .45);
  animation: cardIn .35s backwards, blink 1.2s steps(2) infinite;
}
@keyframes blink { 50% { background-position: 9px 9px, 0 0; } }
#pic { display: block; background: #fff; border-radius: 12px; border: 3px solid #8a5600; }
@keyframes cardIn { from { transform: scale(.8); opacity: 0; } }

#slots { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; padding: 4px 0 12px; }
.word { display: flex; gap: 4px; }
.slot { width: var(--tile); height: calc(var(--tile) * 1.1); border-radius: 9px; border: 2px solid var(--led-l); background: var(--led); color: #fff; display: grid; place-items: center; font-size: calc(var(--tile) * .55); font-weight: 900; box-shadow: inset 0 0 10px rgba(47, 99, 214, .6); }
.slot.f { background: #fff; color: var(--ink); border-color: var(--gold); animation: drop .18s; box-shadow: none; }
.slot.rv { background: #d4ffe4; color: var(--ok-d); border-color: var(--ok); }
.slot.bad { background: #ffd9d9; color: #c0262f; border-color: var(--bad); }
.slot.good { background: var(--ok); color: #fff; border-color: #c6ffd9; animation: hop .4s backwards; }
@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: 10px; border: 2px solid #8a5600; background: linear-gradient(180deg, #ffe58a, var(--gold)); font-size: calc(var(--tile) * .52); font-weight: 900; color: var(--ink); box-shadow: 0 4px 0 #8a5600; padding: 0; transition: transform .08s; }
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 #8a5600; }
.tile.used, .tile.gone { visibility: hidden; }
.tile.press { transform: translateY(3px) scale(.95); box-shadow: 0 1px 0 #8a5600; }

#tools { display: flex; justify-content: center; gap: 7px; flex-wrap: wrap; }
.tool { display: flex; align-items: center; gap: 6px; border: 2px solid var(--gold); border-radius: 14px; background: var(--violet-d); color: #fff; padding: 6px 10px; font-weight: 900; font-size: 14px; box-shadow: 0 3px 0 #120830; 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: #120830; color: var(--gold); border-radius: 10px; padding: 2px 7px 2px 3px; font-size: 13px; }
.tool.friend { background: var(--pink); border-color: #ffd0e0; }
.tool.friend em { padding: 2px 7px; color: #fff; background: var(--pink-d); }
.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 #120830; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(12, 4, 36, .65); z-index: 10; padding: 16px; touch-action: none; overflow: auto; }
.panel { position: relative; width: min(430px, 100%); background: linear-gradient(180deg, #fffaf0, #f1e6ff); border: 4px solid var(--gold); border-radius: 26px; box-shadow: 0 7px 0 var(--gold-d), 0 0 50px rgba(255, 201, 60, .3), 0 20px 40px rgba(0, 0, 0, .4); text-align: center; padding: 84px 22px 20px; margin-top: 70px; animation: pop .3s; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.mcBig { position: absolute; left: 50%; top: -86px; width: 165px; height: 165px; object-fit: contain; transform: translateX(-50%); filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .3)); }
#win .mcBig { width: 140px; height: 140px; top: -74px; }
#win .panel { padding-top: 70px; }
.panel h1 { margin: 0; font-size: 40px; font-weight: 900; line-height: 1.02; color: var(--violet-d); }
.panel h1 span { color: var(--pink); display: block; }
.panel .tag { margin: 6px 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: 34px; font-weight: 900; color: var(--ok-d); }
.btn { display: block; width: 100%; border: 3px solid var(--ink); border-radius: 18px; background: linear-gradient(180deg, #ff77a6, var(--pink)); color: #fff; font-weight: 900; font-size: 20px; padding: 10px; box-shadow: 0 5px 0 var(--ink); margin-top: 8px; text-shadow: 0 2px 0 rgba(0, 0, 0, .2); }
.btn.big { font-size: 26px; padding: 14px; }
.btn.ghost { background: #fff; color: var(--ink); font-size: 16px; padding: 8px; box-shadow: 0 3px 0 var(--ink); text-shadow: none; }
.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: 4px 0 6px; font-size: 28px; font-weight: 900; color: var(--violet-d); letter-spacing: 1px; word-break: break-word; line-height: 1.15; }
#winExp { margin: 0 0 4px; font-size: 14px; font-weight: 800; color: var(--ink2); }
#winMean { margin: 0 0 10px; font-size: 14px; line-height: 1.35; color: var(--ink); background: #fff; border: 2px dashed #d6c6ff; border-radius: 12px; padding: 6px 10px; }
#winMean:empty, #winExp:empty { display: none; }
#winCoins { display: inline-flex; align-items: center; gap: 6px; background: var(--ink); color: var(--gold); border-radius: 20px; padding: 4px 14px 4px 6px; font-size: 20px; font-weight: 900; }
#winCoins.zero { display: none; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; background: #120830; color: #fff; border: 2px solid var(--gold); border-radius: 14px; padding: 10px 16px; font-weight: 800; font-size: 14px; max-width: calc(100% - 32px); text-align: center; animation: pop .25s; }
#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; }
  #ask { min-height: 40px; }
  #mcMini { width: 44px; height: 44px; }
}
@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 { font-size: 13px; padding: 6px 8px; gap: 4px; }
  .tool svg { display: none; }
  .tool.friend em { display: none; }
  .tool.small svg { display: block; }
  .panel h1 { font-size: 34px; }
  #screen { padding: 12px; }
}
