/* ==========================================
   2048 BLOUM - Styles
   ========================================== */

/* Variables */
:root {
    --primary: #00d9ff;
    --secondary: #a855f7;
    --accent: #f472b6;
    --bg-dark: #0a0a0f;
    --bg-card: rgba(255, 255, 255, 0.05);
    --text: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.6);
    
    /* Grid colors */
    --grid-bg: rgba(255, 255, 255, 0.08);
    --cell-bg: rgba(255, 255, 255, 0.05);
    
    /* Tile colors - Aurora palette */
    --tile-2: #e0f7fa;
    --tile-4: #b2ebf2;
    --tile-8: #81d4fa;
    --tile-16: #4fc3f7;
    --tile-32: #29b6f6;
    --tile-64: #03a9f4;
    --tile-128: #a855f7;
    --tile-256: #9333ea;
    --tile-512: #7c3aed;
    --tile-1024: #f472b6;
    --tile-2048: #ec4899;
    --tile-super: linear-gradient(135deg, #00d9ff, #a855f7, #f472b6);
    
    /* Tile text colors */
    --tile-text-light: #1a1a2e;
    --tile-text-dark: #ffffff;
    
    --grid-size: min(90vw, 420px);
    --cell-gap: 12px;
    --cell-size: calc((var(--grid-size) - var(--cell-gap) * 5) / 4);
}

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

/* Body */
body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Background Grid */
.bg-grid {
    position: fixed;
    inset: 0;
    background-image: 
        linear-gradient(rgba(0, 217, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 217, 255, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
    pointer-events: none;
    z-index: 0;
}

/* Floating Orbs */
.floating-orbs {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.3;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 300px;
    height: 300px;
    background: var(--primary);
    top: -100px;
    right: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 250px;
    height: 250px;
    background: var(--secondary);
    bottom: 20%;
    left: -80px;
    animation-delay: -7s;
}

.orb-3 {
    width: 200px;
    height: 200px;
    background: var(--accent);
    bottom: -50px;
    right: 20%;
    animation-delay: -14s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -30px) scale(1.1); }
    66% { transform: translate(-20px, 20px) scale(0.9); }
}

/* Game Wrapper */
.game-wrapper {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    padding-bottom: env(safe-area-inset-bottom, 1rem);
}

/* Header */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    margin-bottom: 1rem;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.3s;
}

.back-link:hover {
    color: var(--primary);
}

.game-logo {
    font-size: 1.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sound-btn {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.5rem;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
}

.sound-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sound-btn.muted {
    opacity: 0.5;
}

/* Game Container */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

/* Screens */
.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.screen.hidden {
    display: none;
}

/* Menu Screen */
.menu-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.menu-content {
    width: 100%;
    max-width: 400px;
}

.title-glow {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.2); }
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
    font-size: 1.1rem;
}

/* Buttons */
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    color: white;
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 600;
    padding: 1rem 2.5rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 217, 255, 0.3);
}

.btn-glow {
    animation: btnGlow 2s ease-in-out infinite;
}

@keyframes btnGlow {
    0%, 100% { box-shadow: 0 0 20px rgba(0, 217, 255, 0.3); }
    50% { box-shadow: 0 0 40px rgba(168, 85, 247, 0.4); }
}

.btn-secondary {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    padding: 0.8rem 2rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

/* Instructions */
.instructions {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 1.5rem;
    margin: 2rem 0;
    text-align: left;
}

.instructions h3 {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1rem;
    color: var(--primary);
}

.instruction-grid {
    display: grid;
    gap: 0.8rem;
}

.instruction {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.instruction .icon {
    font-size: 1.2rem;
    min-width: 2rem;
    text-align: center;
}

/* Leaderboard */
.leaderboard-preview,
.leaderboard-full {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 1.5rem;
    margin-top: 1.5rem;
}

.leaderboard-preview h3,
.leaderboard-full h3 {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--secondary);
}

.leaderboard-list {
    max-height: 300px;
    overflow-y: auto;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    margin-bottom: 0.4rem;
    background: rgba(255, 255, 255, 0.02);
    transition: background 0.3s;
}

.leaderboard-entry:hover {
    background: rgba(255, 255, 255, 0.05);
}

.leaderboard-entry.top-1 {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.1), rgba(255, 215, 0, 0.05));
}

.leaderboard-entry.top-2 {
    background: linear-gradient(135deg, rgba(192, 192, 192, 0.1), rgba(192, 192, 192, 0.05));
}

.leaderboard-entry.top-3 {
    background: linear-gradient(135deg, rgba(205, 127, 50, 0.1), rgba(205, 127, 50, 0.05));
}

.rank {
    font-weight: 700;
    min-width: 2rem;
    color: var(--text-muted);
}

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

.pseudo {
    flex: 1;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score {
    font-weight: 700;
    color: var(--primary);
}

.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
}

/* Game Screen */
.game-screen {
    align-items: center;
}

.game-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: var(--grid-size);
    margin-bottom: 1rem;
}

.hud-left {
    display: flex;
    gap: 0.5rem;
}

.score-display {
    display: flex;
    gap: 0.5rem;
}

.score-box {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    text-align: center;
    min-width: 80px;
}

.score-box .score-label {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.score-box span:last-child {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
}

.hud-right {
    display: flex;
    gap: 0.5rem;
}

.action-btn {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.5rem 0.8rem;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary);
}

.action-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Grid */
.grid-container {
    position: relative;
    width: var(--grid-size);
    height: var(--grid-size);
    touch-action: none;
}

.grid-background {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--cell-gap);
    padding: var(--cell-gap);
    background: var(--grid-bg);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.grid-cell {
    background: var(--cell-bg);
    border-radius: 8px;
}

.tiles-container {
    position: absolute;
    inset: 0;
    padding: var(--cell-gap);
}

/* Tiles */
.tile {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 8px;
    font-weight: 700;
    font-size: 2rem;
    transition: transform 0.15s ease-out;
    user-select: none;
}

.tile.new {
    animation: tileNew 0.2s ease-out;
}

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

.tile.merge {
    animation: tileMerge 0.2s ease-out;
}

@keyframes tileMerge {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Tile colors */
.tile-2 {
    background: var(--tile-2);
    color: var(--tile-text-light);
}

.tile-4 {
    background: var(--tile-4);
    color: var(--tile-text-light);
}

.tile-8 {
    background: var(--tile-8);
    color: var(--tile-text-light);
}

.tile-16 {
    background: var(--tile-16);
    color: var(--tile-text-light);
}

.tile-32 {
    background: var(--tile-32);
    color: var(--tile-text-dark);
}

.tile-64 {
    background: var(--tile-64);
    color: var(--tile-text-dark);
}

.tile-128 {
    background: var(--tile-128);
    color: var(--tile-text-dark);
    font-size: 1.8rem;
}

.tile-256 {
    background: var(--tile-256);
    color: var(--tile-text-dark);
    font-size: 1.8rem;
}

.tile-512 {
    background: var(--tile-512);
    color: var(--tile-text-dark);
    font-size: 1.8rem;
}

.tile-1024 {
    background: var(--tile-1024);
    color: var(--tile-text-dark);
    font-size: 1.5rem;
}

.tile-2048 {
    background: var(--tile-2048);
    color: var(--tile-text-dark);
    font-size: 1.5rem;
    box-shadow: 0 0 30px rgba(236, 72, 153, 0.6);
}

.tile-super {
    background: var(--tile-super);
    color: var(--tile-text-dark);
    font-size: 1.3rem;
    box-shadow: 0 0 40px rgba(168, 85, 247, 0.7);
    animation: superPulse 1s ease-in-out infinite;
}

@keyframes superPulse {
    0%, 100% { box-shadow: 0 0 30px rgba(168, 85, 247, 0.5); }
    50% { box-shadow: 0 0 50px rgba(0, 217, 255, 0.7); }
}

/* Overlay */
.overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 15, 0.9);
    border-radius: 12px;
    z-index: 10;
    backdrop-filter: blur(5px);
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 2rem;
}

.overlay-content h2 {
    font-size: 2rem;
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.win-message {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

.overlay-content .btn-primary {
    margin-bottom: 1rem;
    display: block;
    width: 100%;
}

/* Game Over Screen */
.gameover-screen {
    justify-content: flex-start;
    padding-top: 2rem;
    overflow-y: auto;
}

.gameover-content {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
    text-align: center;
}

.gameover-title {
    font-size: 2.5rem;
    font-weight: 800;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, var(--accent), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.score-final {
    margin-bottom: 1.5rem;
}

.score-big {
    font-size: 4rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.score-final .score-label {
    color: var(--text-muted);
    font-size: 1rem;
}

.stats-row {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.stat {
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--secondary);
}

/* Save Score Form */
.save-score-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.pseudo-input {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.8rem 1rem;
    color: var(--text);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

.pseudo-input::placeholder {
    color: var(--text-muted);
}

.pseudo-input:focus {
    border-color: var(--primary);
}

.save-score-form .btn-primary {
    padding: 0.8rem 1.5rem;
}

.save-status {
    min-height: 1.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.save-status.success {
    color: #4ade80;
}

.save-status.error {
    color: #f87171;
}

/* Game Over Actions */
.gameover-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

/* Responsive */
@media (max-width: 450px) {
    :root {
        --grid-size: calc(100vw - 2rem);
        --cell-gap: 8px;
    }
    
    .tile {
        font-size: 1.5rem;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 1.3rem;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 1.1rem;
    }
    
    .tile-super {
        font-size: 1rem;
    }
    
    .title-glow {
        font-size: 2rem;
    }
    
    .score-box {
        min-width: 60px;
        padding: 0.4rem 0.6rem;
    }
    
    .score-box span:last-child {
        font-size: 1rem;
    }
}

@media (max-height: 700px) {
    .game-wrapper {
        padding: 0.5rem;
    }
    
    .game-header {
        margin-bottom: 0.5rem;
    }
    
    .instructions {
        margin: 1rem 0;
        padding: 1rem;
    }
    
    .leaderboard-list {
        max-height: 150px;
    }
}

/* Scrollbar */
.leaderboard-list::-webkit-scrollbar {
    width: 6px;
}

.leaderboard-list::-webkit-scrollbar-track {
    background: transparent;
}

.leaderboard-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.leaderboard-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}
