:root {
    --ink: #2d2654;
    --ink-soft: #6b6491;
    --card: rgba(255, 255, 255, .78);
    --go: #2ec4a0;
    --go-dark: #1b9479;
    --btn: #7a6cff;
    --btn-dark: #5446d6;
    --ok: #3ddc84;
    --warn: #ffb627;
    --danger: #ff5d73;
    --gold: #ffc93c;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    font-family: "Fredoka", "Baloo 2", "Arial Rounded MT Bold", sans-serif;
    color: var(--ink);
    background: linear-gradient(160deg, #a6e1ff 0%, #d9ccff 55%, #ffd9ec 100%) fixed;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    touch-action: manipulation;
}

#c {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

button { font: inherit; color: inherit; cursor: pointer; border: 0; }

/* ---------- pills / HUD ---------- */

.pill {
    background: var(--card);
    backdrop-filter: blur(8px);
    border-radius: 999px;
    padding: 6px 16px;
    font-weight: 600;
    font-size: 18px;
    box-shadow: 0 4px 0 rgba(45, 38, 84, .12);
}
.pill.icon { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; font-size: 20px; }
.pill.icon:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(45, 38, 84, .12); }

#mute { position: fixed; right: 12px; bottom: 12px; z-index: 30; }

#hud {
    position: fixed;
    top: 0; left: 0; right: 0;
    padding: 12px 12px 0;
    z-index: 10;
    pointer-events: none;
    opacity: 0;
    transform: translateY(-30px);
    transition: opacity .3s, transform .4s cubic-bezier(.3, 1.6, .5, 1);
}
#hud.open { opacity: 1; transform: none; }
#hud.open .pill { pointer-events: auto; }
.hud-bar { display: flex; gap: 8px; align-items: center; max-width: 620px; margin: 0 auto; }
.hud-bar .score { margin-left: auto; min-width: 84px; text-align: center; font-size: 22px; color: #b07800; }
.hud-bar .score::before { content: "⭐ "; }
.bump { animation: bump .35s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); } 100% { transform: scale(1); } }

#timer {
    max-width: 620px;
    margin: 10px auto 0;
    height: 14px;
    border-radius: 99px;
    background: rgba(255, 255, 255, .6);
    overflow: hidden;
    box-shadow: inset 0 2px 0 rgba(45, 38, 84, .1);
}
#timer-fill {
    height: 100%;
    border-radius: 99px;
    transform-origin: left;
    background: var(--ok);
    transition: background-color .3s;
}
#timer-fill[data-level="warn"] { background: var(--warn); }
#timer-fill[data-level="danger"] { background: var(--danger); animation: pulse .4s infinite alternate; }
@keyframes pulse { to { filter: brightness(1.25); } }

#combo {
    position: absolute;
    left: 50%;
    top: 12px;
    transform: translateX(-50%) scale(0);
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(180deg, #ff9f43, #ff5d73);
    padding: 4px 16px;
    border-radius: 99px;
    box-shadow: 0 4px 0 #c63c55;
    transition: transform .3s cubic-bezier(.3, 1.8, .5, 1);
}
#combo.on { transform: translateX(-50%) scale(1); }
#combo.on.bump { animation: combo-bump .35s cubic-bezier(.3, 1.8, .5, 1); }
#combo small { font-size: 16px; opacity: .9; }
@keyframes combo-bump { 40% { transform: translateX(-50%) scale(1.3) rotate(-6deg); } }

/* ---------- floating text / labels ---------- */

#fx { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }

.float {
    position: absolute;
    transform: translate(-50%, -50%);
    font-size: 44px;
    font-weight: 700;
    color: #fff;
    -webkit-text-stroke: 2px var(--ink);
    paint-order: stroke fill;
    text-shadow: 0 4px 0 rgba(45, 38, 84, .3);
    white-space: nowrap;
    animation: float-up 1.3s cubic-bezier(.2, .8, .3, 1) forwards;
}
.float.points { color: var(--gold); font-size: 52px; }
.float.points.small { font-size: 34px; color: #fff; }
.float.tag { font-size: 26px; color: #fff; -webkit-text-stroke: 0; background: var(--btn); padding: 4px 14px; border-radius: 99px; box-shadow: 0 4px 0 var(--btn-dark); text-shadow: none; }
.float.tag.big { font-size: 32px; background: linear-gradient(180deg, #ff9f43, #ff5d73); box-shadow: 0 4px 0 #c63c55; }
@keyframes float-up {
    0% { transform: translate(-50%, -20%) scale(.3); opacity: 0; }
    20% { transform: translate(-50%, -90%) scale(1.15); opacity: 1; }
    70% { opacity: 1; }
    100% { transform: translate(-50%, -190%) scale(1); opacity: 0; }
}

.vlabel {
    position: absolute;
    left: -100px; top: -100px;
    transform: translate(-50%, -50%);
    font-size: 22px;
    font-weight: 700;
    color: var(--ink);
    background: #fff;
    border-radius: 99px;
    padding: 0 10px;
    box-shadow: 0 3px 0 rgba(45, 38, 84, .18);
    animation: label-in .4s cubic-bezier(.3, 1.8, .5, 1) both;
    transition: opacity .3s;
}
.vlabel.big { font-size: 30px; background: var(--gold); }
.vlabel.out { opacity: 0; }
#title .word { white-space: nowrap; animation: none; }
.vlabel.hint { font-size: 26px; padding: 2px 16px; background: #fff3c4; color: #8a4b00; box-shadow: 0 4px 0 #f0c64a; white-space: nowrap; }
@keyframes label-in { from { scale: 0; } to { scale: 1; } }

/* ---------- screens & cards ---------- */

.screen {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 20;
    pointer-events: none;
    opacity: 0;
    transition: opacity .25s;
}
.screen.open { opacity: 1; pointer-events: auto; background: rgba(60, 40, 120, .12); }
.screen .card { transform: scale(.8) translateY(30px); transition: transform .45s cubic-bezier(.3, 1.6, .5, 1); }
.screen.open .card { transform: none; }
.screen[hidden] { display: none; }

.card {
    background: var(--card);
    backdrop-filter: blur(14px);
    border-radius: 28px;
    padding: 24px;
    width: min(440px, 100%);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 10px 0 rgba(45, 38, 84, .12), 0 20px 50px rgba(45, 38, 84, .2);
}

h1, h2 { margin: 0 0 16px; font-weight: 700; }
h2 { font-size: 26px; }

.title-sym {
    font-size: 64px;
    line-height: 1;
    font-weight: 700;
    color: #ff8a3d;
    animation: spin-bob 3s ease-in-out infinite;
}
@keyframes spin-bob { 50% { transform: translateY(-8px) rotate(12deg); } }

#title { font-size: clamp(40px, 11vw, 60px); letter-spacing: 1px; }
#title span {
    display: inline-block;
    animation: wave 1.8s ease-in-out infinite;
    animation-delay: calc(var(--i) * .1s);
    color: #fff;
    -webkit-text-stroke: 3px var(--ink);
    paint-order: stroke fill;
    text-shadow: 0 5px 0 var(--ink);
}
#title span:nth-child(5n+1) { color: #ff6b8b; }
#title span:nth-child(5n+2) { color: #ffb627; }
#title span:nth-child(5n+3) { color: #2ec4a0; }
#title span:nth-child(5n+4) { color: #4ea8ff; }
#title span:nth-child(5n+5) { color: #a77bff; }
@keyframes wave { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-10px); } }

#today { color: var(--ink-soft); margin: 16px 0 0; font-size: 16px; }
#today b { color: var(--ink); }

.btn {
    display: block;
    width: 100%;
    margin: 10px 0 0;
    padding: 12px 20px;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    background: var(--btn);
    border-radius: 18px;
    box-shadow: 0 6px 0 var(--btn-dark);
    transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-2px); box-shadow: 0 8px 0 var(--btn-dark); }
.btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--btn-dark); }
.btn.go { background: var(--go); box-shadow: 0 6px 0 var(--go-dark); }
.btn.go:hover { box-shadow: 0 8px 0 var(--go-dark); }
.btn.go:active { box-shadow: 0 1px 0 var(--go-dark); }
.btn.big { font-size: 30px; padding: 16px; animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { scale: 1.04; } }

.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }

/* ---------- settings ---------- */

.picker { text-align: left; margin-bottom: 14px; }
.picker-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 6px; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 5px; }
.chip {
    height: 38px;
    border-radius: 12px;
    background: #fff;
    font-weight: 700;
    font-size: 18px;
    color: var(--ink-soft);
    box-shadow: 0 4px 0 #d8d3ee;
    transition: transform .15s cubic-bezier(.3, 1.8, .5, 1), background .15s, box-shadow .15s;
}
.chip.on { background: var(--btn); color: #fff; box-shadow: 0 4px 0 var(--btn-dark); transform: translateY(-2px); }
.chip:active { transform: translateY(3px); box-shadow: 0 1px 0 #d8d3ee; }
.chips.wide { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); }
.chips.wide .chip { font-size: 15px; padding: 0 6px; }
.chip.all { height: 30px; padding: 0 12px; font-size: 15px; background: #fff; color: var(--btn); }
.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { translate: -6px; } 40%, 80% { translate: 6px; } }

.slider { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; text-align: left; font-weight: 600; margin-bottom: 12px; }
.slider input { grid-column: 1 / -1; grid-row: 2; width: 100%; accent-color: var(--btn); height: 28px; }
.slider output { font-weight: 700; color: var(--btn); }

/* ---------- results ---------- */

#res-stars { font-size: 64px; line-height: 1; margin-bottom: 4px; }
.star { display: inline-block; color: rgba(45, 38, 84, .15); margin: 0 4px; }
.star:nth-child(2) { font-size: 80px; }
.star.on { color: var(--gold); text-shadow: 0 4px 0 #d89a00; animation: star-in .5s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes star-in { 0% { transform: scale(0) rotate(-90deg); } 100% { transform: none; } }

.res-score { display: flex; flex-direction: column; margin-bottom: 14px; }
.res-score span { color: var(--ink-soft); font-weight: 600; }
.res-score b { font-size: 48px; color: #b07800; }

#res-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
#res-stats div { background: rgba(255, 255, 255, .7); border-radius: 12px; padding: 6px 10px; display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
#res-stats span { color: var(--ink-soft); }
#res-stats div:last-child:nth-child(odd) { grid-column: 1 / -1; }

/* ---------- footer ---------- */

#games {
    position: fixed;
    left: 12px;
    bottom: 12px;
    display: flex;
    gap: 6px;
    z-index: 25;
    flex-wrap: wrap;
    max-width: calc(100% - 80px);
    transition: opacity .3s;
}
#games a {
    background: var(--card);
    border-radius: 99px;
    padding: 4px 12px;
    color: var(--ink);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
}
#games a.on { background: var(--btn); color: #fff; }
body:has(#hud.open) #games { opacity: 0; pointer-events: none; }

@media (max-width: 520px) {
    #combo { top: 84px; }
    #res-stats div { font-size: 14px; padding: 6px 8px; }
    #res-stats b { white-space: nowrap; }
}

@media (max-height: 640px) {
    .card { padding: 16px; }
    .title-sym { font-size: 44px; }
    .btn.big { font-size: 24px; padding: 12px; }
}

/* ---------- /matematika hub ---------- */
#hub-top { position: fixed; top: 0; left: 0; right: 0; text-align: center; z-index: 6; pointer-events: none; padding-top: 18px; }
#hub-top h1 { margin: 0; }
#hub-top p { margin: 2px 0 0; font-size: 20px; font-weight: 600; color: var(--ink-soft); }
.hub-head {
    position: absolute;
    left: -100px; top: -100px;
    transform: translate(-50%, -50%);
    margin: 0;
    white-space: nowrap;
    font-size: 26px;
    color: #fff;
    -webkit-text-stroke: 6px var(--ink);
    paint-order: stroke fill;
    text-shadow: 0 4px 0 var(--ink);
    transition: opacity .3s;
}
.hub-link {
    position: absolute;
    left: -100px; top: -100px;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: auto;
    text-decoration: none;
    color: var(--ink);
    background: #fff;
    border-radius: 18px;
    padding: 3px 14px;
    box-shadow: 0 4px 0 rgba(45, 38, 84, .18);
    white-space: nowrap;
    animation: label-in .45s cubic-bezier(.3, 1.8, .5, 1) both;
    transition: opacity .3s, scale .2s;
}
.hub-link b { font-size: 19px; }
.hub-link small { font-size: 13px; color: var(--go-dark); font-weight: 600; }
.hub-link small:empty { display: none; }
.hub-link:hover, .hub-link:focus-visible { scale: 1.08; outline: none; box-shadow: 0 4px 0 var(--btn); }
.hub-link.out, .hub-head.out { opacity: 0; }
#hub-list { display: none; }
body.flat { overflow: auto; }
body.flat #hub-top { position: static; }
body.flat #hub-list { display: grid; gap: 10px; max-width: 360px; margin: 20px auto; padding: 0 16px; }
body.flat #hub-list a { background: var(--card); border-radius: 16px; padding: 14px; text-align: center; font-size: 22px; font-weight: 700; color: var(--ink); text-decoration: none; }
@media (max-width: 520px) {
    .hub-link b { font-size: 15px; }
    .hub-head { font-size: 21px; -webkit-text-stroke-width: 5px; }
    #hub-top p { font-size: 16px; }
}
#install { position: fixed; left: 12px; bottom: 12px; z-index: 30; height: 44px; font-size: 17px; }
#install[hidden] { display: none; }
