:root {
    --ink: #0e1a2b;
    --ball: #d4ee1f;
    --ball-dark: #94a80c;
    --white: #ffffff;
    --card: rgba(14, 26, 43, 0.92);
    --card-line: rgba(255, 255, 255, 0.12);
    --accent: #ff5a5f;
    --gold: #ffcf3a;
    --font: "Fredoka", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: #0e1a2b;
    font-family: var(--font);
    color: var(--white);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    overscroll-behavior: none;
}

#app { position: fixed; inset: 0; }

#game {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.hidden { display: none !important; }

/* ---------- Buttons ---------- */
button { font-family: inherit; }

.btn {
    appearance: none;
    border: 0;
    border-radius: 16px;
    padding: 12px 20px;
    font-size: 17px;
    font-weight: 600;
    color: var(--white);
    background: rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
    cursor: pointer;
    transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.12s ease;
    white-space: nowrap;
}
.btn:hover { background: rgba(255, 255, 255, 0.22); }
.btn:active { transform: translateY(2px) scale(0.98); box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.25); }
.btn:focus-visible, .icon-btn:focus-visible, .mode:focus-visible { outline: 3px solid var(--ball); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(180deg, #e3ff4a, #b9d60f);
    color: var(--ink);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2), 0 8px 24px rgba(212, 238, 31, 0.35);
}
.btn-primary:hover { background: linear-gradient(180deg, #ecff6e, #c5e11d); }

.btn-big {
    font-size: 24px;
    padding: 16px 48px;
    border-radius: 22px;
    animation: breathe 2.4s ease-in-out infinite;
}

.btn-soft { font-size: 15px; padding: 10px 14px; }

.icon-btn {
    appearance: none;
    border: 0;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: rgba(14, 26, 43, 0.45);
    color: var(--white);
    font-size: 20px;
    display: grid;
    place-items: center;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: transform 0.12s ease;
}
.icon-btn:active { transform: scale(0.92); }

/* ---------- Screens ---------- */
.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
    touch-action: manipulation;
}
.screen.dim { background: rgba(5, 10, 20, 0.45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }

.card {
    background: var(--card);
    border: 1px solid var(--card-line);
    border-radius: 26px;
    padding: 22px 22px 18px;
    width: min(360px, 100%);
    text-align: center;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    position: relative;
}
.card h2 { margin: 0 0 14px; font-size: 32px; letter-spacing: 0.5px; }

.btn-col { display: flex; flex-direction: column; gap: 10px; }
.btn-row { display: flex; gap: 8px; justify-content: center; margin-top: 16px; }
.btn-row .btn { flex: 1; padding-left: 10px; padding-right: 10px; }
.btn-row #menu-btn { flex: 0 0 56px; }

/* ---------- Menu ---------- */
.menu {
    justify-content: space-between;
    background: linear-gradient(180deg, rgba(14, 26, 43, 0.55) 0%, rgba(14, 26, 43, 0.1) 45%, rgba(14, 26, 43, 0.5) 100%);
    animation: fadeIn 0.4s ease;
}
.menu.leaving { animation: fadeOut 0.3s ease forwards; }

.menu-top {
    width: 100%;
    max-width: 560px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.wallet {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 20px;
    background: rgba(14, 26, 43, 0.45);
    padding: 8px 16px;
    border-radius: 999px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.menu-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    max-width: 520px;
}

.logo {
    margin: 0;
    line-height: 0.88;
    text-align: center;
    font-weight: 700;
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.35);
    animation: logoIn 0.8s cubic-bezier(.2, 1.6, .4, 1) both;
}
.logo-1 { display: block; font-size: clamp(40px, 11vw, 76px); color: var(--white); letter-spacing: 4px; }
.logo-2 {
    display: inline-block;
    position: relative;
    font-size: clamp(48px, 14vw, 96px);
    color: var(--ball);
    -webkit-text-stroke: 2px rgba(14, 26, 43, 0.35);
    letter-spacing: 2px;
}
.logo-ball {
    position: absolute;
    right: -0.42em;
    top: -0.1em;
    width: 0.42em;
    height: 0.42em;
    border-radius: 50%;
    background:
        radial-gradient(circle at 30% 30%, #f6ff9e 0 18%, transparent 19%),
        radial-gradient(circle at 35% 35%, #e3ff4a, #94a80c 85%);
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.12);
    animation: logoBounce 1.1s cubic-bezier(.5, 0, .5, 1) infinite alternate;
}
.logo-ball::before, .logo-ball::after {
    content: "";
    position: absolute;
    width: 90%;
    height: 90%;
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    top: 5%;
}
.logo-ball::before { left: -62%; }
.logo-ball::after { right: -62%; }
.logo-ball { overflow: hidden; }

.best-line {
    font-size: 18px;
    opacity: 0.9;
    background: rgba(14, 26, 43, 0.35);
    padding: 4px 14px;
    border-radius: 999px;
}
.best-line b { color: var(--ball); }

.modes {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 6px;
}
.mode {
    appearance: none;
    border: 2px solid rgba(255, 255, 255, 0.18);
    background: rgba(14, 26, 43, 0.5);
    color: var(--white);
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    position: relative;
    transition: all 0.18s ease;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.mode:hover { border-color: rgba(255, 255, 255, 0.4); }
.mode[aria-checked="true"] {
    background: var(--white);
    color: var(--ink);
    border-color: var(--white);
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.mode .badge {
    position: absolute;
    top: -9px;
    right: -6px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 999px;
    letter-spacing: 0.5px;
    white-space: nowrap;
    animation: wiggle 2s ease-in-out infinite;
}
.mode-desc {
    margin: 0 0 6px;
    min-height: 44px;
    text-align: center;
    font-size: 15px;
    line-height: 1.4;
    max-width: 380px;
    opacity: 0.95;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.menu-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 4px; }
.menu-foot { font-size: 12px; opacity: 0.7; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }

/* ---------- HUD ---------- */
#hud {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
    padding: calc(12px + var(--safe-top)) 14px 0;
}
.hud-left { position: absolute; left: 14px; top: calc(12px + var(--safe-top)); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.pill {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(14, 26, 43, 0.45);
    padding: 5px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 17px;
}
.hud-score {
    position: absolute;
    left: 50%;
    top: calc(14px + var(--safe-top));
    transform: translateX(-50%);
    font-size: 64px;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25), 0 0 24px rgba(0, 0, 0, 0.25);
    -webkit-text-stroke: 2px rgba(14, 26, 43, 0.35);
    white-space: nowrap;
}
.hud-score.pop { animation: scorePop 0.35s cubic-bezier(.2, 1.8, .4, 1); }
.hud-score.big { animation: scoreBig 0.7s cubic-bezier(.2, 1.8, .4, 1); }
.hud-score .p1 { color: var(--ball); }
.hud-score .p2 { color: #ff8ac4; }
.hud-score .sep { opacity: 0.6; margin: 0 10px; font-size: 0.6em; vertical-align: middle; }
.hud-score .out { opacity: 0.35; text-decoration: line-through; }
.hud-pause { position: absolute; right: 14px; top: calc(12px + var(--safe-top)); pointer-events: auto; }
.hud-effects {
    position: absolute;
    top: calc(90px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
}
.fx-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    background: rgba(14, 26, 43, 0.55);
    border-radius: 12px;
    padding: 5px 9px 6px;
    font-size: 15px;
    font-weight: 700;
    animation: popIn 0.3s cubic-bezier(.2, 1.6, .4, 1);
}
.fx-bar { width: 38px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.2); overflow: hidden; }
.fx-bar i { display: block; height: 100%; background: currentColor; border-radius: 4px; }

.coin {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: radial-gradient(circle at 32% 30%, #fff6c8 0 15%, #ffd54a 45%, #b8860b 100%);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15), 0 0 8px rgba(255, 213, 74, 0.6);
    flex: none;
}

/* ---------- Ready ---------- */
.ready {
    position: absolute;
    left: 50%;
    top: 58%;
    transform: translate(-50%, -50%);
    z-index: 15;
    text-align: center;
    pointer-events: none;
    animation: fadeIn 0.3s ease;
}
.ready-title {
    font-size: 34px;
    font-weight: 700;
    text-shadow: 0 3px 0 rgba(0, 0, 0, 0.25), 0 0 20px rgba(0, 0, 0, 0.35);
    animation: pulse 1.2s ease-in-out infinite;
}
.ready-hand { font-size: 44px; margin-top: 6px; animation: tap 1s ease-in-out infinite; }
.ready-sub {
    margin-top: 8px;
    font-size: 15px;
    max-width: 320px;
    line-height: 1.4;
    background: rgba(14, 26, 43, 0.55);
    padding: 8px 14px;
    border-radius: 14px;
}
.ready-sub:empty { display: none; }

/* ---------- Game over ---------- */
.ribbon {
    position: absolute;
    top: -14px;
    right: -8px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 12px;
    transform: rotate(6deg);
    box-shadow: 0 6px 16px rgba(255, 90, 95, 0.45);
    animation: ribbon 0.6s 0.4s cubic-bezier(.2, 1.8, .4, 1) both;
}
.go-body { display: flex; align-items: center; justify-content: center; gap: 20px; }
.go-scores { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.go-scores label { display: block; font-size: 13px; opacity: 0.7; text-transform: uppercase; letter-spacing: 1px; }
.go-scores b { font-size: 34px; line-height: 1; }
.go-extra { margin-top: 14px; font-size: 14px; line-height: 1.5; opacity: 0.9; }
.go-extra .goal { color: var(--ball); }

.medal {
    width: 92px;
    height: 92px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
    color: rgba(0, 0, 0, 0.55);
    background: rgba(255, 255, 255, 0.08);
    border: 3px dashed rgba(255, 255, 255, 0.2);
    position: relative;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.medal.earned { border: 0; animation: medalIn 0.7s 0.3s cubic-bezier(.2, 1.8, .4, 1) both; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), inset 0 -6px 0 rgba(0, 0, 0, 0.15); }
.medal.earned::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, 0.7) 50%, transparent 65%);
    background-size: 250% 100%;
    animation: shine 2.4s 1s ease-in-out infinite;
}
.medal.bronze { background: radial-gradient(circle at 35% 30%, #ffd2a8, #cd7f32 60%, #8a4f1c); }
.medal.silver { background: radial-gradient(circle at 35% 30%, #ffffff, #c0c7cf 60%, #7d8790); }
.medal.gold { background: radial-gradient(circle at 35% 30%, #fff6c8, #ffcf3a 60%, #b8860b); }
.medal.platinum { background: radial-gradient(circle at 35% 30%, #ffffff, #b8f1ff 55%, #6cb4d8); }

/* ---------- Sheet (panels) ---------- */
.sheet {
    background: var(--card);
    border: 1px solid var(--card-line);
    border-radius: 26px;
    width: min(520px, 100%);
    max-height: min(680px, 100%);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px 22px; }
.sheet-head h2 { margin: 0; font-size: 26px; }
.sheet-body { padding: 4px 16px 20px; overflow-y: auto; touch-action: pan-y; -webkit-overflow-scrolling: touch; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.item {
    background: rgba(255, 255, 255, 0.06);
    border: 2px solid transparent;
    border-radius: 18px;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}
.item.equipped { border-color: var(--ball); background: rgba(212, 238, 31, 0.1); }
.item canvas { width: 72px; height: 72px; }
.item .name { font-weight: 600; font-size: 15px; }
.item .btn { width: 100%; padding: 8px 10px; font-size: 14px; display: flex; gap: 6px; align-items: center; justify-content: center; }
.item.locked canvas { filter: grayscale(0.9) brightness(0.6); }
.court-swatch { width: 100%; height: 64px; border-radius: 12px; position: relative; overflow: hidden; }

.ach { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--card-line); }
.ach:last-child { border-bottom: 0; }
.ach .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: rgba(255, 255, 255, 0.08); flex: none; }
.ach.got .ic { background: linear-gradient(180deg, #ffe680, #ffcf3a); }
.ach:not(.got) { opacity: 0.55; }
.ach .t { font-weight: 600; }
.ach .d { font-size: 13px; opacity: 0.75; }
.progress-line { font-size: 14px; opacity: 0.8; margin: 0 0 10px 6px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: rgba(255, 255, 255, 0.06); border-radius: 14px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; opacity: 0.7; }

.settings h3 { margin: 18px 6px 8px; font-size: 17px; opacity: 0.85; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 6px; border-bottom: 1px solid var(--card-line); font-size: 16px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.2); border-radius: 999px; transition: 0.2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + span { background: #9cc20a; }
.switch input:checked + span::before { transform: translateX(22px); }
.howto { font-size: 15px; line-height: 1.55; margin: 0 6px; padding-left: 18px; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 6px; }
.legend div { background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 8px 10px; font-size: 14px; }
.legend b { display: block; }
.danger { background: rgba(255, 90, 95, 0.2); }

/* ---------- Toasts ---------- */
.toasts {
    position: absolute;
    top: calc(12px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    width: max-content;
    max-width: calc(100% - 32px);
}
.toast {
    background: var(--card);
    border: 1px solid rgba(255, 207, 58, 0.5);
    border-radius: 16px;
    padding: 10px 16px;
    display: flex;
    gap: 10px;
    align-items: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    animation: toastIn 0.45s cubic-bezier(.2, 1.6, .4, 1), toastOut 0.4s 2.8s ease forwards;
}
.toast .ti { font-size: 24px; }
.toast b { display: block; font-size: 15px; }
.toast span { font-size: 13px; opacity: 0.8; }

/* ---------- Animations ---------- */
.pop-in { animation: popIn 0.35s cubic-bezier(.2, 1.6, .4, 1); }
.slide-up { animation: slideUp 0.5s cubic-bezier(.2, 1.3, .4, 1); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: scale(1.04); } }
@keyframes popIn { from { opacity: 0; transform: scale(0.7); } to { opacity: 1; transform: scale(1); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(80px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.06); opacity: 0.85; } }
@keyframes tap { 0%, 100% { transform: translateY(0) scale(1); } 45% { transform: translateY(10px) scale(0.92); } }
@keyframes logoIn { from { opacity: 0; transform: translateY(-40px) scale(0.6) rotate(-6deg); } to { opacity: 1; transform: none; } }
@keyframes logoBounce { from { transform: translateY(-0.2em) rotate(0deg); } to { transform: translateY(0.18em) rotate(200deg); } }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-10deg); } 90% { transform: rotate(10deg); } 95% { transform: rotate(-6deg); } }
@keyframes scorePop { 0% { transform: translateX(-50%) scale(1); } 40% { transform: translateX(-50%) scale(1.3); } 100% { transform: translateX(-50%) scale(1); } }
@keyframes scoreBig { 0% { transform: translateX(-50%) scale(1); color: #fff; } 30% { transform: translateX(-50%) scale(1.6) rotate(-4deg); color: var(--gold); } 100% { transform: translateX(-50%) scale(1); color: #fff; } }
@keyframes ribbon { from { opacity: 0; transform: rotate(30deg) scale(0.3); } to { opacity: 1; transform: rotate(6deg) scale(1); } }
@keyframes medalIn { from { opacity: 0; transform: scale(0.2) rotate(-200deg); } to { opacity: 1; transform: none; } }
@keyframes shine { 0% { background-position: 150% 0; } 60%, 100% { background-position: -100% 0; } }
@keyframes toastIn { from { opacity: 0; transform: translateY(-30px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-20px); } }

@media (max-height: 560px) {
    .logo-1 { font-size: 34px; }
    .logo-2 { font-size: 44px; }
    .menu-center { gap: 6px; }
    .btn-big { padding: 10px 36px; font-size: 20px; }
    .mode-desc { min-height: 0; font-size: 13px; }
    .hud-score { font-size: 46px; }
    .hud-effects { top: calc(64px + var(--safe-top)); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
