/* --- Reset and Core Styling --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    background: radial-gradient(circle at 50% 50%, #0b1a30 0%, #030814 100%);
    color: #f8f9fa;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    overflow-x: hidden;
    padding: 40px 20px;
}

/* --- Layout Container --- */
.dashboard-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

/* --- Header Section --- */
.draw-header {
    text-align: center;
    position: relative;
}

.logo-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    margin-bottom: 8px;
}

.logo-wrapper h1 {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 3px;
    background: linear-gradient(135deg, #f8f9fa 30%, #70e0ec 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.logo-icon {
    font-size: 2.2rem;
    filter: drop-shadow(0 0 10px rgba(112, 224, 236, 0.5));
    animation: float 3s ease-in-out infinite alternate;
}

.logo-icon:last-child {
    animation-delay: 1.5s;
}

.subtitle {
    font-size: 1.1rem;
    color: #9ea4c0;
    font-weight: 300;
    letter-spacing: 1px;
}

@keyframes float {
    0% { transform: translateY(0px) rotate(0deg); }
    100% { transform: translateY(-8px) rotate(5deg); }
}

/* --- Back Button --- */
.back-btn {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #f8f9fa;
    padding: 10px 20px;
    border-radius: 14px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    transition: all 0.25s ease;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #70e0ec;
    box-shadow: 0 0 15px rgba(112, 224, 236, 0.25);
    transform: translateY(-50%) translateX(-4px);
}

/* --- Category Navigation & Filters --- */
.controls-panel {
    background: rgba(10, 18, 36, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 20px;
    padding: 16px 24px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.categories {
    display: flex;
    gap: 10px;
}

.category-tab {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: #9ea4c0;
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.category-tab:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #f8f9fa;
}

.category-tab.active {
    background: linear-gradient(135deg, #70e0ec 0%, #1282a2 100%);
    border-color: transparent;
    color: #030814;
    box-shadow: 0 4px 15px rgba(112, 224, 236, 0.4);
}

.search-box {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 8px 16px;
    min-width: 250px;
    transition: all 0.25s ease;
}

.search-box:focus-within {
    border-color: #70e0ec;
    background: rgba(255, 255, 255, 0.04);
    box-shadow: 0 0 10px rgba(112, 224, 236, 0.15);
}

.search-box input {
    background: transparent;
    border: none;
    color: #f8f9fa;
    outline: none;
    font-size: 0.95rem;
    width: 100%;
    margin-left: 8px;
    font-family: inherit;
}

.search-box input::placeholder {
    color: #676e8a;
}

.search-icon {
    font-size: 1.1rem;
    color: #676e8a;
}

/* --- Drawings Grid --- */
.drawings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    width: 100%;
}

.card {
    background: rgba(10, 18, 36, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 20px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-6px) scale(1.02);
    border-color: rgba(112, 224, 236, 0.3);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(112, 224, 236, 0.15);
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(180deg, rgba(112, 224, 236, 0.05) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.card:hover::before {
    opacity: 1;
}

.card-svg-container {
    width: 100%;
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    transition: all 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.02);
}

.card:hover .card-svg-container {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.05);
}

.card-svg-container svg {
    width: 100%;
    height: 100%;
    color: #f8f9fa;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
    transition: transform 0.3s ease, color 0.3s ease;
}

.card:hover .card-svg-container svg {
    transform: scale(1.06);
    color: #70e0ec;
}

.card-info {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-name {
    font-size: 1rem;
    font-weight: 600;
    color: #f8f9fa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70%;
}

.difficulty-badge {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 3px 8px;
    border-radius: 6px;
    border: 1px solid transparent;
}

.difficulty-badge.easy {
    background: rgba(56, 176, 0, 0.15);
    border-color: rgba(56, 176, 0, 0.3);
    color: #38b000;
}

.difficulty-badge.medium {
    background: rgba(255, 183, 3, 0.15);
    border-color: rgba(255, 183, 3, 0.3);
    color: #ffb703;
}

.difficulty-badge.hard {
    background: rgba(230, 57, 70, 0.15);
    border-color: rgba(230, 57, 70, 0.3);
    color: #e63946;
}

/* --- Copy Studio Full-screen Modal --- */
.studio-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #030814;
    z-index: 10000;
    display: none;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
}

.studio-overlay.active {
    display: flex;
}

.studio-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 16px;
}

.studio-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.studio-title h2 {
    font-size: 1.6rem;
    font-weight: 700;
    color: #f8f9fa;
}

.studio-subtitle {
    font-size: 0.95rem;
    color: #9ea4c0;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 4px 12px;
    border-radius: 8px;
}

.studio-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.btn-icon-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-studio {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #f8f9fa;
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-studio:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.15);
}

.btn-studio.accent {
    background: linear-gradient(135deg, #70e0ec 0%, #1282a2 100%);
    color: #030814;
    font-weight: 600;
    border: none;
    box-shadow: 0 4px 15px rgba(112, 224, 236, 0.3);
}

.btn-studio.accent:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(112, 224, 236, 0.4);
}

.btn-studio.danger {
    background: rgba(230, 57, 70, 0.1);
    border-color: rgba(230, 57, 70, 0.3);
    color: #e63946;
}

.btn-studio.danger:hover {
    background: rgba(230, 57, 70, 0.2);
    border-color: #e63946;
}

/* --- Split Panel Workspace --- */
.studio-workspace {
    display: flex;
    flex: 1;
    gap: 20px;
    min-height: 0; /* Important for scroll/flex layout */
}

.reference-panel, .canvas-panel {
    flex: 1;
    background: rgba(10, 18, 36, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 24px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 0;
}

.panel-title {
    position: absolute;
    top: 16px;
    left: 20px;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #9ea4c0;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 10;
}

/* --- Reference Frame & Grid Overlay --- */
.reference-frame {
    width: 90%;
    aspect-ratio: 1;
    max-height: calc(100% - 60px);
    background: #ffffff;
    border-radius: 16px;
    padding: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.reference-frame svg {
    width: 100%;
    height: 100%;
    color: #030814;
}

/* Dynamic CSS Grid for drawing grid overlay */
.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 16px;
    pointer-events: none; /* Let clicks pass through */
    display: grid;
    box-sizing: border-box;
}

.grid-overlay.grid-4 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
}

.grid-overlay.grid-8 {
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
}

.grid-overlay div {
    border-right: 1px dashed rgba(112, 224, 236, 0.45);
    border-bottom: 1px dashed rgba(112, 224, 236, 0.45);
}

/* Remove outer borders */
.grid-overlay.grid-4, .grid-overlay.grid-8 {
    border: 2px solid #70e0ec;
}

/* --- Grid control bar in reference panel --- */
.grid-controls {
    position: absolute;
    bottom: 16px;
    display: flex;
    background: rgba(3, 8, 20, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
    z-index: 10;
}

.grid-btn {
    background: transparent;
    border: none;
    color: #9ea4c0;
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.grid-btn:hover {
    color: #f8f9fa;
}

.grid-btn.active {
    background: rgba(112, 224, 236, 0.15);
    color: #70e0ec;
}

/* --- Virtual Drawing Canvas --- */
.canvas-wrapper {
    width: 90%;
    aspect-ratio: 1;
    max-height: calc(100% - 90px);
    background: #ffffff;
    border-radius: 16px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

canvas#paintCanvas {
    width: 100%;
    height: 100%;
    border-radius: 16px;
    background: #ffffff;
    cursor: crosshair;
    touch-action: none; /* Prevent scroll on touch devices */
}

/* Canvas Overlay Grid (mirrors Reference Grid) */
.canvas-grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    border-radius: 16px;
    display: grid;
    box-sizing: border-box;
}

.canvas-grid-overlay.grid-4 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
}

.canvas-grid-overlay.grid-8 {
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
}

.canvas-grid-overlay div {
    border-right: 1px dashed rgba(0, 0, 0, 0.12);
    border-bottom: 1px dashed rgba(0, 0, 0, 0.12);
}

.canvas-grid-overlay.grid-4, .canvas-grid-overlay.grid-8 {
    border: 2px solid rgba(0, 0, 0, 0.2);
}

/* --- Canvas Drawing Toolbar --- */
.canvas-tools {
    width: 90%;
    margin-top: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(3, 8, 20, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 10px 20px;
    border-radius: 16px;
    z-index: 10;
}

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

.tool-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #676e8a;
    margin-right: 4px;
}

.color-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.color-dot:hover {
    transform: scale(1.15);
}

.color-dot.active {
    border-color: #f8f9fa;
    transform: scale(1.1);
    box-shadow: 0 0 8px rgba(255,255,255,0.4);
}

.brush-size-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #9ea4c0;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.brush-size-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #f8f9fa;
}

.brush-size-btn.active {
    background: rgba(112, 224, 236, 0.15);
    border-color: #70e0ec;
    color: #70e0ec;
}

.brush-indicator {
    background: currentColor;
    border-radius: 50%;
}

.brush-indicator.thin { width: 4px; height: 4px; }
.brush-indicator.medium { width: 8px; height: 8px; }
.brush-indicator.thick { width: 14px; height: 14px; }

.eraser-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #9ea4c0;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.eraser-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #f8f9fa;
}

.eraser-btn.active {
    background: rgba(255, 183, 3, 0.15);
    border-color: #ffb703;
    color: #ffb703;
}

/* --- Footer --- */
.app-footer {
    text-align: center;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.9rem;
    color: #676e8a;
}

/* --- PRINT STYLES --- */
@media print {
    /* Hide all regular web view elements */
    body {
        background: #ffffff !important;
        color: #000000 !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    .dashboard-container,
    .studio-header,
    .grid-controls,
    .canvas-tools,
    .studio-actions,
    .btn-studio,
    .studio-overlay-close-btn,
    .panel-title {
        display: none !important;
    }

    .studio-overlay {
        position: absolute !important;
        display: block !important;
        background: #ffffff !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        z-index: 1 !important;
    }

    /* Print Header */
    .print-header-only {
        display: block !important;
        text-align: center;
        margin-bottom: 20px;
        border-bottom: 2px solid #000000;
        padding-bottom: 10px;
    }

    .print-header-only h1 {
        font-size: 24pt;
        font-weight: 800;
        margin-bottom: 5px;
    }

    .print-header-only p {
        font-size: 11pt;
        color: #555;
    }

    /* Printable side-by-side workspace */
    .studio-workspace {
        display: flex !important;
        flex-direction: row !important;
        gap: 30px !important;
        width: 100% !important;
        height: auto !important;
        margin-top: 20px;
    }

    .reference-panel, .canvas-panel {
        flex: 1 !important;
        border: 2px solid #000000 !important;
        border-radius: 0 !important;
        padding: 20px !important;
        background: #ffffff !important;
        height: 380pt !important;
        box-shadow: none !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .reference-panel::before {
        content: '1. Look at this drawing';
        position: absolute;
        top: 10px;
        left: 15px;
        font-size: 11pt;
        font-weight: bold;
        color: #000;
    }

    .canvas-panel::before {
        content: '2. Draw your copy here!';
        position: absolute;
        top: 10px;
        left: 15px;
        font-size: 11pt;
        font-weight: bold;
        color: #000;
    }

    .reference-frame {
        width: 90% !important;
        height: 90% !important;
        box-shadow: none !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
    }

    .reference-frame svg {
        width: 100% !important;
        height: 100% !important;
        color: #000000 !important;
    }

    .canvas-wrapper {
        width: 90% !important;
        height: 90% !important;
        box-shadow: none !important;
        border: none !important;
        background: transparent !important;
    }

    canvas#paintCanvas {
        display: none !important; /* Hide the virtual drawings */
    }

    /* Keep the grid overlays visible for printing */
    .grid-overlay {
        border: 2px solid #000000 !important;
        border-radius: 0 !important;
    }

    .grid-overlay div {
        border-right: 1px dashed rgba(0, 0, 0, 0.4) !important;
        border-bottom: 1px dashed rgba(0, 0, 0, 0.4) !important;
    }

    .canvas-grid-overlay {
        display: grid !important;
        border: 2px solid #000000 !important;
        border-radius: 0 !important;
    }

    .canvas-grid-overlay div {
        border-right: 1px dashed rgba(0, 0, 0, 0.4) !important;
        border-bottom: 1px dashed rgba(0, 0, 0, 0.4) !important;
    }
}

/* Hide print header on screen */
.print-header-only {
    display: none;
}
