:root {
    /* Brand Colors */
    --brand-orange: #FF7A00;
    --brand-orange-deep: #CC5500;
    --brand-orange-light: #FFB347;
    --bg-deep: #0a0a1a;
    --bg-navy: #001D3B;

    /* UI Palette */
    --background: var(--bg-deep);
    --foreground: #f8fafc;
    --accent-color: var(--brand-orange);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-blur: blur(12px);

    /* Typography */
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;

    /* Shadows & Glows */
    --glow-orange: 0 0 30px rgba(255, 122, 0, 0.4), 0 0 50px rgba(255, 179, 71, 0.2);
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.8);
}

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

body {
    background-color: var(--background);
    color: var(--foreground);
    font-family: var(--font-main);
    min-height: 100vh;
    overflow-x: hidden;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(251, 119, 0, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(0, 29, 59, 0.2) 0%, transparent 40%);
    background-attachment: fixed;
}

/* Utilities */
.gradient-text {
    background: linear-gradient(90deg, var(--brand-orange-deep) 0%, var(--brand-orange) 50%, var(--brand-orange-light) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

.bg-gradient-orange {
    background: linear-gradient(135deg, var(--brand-orange-deep) 0%, var(--brand-orange) 50%, var(--brand-orange-light) 100%);
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--card-shadow);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

/* Glassmorphism Classes */
.glass {
    background: var(--card-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Typography */
h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 2rem;
    background: linear-gradient(90deg, var(--brand-orange-deep) 0%, var(--brand-orange) 50%, var(--brand-orange-light) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: center;
    letter-spacing: -1px;
}

/* UI Elements */
.btn {
    padding: 12px 24px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 1rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--brand-orange-deep) 0%, var(--brand-orange) 50%, var(--brand-orange-light) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 122, 0, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow-orange);
}

.input-group {
    margin-bottom: 1.5rem;
}

.input-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: #cbd5e1;
}

input,
textarea,
select {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: white;
    padding: 0.8rem 1rem;
    width: 100%;
    font-size: 1rem;
    transition: all 0.2s;
    outline: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--brand-orange);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 10px rgba(255, 122, 0, 0.2);
}

/* Admin Dashboard */
.admin-grid {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 2rem;
    margin-top: 2rem;
}

header {
    background: rgba(10, 10, 26, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--glass-border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.8rem;
    letter-spacing: -0.02em;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo-container img {
    height: 48px;
    width: auto;
}

.preview-area {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--glass-border);
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
}

.preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Range Slider */
.slider-container {
    padding: 1rem 0;
}

/* Custom Stylized Range Slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    outline: none;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

/* Chrome, Safari, Edge, Opera */
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--brand-orange);
    border: 3px solid #0a0a1a;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(255, 122, 0, 0.6);
    transition: all 0.2s ease;
    margin-top: -8.5px;
    /* Centers thumb on track */
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    cursor: pointer;
    background: linear-gradient(90deg, var(--brand-orange-deep) 0%, rgba(255, 255, 255, 0.05) var(--percent, 50%));
    border-radius: 10px;
}

input[type="range"]:active::-webkit-slider-thumb {
    transform: scale(1.1);
    box-shadow: 0 0 25px rgba(255, 122, 0, 0.8);
}

/* Firefox */
input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--brand-orange);
    border: 3px solid #0a0a1a;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(255, 122, 0, 0.6);
}

input[type="range"]::-moz-range-progress {
    background-color: var(--brand-orange);
    border-radius: 10px;
    height: 8px;
}

/* Puzzle Area */
#puzzle-canvas {
    width: 100%;
    height: 600px;
    margin-top: 2rem;
    border-radius: var(--border-radius);
    background: rgba(0, 0, 0, 0.2);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

#puzzle-canvas canvas {
    display: block;
    margin: 0 auto;
}

/* Overlay for finishing message */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    text-align: center;
    padding: 2rem;
    overflow-y: auto;
}

.overlay.active {
    display: flex;
    animation: fadeIn 0.5s ease;
}

.success-content {
    max-width: 800px;
    width: 100%;
}

.success-icon {
    font-size: 5rem;
    color: var(--brand-orange);
    margin-bottom: 1rem;
    animation: scaleIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0);
    }

    to {
        transform: scale(1);
    }
}

#puzzle-code-display {
    font-family: 'Space Mono', monospace;
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem;
    border-radius: 12px;
    margin: 1rem 0;
    border: 1px solid var(--brand-orange);
    color: var(--brand-orange);
    display: inline-block;
    font-size: 1.5rem;
    font-weight: 700;
}

/* Loading States */
.loader {
    width: 48px;
    height: 48px;
    border: 5px solid #FFF;
    border-bottom-color: transparent;
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* History Grid */
.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem !important;
    background: rgba(255, 255, 255, 0.03) !important;
}

.history-thumb {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.history-info {
    flex: 1;
}

.history-code {
    font-family: 'Space Mono', monospace;
    font-weight: 600;
    color: var(--primary-light);
    font-size: 1.1rem;
}

.history-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.btn-copy {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
}

.btn-copy:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--brand-orange);
    color: var(--brand-orange);
}

/* Timer */
.timer-container {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    border: 1px solid rgba(0, 210, 255, 0.3);
    font-family: 'Space Mono', monospace;
    color: var(--primary-light);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.1rem;
    height: fit-content;
}

.timer-icon {
    font-size: 1.2rem;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {

    /* Container adjustments */
    .container {
        padding: 1rem;
    }

    /* Header responsive */
    header .container {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem !important;
    }

    .logo-container {
        justify-content: center;
        width: 100%;
    }

    .logo-container img {
        width: 40px;
        height: 40px;
    }

    .logo-container h1 {
        font-size: 1.2rem !important;
    }

    /* Game header mobile */
    #gameHeader {
        flex-direction: column !important;
        gap: 1rem !important;
        width: 100%;
    }

    #gameHeader>div:first-child {
        text-align: center;
    }

    #puzzleTitle {
        font-size: 1rem !important;
    }

    #puzzleMeta {
        font-size: 0.75rem !important;
    }

    .timer-container {
        flex-wrap: wrap;
        justify-content: center;
        font-size: 0.9rem !important;
        padding: 0.75rem !important;
    }

    .timer-container span {
        font-size: 0.85rem !important;
    }

    .btn-copy {
        font-size: 0.7rem !important;
        padding: 0.3rem 0.6rem !important;
    }

    /* Code entry area mobile */
    #codeEntryArea {
        padding: 0 1rem;
    }

    #codeEntryArea h2 {
        font-size: 1.8rem !important;
        line-height: 1.2;
    }

    #codeEntryArea p {
        font-size: 0.95rem !important;
        margin-bottom: 1.5rem !important;
    }

    .glass-card {
        padding: 1.5rem !important;
    }

    #puzzleCodeInput {
        font-size: 1.5rem !important;
        padding: 1rem !important;
    }

    #loadBtn {
        padding: 1rem !important;
        font-size: 1rem !important;
    }

    /* Puzzle canvas mobile */
    #puzzle-canvas {
        height: 400px !important;
        margin-top: 1rem !important;
        border: 2px solid rgba(255, 122, 0, 0.3);
    }

    /* Add scroll hint */
    #puzzle-canvas::after {
        content: '👆 Scroll to view all pieces';
        position: absolute;
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(255, 122, 0, 0.9);
        color: white;
        padding: 0.5rem 1rem;
        border-radius: 20px;
        font-size: 0.75rem;
        pointer-events: none;
        animation: fadeOut 3s forwards;
        z-index: 10;
    }

    @keyframes fadeOut {

        0%,
        70% {
            opacity: 1;
        }

        100% {
            opacity: 0;
        }
    }

    /* Success overlay mobile */
    .success-icon {
        font-size: 3.5rem !important;
    }

    .success-content {
        padding: 1rem;
    }

    #successOverlay h2 {
        font-size: 1.8rem !important;
    }

    #completedImageContainer {
        max-width: 100% !important;
        margin: 1.5rem auto !important;
    }

    #finalMessage {
        font-size: 1rem !important;
        padding: 0 1rem;
    }

    #finalMessage>div {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }

    /* Button adjustments */
    .btn {
        padding: 0.8rem 1.2rem !important;
        font-size: 0.9rem !important;
    }

    .btn-primary {
        width: 100%;
    }

    .btn-secondary {
        padding: 0.6rem 1rem !important;
        font-size: 0.75rem !important;
    }

    /* Typography mobile */
    h1 {
        font-size: 2rem !important;
    }

    h2 {
        font-size: 1.5rem !important;
    }

    /* Admin grid mobile */
    .admin-grid {
        grid-template-columns: 1fr !important;
    }

    /* History grid mobile */
    .history-grid {
        grid-template-columns: 1fr !important;
    }

    .history-item {
        flex-direction: column;
        text-align: center;
    }

    .history-thumb {
        width: 100%;
        height: 150px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    #codeEntryArea h2 {
        font-size: 1.5rem !important;
    }

    #puzzleCodeInput {
        font-size: 1.2rem !important;
    }

    #puzzle-canvas {
        height: 300px !important;
    }

    .timer-container {
        font-size: 0.8rem !important;
    }

    .timer-icon {
        font-size: 1rem !important;
    }
}

/* Tablet landscape */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 1.5rem;
    }

    #puzzle-canvas {
        height: 500px;
    }

    .admin-grid {
        grid-template-columns: 1fr !important;
    }
}