:root {
    --bg-body: #050505;
    --bg-sidebar: #0b0b0d;
    --bg-card: #141416;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.4);
    --border: rgba(255, 255, 255, 0.08);
    --text: #ffffff;
    --text-muted: #888899;
}

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

body {
    background: var(--bg-body);
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

/* --- APP SHELL (Desktop Default) --- */
.app-shell {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* SIDEBAR */
.sidebar {
    width: 340px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 25px;
    z-index: 20;
    box-shadow: 10px 0 40px rgba(0, 0, 0, 0.4);
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.brand {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
}

.brand i {
    color: var(--accent);
}

.badge {
    background: var(--accent);
    color: #fff;
    font-size: 0.6rem;
    padding: 3px 6px;
    border-radius: 4px;
    font-weight: 800;
    vertical-align: middle;
    letter-spacing: 1px;
}

.back-link {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    transition: 0.2s ease;
    margin-bottom: 25px;
    width: fit-content;
}

.back-link:hover {
    color: #fff;
    border-color: var(--accent);
}

.back-link-icon {
    display: none;
    color: var(--text-muted);
    font-size: 1.2rem;
}

.scroll-controls {
    flex: 1;
    overflow-y: auto;
    padding-right: 5px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.scroll-controls::-webkit-scrollbar {
    width: 4px;
}

.scroll-controls::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 2px;
}

/* CONTROLS */
.control-group label {
    display: block;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.group-header label {
    margin-bottom: 0;
}

.actions {
    display: flex;
    gap: 5px;
}

.icon-btn,
.tool-btn {
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
}

.icon-btn {
    background: transparent;
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    border-radius: 4px;
    font-size: 0.75rem;
}

.icon-btn:hover {
    color: #fff;
    border-color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.tool-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    padding: 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    gap: 8px;
}

.tool-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #fff;
}

.tool-btn.active {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--accent);
    color: var(--accent);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

/* INSPECTOR */
.inspector-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.split-preview {
    display: flex;
    gap: 10px;
    height: 50px;
}

.color-preview-large {
    flex: 1;
    border-radius: 6px;
    background: #000;
    border: 1px solid var(--border);
    transition: background-color 0.05s;
}

.contrast-info {
    width: 60px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    border: 1px solid var(--border);
}

#contrastText {
    font-weight: 700;
    font-family: serif;
    font-size: 1rem;
    line-height: 1;
}

.contrast-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.val-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 4px;
}

.val-row:hover {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
}

.val-row .lbl {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 700;
    width: 35px;
}

.val-row .val {
    font-size: 0.8rem;
    font-family: 'Space Grotesk', monospace;
    color: #fff;
    flex: 1;
    text-align: right;
    margin-right: 10px;
}

.val-row i {
    font-size: 0.75rem;
    color: var(--accent);
    opacity: 0.5;
}

/* HARMONIES & PALETTES */
.harmony-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.harmony-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.mini-swatch,
.multi-swatch div {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
}

.multi-swatch {
    display: flex;
    gap: 4px;
}

.palette-grid,
.history-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}

.swatch,
.hist-swatch {
    aspect-ratio: 1;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: 0.2s;
}

.swatch:hover {
    transform: scale(1.1);
    border-color: #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    z-index: 2;
}

.empty-state {
    grid-column: span 5;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-style: italic;
    opacity: 0.7;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 6px;
    border: 1px dashed var(--border);
}

/* --- MAIN CANVAS AREA --- */
.main-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #080808;
    background-image: linear-gradient(#151515 1px, transparent 1px), linear-gradient(90deg, #151515 1px, transparent 1px);
    background-size: 50px 50px;
}

.main-area.drag-over-global {
    box-shadow: inset 0 0 0 4px var(--accent);
    background: rgba(99, 102, 241, 0.05);
}

.viewport {
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
    cursor: grab;
    touch-action: none;
    /* Prevent scroll on canvas */
}

.viewport.picking {
    cursor: crosshair;
}

.transform-layer {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
}

canvas {
    display: block;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    image-rendering: auto;
}

canvas.pixelated {
    image-rendering: pixelated;
}

canvas.grayscale {
    filter: grayscale(100%);
}

.placeholder-msg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #444;
    pointer-events: none;
}

.icon-box {
    font-size: 3rem;
    margin-bottom: 10px;
    color: #333;
}

.mobile-msg {
    display: none;
}

/* LOUPE */
.magnifier {
    position: fixed;
    width: 120px;
    height: 120px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    background-color: #000;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 1000;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    display: none;
}

.crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 6px;
    transform: translate(-50%, -50%);
    border: 1px solid var(--accent);
    background: rgba(99, 102, 241, 0.2);
}

.pixel-val {
    position: absolute;
    bottom: 10px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 2px 4px #000;
}

/* FLOATING TOOLBAR */
.toolbar-float {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(20, 20, 22, 0.9);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 8px 16px;
    display: flex;
    gap: 15px;
    align-items: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    z-index: 500;
}

.tool-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.divider {
    width: 1px;
    height: 20px;
    background: var(--border);
}

.toolbar-float button {
    background: transparent;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 1rem;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.2s;
}

.toolbar-float button:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

.toolbar-float button.active {
    color: #fff;
    background: var(--accent);
}

#zoomLevel {
    font-family: monospace;
    font-size: 0.85rem;
    color: #fff;
    width: 45px;
    text-align: center;
}

/* TOAST */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(20, 20, 22, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(168, 85, 247, 0.4);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: 0 10px 40px rgba(147, 51, 234, 0.2);
    animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    font-size: 0.9rem;
    font-weight: 500;
    min-width: 260px;
}

.toast i {
    color: #d8b4fe;
    font-size: 1.1rem;
    filter: drop-shadow(0 0 5px rgba(168, 85, 247, 0.5));
}

.hidden {
    display: none !important;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

/* ================================================= */
/* MOBILE RESPONSIVE STYLES (Max-Width: 900px)       */
/* ================================================= */
@media (max-width: 900px) {
    body {
        height: auto;
        overflow: hidden;
    }

    /* Lock scroll to app-shell */

    .app-shell {
        flex-direction: column;
        height: 100vh;
        /* Full viewport height */
        width: 100%;
        overflow: hidden;
    }

    /* 1. Main Canvas Area (Top Part) */
    .main-area {
        order: 1;
        width: 100%;
        height: 55vh;
        /* Top 55% for Canvas */
        flex-shrink: 0;
        border-bottom: 1px solid var(--border);
    }

    /* 2. Sidebar / Controls (Bottom Part) */
    .sidebar {
        order: 2;
        width: 100%;
        height: 45vh;
        /* Bottom 45% for Controls */
        border-right: none;
        padding: 20px;
        box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
    }

    .back-link {
        display: none;
    }

    /* Hide large back link */
    .sidebar-header {
        margin-bottom: 15px;
    }

    .back-link-icon {
        display: block;
    }

    /* Show icon only */

    /* Adjust Toolbars */
    .toolbar-float {
        bottom: 20px;
        /* Closer to bottom of main area */
        width: 90%;
        max-width: 400px;
        padding: 6px 15px;
        justify-content: space-around;
    }

    .toolbar-float button {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    /* Adjust Messages */
    .desktop-msg {
        display: none;
    }

    .mobile-msg {
        display: block;
        font-weight: 600;
        color: #666;
    }

    /* Fix Magnifier Position on Mobile */
    /* It will be offset via JS, but we ensure it fits */
    .magnifier {
        width: 90px;
        height: 90px;
        border-width: 2px;
    }

    /* Toast positioning */
    .toast-container {
        top: 10px;
        left: 10px;
        right: 10px;
        align-items: center;
    }

    .toast {
        width: 100%;
        min-width: auto;
        justify-content: center;
    }
}
