/* =========================================================
   DIGITAL SKETCHPAD STYLES 
   Based on OptiScanner UI (Terminal/Microfilm Aesthetic)
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap');

/* ------------------------------ */
/* 1) TOKENS & THEMES             */
/* ------------------------------ */
:root {
    /* OptiScanner Base Tokens */
    --os-font-ui: 'Roboto Mono', 'Courier New', monospace;
    --os-font-body: system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
    
    /* Neutral "microfilm" palette */
    --os-bg: #e9e9e9;        
    --os-surface: #d1d1d1;   
    --os-backdrop: #ffffff;  
    --os-text: #2c2c2c;
    --os-border: #555555;
    --os-interactive: #4a4a4a; 

    /* Spacing (4px base) */
    --os-s-2: 8px;  
    --os-s-3: 12px; 
    --os-s-4: 16px;
    --os-s-5: 20px; 

    /* Square corners */
    --os-radius: 0;
}

/* 🌙 Neon Dark Mode Overrides */
body.neon-mode {
    --os-bg: #0a0a0a;        /* Pitch black background */
    --os-surface: #1a1a1a;   /* Dark panels */
    --os-backdrop: #000000;  /* Pure black canvas */
    --os-text: #00ffcc;      /* Glowing cyan/neon text */
    --os-border: #333333;
    --os-interactive: #00ffcc;
}

/* ------------------------------ */
/* 2) BASE LAYOUT (The iPad Setup)*/
/* ------------------------------ */
html, body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden; 
    background: var(--os-bg);
    color: var(--os-text);
    font-family: var(--os-font-body);
    touch-action: none; 
}

body, #canvas-container, canvas {
    -webkit-touch-callout: none; /* Kills the iOS popup menu */
    -webkit-user-select: none;   /* Kills Safari text selection */
    -moz-user-select: none;      /* Kills Firefox text selection */
    -ms-user-select: none;       /* Kills Edge text selection */
    user-select: none;           /* The modern standard */
    touch-action: none;          /* Prevents native swipe-to-scroll/pinch-to-zoom */
}

/* ------------------------------ */
/* 3) THE WORKSPACE & CANVAS      */
/* ------------------------------ */
#workspace {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Prevent native scrollbars from clipping our zoomed canvas! */
}

#canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
    /* NEW: Smoothly animate the camera moves, and scale from the center */
    transform-origin: center center;
    transition: transform 0.05s linear; 
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#layer-background {
    background-color: var(--os-backdrop);
    transition: background-color 0.3s ease;
}

/* ------------------------------ */
/* 4) MINIMALIST UI TOGGLE        */
/* ------------------------------ */
.floating-btn {
    position: absolute;
    top: var(--os-s-4);
    left: var(--os-s-4);
    z-index: 100;
    
    font-family: var(--os-font-ui);
    text-transform: uppercase;
    font-size: 1rem;
    background: var(--os-surface);
    color: var(--os-text);
    border: 1px solid var(--os-border);
    padding: 10px 14px;
    border-radius: var(--os-radius);
    cursor: pointer;
    
    display: flex;
    align-items: center;
    gap: var(--os-s-3);
    transition: background 0.2s, color 0.2s;
}

.floating-btn:hover {
    background: var(--os-interactive);
    color: var(--os-bg);
}

#active-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: var(--os-text);
    border-radius: 50%; /* The only non-square element! */
}

/* Make it glow in Neon Mode */
body.neon-mode #active-indicator {
    box-shadow: 0 0 8px var(--os-text);
}

/* ------------------------------ */
/* 5) SLIDING DRAWER              */
/* ------------------------------ */
.drawer {
    position: absolute;
    top: 0;
    left: 0;
    width: 330px; /* NEW: Widened to comfortably fit all 7 layer buttons! */
    height: 100%;
    z-index: 200;
    
    background: var(--os-surface);
    border-right: 1px solid var(--os-border);
    display: flex;
    flex-direction: column;
    padding: var(--os-s-5);
    padding-bottom: 120px; /* NEW: Extra padding so the Export button clears the bottom */
    gap: var(--os-s-5);
    overflow-y: auto;
    
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.drawer.hidden {
    transform: translateX(-100%);
}

/* ------------------------------ */
/* 6) DRAWER TYPOGRAPHY           */
/* ------------------------------ */
.drawer header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px dashed var(--os-border);
    padding-bottom: var(--os-s-3);
}

.drawer h2 {
    font-family: var(--os-font-ui);
    text-transform: uppercase;
    font-size: 1.2rem;
    margin: 0;
    font-weight: 700;
}

.drawer h3 {
    font-family: var(--os-font-ui);
    text-transform: uppercase;
    font-size: 0.85rem;
    color: var(--os-text);
    opacity: 0.7;
    margin: 0 0 var(--os-s-2) 0;
}

/* ------------------------------ */
/* 7) TOOLS & CONTROLS            */
/* ------------------------------ */
.tool-group {
    display: flex;
    flex-direction: column;
    gap: var(--os-s-2);
}

.tool-group button, #theme-toggle {
    font-family: var(--os-font-ui);
    text-transform: uppercase;
    font-size: 0.9rem;
    border: 1px solid var(--os-border);
    background: var(--os-bg);
    color: var(--os-text);
    padding: 10px 18px;
    cursor: pointer;
    border-radius: var(--os-radius);
    text-align: left;
    transition: background 0.2s, color 0.2s;
}

.tool-group button:hover, #theme-toggle:hover {
    background: var(--os-interactive);
    color: var(--os-bg);
}

/* The selected tool gets an outline just like the OptiScanner segments */
.tool-group button.active {
    background: var(--os-text);
    color: var(--os-bg);
    outline: 2px solid var(--os-text);
    outline-offset: 2px;
}

/* Range Sliders (Brush Size) */
input[type="range"] {
    width: 100%;
    cursor: pointer;
    accent-color: var(--os-text);
}

/* Native Color Picker (Make it massive and square for easy tapping) */
input[type="color"] {
    width: 100%;
    height: 48px;
    padding: 2px;
    background: var(--os-backdrop);
    border: 1px solid var(--os-border);
    border-radius: var(--os-radius);
    cursor: pointer;
}

/* The tiny X badge for deleting swatches */
.delete-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #ff3b30;
    color: white;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    font-size: 12px;
    line-height: 14px;
    text-align: center;
    font-family: sans-serif;
    font-weight: bold;
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
    z-index: 10;
}

/* The iOS-style jiggle animation */
@keyframes jiggle {
    0% { transform: rotate(-2deg); }
    50% { transform: rotate(2deg); }
    100% { transform: rotate(-2deg); }
}

.swatch-jiggle {
    animation: jiggle 0.3s infinite;
    transform-origin: center;
}

/* Neon mode color picker override to look more cyberpunk */
body.neon-mode input[type="color"] {
    border-color: var(--os-text);
    box-shadow: 0 0 5px var(--os-text);
}

/* Real-time additive blending for the Draft Layer preview! */
body.neon-mode #layer-draft {
    mix-blend-mode: plus-lighter;
}

/* --- DRAWER FOOTER --- */
.drawer-footer {
    margin-top: auto;
    padding-top: var(--os-s-4);
    padding-bottom: 100px;
    border-top: 1px dashed var(--os-border);
    display: flex;
    justify-content: center; /* NEW: Groups everything in the middle */
    gap: 12px;               /* NEW: Sets the exact spacing between items */
    font-family: var(--os-font-ui);
    font-size: 0.8rem;
}

.drawer-footer a {
    color: var(--os-text);
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.drawer-footer a:hover {
    opacity: 1;
    text-decoration: underline dashed;
}

/* ------------------------------ */
/* 8) COLLAPSIBLE WORKSPACES      */
/* ------------------------------ */
.tool-group > *:first-child {
    user-select: none;
    transition: color 0.2s;
}

.tool-group > *:first-child:hover {
    color: var(--os-interactive);
}

/* Hide everything except the header when collapsed */
.tool-group.collapsed > *:not(:first-child) {
    display: none !important;
}

/* The dynamically added +/- icon */
.panel-toggle-icon {
    font-family: var(--os-font-ui);
    font-size: 0.9rem;
    opacity: 0.7;
    font-weight: normal;
}

/* ------------------------------ */
/* 9) THE FLOATING SMART RULER    */
/* ------------------------------ */
#ruler-overlay {
    position: absolute;
    width: 600px;
    height: 60px;
    background: rgba(150, 150, 150, 0.15); 
    backdrop-filter: blur(3px); 
    border: 1px solid var(--os-border);
    border-top: 2px solid var(--os-text); /* The solid drawing edge */
    z-index: 9999; /* UPDATE: Force it above all generated canvas layers */
    overflow: hidden; /* NEW: Clips the numbers perfectly! */ 
    cursor: grab;
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* CSS Magic: Procedural measurement ticks! */
    background-image: repeating-linear-gradient(
        to right,
        var(--os-text) 0,
        var(--os-text) 1px,
        transparent 1px,
        transparent 10px
    );
    background-size: 100% 10px;
    background-repeat: no-repeat;
    background-position: top;
    
    /* Removed the CSS transition so free-rotation and dragging is perfectly instant! */
    transform-origin: center center;
}

#ruler-overlay.hidden {
    display: none !important;
}

#ruler-overlay:active {
    cursor: grabbing;
}

/* Update this specific block in your CSS */
.ruler-tick-label {
    position: absolute;
    top: 12px;
    font-family: var(--os-font-ui);
    font-size: 0.65rem;
    font-weight: bold; /* NEW: Thicker text */
    color: var(--os-text);
    user-select: none;
    transform: translateX(-50%); 
    
    /* NEW: A strong outline so it pops off the background */
    text-shadow: 
        -1px -1px 0 var(--os-backdrop),  
         1px -1px 0 var(--os-backdrop),
        -1px  1px 0 var(--os-backdrop),
         1px  1px 0 var(--os-backdrop);
}

/* The Rotation Handle */
#ruler-rotate-handle {
    background: var(--os-bg);
    color: var(--os-text);
    border: 2px solid var(--os-text);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: crosshair; /* Indicates it can be dragged in any direction */
    font-size: 1.2rem;
    font-weight: bold;
    user-select: none;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* NEW: The Length Resize Handle */
#ruler-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    width: 20px;
    height: 100%;
    background: rgba(0, 0, 0, 0.1);
    cursor: ew-resize; /* East-West Resize Cursor */
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: 1px dashed var(--os-border);
}

#ruler-resize-handle::after {
    content: "||";
    font-size: 0.6rem;
    color: var(--os-text);
}

/* ==========================================
   THE STENCIL OVERLAY UI
   ========================================== */
#stencil-overlay {
    position: absolute;
    top: 0; 
    left: 0;
    transform-origin: center center;
    border: 1px dashed rgba(150, 150, 150, 0.4);
    z-index: 50; 
}

#stencil-overlay.hidden {
    display: none !important;
}

#stencil-rotate-handle {
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 28px; 
    height: 28px;
    background: var(--os-text);
    color: var(--os-bg);
    border-radius: 50%;
    display: flex; 
    justify-content: center; 
    align-items: center;
    cursor: grab;
    font-size: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

#stencil-resize-handle {
    position: absolute;
    bottom: -10px;
    right: -10px;
    width: 24px; 
    height: 24px;
    background: #1982c4;
    border: 3px solid var(--os-bg);
    border-radius: 50%;
    cursor: nwse-resize;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}