:root {
    --app-height: 100dvh;
}

html {
    background-color: #0f172a;
    height: 100%;
}

body {
    font-family: 'Fredoka', sans-serif;
    background-color: #0f172a;
    color: white;
    overflow: hidden;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    height: var(--app-height);
    width: 100vw;
    position: fixed;
    inset: 0;
    padding: 0;
    margin: 0;
}

.fraction-text { 
    font-feature-settings: "frac"; 
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px; }

/* Dynamic Backgrounds */
.bg-space { background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%); }
.bg-ice { background: linear-gradient(to bottom right, #06b6d4, #1e40af); }
.bg-volcano { background: linear-gradient(to bottom right, #ef4444, #7f1d1d); }
.bg-jungle { background: linear-gradient(to bottom right, #22c55e, #14532d); }
.bg-tech { background: linear-gradient(to bottom right, #a855f7, #4c1d95); }
.bg-aqua { background: linear-gradient(to bottom, #0ea5e9, #0f172a); } 
.bg-candy { background: linear-gradient(to bottom right, #f472b6, #a855f7); } 
.bg-climax { background: linear-gradient(to bottom, #7f1d1d, #000000); animation: pulseRed 2s infinite; }

@keyframes pulseRed {
    0% { box-shadow: inset 0 0 0 0 rgba(255, 0, 0, 0); }
    50% { box-shadow: inset 0 0 50px 0 rgba(255, 0, 0, 0.3); }
    100% { box-shadow: inset 0 0 0 0 rgba(255, 0, 0, 0); }
}

.btn-press {
    transition: transform 0.1s, box-shadow 0.1s;
}
.btn-press:active {
    transform: scale(0.96);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.app-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 0.25rem;
    padding-bottom: calc(env(safe-area-inset-bottom) + 3rem); 
    padding-top: env(safe-area-inset-top, 0.25rem);
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.game-card {
    background: rgba(15, 23, 42, 0.95); 
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border-radius: 1rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
    width: 100%;
    position: relative;
}

.card-content-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
    min-height: 0;
    justify-content: center;
}

.card-footer {
    padding: 0.75rem;
    padding-top: 0.5rem;
    flex-shrink: 0;
    background: linear-gradient(to top, rgba(15, 23, 42, 1) 20%, rgba(15, 23, 42, 0.8) 80%, transparent 100%);
    z-index: 20;
}

.card-header {
    padding: 0.75rem;
    padding-bottom: 0.25rem;
    flex-shrink: 0;
    text-align: center;
}

/* Animations */
@keyframes bounceIn {
    0% { transform: scale(0.8); opacity: 0; }
    60% { transform: scale(1.05); opacity: 1; }
    100% { transform: scale(1); }
}
.anim-pop { animation: bounceIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}
.anim-shake { animation: shake 0.3s ease-in-out; }

@keyframes wobble {
    0% { transform: rotate(var(--rot)); }
    25% { transform: rotate(calc(var(--rot) - 5deg)); }
    50% { transform: rotate(calc(var(--rot) + 3deg)); }
    75% { transform: rotate(calc(var(--rot) - 1deg)); }
    100% { transform: rotate(var(--rot)); }
}
.anim-wobble { animation: wobble 0.6s ease-out; }

@keyframes bubble-rise {
    0% { transform: translateY(0) scale(1); opacity: 0; }
    50% { opacity: 0.8; }
    100% { transform: translateY(-40px) scale(1.2); opacity: 0; }
}
.animate-bubble { animation: bubble-rise 2s infinite ease-in; }

/* FX */
@keyframes laserShot {
    0% { opacity: 1; transform: translateX(-50%) scaleX(0.1); }
    30% { opacity: 1; transform: translateX(-50%) scaleX(1.5); }
    100% { opacity: 0; transform: translateX(-50%) scaleX(0.1); }
}
.laser-beam {
    position: absolute; top: 0; bottom: 0; left: 50%; width: 6px;
    background: #f472b6;
    box-shadow: 0 0 15px #f472b6, 0 0 30px #ec4899;
    transform: translateX(-50%); pointer-events: none; z-index: 30;
    animation: laserShot 0.3s ease-out forwards;
}

@keyframes rocketFlame {
    0% { height: 10px; opacity: 0.8; }
    50% { height: 25px; opacity: 1; }
    100% { height: 10px; opacity: 0.8; }
}
.rocket-flame {
    animation: rocketFlame 0.15s infinite;
    background: linear-gradient(to bottom, #facc15, #ef4444);
    width: 8px; border-radius: 4px; position: absolute;
    bottom: -10px; left: 50%; transform: translateX(-50%); z-index: 5;
    box-shadow: 0 0 10px #ef4444;
}

@keyframes shine {
    0% { left: -100%; opacity: 0; }
    50% { opacity: 0.5; }
    100% { left: 100%; opacity: 0; }
}
.coin-shine::after {
    content: ''; position: absolute; top: 0; left: -100%; width: 50%; height: 100%;
    background: linear-gradient(to right, transparent, rgba(255,255,255,0.8), transparent);
    transform: skewX(-25deg); animation: shine 3s infinite;
}

@keyframes powerFailure {
    0% { opacity: 1; transform: scale(1); filter: brightness(1.5); }
    10% { opacity: 0.6; transform: scale(0.99); filter: brightness(0.8); }
    15% { opacity: 0.9; transform: scale(0.98); filter: brightness(1.2); }
    30% { opacity: 0.4; transform: scale(0.97); filter: brightness(0.6); }
    40% { opacity: 0.7; transform: scale(0.96); filter: brightness(0.9); }
    60% { opacity: 0.3; transform: scale(0.95); filter: brightness(0.4); }
    70% { opacity: 0.5; transform: scale(0.94); filter: brightness(0.5); }
    80% { opacity: 0.2; transform: scale(0.92); filter: brightness(0.3); }
    100% { opacity: 0.3; transform: scale(0.9); filter: brightness(0.3); }
}

.poly-slice { transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1); transform-origin: center; cursor: pointer; }
.poly-slice.charged { fill: #06b6d4; stroke: #cffafe; stroke-width: 2px; filter: drop-shadow(0 0 10px rgba(6, 182, 212, 0.8)); transform: scale(1.02); z-index: 10; }
.poly-slice.discharged { fill: rgba(15, 23, 42, 0.5); stroke: #334155; stroke-width: 1px; animation: powerFailure 2s ease-out forwards; }

.fuel-cell {
    background-color: rgba(30, 41, 59, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    width: 100%;
    height: 1.5rem;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
}
.fuel-cell.active {
    background-color: #0ea5e9;
    border-color: #bae6fd;
    box-shadow: 0 0 15px #0ea5e9, inset 0 0 5px rgba(255,255,255,0.5);
    transform: scaleX(1.05) scaleY(1.05);
    z-index: 10;
}
.fuel-cell.active::after {
    content: ''; position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: shine 2s infinite;
}

.grid-item { aspect-ratio: 1; transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.grid-item.selected { 
    background-color: #fbbf24 !important; border-color: #fff !important; color: #451a03 !important;
    box-shadow: 0 0 15px #fbbf24, inset 0 0 10px rgba(255,255,255,0.5) !important;
    transform: scale(0.95); z-index: 10;
}
.grid-item.correct-hint {
    border-color: #4ade80 !important; background-color: rgba(74, 222, 128, 0.5) !important;
    box-shadow: 0 0 25px #4ade80; transform: scale(1.1);
}

.match-card {
    background-color: #1e293b; border: 3px solid #334155; border-radius: 1rem;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: bold; color: white;
    transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.3); min-height: 5rem;
}
.match-card.selected { border-color: #fbbf24; background-color: #451a03; transform: scale(1.05) translateY(-5px); box-shadow: 0 10px 20px rgba(251, 191, 36, 0.3); }
.match-card.matched { border-color: #22c55e; background-color: #14532d; opacity: 0.5; transform: scale(0.95); }
.match-card.error { border-color: #ef4444; background-color: #7f1d1d; animation: shake 0.3s; }

.pie-slice { transition: all 0.2s ease; cursor: pointer; stroke-width: 2px; transform-origin: center; }
.pie-slice:hover { filter: brightness(1.3); }
.pie-slice.selected { fill: #fbbf24; filter: drop-shadow(0 0 8px rgba(251,191,36,0.8)); transform: scale(1.05); stroke: white; stroke-width: 3px; z-index: 10; }
.pie-slice.unselected { fill: rgba(255, 255, 255, 0.1); }
.pie-slice.correct-hint { fill: #4ade80; opacity: 0.8; }

.digi-btn { box-shadow: 0 4px 0 #1e293b; transition: all 0.1s cubic-bezier(0.34, 1.56, 0.64, 1); width: 3.5rem; height: 3.5rem; }
.digi-btn:active { transform: translateY(4px); box-shadow: 0 0 0 #1e293b; }
.digi-btn.active {
    background-color: #4ade80; color: #14532d; border-color: #22c55e;
    box-shadow: 0 0 15px #4ade80, 0 4px 0 #15803d; transform: scale(1.1);
}

.weight-item-container { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.weight-item {
    background: linear-gradient(135deg, #fbbf24 0%, #d97706 100%);
    border: 2px solid #fff; box-shadow: 0 4px 6px rgba(0,0,0,0.4); border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; color: #451a03; user-select: none; cursor: grab; touch-action: none;
    transition: transform 0.1s; width: 4rem; height: 3.5rem;
}
.weight-item:active { cursor: grabbing; transform: scale(1.1); }
.weight-count { background: rgba(0,0,0,0.5); padding: 2px 8px; border-radius: 10px; font-size: 0.8rem; color: #fbbf24; }

.training-btn { min-height: 5rem; background: rgba(30, 41, 59, 0.6); border: 1px solid rgba(255, 255, 255, 0.1); }
.training-btn:hover { background: rgba(51, 65, 85, 0.8); }