:root {
    --bg-dark: #0d060e;
    --card-bg: rgba(255, 112, 166, 0.05);
    --card-border: rgba(255, 112, 166, 0.18);
    --pink-primary: #ff70a6;
    --pink-accent: #ff9ebb;
    --pink-glow: rgba(255, 112, 166, 0.45);
    --purple-accent: #a06cd5;
    --gold-accent: #ffd166;
    --text-main: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.7);
    --font-heading: 'Outfit', 'Noto Sans SC', sans-serif;
    
    --board-size: min(84vw, 420px);
    --grid-gap: 10px;
    --cell-size: calc((var(--board-size) - (var(--grid-gap) * 5)) / 4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-heading);
    touch-action: none;
    background-image: 
        radial-gradient(circle at 15% 20%, rgba(255, 112, 166, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 85% 75%, rgba(160, 108, 213, 0.15) 0%, transparent 45%);
}

/* Ambient Orbs */
.ambient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
    z-index: 0;
    opacity: 0.5;
    animation: orbFloat 14s ease-in-out infinite alternate;
}
.orb-1 {
    width: 350px;
    height: 350px;
    background: rgba(255, 112, 166, 0.25);
    top: -50px;
    left: 10%;
}
.orb-2 {
    width: 400px;
    height: 400px;
    background: rgba(160, 108, 213, 0.2);
    bottom: 5%;
    right: 10%;
    animation-delay: -7s;
}

@keyframes orbFloat {
    0% { transform: translateY(0) scale(1); }
    100% { transform: translateY(40px) scale(1.1); }
}

/* Full screen FX canvas */
#fx-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 99;
}

.container {
    width: 100%;
    max-width: 500px;
    height: 100vh;
    max-height: 100vh;
    padding: 10px 14px 16px 14px;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    overflow: hidden;
    margin: 0 auto;
}

/* Header Navbar */
header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: rgba(255, 112, 166, 0.04);
    backdrop-filter: blur(20px);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text-main);
}

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(255, 112, 166, 0.12);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: var(--pink-accent);
    font-size: 1rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.back-btn:hover {
    background: var(--pink-primary);
    color: #fff;
    transform: translateX(-2px);
}

.brand-title {
    font-size: 1.15rem;
    font-weight: 900;
    background: linear-gradient(135deg, #fff 30%, var(--pink-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nav-btn {
    background: rgba(255, 112, 166, 0.1);
    border: 1px solid var(--card-border);
    color: var(--pink-accent);
    padding: 5px 10px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-btn:hover {
    background: var(--pink-primary);
    color: #fff;
    box-shadow: 0 0 12px var(--pink-glow);
}

.nav-btn.muted {
    opacity: 0.6;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    border-color: rgba(255, 255, 255, 0.1);
}

.nav-select {
    background: rgba(255, 112, 166, 0.1);
    border: 1px solid var(--card-border);
    color: var(--pink-accent);
    padding: 5px 6px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
}

.nav-select option {
    background: #18091a;
    color: #fff;
}

/* Dashboard Score Bar */
.dashboard-bar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin: 6px 0;
}

.stat-box {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 6px 4px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.stat-label {
    font-size: 0.64rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
    font-weight: 600;
}

.stat-value {
    font-size: 1.05rem;
    font-weight: 900;
    color: #fff;
}

.stat-value.pink {
    color: var(--pink-accent);
    text-shadow: 0 0 8px var(--pink-glow);
}

.stat-value.combo {
    color: var(--gold-accent);
    text-shadow: 0 0 10px rgba(255, 209, 102, 0.6);
}

/* Control Bar */
.controls-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    gap: 8px;
}

.diff-toggle {
    display: flex;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 2px;
}

.diff-btn {
    padding: 4px 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.diff-btn.active {
    background: linear-gradient(135deg, #ff70a6, #ff4d8d);
    color: #fff;
    box-shadow: 0 2px 10px rgba(255, 112, 166, 0.4);
}

.action-bar {
    display: flex;
    gap: 6px;
}

.btn-action {
    background: rgba(255, 112, 166, 0.12);
    border: 1px solid var(--card-border);
    color: var(--pink-accent);
    padding: 5px 12px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.btn-action:hover:not(:disabled) {
    background: var(--pink-primary);
    color: #fff;
    box-shadow: 0 4px 16px var(--pink-glow);
    transform: translateY(-1px);
}

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

/* 2048 Game Board Container */
.board-container {
    width: var(--board-size);
    height: var(--board-size);
    background: rgba(20, 10, 25, 0.75);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(255, 112, 166, 0.3);
    border-radius: 20px;
    padding: var(--grid-gap);
    position: relative;
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.6), 0 0 20px rgba(255, 112, 166, 0.15);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: var(--grid-gap);
    touch-action: none;
    flex-shrink: 0;
}

.grid-cell {
    background: rgba(255, 112, 166, 0.06);
    border: 1px solid rgba(255, 112, 166, 0.08);
    border-radius: 12px;
    width: 100%;
    height: 100%;
}

/* Dynamic Tile Container on Board */
.tile-container {
    position: absolute;
    top: var(--grid-gap);
    left: var(--grid-gap);
    right: var(--grid-gap);
    bottom: var(--grid-gap);
    pointer-events: none;
}

/* Smooth GPU Accelerated Tile Sliding */
.tile {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: calc(var(--cell-size) * 0.42);
    font-weight: 900;
    /* GPU Hardware Acceleration & Smooth 60FPS Sliding */
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1), background 0.25s ease;
    will-change: transform;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    line-height: 1;
    z-index: 2;
}

.tile.tile-merged-source {
    z-index: 1; /* Below merged tile */
}

/* Tile scale animations */
.tile-new {
    animation: popIn 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tile-merged {
    animation: mergePulse 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 3;
}

@keyframes popIn {
    0% { opacity: 0; scale: 0; }
    100% { opacity: 1; scale: 1; }
}

@keyframes mergePulse {
    0% { scale: 1; }
    50% { scale: 1.15; box-shadow: 0 0 20px var(--pink-glow); }
    100% { scale: 1; }
}

/* Default Tile Color Gradients */
.tile[data-value="1"] {
    background: linear-gradient(135deg, rgba(255, 182, 193, 0.3), rgba(255, 140, 175, 0.4));
    color: #fff;
    border: 1px solid rgba(255, 182, 193, 0.6);
}
.tile[data-value="2"] {
    background: linear-gradient(135deg, #ff9ebb, #ff6097);
    color: #ffffff;
    box-shadow: 0 4px 15px rgba(255, 96, 151, 0.4);
}
.tile[data-value="4"] {
    background: linear-gradient(135deg, #ff6b8b, #ff3366);
    color: #ffffff;
    box-shadow: 0 4px 16px rgba(255, 51, 102, 0.45);
}
.tile[data-value="8"] {
    background: linear-gradient(135deg, #ff4071, #e6004c);
    color: #ffffff;
    box-shadow: 0 4px 18px rgba(230, 0, 76, 0.5);
}
.tile[data-value="16"] {
    background: linear-gradient(135deg, #b552e6, #7c25c9);
    color: #ffffff;
    box-shadow: 0 4px 18px rgba(124, 37, 201, 0.5);
    font-size: calc(var(--cell-size) * 0.38);
}
.tile[data-value="32"] {
    background: linear-gradient(135deg, #9b51e0, #5c18a8);
    color: #ffffff;
    box-shadow: 0 4px 20px rgba(92, 24, 168, 0.55);
    font-size: calc(var(--cell-size) * 0.38);
}
.tile[data-value="64"] {
    background: linear-gradient(135deg, #6c5ce7, #3c24b5);
    color: #ffffff;
    box-shadow: 0 4px 20px rgba(60, 36, 181, 0.6);
    font-size: calc(var(--cell-size) * 0.38);
}
.tile[data-value="128"] {
    background: linear-gradient(135deg, #ff7675, #d63031);
    color: #ffffff;
    box-shadow: 0 4px 22px rgba(214, 48, 49, 0.6);
    font-size: calc(var(--cell-size) * 0.33);
}
.tile[data-value="256"] {
    background: linear-gradient(135deg, #fd79a8, #e84393);
    color: #ffffff;
    box-shadow: 0 4px 24px rgba(232, 67, 147, 0.65);
    font-size: calc(var(--cell-size) * 0.33);
}
.tile[data-value="512"] {
    background: linear-gradient(135deg, #ffeaa7, #fdcb6e);
    color: #5c3c00;
    box-shadow: 0 4px 25px rgba(253, 203, 110, 0.7);
    font-size: calc(var(--cell-size) * 0.33);
}
.tile[data-value="1024"] {
    background: linear-gradient(135deg, #fdcb6e, #e17055);
    color: #ffffff;
    box-shadow: 0 4px 26px rgba(225, 112, 85, 0.75);
    font-size: calc(var(--cell-size) * 0.28);
}
.tile[data-value="2048"] {
    background: linear-gradient(135deg, #ff007f, #7928ca);
    color: #ffffff;
    box-shadow: 0 0 30px #ff007f;
    font-size: calc(var(--cell-size) * 0.28);
    animation: goldGlow 1.5s infinite alternate;
}
.tile[data-value="4096"] {
    background: linear-gradient(135deg, #00f2fe, #4facfe);
    color: #ffffff;
    box-shadow: 0 0 30px #00f2fe;
    font-size: calc(var(--cell-size) * 0.28);
}

@keyframes goldGlow {
    0% { box-shadow: 0 0 15px rgba(255, 0, 127, 0.6); }
    100% { box-shadow: 0 0 32px rgba(255, 0, 127, 0.95), 0 0 15px rgba(255, 209, 102, 0.8); }
}

/* Custom Skin Tile Text Overlay */
.tile.has-skin {
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8), 0 0 8px rgba(0, 0, 0, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.4);
}

/* Floating Combo Badge Overlay */
.combo-badge-floating {
    position: absolute;
    top: -20px;
    right: 10px;
    background: linear-gradient(135deg, #ffd166, #ff70a6);
    color: #0d060e;
    font-weight: 900;
    font-size: 0.8rem;
    padding: 3px 10px;
    border-radius: 20px;
    box-shadow: 0 4px 15px rgba(255, 209, 102, 0.6);
    animation: bouncePop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 10;
}

@keyframes bouncePop {
    0% { transform: scale(0) translateY(10px); }
    50% { transform: scale(1.2) translateY(-5px); }
    100% { transform: scale(1) translateY(0); }
}

/* Instructions Footer */
.instructions {
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.4;
}

/* Modals & Drawers */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(12px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    padding: 16px;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: rgba(25, 12, 30, 0.95);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    transform: translateY(20px);
    transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-height: 85vh;
    overflow-y: auto;
}

.modal-overlay.active .modal-card {
    transform: translateY(0);
}

.modal-title {
    font-size: 1.35rem;
    font-weight: 900;
    margin-bottom: 6px;
    background: linear-gradient(135deg, #fff, var(--pink-accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-subtitle {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Skin Grid Manager inside Modal */
.skin-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.skin-item {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 6px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.skin-item:hover {
    border-color: var(--pink-primary);
    background: rgba(255, 112, 166, 0.1);
}

.skin-preview-box {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 900;
    font-size: 0.8rem;
    background-size: cover;
    background-position: center;
    position: relative;
    transform: none !important;
}

.skin-val-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 700;
}

.skin-btn-clear {
    font-size: 0.62rem;
    color: #ff4d8d;
    background: transparent;
    border: none;
    cursor: pointer;
}

/* Input Styles */
.form-group {
    margin-bottom: 14px;
}

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

.form-input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: #fff;
    font-size: 0.9rem;
    outline: none;
}

.form-input:focus {
    border-color: var(--pink-primary);
    box-shadow: 0 0 10px var(--pink-glow);
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.btn-modal {
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 800;
    font-size: 0.85rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #ff70a6, #ff4d8d);
    color: #fff;
    box-shadow: 0 4px 15px rgba(255, 112, 166, 0.4);
}

.btn-primary:hover {
    transform: scale(1.03);
    box-shadow: 0 6px 20px rgba(255, 112, 166, 0.6);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* Leaderboard Drawer List */
.lb-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 280px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.lb-item {
    display: grid;
    grid-template-columns: 32px 1fr 85px 65px;
    align-items: center;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 112, 166, 0.1);
    border-radius: 8px;
    font-size: 0.82rem;
}

.lb-rank {
    font-weight: 900;
    color: var(--pink-accent);
}

.lb-name {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lb-score {
    font-weight: 800;
    color: var(--pink-primary);
    text-align: right;
}

.lb-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
}

@media (max-width: 480px) {
    :root {
        --board-size: min(88vw, 340px);
        --grid-gap: 8px;
    }
    .container { padding: 8px 10px 12px 10px; }
    .stat-label { font-size: 0.58rem; }
    .stat-value { font-size: 0.95rem; }
    .brand-title { font-size: 1rem; }
    .skin-grid { grid-template-columns: repeat(3, 1fr); }
}
