/* NEON BLOCK - Full Viewport Responsive Layout */

:root {
    --primary-bg: #1a1a2e;
    --secondary-bg: #16213e;
    --accent-color: #0f3460;
    --highlight-color: #e94560;
    --text-color: #f5f5f5;
    --border-color: #333;
    --block-size: 32px;
    --gap: 1px;

    --color-red: #ff4757;
    --color-blue: #3742fa;
    --color-green: #2ed573;
    --color-yellow: #ffa502;
    --color-purple: #a55eea;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Press Start 2P', monospace;
    background: var(--primary-bg);
    color: var(--text-color);
}

/* === Layout === */
.game-container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    height: 100vh;
}

/* === Header Bar === */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--secondary-bg);
    border-bottom: 2px solid var(--border-color);
    flex-shrink: 0;
    gap: 8px;
}

.game-info {
    display: flex;
    gap: 16px;
    align-items: center;
}

.info-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.info-label {
    font-size: 0.5rem;
    color: #666;
}

.info-value {
    font-size: 0.9rem;
    color: var(--highlight-color);
    text-shadow: 0 0 6px rgba(233, 69, 96, 0.4);
    transition: all 0.3s;
}

#score.score-update {
    animation: scoreFlash 0.5s ease-out;
}

@keyframes scoreFlash {
    0% { color: var(--highlight-color); }
    50% { color: #ffd700; text-shadow: 0 0 12px #ffd700; transform: scale(1.2); }
    100% { color: var(--highlight-color); }
}

/* === Controls === */
.game-controls {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.ctrl-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 0.55rem;
    padding: 7px 12px;
    background: var(--accent-color);
    color: var(--text-color);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}

.ctrl-btn:hover {
    background: var(--highlight-color);
}

.ctrl-btn:active {
    transform: scale(0.95);
}

/* Sound button with icon */
.ctrl-btn.sound-on::before { content: "♪ ON"; }
.ctrl-btn.sound-off::before { content: "♪ OFF"; }

/* === Game Board === */
.game-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    overflow: hidden;
}

.game-board {
    display: grid;
    gap: var(--gap);
    background: var(--secondary-bg);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    padding: 4px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.4), 0 0 30px rgba(0, 0, 0, 0.3);
}

/* === Blocks === */
.block {
    width: var(--block-size);
    height: var(--block-size);
    border-radius: 3px;
    cursor: pointer;
    transition: transform 0.12s, box-shadow 0.12s;
    border: 1px solid rgba(255, 255, 255, 0.12);
    position: relative;
}

.block.red { background: var(--color-red); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), inset 0 2px 4px rgba(255,255,255,0.15); }
.block.blue { background: var(--color-blue); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), inset 0 2px 4px rgba(255,255,255,0.15); }
.block.green { background: var(--color-green); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), inset 0 2px 4px rgba(255,255,255,0.15); }
.block.yellow { background: var(--color-yellow); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), inset 0 2px 4px rgba(255,255,255,0.15); }
.block.purple { background: var(--color-purple); box-shadow: inset 0 -2px 4px rgba(0,0,0,0.2), inset 0 2px 4px rgba(255,255,255,0.15); }

/* Hover - only on devices with hover capability */
@media (hover: hover) {
    .block:hover {
        transform: scale(1.08);
        box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
        z-index: 5;
    }
}

/* Selected (highlighted group) */
.block.selected {
    animation: selectedGlow 0.5s ease-in-out infinite alternate;
    z-index: 10;
}

@keyframes selectedGlow {
    from {
        transform: scale(1.05);
        box-shadow: 0 0 8px rgba(255, 255, 255, 0.6),
                    inset 0 0 6px rgba(255, 255, 255, 0.3);
        border-color: rgba(255, 255, 255, 0.6);
    }
    to {
        transform: scale(1.12);
        box-shadow: 0 0 16px rgba(255, 255, 255, 0.9),
                    inset 0 0 10px rgba(255, 255, 255, 0.5);
        border-color: rgba(255, 255, 255, 0.9);
    }
}

/* Removal animation */
.block.removing {
    animation: blockRemove 0.5s ease-out forwards;
    z-index: 20;
}

@keyframes blockRemove {
    0% {
        transform: scale(1.1);
        opacity: 1;
        filter: brightness(1.2);
    }
    40% {
        transform: scale(1.4);
        opacity: 0.7;
        filter: brightness(1.8) saturate(1.5);
        box-shadow: 0 0 20px currentColor;
    }
    100% {
        transform: scale(0);
        opacity: 0;
        filter: brightness(2);
    }
}

/* Chain delay classes */
.block.chain-1 { animation-delay: 0.05s; }
.block.chain-2 { animation-delay: 0.1s; }
.block.chain-3 { animation-delay: 0.15s; }
.block.chain-4 { animation-delay: 0.2s; }
.block.chain-5 { animation-delay: 0.25s; }

/* === Modals === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--secondary-bg);
    border: 3px solid var(--highlight-color);
    border-radius: 12px;
    padding: 36px 48px;
    text-align: center;
    box-shadow: 0 0 40px rgba(233, 69, 96, 0.3);
    animation: modalPop 0.3s ease-out;
}

@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-content h2 {
    color: var(--highlight-color);
    font-size: 1.3rem;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(233, 69, 96, 0.5);
}

.modal-content p {
    font-size: 0.7rem;
    margin-bottom: 10px;
    color: #ccc;
}

.modal-content span {
    color: var(--highlight-color);
    font-size: 0.85rem;
}

.modal-content .ctrl-btn {
    margin-top: 20px;
    font-size: 0.7rem;
    padding: 10px 24px;
}

/* === Level Clear Modal === */
.level-clear-content {
    min-width: 260px;
    border-color: #ffd700;
    box-shadow: 0 0 40px rgba(255, 215, 0, 0.2);
}

.clear-stars {
    font-size: 1.8rem;
    margin-bottom: 8px;
    letter-spacing: 6px;
    min-height: 2.2rem;
}

.star {
    display: inline-block;
    opacity: 0;
    transform: scale(0) rotate(-30deg);
    animation: starPop 0.4s ease-out forwards;
}

.star:nth-child(1) { animation-delay: 0.3s; }
.star:nth-child(2) { animation-delay: 0.5s; }
.star:nth-child(3) { animation-delay: 0.7s; }

.star.lit { color: #ffd700; text-shadow: 0 0 12px #ffd700; }
.star.dim { color: #444; text-shadow: none; }

@keyframes starPop {
    0% { opacity: 0; transform: scale(0) rotate(-30deg); }
    60% { opacity: 1; transform: scale(1.4) rotate(5deg); }
    100% { opacity: 1; transform: scale(1) rotate(0); }
}

.clear-stats {
    margin: 16px 0;
    text-align: left;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.55rem;
}

.stat-label {
    color: #888;
}

.stat-value {
    color: var(--text-color);
    font-size: 0.6rem;
}

.bonus-row {
    border-bottom: none;
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px solid var(--border-color);
}

.bonus-value {
    color: #ffd700 !important;
    font-size: 0.75rem !important;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

#clear-title.perfect {
    color: #ffd700;
    text-shadow: 0 0 15px #ffd700, 0 0 30px #ff8c00;
    animation: perfectPulse 0.8s ease-in-out infinite alternate;
}

@keyframes perfectPulse {
    from { text-shadow: 0 0 15px #ffd700, 0 0 30px #ff8c00; }
    to { text-shadow: 0 0 25px #ffd700, 0 0 50px #ff8c00, 0 0 70px #ffd700; }
}

/* Perfect clear fireworks overlay */
.perfect-overlay {
    position: fixed;
    inset: 0;
    z-index: 99;
    pointer-events: none;
}

.firework {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: fireworkBurst 1s ease-out forwards;
}

@keyframes fireworkBurst {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}

.firework-particle {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    animation: particleFly 0.8s ease-out forwards;
}

@keyframes particleFly {
    0% { transform: translate(0, 0) scale(1); opacity: 1; }
    100% { opacity: 0; }
}

/* Hi-score in header */
.hi-score .info-value {
    color: #ffd700;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.4);
}

/* NEW RECORD flash */
.new-record {
    color: #ffd700;
    font-size: 0.75rem;
    margin: 12px 0 4px;
    animation: recordFlash 0.6s ease-in-out infinite alternate;
}

@keyframes recordFlash {
    from { text-shadow: 0 0 8px #ffd700; opacity: 0.8; }
    to { text-shadow: 0 0 20px #ffd700, 0 0 40px #ff8c00; opacity: 1; }
}

/* Ranking modal */
.ranking-content {
    min-width: 280px;
    max-width: 90vw;
}

.ranking-list {
    list-style: none;
    margin: 16px 0;
    padding: 0;
    max-height: 45vh;
    overflow-y: auto;
}

.ranking-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    font-size: 0.55rem;
    border-bottom: 1px solid var(--border-color);
    gap: 8px;
}

.ranking-list li:last-child {
    border-bottom: none;
}

.rank-num {
    color: #888;
    min-width: 24px;
}

.rank-num.top-1 { color: #ffd700; }
.rank-num.top-2 { color: #c0c0c0; }
.rank-num.top-3 { color: #cd7f32; }

.rank-score {
    color: var(--highlight-color);
    font-size: 0.65rem;
    flex: 1;
    text-align: right;
}

.rank-detail {
    color: #666;
    font-size: 0.4rem;
    min-width: 80px;
    text-align: right;
}

.ranking-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
}

.btn-danger {
    color: #ff6b6b;
    border-color: #ff6b6b44;
    font-size: 0.45rem !important;
    padding: 5px 10px !important;
}

.btn-danger:hover {
    background: #ff6b6b;
    color: #fff;
}

.ranking-empty {
    color: #666;
    font-size: 0.55rem;
    padding: 24px 0;
    text-align: center;
}

.hidden {
    display: none !important;
}

/* === Responsive: Small phones === */
@media (max-width: 480px) {
    .game-header {
        padding: 6px 8px;
    }
    .game-info {
        gap: 8px;
    }
    .info-label {
        font-size: 0.4rem;
    }
    .info-value {
        font-size: 0.7rem;
    }
    .ctrl-btn {
        font-size: 0.45rem;
        padding: 5px 8px;
    }
    .game-main {
        padding: 4px;
    }
    .game-board {
        padding: 2px;
        border-width: 1px;
    }
    .modal-content {
        padding: 24px 20px;
        margin: 16px;
    }
    .modal-content h2 {
        font-size: 1rem;
    }
}

/* === Landscape phones === */
@media (max-height: 500px) {
    .game-header {
        padding: 4px 12px;
    }
    .info-label {
        display: none;
    }
    .info-item::before {
        font-size: 0.4rem;
        color: #666;
        margin-right: 4px;
    }
    .info-item:nth-child(1)::before { content: "S"; }
    .info-item:nth-child(2)::before { content: "L"; }
    .info-item:nth-child(3)::before { content: "B"; }
    .game-main {
        padding: 4px;
    }
}
