:root {
    --primary: #8b5cf6;
    --primary-hov: #7c3aed;
    --accent: #ec4899;
    --bg-dark: #0f172a;
    --glass-bg: rgba(30, 41, 59, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --text-main: #f8fafc;
    --text-muted: #cbd5e1;
    --error: #ef4444;
}

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

body,
html {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* Background */
.background-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    background: radial-gradient(circle at top left, #1e1b4b, #0f172a 50%);
}

.shape {
    position: absolute;
    filter: blur(80px);
    opacity: 0.5;
    border-radius: 50%;
    animation: float 20s infinite alternate cubic-bezier(0.5, 0, 0.5, 1);
}

.shape:nth-child(1) {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: var(--primary);
}

.shape:nth-child(2) {
    bottom: -20%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: var(--accent);
    animation-delay: -5s;
}

.shape:nth-child(3) {
    top: 40%;
    left: 50%;
    width: 40vw;
    height: 40vw;
    background: #3b82f6;
    animation-delay: -10s;
}

@keyframes float {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(10%, -10%) scale(1.1);
    }
}

/* Layout */
.container {
    max-width: 900px;
    margin: 2rem auto;
    padding: 2.5rem;
    border-radius: 24px;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

h1.gradient-text {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #a855f7, #ec4899);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.subtitle {
    font-size: 1.15rem;
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
}

/* 3D Cube Scene */
.scene {
    width: 240px;
    height: 240px;
    margin: 40px auto;
    perspective: 1000px;
    user-select: none;
}

.cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-20deg) rotateY(-30deg);
}

.cube-face {
    position: absolute;
    width: 240px;
    height: 240px;
    border: 3px solid #111;
    background: #1e293b;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: box-shadow 0.3s, border-color 0.3s;
}

.cube-face.selected {
    box-shadow: 0 0 20px var(--primary);
    border-color: var(--primary);
}

.cube-face canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
    pointer-events: none;
    opacity: 0.6;
    /* Slightly dim image to see grid/colors based on UI rules, or fully opaque? keep 1 later if full */
}

/* Base face logic */
.face-label {
    position: absolute;
    z-index: 0;
    font-size: 2rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

/* Overlay 3x3 Grid for Cube Faces */
.color-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 4px;
    padding: 4px;
    z-index: 2;
    pointer-events: none;
}

.color-grid>div {
    background: rgba(0, 0, 0, 0.5);
    border-radius: 6px;
    transition: background 0.3s;
}

/* Face positioning */
.cube-up {
    transform: rotateX(90deg) translateZ(120px);
}

.cube-down {
    transform: rotateX(-90deg) translateZ(120px);
}

.cube-right {
    transform: rotateY(90deg) translateZ(120px);
}

.cube-left {
    transform: rotateY(-90deg) translateZ(120px);
}

.cube-front {
    transform: rotateY(0deg) translateZ(120px);
}

.cube-back {
    transform: rotateY(180deg) translateZ(120px);
}

/* Selected Face Actions */
.action-panel {
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 1.5rem;
    margin-top: 2rem;
    border: 1px solid var(--primary);
    animation: fadeIn 0.4s ease;
}

.action-panel h3 {
    margin-bottom: 1rem;
    color: #fff;
}

.action-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    font-size: 1.5rem;
    border: none;
    outline: none;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

.file-input {
    display: none;
}

.global-actions {
    text-align: center;
    margin-top: 2rem;
}

.btn {
    border: none;
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.6);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.error-notification {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border-left: 4px solid var(--error);
    padding: 1rem;
    margin-top: 1rem;
    border-radius: 8px;
}

.hidden {
    display: none !important;
}

/* Result Section */
.result-section {
    margin-top: 3rem;
    border-top: 1px solid var(--glass-border);
    padding-top: 2rem;
    text-align: center;
    animation: fadeIn 0.5s ease;
}

.solution-moves {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    background: rgba(0, 0, 0, 0.3);
    padding: 1.5rem;
    border-radius: 12px;
    margin-top: 1rem;
    word-spacing: 0.5rem;
    letter-spacing: 2px;
    border: 1px dashed rgba(139, 92, 246, 0.5);
    display: inline-block;
    max-width: 100%;
}

.mt-4 {
    margin-top: 1.5rem;
}

footer {
    text-align: center;
    margin-top: 3rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal-content {
    padding: 2rem;
    border-radius: 20px;
    text-align: center;
    max-width: 90vw;
}

.video-container {
    position: relative;
    width: 250px;
    height: 250px;
    margin: 1.5rem auto;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
}

#camera-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.overlay-grid {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 200px;
    height: 200px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 2px;
    pointer-events: none;
}

.guideline {
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 4px;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1rem;
}

/* Manual Paint */
.palette {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin: 1rem 0;
}

.color-swatch {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.2s, border 0.2s;
}

.color-swatch:hover,
.color-swatch.selected {
    transform: scale(1.15);
    border: 2px solid white;
}

.manual-grid {
    display: grid;
    grid-template-columns: repeat(3, 50px);
    grid-template-rows: repeat(3, 50px);
    gap: 4px;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.manual-cell {
    width: 50px;
    height: 50px;
    background: #333;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.manual-cell:hover {
    border-color: rgba(255, 255, 255, 0.8);
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}