:root { --ink: #eef0fa; --dim: rgba(238, 240, 250, 0.66); --glass: rgba(20, 18, 48, 0.74); --line: rgba(255, 255, 255, 0.14);
  --gold: #ffcf6a; --violet: #b9a2ff; --cyan: #8feaff; --bad: #ff8a8a; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #070616; color: var(--ink); font: 14px/1.45 Inter, system-ui, sans-serif; user-select: none; -webkit-user-select: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: none; }
button:disabled { cursor: default; opacity: 0.4; }
.primary { background: linear-gradient(180deg, #d8c8ff, #8a6af0); color: #160c38; border-radius: 14px; padding: 9px 16px; font: 800 16px 'Baloo 2', sans-serif;
  box-shadow: 0 6px 22px rgba(150, 110, 255, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.55); }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.primary.big { font-size: 22px; padding: 10px 30px; }
.ghost { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; backdrop-filter: blur(6px); }
.ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.16); }
.ghost.icon { padding: 6px 10px; min-width: 36px; }

.screen { position: fixed; inset: 0; display: grid; place-items: center; z-index: 5; padding: 16px; }
#title { background: radial-gradient(ellipse 60% 45% at center, rgba(12, 8, 34, 0.72) 0%, rgba(12, 8, 34, 0.45) 55%, rgba(7, 6, 22, 0.7)); }
.logo { text-align: center; }
.logo h1 { margin: 0; font: 800 clamp(58px, 12vw, 128px)/0.9 'Baloo 2', sans-serif; letter-spacing: -0.02em; text-shadow: 0 0 40px rgba(170, 130, 255, 0.45); }
.logo h1 span { background: linear-gradient(0deg, #fff3c4, #ffcf6a 45%, #b9a2ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo p { color: var(--ink); font-size: 18px; margin: 12px 0 22px; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7); }
.logo .small { font-size: 13px; margin-top: 18px; color: var(--dim); }

#select { background: rgba(7, 6, 22, 0.5); backdrop-filter: blur(6px); }
.selbox { width: min(820px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--glass); border: 1px solid var(--line);
  border-radius: 22px; padding: 18px 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.selhead { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.selhead h2 { flex: 1; margin: 0; font: 800 28px 'Baloo 2', sans-serif; }
.startotal { color: var(--gold); font: 700 18px 'Baloo 2', sans-serif; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.tile { text-align: left; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; display: grid; gap: 2px; transition: transform 0.12s, background 0.12s; }
.tile:hover:not(:disabled) { transform: translateY(-2px); background: rgba(185, 162, 255, 0.14); border-color: rgba(185, 162, 255, 0.6); }
.tile .num { font: 700 12px 'Baloo 2', sans-serif; color: var(--violet); letter-spacing: 0.08em; }
.tile .nm { font-weight: 600; }
.tile .st i { font-style: normal; color: rgba(255, 255, 255, 0.2); }
.tile .st i.on { color: var(--gold); text-shadow: 0 0 8px rgba(255, 207, 106, 0.8); }
.tile.locked { opacity: 0.4; }
.keys { color: var(--dim); font-size: 12.5px; margin: 14px 0 0; text-align: center; }
.keys b { color: var(--ink); font-weight: 600; background: rgba(255, 255, 255, 0.08); border-radius: 5px; padding: 0 5px; }

.topbar { position: fixed; top: 12px; left: 12px; display: flex; gap: 12px; align-items: center; z-index: 3; }
.lvlid { color: var(--violet); font: 700 12px 'Baloo 2', sans-serif; letter-spacing: 0.14em; text-transform: uppercase; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7); }
.lvlname { font: 800 26px/1 'Baloo 2', sans-serif; text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6); }
.topright { position: fixed; top: 12px; right: 12px; display: flex; gap: 8px; align-items: center; z-index: 3; }
.stats { font: 600 13px Inter, sans-serif; color: var(--ink); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8); margin-right: 6px; display: flex; gap: 12px; }
.stats span b { color: var(--cyan); }

.badge { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); display: flex; background: rgba(10, 8, 30, 0.6); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px; z-index: 3; font: 800 14px 'Baloo 2', sans-serif; letter-spacing: 0.08em; text-transform: uppercase; backdrop-filter: blur(6px); }
.badge span { padding: 2px 14px; border-radius: 999px; color: var(--dim); transition: background 0.3s, color 0.3s; }
.badge.globe .g { background: #3a4a9a; color: #fff; box-shadow: 0 0 14px rgba(110, 140, 255, 0.6); }
.badge.cell .c { background: #ffcf6a; color: #2a1604; box-shadow: 0 0 14px rgba(255, 207, 106, 0.6); }

.story { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); width: min(620px, calc(100% - 32px)); text-align: center; z-index: 3;
  background: var(--glass); border: 1px solid var(--line); border-radius: 16px; padding: 10px 16px; backdrop-filter: blur(10px); transition: opacity 0.6s; font-size: 15px; }
.story em { color: var(--gold); font-style: normal; font-weight: 600; }
.story.fade { opacity: 0; pointer-events: none; }
.toast { position: fixed; top: 108px; left: 50%; transform: translateX(-50%); background: rgba(40, 10, 30, 0.85); border: 1px solid rgba(255, 138, 138, 0.5);
  padding: 7px 16px; border-radius: 12px; opacity: 0; transition: opacity 0.3s; z-index: 4; font-weight: 600; pointer-events: none; white-space: nowrap; }
.toast.on { opacity: 1; }

.touch .pad { position: fixed; bottom: 18px; display: flex; gap: 12px; z-index: 4; }
.touch .pad.left { left: 16px; } .touch .pad.right { right: 16px; align-items: flex-end; }
.touch button { width: 70px; height: 70px; border-radius: 50%; background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.25);
  font-size: 26px; backdrop-filter: blur(6px); touch-action: none; }
.touch button.flip { background: rgba(150, 110, 255, 0.35); border-color: rgba(200, 170, 255, 0.7); font-size: 30px; }
.touch button.small { width: 48px; height: 48px; font-size: 20px; position: absolute; top: -60px; left: 11px; }
@media (max-width: 420px) { .touch button:not(.small) { width: 62px; height: 62px; } .touch .pad { gap: 8px; } .touch .pad.left { left: 10px; } .touch .pad.right { right: 10px; } }
.touch button.on { background: rgba(255, 255, 255, 0.32); }
body.touching .story { bottom: 170px; }

#win { background: rgba(7, 6, 22, 0.45); backdrop-filter: blur(4px); }
.winbox { background: var(--glass); border: 1px solid rgba(185, 162, 255, 0.45); border-radius: 24px; padding: 24px 30px; text-align: center; width: min(420px, 100%);
  box-shadow: 0 0 80px rgba(160, 120, 255, 0.3), 0 20px 60px rgba(0, 0, 0, 0.5); animation: rise 0.4s ease-out; }
.wtitle { font: 800 40px/1 'Baloo 2', sans-serif; background: linear-gradient(180deg, #fff3c4, #ffcf6a 55%, #b9a2ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.wstars { font-size: 54px; margin: 8px 0 2px; }
.wstars i { font-style: normal; color: rgba(255, 255, 255, 0.15); display: inline-block; }
.wstars i.on { color: var(--gold); text-shadow: 0 0 20px rgba(255, 207, 106, 0.9); animation: pop 0.5s cubic-bezier(0.2, 1.8, 0.4, 1) backwards; }
.wrows { display: grid; gap: 4px; margin: 6px 0 16px; color: var(--dim); }
.wrows div { display: flex; justify-content: space-between; gap: 12px; }
.wrows div.ok b { color: var(--gold); }
.wbtns { display: grid; gap: 8px; }
.wbtns button:not(.primary) { background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
@keyframes pop { from { transform: scale(0) rotate(-40deg); } to { transform: scale(1) rotate(0); } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(calc(-50% - 6px)); } 40%, 80% { transform: translateX(calc(-50% + 6px)); } }

@media (max-width: 700px) {
  .lvlname { font-size: 20px; } .stats { display: none; }
  .badge { top: 58px; font-size: 12px; }
  .story { font-size: 13.5px; }
}
