/* ── 2048 Drop — Stylesheet (Chuẩn 9:16 — Lưới 5x8 + Hàng 9 Xuất Phát) ── */
/* Tác giả: Kome Studio */
@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@600;700;800&display=swap');

:root {
    --bg-main: #0c1021;
    --bg-board: #11172e;
    --accent-glow: #00d2ff;
    --text-primary: #ffffff;
    --text-muted: #8c9ec5;
    --cols: 5;
    --rows: 8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: radial-gradient(circle at 50% 20%, #172044 0%, #0c1021 100%);
    color: var(--text-primary);
    font-family: 'Fredoka', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Container Chuẩn Tỷ Lệ 9:16 ── */
#game-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    aspect-ratio: 9 / 16;
    max-width: calc(100vh * 9 / 16);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px 10px 10px 10px;
}

/* ── Top Header ── */
.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    z-index: 10;
    padding-bottom: 6px;
    height: 48px;
    flex-shrink: 0;
}

.brand-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-kome {
    display: flex;
    align-items: center;
    text-decoration: none;
    opacity: 0.9;
    transition: transform 0.2s;
}
.logo-kome:hover { transform: scale(1.05); }
.logo-kome img {
    height: 28px;
    width: auto;
}

.game-title {
    font-size: 19px;
    font-weight: 800;
    background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.score-boards {
    display: flex;
    gap: 6px;
}

.score-box {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    padding: 3px 8px;
    min-width: 65px;
    text-align: center;
}
.score-box .label {
    font-size: 9px;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
}
.score-box .value {
    font-size: 14px;
    font-weight: 800;
    color: #ffd15c;
}

.header-actions {
    display: flex;
    gap: 6px;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.15s;
    outline: none;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.2); transform: scale(1.06); }
.icon-btn:active { transform: scale(0.92); }

/* ── Main Board Container ── */
#board-container {
    position: relative;
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Khu Vực Lưới Chơi 5x8 ── */
#grid-play-area {
    position: relative;
    flex: 8;
    width: 100%;
    background: var(--bg-board);
    border-radius: 16px 16px 6px 6px;
    border: 2px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5), 0 6px 20px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

/* 5 Cột Lưới */
#columns-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 6px;
}

.board-column {
    position: relative;
    height: 100%;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.03);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.board-column.aim-highlight {
    background: rgba(0, 210, 255, 0.07);
    border-color: rgba(0, 210, 255, 0.35);
}

/* Tia ngắm Laser */
#aim-laser {
    position: absolute;
    width: 3px;
    background: linear-gradient(to top, rgba(0, 242, 254, 0.95), rgba(0, 242, 254, 0.15));
    border-radius: 3px;
    pointer-events: none;
    z-index: 15;
    transform-origin: bottom center;
    box-shadow: 0 0 8px rgba(0, 242, 254, 0.8);
    display: none;
}
#aim-laser.match-beam {
    background: linear-gradient(to top, #ffe000, #ff007f);
    box-shadow: 0 0 12px #ffe000, 0 0 20px #ff007f;
    width: 4px;
}

/* Khối bóng ma mờ tại điểm va chạm (Ghost Preview Tile) */
.tile.ghost-tile {
    opacity: 0.52;
    border: 2px dashed rgba(255, 255, 255, 0.7);
    box-shadow: 0 0 14px rgba(0, 242, 254, 0.5);
    display: none;
    pointer-events: none;
    z-index: 22;
    transition: left 0.08s ease-out, top 0.08s ease-out;
}
.tile.ghost-tile.ghost-match {
    opacity: 0.75;
    border: 2px solid #ffe000;
    box-shadow: 0 0 16px rgba(255, 224, 0, 0.9), 0 0 25px rgba(255, 0, 127, 0.6);
    animation: ghostPulse 0.6s infinite alternate;
}
@keyframes ghostPulse {
    from { transform: scale(0.96); filter: brightness(1); }
    to   { transform: scale(1.04); filter: brightness(1.25); }
}

/* Vạch nguy hiểm (Danger line) giữa hàng 7 và 8 */
#danger-line {
    position: absolute;
    left: 0;
    width: 100%;
    height: 2px;
    background: repeating-linear-gradient(90deg, #ff3366, #ff3366 8px, transparent 8px, transparent 16px);
    z-index: 12;
    pointer-events: none;
    opacity: 0.65;
    transition: opacity 0.3s;
}
#danger-line.alert {
    opacity: 1;
    animation: dangerBlink 0.6s infinite alternate;
}
@keyframes dangerBlink {
    from { filter: drop-shadow(0 0 2px #ff3366); }
    to   { filter: drop-shadow(0 0 10px #ff0044); }
}

/* ── Tiles Layer (Lớp chứa các khối đang chơi) ── */
#tiles-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

/* ── HÀNG THỨ 9: HÀNG XUẤT PHÁT (LAUNCH ROW) ── */
#launch-row {
    position: relative;
    flex: 1.15;
    width: 100%;
    margin-top: 6px;
    background: #0d1226;
    border-radius: 6px 6px 16px 16px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    padding: 6px;
    align-items: center;
}

.launch-slot {
    position: relative;
    height: 100%;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
}

.launch-slot.slot-active {
    background: rgba(0, 210, 255, 0.1);
    border-color: rgba(0, 210, 255, 0.4);
}

.arrow-up {
    font-size: 13px;
    color: rgba(0, 210, 255, 0.5);
    transition: transform 0.2s, color 0.2s;
}
.launch-slot.slot-active .arrow-up {
    color: #00f2fe;
    transform: translateY(-2px);
    text-shadow: 0 0 6px rgba(0, 242, 254, 0.8);
}

/* Khối xuất phát ở hàng 9 */
#launch-tile {
    position: absolute;
    top: 6px;
    z-index: 25;
    transition: transform 0.12s ease-out;
    pointer-events: none;
    box-shadow: 0 0 16px rgba(0, 210, 255, 0.4);
}

/* ── HIỆU ỨNG SỐ SẼ GHÉP (MINH HỌA 2 ĐẦU) ── */
/* Huy hiệu số kết quả (Preview Badge) xuất hiện ở cả 2 đầu */
.preview-badge {
    position: absolute;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #ffe000, #ff007f);
    box-shadow: 0 0 12px rgba(255, 224, 0, 0.9), 0 0 20px rgba(255, 0, 127, 0.7);
    border: 2px solid #ffffff;
    z-index: 40;
    animation: badgePulse 0.6s infinite alternate;
    pointer-events: none;
}
@keyframes badgePulse {
    from { transform: translate(-50%, -50%) scale(0.9); }
    to   { transform: translate(-50%, -50%) scale(1.15); }
}

/* Khối đích ở cột đang chuẩn bị gộp */
.tile.merge-target-highlight {
    box-shadow: 0 0 20px #ffe000, 0 0 30px #ff007f !important;
    animation: targetGlow 0.5s infinite alternate !important;
    z-index: 35 !important;
}
@keyframes targetGlow {
    from { transform: scale(1); filter: brightness(1.1); }
    to   { transform: scale(1.08); filter: brightness(1.35); }
}

/* Khối bắn ở hàng 9 khi sẵn sàng gộp */
#launch-tile.merge-shooter-highlight {
    box-shadow: 0 0 22px #ffe000, 0 0 35px #ff007f !important;
    animation: shooterPulse 0.5s infinite alternate;
}
@keyframes shooterPulse {
    from { filter: brightness(1); }
    to   { filter: brightness(1.3); }
}

/* ── TILE STYLING (HOÀN TOÀN BẰNG CSS) ── */
.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #ffffff;
    border-radius: 12px;
    box-shadow: 
        inset 0 2px 2px rgba(255, 255, 255, 0.45),
        inset 0 -3px 4px rgba(0, 0, 0, 0.35),
        0 4px 10px rgba(0, 0, 0, 0.4);
    text-shadow: 0 2px 3px rgba(0, 0, 0, 0.5);
    letter-spacing: -0.5px;
    pointer-events: none;
    will-change: transform, left, top;
}

.tile-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    text-align: center;
    line-height: 1;
}

/* Animation khi gộp thành công (Pop Bounce) */
.tile.pop-merge {
    animation: popBounce 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 30 !important;
}

@keyframes popBounce {
    0%   { transform: scale(0.8); }
    50%  { transform: scale(1.28); filter: brightness(1.3); }
    100% { transform: scale(1); }
}

/* Animation khi sinh mới */
.tile.spawn-pop {
    animation: spawnZoom 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes spawnZoom {
    0%   { transform: scale(0.3); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ── 50 CẤP SỐ TIÊU CHUẨN (TIER 1 ĐẾN TIER 50) ── */
/* 2 - 2048 */
.tile-tier-1  { background: linear-gradient(145deg, #4facfe, #00f2fe); font-size: 24px; } /* 2 */
.tile-tier-2  { background: linear-gradient(145deg, #43e97b, #38f9d7); font-size: 24px; } /* 4 */
.tile-tier-3  { background: linear-gradient(145deg, #fa709a, #fee140); font-size: 24px; } /* 8 */
.tile-tier-4  { background: linear-gradient(145deg, #f83600, #f9d423); font-size: 23px; } /* 16 */
.tile-tier-5  { background: linear-gradient(145deg, #ff5858, #f09819); font-size: 23px; } /* 32 */
.tile-tier-6  { background: linear-gradient(145deg, #ff0844, #ffb199); font-size: 23px; } /* 64 */
.tile-tier-7  { background: linear-gradient(145deg, #f6d365, #fda085); font-size: 21px; } /* 128 */
.tile-tier-8  { background: linear-gradient(145deg, #fbc2eb, #a6c1ee); font-size: 21px; } /* 256 */
.tile-tier-9  { background: linear-gradient(145deg, #a18cd1, #fbc2eb); font-size: 21px; } /* 512 */
.tile-tier-10 { background: linear-gradient(145deg, #8ec5fc, #e0c3fc); font-size: 18px; } /* 1024 */
.tile-tier-11 { background: linear-gradient(145deg, #f12711, #f5af19); font-size: 18px; box-shadow: 0 0 14px rgba(241, 39, 17, 0.7); } /* 2048 */

/* 4K - 1024K */
.tile-tier-12 { background: linear-gradient(145deg, #ec4899, #be185d); font-size: 23px; } /* 4K */
.tile-tier-13 { background: linear-gradient(145deg, #d946ef, #a21caf); font-size: 23px; } /* 8K */
.tile-tier-14 { background: linear-gradient(145deg, #a855f7, #7e22ce); font-size: 22px; } /* 16K */
.tile-tier-15 { background: linear-gradient(145deg, #8b5cf6, #6d28d9); font-size: 22px; } /* 32K */
.tile-tier-16 { background: linear-gradient(145deg, #6366f1, #4338ca); font-size: 22px; } /* 64K */
.tile-tier-17 { background: linear-gradient(145deg, #3b82f6, #1d4ed8); font-size: 19px; } /* 128K */
.tile-tier-18 { background: linear-gradient(145deg, #0ea5e9, #0369a1); font-size: 19px; } /* 256K */
.tile-tier-19 { background: linear-gradient(145deg, #14b8a6, #0f766e); font-size: 19px; } /* 512K */
.tile-tier-20 { background: linear-gradient(145deg, #10b981, #047857); font-size: 16px; box-shadow: 0 0 16px rgba(16, 185, 129, 0.8); } /* 1024K */

/* 2M - 1024M */
.tile-tier-21 { background: linear-gradient(145deg, #f97316, #c2410c); font-size: 23px; } /* 2M */
.tile-tier-22 { background: linear-gradient(145deg, #ef4444, #b91c1c); font-size: 23px; } /* 4M */
.tile-tier-23 { background: linear-gradient(145deg, #e11d48, #9f1239); font-size: 23px; } /* 8M */
.tile-tier-24 { background: linear-gradient(145deg, #db2777, #9d174d); font-size: 22px; } /* 16M */
.tile-tier-25 { background: linear-gradient(145deg, #c026d3, #86198f); font-size: 22px; } /* 32M */
.tile-tier-26 { background: linear-gradient(145deg, #9333ea, #6b21a8); font-size: 22px; } /* 64M */
.tile-tier-27 { background: linear-gradient(145deg, #7c3aed, #5b21b6); font-size: 19px; } /* 128M */
.tile-tier-28 { background: linear-gradient(145deg, #4f46e5, #3730a3); font-size: 19px; } /* 256M */
.tile-tier-29 { background: linear-gradient(145deg, #2563eb, #1e40af); font-size: 19px; } /* 512M */
.tile-tier-30 { background: linear-gradient(145deg, #0284c7, #075985); font-size: 16px; box-shadow: 0 0 16px rgba(2, 132, 199, 0.85); } /* 1024M */

/* 2B - 1024B */
.tile-tier-31 { background: linear-gradient(145deg, #0d9488, #115e59); font-size: 23px; } /* 2B */
.tile-tier-32 { background: linear-gradient(145deg, #059669, #065f46); font-size: 23px; } /* 4B */
.tile-tier-33 { background: linear-gradient(145deg, #65a30d, #3f6212); font-size: 23px; } /* 8B */
.tile-tier-34 { background: linear-gradient(145deg, #ca8a04, #854d0e); font-size: 22px; } /* 16B */
.tile-tier-35 { background: linear-gradient(145deg, #d97706, #92400e); font-size: 22px; } /* 32B */
.tile-tier-36 { background: linear-gradient(145deg, #ea580c, #9a3412); font-size: 22px; } /* 64B */
.tile-tier-37 { background: linear-gradient(145deg, #dc2626, #991b1b); font-size: 19px; } /* 128B */
.tile-tier-38 { background: linear-gradient(145deg, #e11d48, #881337); font-size: 19px; } /* 256B */
.tile-tier-39 { background: linear-gradient(145deg, #be185d, #700d36); font-size: 19px; } /* 512B */
.tile-tier-40 { background: linear-gradient(145deg, #a21caf, #581c87); font-size: 16px; box-shadow: 0 0 18px rgba(162, 28, 175, 0.9); } /* 1024B */

/* 2T - 1024T */
.tile-tier-41 { background: linear-gradient(145deg, #7e22ce, #3b0764); font-size: 23px; } /* 2T */
.tile-tier-42 { background: linear-gradient(145deg, #6d28d9, #2e1065); font-size: 23px; } /* 4T */
.tile-tier-43 { background: linear-gradient(145deg, #4338ca, #1e1b4b); font-size: 23px; } /* 8T */
.tile-tier-44 { background: linear-gradient(145deg, #1d4ed8, #172554); font-size: 22px; } /* 16T */
.tile-tier-45 { background: linear-gradient(145deg, #0369a1, #082f49); font-size: 22px; } /* 32T */
.tile-tier-46 { background: linear-gradient(145deg, #0f766e, #042f2e); font-size: 22px; } /* 64T */
.tile-tier-47 { background: linear-gradient(145deg, #047857, #022c22); font-size: 19px; } /* 128T */
.tile-tier-48 { background: linear-gradient(145deg, #b45309, #451a03); font-size: 19px; } /* 256T */
.tile-tier-49 { background: linear-gradient(145deg, #b91c1c, #450a0a); font-size: 19px; } /* 512T */
.tile-tier-50 { 
    background: linear-gradient(135deg, #ffe000 0%, #ff007f 50%, #00f2fe 100%); 
    font-size: 16px; 
    box-shadow: 0 0 25px rgba(255, 224, 0, 1), 0 0 40px rgba(255, 0, 127, 0.6); 
    animation: rainbowPulse 1.8s infinite alternate; 
} /* 1024T */

@keyframes rainbowPulse {
    0%   { filter: hue-rotate(0deg); transform: scale(1); }
    100% { filter: hue-rotate(60deg); transform: scale(1.05); }
}

/* Floating Score Text */
.floating-score {
    position: absolute;
    font-size: 18px;
    font-weight: 800;
    color: #ffd15c;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
    pointer-events: none;
    z-index: 50;
    animation: floatUpFade 0.75s ease-out forwards;
}
@keyframes floatUpFade {
    0%   { transform: translate(-50%, 0) scale(0.8); opacity: 1; }
    50%  { transform: translate(-50%, -24px) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -45px) scale(1); opacity: 0; }
}

/* ── Modal / Overlay ── */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(8, 12, 26, 0.85);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-card {
    background: #151d3b;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 24px;
    padding: 28px 24px;
    text-align: center;
    max-width: 320px;
    width: 100%;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes modalPop {
    0%   { transform: scale(0.7); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal-title {
    font-size: 26px;
    font-weight: 800;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #ff416c, #ff4b2b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.modal-stats {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 16px;
    padding: 14px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    color: var(--text-muted);
}
.stat-row .val {
    font-weight: 800;
    color: #fff;
}
.stat-row.highlight .val {
    color: #ffd15c;
    font-size: 18px;
}

.modal-btn {
    width: 100%;
    padding: 12px;
    border-radius: 14px;
    border: none;
    background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
    color: #fff;
    font-family: inherit;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 242, 254, 0.4);
    transition: transform 0.15s;
    outline: none;
}
.modal-btn:hover { transform: scale(1.03); }
.modal-btn:active { transform: scale(0.96); }
