* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    background: #0a0f1c;
    color: #e5e7eb;
    line-height: 1.6;
}

header {
    background: linear-gradient(135deg, #0a1f3d, #1e40af);
    padding: 1.5rem 1rem;
    text-align: center;
    border-bottom: 3px solid #60a5fa;
}

h1 { margin: 0; font-size: 2.1rem; color: #fff; }
.tagline { color: #d4af37; font-weight: 600; margin: 0.5rem 0 0; font-size: 1.05rem; }

.container {
    max-width: 1380px;
    margin: 1rem auto;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Controls - Collapsible on mobile */
.controls {
    background: #111827;
    border-radius: 20px;
    padding: 1.25rem;
    box-shadow: 0 20px 50px -12px rgb(0 0 0 / 0.6);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.control-section {
    border-bottom: 1px solid #334155;
    padding-bottom: 1.25rem;
}
.control-section:last-child { border-bottom: none; padding-bottom: 0; }

h3 { color: #60a5fa; margin: 0 0 0.8rem; font-size: 1.2rem; }
h4 { color: #93c5fd; margin: 1rem 0 0.5rem; font-size: 1rem; }

input[type="url"], input[type="text"] {
    width: 100%; padding: 12px 14px; background: #1f2937; border: 1px solid #475569;
    border-radius: 10px; color: white; font-size: 1rem;
}
input[type="range"] { width: 100%; accent-color: #60a5fa; }

/* Buttons */
.primary-btn {
    background: linear-gradient(90deg, #1e40af, #3b82f6);
    color: white; font-weight: 700; padding: 16px; border-radius: 12px;
    width: 100%; cursor: pointer; font-size: 1.1rem;
}
.secondary-btn {
    background: #334155; color: #e2e8f0; padding: 12px 20px; border-radius: 10px;
    cursor: pointer;
}

/* Preview - Sticky & Responsive */
.canvas-panel {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #0a0f1c;
    padding-bottom: 1rem;
}

.canvas-wrapper {
    background: #111827;
    padding: 12px;
    border-radius: 20px;
    box-shadow: 0 20px 50px -12px rgb(0 0 0 / 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 320px; /* Mobile default */
    position: relative;
}

canvas {
    max-width: 100%;
    height: auto;
    max-height: 45vh; /* Critical: Keeps preview in viewport */
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.7);
    background: #000;
    border: 1px solid #475569;
}

/* Desktop / Large screens */
@media (min-width: 960px) {
    .container { 
        flex-direction: row; 
        gap: 2.5rem; 
        margin: 2rem auto; 
    }
    .controls { width: 38%; }
    .canvas-panel { 
        flex: 1; 
        position: static; /* Reset sticky on desktop */
    }
    .canvas-wrapper { 
        min-height: 580px; 
        padding: 32px; 
    }
    canvas { max-height: none; }
}

/* Mobile Landscape Optimization */
@media (max-width: 959px) and (orientation: landscape) {
    .canvas-wrapper { min-height: 280px; }
    canvas { max-height: 55vh; }
}

.header-content {
    position: relative;
    max-width: 1380px;
    margin: 0 auto;
    padding: 0 1rem;
}

.back-link {
    position: absolute;
    top: 1.25rem;
    left: 1rem;
    color: #ffffff;
    text-decoration: none;
    font-weight: 600;
    font-size: 1.05rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    transition: all 0.25s ease;
    background: rgba(255,255,255,0.08);
    backdrop-filter: blur(8px);
}

.back-link:hover {
    background: rgba(255,255,255,0.15);
    color: #d4af37;
    transform: translateX(-4px);
}

@media (min-width: 768px) {
    .back-link {
        top: 1.75rem;
        left: 2rem;
        font-size: 1.1rem;
    }
}

/* Adjust header padding if needed */
header {
    padding: 2.25rem 0 1.75rem 0; /* Extra top space for the back link */
}