:root {
    --cell-size: 45px;
    --anim-fall: 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --anim-slide: 0.15s cubic-bezier(0.2, 0.8, 0.2, 1);
    --hint-color: rgba(105, 240, 174, 0.6);
    --skill-btn-size: 50px;
}

* { box-sizing: border-box; }

body {
    background-color: #0d0616;
    color: white;
    font-family: "Segoe UI", Roboto, sans-serif;
    margin: 0;
    overflow-x: hidden;
    overflow-y: auto;
    touch-action: manipulation;
    user-select: none;
    min-height: 100dvh;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

#app-shell {
    width: 100%;
    min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    display: grid;
    place-items: center;
    overflow-y: auto;
}

.screen {
    width: min(980px, 100%);
    max-height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.screen.active { display: flex; }

.menu-title { margin: 0; letter-spacing: 1px; text-shadow: 0 0 15px rgba(255,255,255,0.2); }
.menu-title.small { font-size: 1.4rem; }
.menu-subtitle { margin: 0; color: #c5b8d9; }
.menu-points { color: #00e5ff; text-shadow: 0 0 5px #00e5ff; }

.menu-buttons { display: flex; flex-direction: column; gap: 10px; width: min(360px, 100%); }
.menu-buttons.compact { width: min(260px, 100%); }

.menu-btn {
    min-height: 44px;
    border: none;
    border-radius: 14px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #6c3dd4, #48239e);
    color: #fff;
    cursor: pointer;
    font-size: 0.98rem;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
}
.menu-btn:active { transform: scale(0.97); }
.menu-btn.ghost { background: linear-gradient(135deg, #2d203f, #1e1630); border: 1px solid #4f3d6c; }
.menu-btn.danger { background: linear-gradient(45deg, #b92843, #e8536c); }
.menu-btn.tab.active { filter: brightness(1.2); }
.menu-btn.shop { text-align: left; }

.tab-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.rank-list {
    width: min(560px, 100%);
    max-height: 48dvh;
    overflow: auto;
    margin: 0;
    padding: 8px 20px 8px 36px;
    border: 2px solid #3d2263;
    border-radius: 12px;
    background: rgba(30, 16, 53, 0.85);
}
.rank-list li { margin: 8px 0; padding: 8px; border-radius: 8px; background: rgba(10, 6, 20, 0.55); }
.rank-item {
    margin: 8px 0;
    padding: 10px;
    border-radius: 10px;
    background: rgba(10, 6, 20, 0.55);
    border: 1px solid rgba(108, 61, 212, 0.24);
}
.rank-item.mine {
    border-color: rgba(0, 229, 255, 0.75);
    box-shadow: 0 0 0 1px rgba(0, 229, 255, 0.35), inset 0 0 16px rgba(0, 229, 255, 0.08);
}
.rank-row {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: space-between;
}
.rank-row.sub {
    margin-top: 6px;
    color: #c8c0d9;
    font-size: 0.86rem;
    gap: 12px;
    flex-wrap: wrap;
}
.rank-pos {
    font-weight: 800;
    color: #ffd36b;
    min-width: 42px;
}
.rank-player {
    flex: 1;
    font-weight: 600;
    color: #f2eefc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.rank-mine-tag {
    font-size: 0.72rem;
    color: #001826;
    background: #00e5ff;
    border-radius: 999px;
    padding: 2px 8px;
    font-weight: 700;
}
.rank-score {
    color: #fbe18c;
    font-weight: 700;
}
.rank-diff {
    color: #9de6b3;
}
.rank-time {
    color: #b9acd3;
    margin-left: auto;
}

.shop-section {
    width: min(560px, 100%);
    border: 2px solid #3d2263;
    border-radius: 14px;
    padding: 12px;
    background: rgba(30, 16, 53, 0.85);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.shop-section h3 { margin: 0 0 4px 0; font-size: 0.95rem; color: #cab4f5; }

#shop-screen,
#leaderboard-screen,
#difficulty-menu,
#main-menu {
    width: min(980px, 100%);
    justify-content: flex-start;
    padding-bottom: 24px;
}

#game-screen {
    justify-content: center;
    min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    overflow-y: auto;
    overflow-x: hidden;
}

#main-container {
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: 100%;
}

#skill-panel {
    display: flex;
    flex-direction: row;
    gap: 8px;
    background: rgba(30, 16, 53, 0.8);
    padding: 8px;
    border-radius: 16px;
    border: 2px solid #3d2263;
    flex: 0 0 auto;
    width: 100%;
    max-width: 450px;
    justify-content: center;
    align-items: stretch;
}

.skill-points-display { text-align: center; }
.sp-label { font-size: 0.75rem; color: #b8a8d5; }
.sp-val { font-size: 1.45rem; color: #00e5ff; font-weight: bold; text-shadow: 0 0 5px #00e5ff; }

.skill-btn {
    width: max(54px, calc(var(--skill-btn-size) * 0.9));
    min-height: max(54px, calc(var(--skill-btn-size) * 0.9));
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #6c3dd4, #48239e);
    color: white;
    font-size: 0.62rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 4px;
}
.skill-btn span { font-size: 0.68rem; margin-bottom: 2px; line-height: 1.1; }
.skill-btn small { font-size: 0.58rem; }
.skill-btn:disabled { background: #2a2a35; color: #666; cursor: not-allowed; border: 1px solid #444; }

#game-column { display: flex; flex-direction: column; align-items: center; }
#ui-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    background: #1e1035;
    border-radius: 16px 16px 0 0;
    border-bottom: 2px solid #3d2263;
    max-width: 450px;
}
.score-box { text-align: center; min-width: 64px; }
.score-label { font-size: 0.72rem; color: #9f92b6; }
.score-num { font-size: 1.28rem; font-weight: 800; color: #fff; text-shadow: 0 0 10px rgba(255,255,255,0.3); }

#game-viewport {
    position: relative;
    background-color: #160a25;
    border: 3px solid #3d2263;
    border-top: none;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
    touch-action: none;
}

#game-board { position: absolute; inset: 0; }
.grid-line-h,.grid-line-v { position: absolute; pointer-events: none; background: rgba(255,255,255,0.04); }
.grid-line-h { width: 100%; height: 1px; left: 0; }
.grid-line-v { width: 1px; height: 100%; top: 0; }

#drop-hint {
    position: absolute;
    border: 2px solid var(--hint-color);
    background: rgba(105, 240, 174, 0.1);
    border-radius: 6px;
    pointer-events: none;
    z-index: 8;
    display: none;
    margin-top: 2px;
    height: calc(var(--cell-size) - 4px);
}

.block {
    position: absolute;
    height: calc(var(--cell-size) - 4px);
    margin-top: 2px;
    border-radius: 6px;
    transition: left var(--anim-slide), top var(--anim-fall), transform 0.15s, width 0.3s cubic-bezier(0.34,1.56,0.64,1);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 3px 5px rgba(0,0,0,0.3);
    border: 1px solid rgba(0,0,0,0.2);
    z-index: 10;
}
.block[data-w="1"] { background: linear-gradient(135deg, #2196f3 0%, #42a5f5 100%); }
.block[data-w="2"] { background: linear-gradient(135deg, #4caf50 0%, #66bb6a 100%); }
.block[data-w="3"] { background: linear-gradient(135deg, #ff9800 0%, #ffb74d 100%); }
.block[data-w="4"] { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }
.block[data-w="5"] { background: linear-gradient(135deg, #a18cd1 0%, #fbc2eb 100%); }
.block.hard { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.15), rgba(255,255,255,0.15) 10px, rgba(255,255,255,0) 10px, rgba(255,255,255,0) 20px) !important; border: 2px solid #ffd700 !important; }
.block.stone { background: #2a2a35 !important; border: 1px solid #444 !important; }
.block.active { z-index: 100; transform: scale(1.05); transition: none !important; }

.eliminating { animation: popOut 0.3s ease-out forwards; }
.morphing { animation: morphFlash 0.6s ease-out; }
.spawn-anim { animation: spawnPop 0.6s ease-out; }
.hard-hit { animation: hardHitAnim 0.3s ease-out; }
.shake { animation: shake 0.2s cubic-bezier(.36,.07,.19,.97) both; }

@keyframes shake { 10%,90%{transform:translate3d(-2px,0,0);}20%,80%{transform:translate3d(3px,0,0);}30%,50%,70%{transform:translate3d(-4px,0,0);}40%,60%{transform:translate3d(4px,0,0);} }
@keyframes popOut { 0%{transform:scale(1);}30%{transform:scale(1.15);}100%{transform:scale(0);opacity:0;} }
@keyframes morphFlash { 0%{filter:brightness(1);}30%{filter:brightness(2.5) hue-rotate(90deg);transform:scale(1.05);}100%{filter:brightness(1);} }
@keyframes spawnPop { 0%{transform:scale(0);opacity:0;}50%{transform:scale(1.1);opacity:1;}100%{transform:scale(1);} }
@keyframes hardHitAnim { 0%{transform:scale(1);filter:brightness(2);}50%{transform:scale(0.9);}100%{transform:scale(1);} }

#game-over-modal {
    position: absolute;
    inset: 0;
    background: rgba(11, 11, 18, 0.95);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999;
    text-align: center;
}
#game-over-modal h1 { margin: 0; }
#final-score { font-size: 2.3rem; font-weight: bold; color: #ff4f85; }

.global-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: grid;
    place-items: center;
    z-index: 1200;
    padding: 14px;
}
.global-modal.hidden { display: none; }
.modal-card {
    width: min(420px, 100%);
    border: 2px solid #3d2263;
    border-radius: 14px;
    background: #1e1035;
    padding: 14px;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

@media (max-width: 840px) {
    #main-container { flex-direction: column-reverse; align-items: center; gap: 8px; }
    #skill-panel { flex-direction: row; width: 100%; max-width: 450px; justify-content: center; align-items: stretch; padding: 8px; }
    .skill-points-display { min-width: 52px; display: flex; flex-direction: column; justify-content: center; }
    .skill-btn { width: 74px; min-height: 74px; }
    #ui-header { padding: 8px 10px; }
    .score-num { font-size: 1.15rem; }
    .score-box { min-width: 56px; }
    #game-column { min-width: 0; }
    #game-screen { width: 100%; overflow-x: hidden; overflow-y: auto; justify-content: center; }
    .rank-row {
        gap: 6px;
    }
    .rank-row.sub {
        font-size: 0.78rem;
    }
    .rank-time {
        width: 100%;
        margin-left: 0;
    }
}
