:root {
    --bg-color: #111119;
    --text-color: #ffffff;
    --primary-color: #f39c12;
    /* 2048 gold-ish */
    --grid-bg: #bbada0;
    --grid-cell: #cdc1b4;

    /* Tile colors 2048 style but modernized */
    --tile-2: #eee4da;
    --tile-4: #ede0c8;
    --tile-8: #f2b179;
    --tile-16: #f59563;
    --tile-32: #f67c5f;
    --tile-64: #f65e3b;
    --tile-128: #edcf72;
    --tile-256: #edcc61;
    --tile-512: #edc850;
    --tile-1024: #edc53f;
    --tile-2048: #edc22e;

    --font-main: 'Outfit', sans-serif;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-blur: 10px;

    /* Grid and Tile Sizing */
    --tile-size: 80px;
    --grid-gap: 10px;
    --grid-padding: 10px;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    font-family: var(--font-main);
    color: var(--text-color);
    overflow: hidden;
    /* Prevent scrolling */
}

.bg-gradient {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 10% 20%, rgba(67, 67, 145, 0.2) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(200, 100, 50, 0.15) 0%, transparent 40%);
    z-index: -1;
}

.app-container {
    display: flex;
    flex-direction: column;
    /* Changed to column to stack main content and footer */
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    /* Changed from height to min-height */
    padding: 20px;
    box-sizing: border-box;
}

.main-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 40px;
    width: 100%;
}

/* Vision Container */
.vision-container {
    position: relative;
    width: 480px;
    max-width: 40vw;
    aspect-ratio: 4/3;
    background: #000;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--glass-border);
}

.output_canvas {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    /* Mirror effect */
}

.input_video {
    position: absolute;
    top: 0;
    left: 0;
    width: 640px;
    height: 480px;
    opacity: 0;
    z-index: -1;
}

.vision-status {
    position: absolute;
    top: 15px;
    left: 15px;
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 16px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #ff3b30;
    /* Red for inactive */
    box-shadow: 0 0 10px #ff3b30;
    transition: all 0.3s ease;
}

.status-dot.active {
    background-color: #34c759;
    /* Green for active */
    box-shadow: 0 0 10px #34c759;
}

.instruction-overlay {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px 20px;
    border-radius: 12px;
    backdrop-filter: blur(4px);
}

.instruction-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.8rem;
    opacity: 0.7;
}

.instruction-item .icon {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

/* Game Container */
.game-container {
    background: var(--glass-bg);
    padding: 30px;
    border-radius: 20px;
    backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    width: 450px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.title {
    font-size: 3rem;
    font-weight: 800;
    margin: 0;
    color: var(--text-color);
}

.score-box,
.best-box {
    background: rgba(255, 255, 255, 0.1);
    padding: 5px 15px;
    border-radius: 6px;
    text-align: center;
    min-width: 70px;
}

.score-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #dbdbdb;
    font-weight: 600;
}

#score-value,
#best-value {
    font-size: 1.4rem;
    font-weight: 700;
}

.game-board {
    position: relative;
    background: #1e1e24;
    /* Darker grid bg */
    border-radius: 8px;
    width: calc(4 * var(--tile-size) + 3 * var(--grid-gap) + 2 * var(--grid-padding));
    height: calc(4 * var(--tile-size) + 3 * var(--grid-gap) + 2 * var(--grid-padding));
    padding: var(--grid-padding);
    box-sizing: border-box;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: var(--grid-gap);
}

.grid-cell {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    width: 100%;
    height: 100%;
}

.tile {
    position: absolute;
    width: var(--tile-size);
    height: var(--tile-size);
    border-radius: 4px;
    background: var(--tile-2);
    color: #776e65;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5rem;
    font-weight: bold;
    transition: transform 150ms ease-in-out, opacity 100ms ease-in-out;
}

/* Tile Colors */
.tile-2 {
    background: var(--tile-2);
    color: #776e65;
    font-size: 3.5rem;
}

.tile-4 {
    background: var(--tile-4);
    color: #776e65;
    font-size: 3.5rem;
}

.tile-8 {
    background: var(--tile-8);
    color: #f9f6f2;
    font-size: 3.5rem;
}

.tile-16 {
    background: var(--tile-16);
    color: #f9f6f2;
    font-size: 3rem;
}

.tile-32 {
    background: var(--tile-32);
    color: #f9f6f2;
    font-size: 3rem;
}

.tile-64 {
    background: var(--tile-64);
    color: #f9f6f2;
    font-size: 3rem;
}

.tile-128 {
    background: var(--tile-128);
    color: #f9f6f2;
    font-size: 2.5rem;
    box-shadow: 0 0 10px rgba(237, 207, 114, 0.3);
}

.tile-256 {
    background: var(--tile-256);
    color: #f9f6f2;
    font-size: 2.5rem;
    box-shadow: 0 0 15px rgba(237, 204, 97, 0.4);
}

.tile-512 {
    background: var(--tile-512);
    color: #f9f6f2;
    font-size: 2.5rem;
    box-shadow: 0 0 20px rgba(237, 200, 80, 0.5);
}

.tile-1024 {
    background: var(--tile-1024);
    color: #f9f6f2;
    font-size: 2rem;
    box-shadow: 0 0 25px rgba(237, 197, 63, 0.6);
}

.tile-2048 {
    background: var(--tile-2048);
    color: #f9f6f2;
    font-size: 2rem;
    box-shadow: 0 0 30px rgba(237, 194, 46, 0.7);
}

.tile-new {
    animation: appear 200ms ease-in-out;
}

.tile-merged {
    animation: pop 200ms ease-in-out;
    z-index: 20;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.game-message {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #fff;
    border-radius: 20px;
    animation: fade-in 800ms ease 1200ms;
    animation-fill-mode: both;
}

.game-message.game-over {
    display: flex;
}

.game-message.game-won {
    display: flex;
    background: rgba(237, 194, 46, 0.5);
}

.game-message p {
    font-size: 3rem;
    font-weight: bold;
    margin-bottom: 30px;
}

.retry-button {
    background: #8f7a66;
    border-radius: 3px;
    color: #f9f6f2;
    height: 40px;
    line-height: 42px;
    padding: 0 20px;
    text-decoration: none;
    cursor: pointer;
    border: none;
    font-size: 1.1rem;
    font-weight: bold;
    transition: background 0.2s;
}

.retry-button:hover {
    background: #9f8b77;
}

/* Responsiveness */
@media screen and (max-width: 900px) {

    html,
    body {
        overflow: auto;
        /* Allow scrolling on mobile */
        height: auto;
    }

    .app-container {
        padding: 10px;
        min-height: 100vh;
        height: auto;
        overflow-y: visible;
    }

    .main-content {
        flex-direction: column;
        gap: 20px;
    }

    /* Make left-panel transparent to flex layout so children can be reordered */
    .left-panel {
        display: contents;
    }

    .vision-container {
        width: 100%;
        max-width: 480px;
        aspect-ratio: 4/3;
        order: 1;
        /* Camera first */
        margin-bottom: 20px;
        display: block;
        /* Restore visibility */
    }

    .manual-controls {
        display: none;
        /* Hide control buttons as requested */
    }

    .game-container {
        width: 100%;
        max-width: 400px;
        order: 2;
        /* Game board second */
        margin-bottom: 40px;
        /* Space before controls appear */
    }

    /* Hide logo on mobile as requested */
    .side-logo {
        display: none;
    }

    /* Ensure footer comes last if it wraps */
    .app-footer {
        order: 4;
        width: 100%;
        justify-content: center;
        padding-bottom: 30px;
    }
}

@media screen and (max-width: 500px) {
    :root {
        --tile-size: 65px;
        --grid-gap: 8px;
        --grid-padding: 8px;
    }

    .app-footer {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }

    .title {
        font-size: 2rem;
    }

    .side-logo {
        max-width: 50px;
    }

    .control-btn {
        width: 45px;
        height: 45px;
        font-size: 1.2rem;
    }

    .awesome-button {
        padding: 10px 25px;
        font-size: 0.9rem;
    }
}

@media screen and (max-width: 360px) {
    :root {
        --tile-size: 55px;
        --grid-gap: 5px;
        --grid-padding: 5px;
    }
}

/* Footer Styles */
.app-footer {
    display: flex;
    gap: 20px;
    margin-top: 30px;
    z-index: 10;
}

.footer-link {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-family: var(--font-main);
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    transition: color 0.3s ease;
    padding: 5px 10px;
}

.footer-link:hover {
    color: var(--primary-color);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: rgba(30, 30, 40, 0.95);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 40px;
    width: 90%;
    max-width: 500px;
    color: var(--text-color);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    position: relative;
    text-align: center;
    animation: fadeIn 0.3s ease;
}

.modal-content h2 {
    color: var(--primary-color);
    margin-top: 0;
    margin-bottom: 20px;
}

.modal-content p {
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.9);
}

.close-modal {
    color: #aaa;
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.3s;
}

.close-modal:hover,
.close-modal:focus {
    color: var(--primary-color);
    text-decoration: none;
    cursor: pointer;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Left Panel & Controls */
.left-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

/* Manual controls styles removed */

/* Awesome Button */
.awesome-button {
    margin-top: 10px;
    padding: 12px 35px;
    font-size: 1.1rem;
    font-weight: 800;
    color: white;
    background: linear-gradient(45deg, #FF00CC, #333399);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(51, 51, 153, 0.4);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-family: var(--font-main);
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
    z-index: 10;
}

.awesome-button:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 25px rgba(255, 0, 204, 0.6);
}

.awesome-button:active {
    transform: translateY(-1px) scale(0.98);
}

.side-logo {
    align-self: flex-start;
    /* Aligns with the top of the camera in the centered main-content */
    max-width: 80px;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.2));
    z-index: 100;
    transition: all 0.3s ease;
}

.side-logo:hover {
    filter: drop-shadow(0 0 15px var(--primary-color));
    transform: scale(1.05);
}