/**
 * Studio Canvas CSS
 * 
 * Modern infinite canvas design with floating controls.
 * Inspired by Figma, Miro, and modern design tools.
 * 
 * Structure:
 * - Canvas Container - The main "stage" area (Bento card style)
 * - Virtual Canvas - Transformable layer for pan/zoom
 * - Studio Elements - Draggable/resizable design elements
 * - Resize Handles - Interactive corner/edge handles
 * - Floating Dock - Bottom toolbar (glassmorphism)
 * - iPhone Frame - Mobile preview device
 * - Alignment Guides - Snap-to guides
 * 
 * @see CanvasRenderer.ts for the JavaScript implementation
 */

/* ============================================
   CANVAS CONTAINER - Center Island (Bento Style)
   ============================================ */

.studio-canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 0;
    overflow: hidden !important;
    background-color: #F0F0F0;
    
    /* Bento floating card style */
    border-radius: var(--bento-radius, 16px);
    box-shadow: 
        inset 0 2px 4px rgba(0, 0, 0, 0.02),
        0 0 0 1px rgba(0, 0, 0, 0.04);
    
    /* Dot grid pattern - subtle workspace indicator */
    background-image: 
        radial-gradient(circle, rgba(0, 0, 0, 0.06) 1px, transparent 1px);
    background-size: 20px 20px;
    background-position: 10px 10px;
    
    /* Optical balance - nudge phone down 15px for breathing room */
    padding-top: 15px;
}

/* Canvas Area - the visible working area */
.studio-canvas {
    position: relative;
    background-color: transparent;
    box-shadow: var(--studio-shadow-md);
    border-radius: var(--studio-radius-lg);
    overflow: visible !important;
    width: 1280px;
    height: 720px;
    aspect-ratio: 16 / 9;
    margin: auto;
    border: 1px solid var(--studio-border);
    transform-origin: center center;
    transition: all 0.3s ease;
}

.studio-canvas.mobile-mode {
    background-color: transparent;
    box-shadow: none;
    border: none;
    width: 100%;
    height: 100%;
}

/* Grid System */
.studio-canvas.show-grid {
    background-image: 
        linear-gradient(to right, rgba(0, 102, 255, 0.04) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(0, 102, 255, 0.04) 1px, transparent 1px);
    background-size: 2% 2%;
}

/* ============================================
   VIRTUAL CANVAS CONTAINER
   The transformable layer that holds all elements
   ============================================ */

.virtual-canvas-container {
    position: absolute !important;
    left: 50%;
    top: 50%;
    transform-origin: center center !important;
    background-color: transparent !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    aspect-ratio: unset !important;
    border: none !important;
    
    /* Smooth text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    
    /* GPU acceleration */
    backface-visibility: hidden;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0.1, 1);
}

/* ============================================
   STUDIO ELEMENTS - Base Styles
   ============================================ */

.studio-element {
    position: absolute;
    overflow: visible !important;
    box-sizing: border-box;
    padding: 0;
    margin: 0;
    outline: none;
    image-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    cursor: move;
    /* Disable transitions during drag for instant feedback */
    transition: none;
}

/* Re-enable transitions when not dragging */
.studio-element:not(.active-dragging) {
    transition: opacity 0.15s ease;
}

/* Selected Element - Rectangular bounding box selection (like Figma) */
.studio-element.selected {
    /* Use outline for rectangular selection - outline ignores border-radius */
    outline: 2px solid var(--studio-primary);
    outline-offset: 0px;
}

/* Hide selection UI when previewing */
.studio-element.selected.prize-preview-mode {
    outline: none !important;
    box-shadow: none !important;
}

.studio-element.selected.prize-preview-mode .resize-handle {
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ============================================
   TEXT ELEMENTS
   ============================================ */

.studio-element.studio-text,
.studio-element.text {
    font-family: var(--studio-font-sans);
    line-height: 1.2;
    white-space: pre-wrap;
    box-sizing: border-box;
    overflow: visible !important;
    font-size: inherit;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    max-width: 100%;
    word-wrap: break-word;
}

.studio-element.studio-text.editing,
.studio-element.text.editing {
    outline: none !important;
    cursor: text !important;
}

/* ============================================
   IMAGE ELEMENTS
   ============================================ */

.studio-element.image .image-inner-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: inherit;
}

.studio-element.image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    image-rendering: smooth;
}

/* Image placeholder - Clean & Minimal */
.canvas-image-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: var(--studio-bg-main);
    border: 2px dashed var(--studio-border);
    border-radius: inherit;
    color: var(--studio-text-muted);
    font-size: var(--studio-text-sm);
    text-align: center;
    cursor: pointer;
    padding: 1.5rem;
    box-sizing: border-box;
    transition: all 0.15s ease;
}

.canvas-image-placeholder i {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    color: var(--studio-text-light);
    opacity: 0.6;
    transition: all 0.15s ease;
}

.canvas-image-placeholder:hover {
    border-color: var(--studio-primary);
    background-color: var(--studio-primary-lighter);
}

.canvas-image-placeholder:hover i {
    color: var(--studio-primary);
    opacity: 1;
}

/* ============================================
   CONTAINER ELEMENTS
   ============================================ */

.studio-element.container {
    background-color: #ffffff;
    border-radius: var(--studio-radius-lg);
}

/* ============================================
   SCRATCH AREA ELEMENTS
   ============================================ */

.studio-element.scratch-area {
    position: relative;
    overflow: visible !important;
}

.studio-element.scratch-area .scratch-area-cover {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    border-radius: inherit;
}

/* Cover Designs */
.scratch-area-cover[data-cover-design="solid-color"] {
    background-color: var(--cover-color, #888888);
}

.scratch-area-cover[data-cover-design="gradient"] {
    background: linear-gradient(
        var(--gradient-angle, 135deg),
        var(--gradient-start, #667eea),
        var(--gradient-end, #764ba2)
    );
}

/* Pattern Designs */
.scratch-area-cover[data-cover-design="pattern-dots"] {
    background-color: var(--pattern-bg, #f5f5f5);
    background-image: radial-gradient(var(--pattern-color, #ddd) 2px, transparent 2px);
    background-size: 12px 12px;
}

.scratch-area-cover[data-cover-design="pattern-stripes"] {
    background: repeating-linear-gradient(
        45deg,
        var(--pattern-bg, #f5f5f5),
        var(--pattern-bg, #f5f5f5) 10px,
        var(--pattern-color, #ddd) 10px,
        var(--pattern-color, #ddd) 20px
    );
}

.scratch-area-cover[data-cover-design="pattern-grid"] {
    background-color: var(--pattern-bg, #f5f5f5);
    background-image: 
        linear-gradient(var(--pattern-color, #ddd) 1px, transparent 1px),
        linear-gradient(90deg, var(--pattern-color, #ddd) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Foil Designs */
.scratch-area-cover[data-cover-design="foil-gold"] {
    background: linear-gradient(135deg, #bf953f 0%, #fcf6ba 25%, #b38728 50%, #fbf5b7 75%, #aa771c 100%);
}

.scratch-area-cover[data-cover-design="foil-silver"] {
    background: linear-gradient(135deg, #c0c0c0 0%, #f5f5f5 25%, #a8a8a8 50%, #f0f0f0 75%, #909090 100%);
}

.scratch-area-cover[data-cover-design="foil-holographic"] {
    background: linear-gradient(
        135deg,
        hsl(0, 100%, 75%) 0%,
        hsl(60, 100%, 75%) 17%,
        hsl(120, 100%, 75%) 33%,
        hsl(180, 100%, 75%) 50%,
        hsl(240, 100%, 75%) 67%,
        hsl(300, 100%, 75%) 83%,
        hsl(360, 100%, 75%) 100%
    );
    animation: holographic-shift 3s ease infinite;
}

@keyframes holographic-shift {
    0%, 100% { filter: hue-rotate(0deg); }
    50% { filter: hue-rotate(30deg); }
}

/* Shape variants */
.scratch-area-cover[data-shape="rounded"] {
    border-radius: 12px;
}

.scratch-area-cover[data-shape="circle"] {
    border-radius: 50%;
}

.scratch-area-cover[data-shape="pill"] {
    border-radius: 9999px;
}

/* Graininess overlay */
.scratch-area-cover[data-graininess]::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: var(--graininess, 0);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    mix-blend-mode: overlay;
}

/* ============================================
   RESIZE HANDLES - Hollow Square Design
   White squares with blue borders for contrast
   ============================================ */

.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #FFFFFF;
    border: 2px solid #3B82F6;
    border-radius: 2px;
    z-index: 110;
    transform: translate(-50%, -50%);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.resize-handle:hover {
    transform: translate(-50%, -50%) scale(1.15);
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.4);
}

/* Active/dragging state */
.resize-handle:active {
    background-color: #3B82F6;
    border-color: #FFFFFF;
}

.studio-element.selected .resize-handle {
    opacity: 1;
}

/* Corner handles - squares */
.resize-handle.nw { top: 0; left: 0; cursor: nwse-resize; }
.resize-handle.ne { top: 0; left: 100%; cursor: nesw-resize; }
.resize-handle.se { top: 100%; left: 100%; cursor: nwse-resize; }
.resize-handle.sw { top: 100%; left: 0; cursor: nesw-resize; }

/* Edge handles - rectangles */
.resize-handle.n  { top: 0; left: 50%; cursor: ns-resize; width: 16px; height: 6px; border-radius: 3px; }
.resize-handle.e  { top: 50%; left: 100%; cursor: ew-resize; width: 6px; height: 16px; border-radius: 3px; }
.resize-handle.s  { top: 100%; left: 50%; cursor: ns-resize; width: 16px; height: 6px; border-radius: 3px; }
.resize-handle.w  { top: 50%; left: 0; cursor: ew-resize; width: 6px; height: 16px; border-radius: 3px; }

/* ============================================
   FLOATING DOCK - State-of-the-Art 2025
   Inspired by Linear, Raycast, Arc Browser
   ============================================ */

.floating-dock {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px;
    
    /* White frosted glass - matches top menu and sidebars */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    
    /* Subtle border */
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 14px;
    
    /* Modern Figma glow - light and elevated */
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.08),
        0 4px 8px rgba(0, 0, 0, 0.04);
    
    z-index: 2000;
    transition: 
        opacity 0.25s ease,
        transform 0.25s cubic-bezier(0.2, 0, 0, 1),
        box-shadow 0.25s ease;
    
    white-space: nowrap;
}

.floating-dock:hover {
    box-shadow:
        0 12px 32px rgba(0, 0, 0, 0.1),
        0 6px 12px rgba(0, 0, 0, 0.05);
}

.floating-dock.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(16px) scale(0.95);
}

.floating-dock-group {
    display: flex;
    align-items: center;
    gap: 1px;
    padding: 2px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 10px;
}

.floating-dock-separator {
    width: 1px;
    height: 24px;
    background: linear-gradient(
        to bottom,
        transparent 0%,
        rgba(0, 0, 0, 0.08) 20%,
        rgba(0, 0, 0, 0.08) 80%,
        transparent 100%
    );
    margin: 0 6px;
}

.floating-dock-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    color: #6B7280;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.2, 0, 0, 1);
    position: relative;
}

.floating-dock-button:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.05);
    color: #1F2937;
    transform: scale(1.05);
}

.floating-dock-button:active:not(:disabled) {
    transform: scale(0.95);
    background: rgba(0, 0, 0, 0.08);
}

.floating-dock-button:disabled,
.floating-dock-button.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none !important;
}

.floating-dock-button.active {
    color: #4F46E5;
    background: rgba(79, 70, 229, 0.1);
}

.floating-dock-button i {
    font-size: 17px;
    font-weight: 500;
}

.floating-dock-zoom-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    height: 34px;
    padding: 0 8px;
    color: #1F2937;
    font-size: 11px;
    font-weight: 600;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-feature-settings: 'tnum' on;
    letter-spacing: 0.02em;
    pointer-events: none;
    user-select: none;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
    margin: 0 2px;
}

/* ============================================
   iPHONE 17 FRAME (Mobile Preview)
   ============================================ */

.iphone-17-frame {
    position: relative;
    width: 375px;
    height: 812px;
    background: #1a1a1a;
    border-radius: 54px;
    padding: 12px;
    box-shadow: 
        0 0 0 3px #222,
        0 0 0 6px #111,
        0 8px 24px rgba(0, 0, 0, 0.08),
        0 4px 8px rgba(0, 0, 0, 0.04);
    border: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 5;
    overflow: visible;
    transform-origin: center center;
    margin: 0;
    flex-shrink: 0;
}

.phone-screen {
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
    border-radius: 42px;
    overflow: hidden; /* Always clip content to phone screen boundary */
    /* Removed flex display - it can interfere with absolutely positioned children */
}

/* WinningReveal container - must fill entire phone screen */
.phone-screen > [data-winning-reveal] {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 100% !important;
    min-height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: inherit;
    box-sizing: border-box !important;
}

/* Reset all children inside WinningReveal */
.phone-screen > [data-winning-reveal] * {
    box-sizing: border-box;
}

/* Ensure the Canvas inside WinningReveal fills completely */
.phone-screen > [data-winning-reveal] > canvas,
.phone-screen > [data-winning-reveal] canvas {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 100% !important;
    min-height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Ensure inner div of WinningReveal also fills */
.phone-screen > [data-winning-reveal] > div {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
}

/* Edit mode styling - content always clipped, only z-index changes */
.phone-screen:has(.virtual-canvas-container.edit-mode),
.phone-screen.edit-mode-active {
    z-index: 150;
    /* Keep overflow: hidden to clip element content to screen boundary */
}

/* Screen shine effect */
.phone-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 100%;
    background: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, transparent 50%, rgba(0,0,0,0.05) 100%);
    pointer-events: none;
    z-index: 50;
    border-radius: inherit;
}

.phone-screen.edit-mode-active::before,
.phone-screen:has(.virtual-canvas-container.edit-mode)::before {
    display: none;
}

/* Frame overlay */
.phone-frame-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 12px solid #1a1a1a;
    border-radius: 54px;
    pointer-events: none;
    z-index: 100;
    box-shadow: 
        inset 0 0 0 1px rgba(255, 255, 255, 0.1),
        inset 0 0 20px rgba(0, 0, 0, 0.3);
}

.dynamic-island {
    position: absolute;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 30px;
    background: #000;
    border-radius: 15px;
    z-index: 200;
    box-shadow: inset 0 0 4px rgba(255,255,255,0.1);
}

.dynamic-island::after {
    content: '';
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    background: #111;
    border-radius: 50%;
    box-shadow: inset 0 0 2px rgba(255,255,255,0.2);
}

/* Phone Buttons */
.phone-button {
    position: absolute;
    background: #222;
    border-radius: 2px;
    z-index: 1;
}

.action-btn {
    left: -3px;
    top: 130px;
    width: 3px;
    height: 26px;
    border-radius: 2px 0 0 2px;
}

.volume-up {
    left: -3px;
    top: 180px;
    width: 3px;
    height: 54px;
    border-radius: 2px 0 0 2px;
}

.volume-down {
    left: -3px;
    top: 245px;
    width: 3px;
    height: 54px;
    border-radius: 2px 0 0 2px;
}

.side-btn {
    right: -3px;
    top: 200px;
    width: 3px;
    height: 86px;
    border-radius: 0 2px 2px 0;
}

/* ============================================
   DRAG & DROP STATES
   ============================================ */

.studio-canvas.dragover,
.studio-canvas-container.dragover {
    background-color: rgba(0, 102, 255, 0.04);
}

.studio-element.active-dragging {
    opacity: 0.9;
    z-index: 5000 !important;
    /* Force immediate updates - disable all transitions during drag */
    transition: none !important;
    /* Tell browser to optimize for transform changes */
    will-change: transform;
}

/* Optimize performance during dragging by disabling pointer events on children */
.studio-element.active-dragging * {
    pointer-events: none !important;
    /* Also disable transitions on children */
    transition: none !important;
}

.studio-element.active-resizing {
    z-index: 5000 !important;
}

/* ============================================
   ALIGNMENT GUIDES
   ============================================ */

.alignment-guide {
    position: absolute;
    background-color: var(--studio-primary);
    z-index: 9999;
    pointer-events: none;
    display: none;
}

.horizontal-guide {
    left: -10000px;
    right: -10000px;
    height: 1px;
    box-shadow: 0 0 8px rgba(0, 102, 255, 0.6);
    opacity: 1;
}

.vertical-guide {
    top: -10000px;
    bottom: -10000px;
    width: 1px;
    box-shadow: 0 0 8px rgba(0, 102, 255, 0.6);
    opacity: 1;
}

/* ============================================
   PREVIEW MODE OVERRIDES
   ============================================ */

.virtual-canvas-container.preview-mode .studio-element {
    cursor: default !important;
}

.virtual-canvas-container.preview-mode .resize-handle {
    display: none !important;
}
