* {
    box-sizing: border-box;
}

body, html {
    height: 100%;
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.game-container {
    background: white;
    border-radius: 30px;
    padding: 16px 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 90vw;
    width: 95vw;
    height: 95vh;
    display: flex;
    flex-direction: column;
}

.header {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 30px;
    margin-bottom: 6px;
}

.stat {
    display: flex;
    flex-direction: row;
    align-items: baseline;
    gap: 6px;
}

.label {
    font-size: 16px;
    color: #666;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.value {
    font-size: 28px;
    font-weight: bold;
    color: #667eea;
}

/* Push shuffle to the right */
.header .btn-shuffle {
    margin-left: auto;
}

/* Timer bar */
.timer-bar-container {
    width: 100%;
    height: 22px;
    background: #ddd;
    border-radius: 11px;
    overflow: hidden;
    margin-bottom: 6px;
}

.timer-bar-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #667eea, #764ba2);
    border-radius: 11px;
    transition: width 1s linear;
}

.timer-bar-fill.urgent {
    background: linear-gradient(90deg, #ff4444, #ff0000);
}

.timer-value.urgent {
    color: #ff0000;
}

.game-board-container {
    position: relative;
    margin: 6px 0;
    display: flex;
    justify-content: center;
    flex: 1;
    align-items: center;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
    background: #f0f0f0;
    padding: 20px;
    border-radius: 15px;
    width: fit-content;
    height: fit-content;
    max-width: 85vw;
    max-height: 85vh;
    aspect-ratio: 1;
}

.tile {
    aspect-ratio: 1;
    border-radius: 12px;
    cursor: pointer;
    border: 4px solid transparent;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: white;
    font-size: 24px;
    user-select: none;
    position: relative;
    min-width: 60px;
    min-height: 60px;
}

.tile:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tile.selected {
    border-color: #333;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.6);
    transform: scale(1.1);
}

.tile.red { background: #FF6B6B; }
.tile.blue { background: #2196F3; }
.tile.green { background: #66BB6A; }
.tile.yellow { background: #FFA502; }
.tile.purple { background: #9B59B6; }
.tile.pink { background: #FF69B4; }

.tile.matched {
    animation: matchPulse 0.4s ease-out;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.8), inset 0 0 20px rgba(255, 255, 255, 0.5);
    border-color: white !important;
}

@keyframes matchPulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 30px rgba(255, 255, 255, 0.8), inset 0 0 20px rgba(255, 255, 255, 0.5);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 50px rgba(255, 255, 255, 1), inset 0 0 30px rgba(255, 255, 255, 0.8);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 30px rgba(255, 255, 255, 0.8), inset 0 0 20px rgba(255, 255, 255, 0.5);
    }
}

.particle {
    position: fixed;
    pointer-events: none;
    font-size: 24px;
    font-weight: bold;
    z-index: 1000;
}

@keyframes particleFloat {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0);
    }
}

.no-moves-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 10px;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.no-moves-overlay.active {
    display: flex;
}

.no-moves-message {
    text-align: center;
    background: white;
    padding: 40px;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.no-moves-message p {
    margin: 10px 0;
    font-size: 28px;
    font-weight: bold;
    color: #333;
}

.move-cost {
    font-size: 18px !important;
    color: #667eea !important;
}

/* Start screen overlay */
.start-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 12px;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 20;
}

.start-overlay.active {
    display: flex;
}

.start-message {
    text-align: center;
    color: white;
    padding: 40px;
}

.start-title {
    font-size: 56px;
    font-weight: bold;
    margin: 0 0 12px 0;
}

.start-sub {
    font-size: 26px;
    margin: 0 0 30px 0;
    color: #ccc;
}

.btn-start {
    font-size: 28px !important;
    padding: 16px 48px !important;
    display: block;
    margin: 0 auto;
}

.start-hint {
    font-size: 18px;
    color: #888;
    margin: 16px 0 0 0;
}

.start-bonuses {
    list-style: none;
    padding: 0;
    margin: 0 0 28px 0;
    display: inline-block;
    text-align: left;
}

.start-bonuses li {
    font-size: 18px;
    color: #e0d0ff;
    padding: 4px 0;
}

.start-bonuses li::before {
    content: '★ ';
    color: #ffd700;
}

/* Game Over overlay */
.game-over-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 12px;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 20;
}

.game-over-overlay.active {
    display: flex;
}

.game-over-message {
    text-align: center;
    color: white;
    padding: 40px;
}

.game-over-title {
    font-size: 56px;
    font-weight: bold;
    margin: 0 0 16px 0;
}

.game-over-score {
    font-size: 36px;
    margin: 0 0 30px 0;
}

.btn-play-again {
    font-size: 28px !important;
    padding: 16px 48px !important;
}

.btn-shuffle {
    padding: 9px 25px !important;
    font-size: 12px !important;
    align-self: center;
}

.btn-shuffle:hover {
    background: #FF5252;
}

.bottom-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.bottom-panels {
    display: flex;
    flex-direction: row;
    gap: 15px;
}

.console {
    background: #222;
    border: 2px solid #667eea;
    border-radius: 10px;
    padding: 15px;
    height: 220px;
    overflow-y: auto;
    display: flex;
    flex-direction: column-reverse;
    flex: 1;
}

.console-messages {
    font-family: 'Arial', 'Helvetica', sans-serif;
    font-size: 16px;
    font-weight: bold;
    color: #00ff00;
    line-height: 1.5;
}

.high-score-panel {
    flex: 1;
    background: #1a1a2e;
    border: 2px solid #667eea;
    border-radius: 10px;
    padding: 10px 15px;
    height: 220px;
    overflow-y: auto;
}

.high-score-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 5px;
    border-bottom: 1px solid #333;
    padding-bottom: 4px;
}

.high-score-title {
    color: #667eea;
    font-size: 13px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 2px;
    flex: 1;
    text-align: center;
}

.hs-clear-btn {
    background: none;
    border: 1px solid #444;
    border-radius: 4px;
    color: #888;
    font-size: 11px;
    padding: 2px 7px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.hs-clear-btn:hover {
    color: #ff6b6b;
    border-color: #ff6b6b;
}

.high-score-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.high-score-list li {
    display: flex;
    justify-content: space-between;
    font-size: 15px;
    font-weight: bold;
    color: #fff;
    padding: 2px 0;
    font-family: monospace;
}

.high-score-list li.new-entry {
    color: #ffd700;
}

.high-score-list .hs-rank {
    color: #888;
    width: 20px;
}

.high-score-list .hs-initials {
    flex: 1;
    padding-left: 6px;
}

.high-score-list .hs-score {
    color: #667eea;
}

.initials-label {
    font-size: 22px;
    margin: 0 0 12px 0;
    color: #ccc;
}

.initials-inputs {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 16px;
}

.initial-input {
    width: 52px;
    height: 60px;
    font-size: 32px;
    font-weight: bold;
    text-align: center;
    text-transform: uppercase;
    border: 3px solid #667eea;
    border-radius: 8px;
    background: #1a1a2e;
    color: white;
    outline: none;
}

.initial-input:focus {
    border-color: #ffd700;
}

.btn-submit-initials {
    font-size: 20px !important;
    padding: 10px 32px !important;
    margin-bottom: 16px;
}

.btn {
    padding: 18px 50px;
    font-size: 24px;
    font-weight: bold;
    border: none;
    border-radius: 12px;
    background: #667eea;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn:hover {
    background: #764ba2;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(0);
}

/* Combo flash display */
#comboDisplay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 52px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 2px 2px 0 #a07000;
    pointer-events: none;
    z-index: 15;
    opacity: 0;
    white-space: nowrap;
}

#comboDisplay.combo-animate {
    animation: comboFlash 1s ease-out forwards;
}

@keyframes comboFlash {
    0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
    20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
    50%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

@media (max-width: 600px) {
    .game-container {
        padding: 15px;
    }

    .header h1 {
        font-size: 24px;
    }

    .stats {
        gap: 20px;
    }

    .value {
        font-size: 24px;
    }

    .tile {
        font-size: 10px;
    }
}
