/* DEV_PROGRESS
[x] Phase 0: Baseline stereogram app implemented
[x] Phase 9: JS modularization into core.js, ui.js, ai.js
[x] Phase 10: SEO and AEO enhancements
[x] Phase 11: Accessibility to WCAG 2.1 AAA target
[x] Phase 12: AI provider selection and integration
[x] Phase 13: Depth design DSL and system prompt
[x] Phase 14: Local storage for AI keys and prompts
[x] Phase 15: Final QA for v2

[x] Phase 16: Experimental live preview toggle (UI and accessibility)
[x] Phase 17: Render scheduler, debouncing, and cancellation
[x] Phase 18: Multi-resolution preview pipeline
[x] Phase 19: Optional inline Web Worker offloading
[x] Phase 20: Live preview integration with AI and controls
[x] Phase 21: Performance guards, thresholds, and tuning
[x] Phase 22: Documentation and UI hints for live preview
DEV_PROGRESS_END */

/* CSS Variables & Theme */
:root {
    /* Executive Dark Theme Palette */
    --bg-main: #05070a;
    --bg-elevated: #10131a;
    --bg-input: #151921;

    --accent-primary: #1ee3cf;
    /* Vibrant Teal */
    --accent-secondary: #8c8aff;
    /* Cool Violet - Lightened for AAA contrast against dark bg */
    --accent-danger: #ff5c7c;
    /* Lightened for AAA */

    --text-main: #f5f7fb;
    --text-muted: #a8b0c0;

    --border-soft: rgba(255, 255, 255, 0.15);
    /* Increased visibility */
    --border-highlight: rgba(30, 227, 207, 0.8);

    /* Spacing & Sizing */
    --gap-sm: 8px;
    --gap-md: 16px;
    --gap-lg: 24px;

    --radius-soft: 8px;
    --radius-pill: 9999px;

    --font-heading: "Inter", system-ui, -apple-system, sans-serif;
    --font-ui: "Inter", system-ui, -apple-system, sans-serif;

    --header-height: 70px;
}

/* Global Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-main);
    background-image: linear-gradient(to bottom right, #05070a 0%, #0a0d14 100%);
    color: var(--text-main);
    font-family: var(--font-ui);
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Accessibility: Skip Link */
.skip-link {
    position: absolute;
    top: -999px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent-primary);
    color: #000;
    padding: 8px 16px;
    z-index: 1000;
    font-weight: bold;
    border-radius: 0 0 4px 4px;
    text-decoration: none;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #fff;
}

/* Typography */
h1,
h2,
h3,
h4,
h5,
h6 {
    margin: 0;
    font-weight: 600;
    letter-spacing: -0.01em;
}

p {
    margin: 0 0 1em 0;
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.6;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

a:hover {
    border-bottom-color: var(--accent-primary);
}

a:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Header */
header {
    height: var(--header-height);
    background-color: var(--bg-elevated);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--gap-lg);
    position: relative;
    border-bottom: 1px solid var(--border-soft);
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--gap-md);
}

.header-left h1 {
    font-size: 1.25rem;
    letter-spacing: -0.02em;
    color: var(--text-main);
}

.header-left .subtitle {
    font-size: 0.8rem;
    margin: 0;
    color: var(--text-muted);
    font-weight: 400;
}

.header-right {
    display: flex;
    gap: var(--gap-sm);
}

.header-accent {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, var(--accent-secondary), var(--accent-primary));
    opacity: 0.8;
}

/* Main Layout */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1800px;
    margin: 0 auto;
    padding: var(--gap-lg);
}

#main-layout-grid {
    display: grid;
    grid-template-columns: 24rem 1fr;
    gap: var(--gap-lg);
    flex: 1;
    /* This actually makes the grid take available space, ensuring panels stretch */
}

@media (max-width: 960px) {
    #main-layout-grid {
        grid-template-columns: 1fr;
    }
}

/* Content Sections (SEO compatible) */
.intro-content {
    margin-bottom: 2rem;
    max-width: 800px;
}

.intro-content h2 {
    font-size: 1.4rem;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

/* Section Panels */
section {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Controls Panel */
#controls-panel {
    display: flex;
    flex-direction: column;
}

fieldset {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-soft);
    padding: var(--gap-md);
    margin: 0 0 var(--gap-lg) 0;
    background-color: transparent;
}

legend {
    color: var(--accent-primary);
    font-size: 0.85rem;
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 0 6px;
}

.control-group {
    margin-bottom: var(--gap-md);
    display: flex;
    flex-direction: column;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-row {
    display: flex;
    gap: var(--gap-md);
}

.control-row .control-group {
    flex: 1;
}

label {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: block;
    font-weight: 500;
}

/* Inputs & Form Elements */
input[type="text"],
input[type="number"],
input[type="password"],
select,
input[type="file"],
textarea {
    background-color: var(--bg-input);
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    color: var(--text-main);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 1rem;
    /* 16px prevents zoom on iOS */
    width: 100%;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* Visible Focus States */
input:focus,
select:focus,
textarea:focus,
button:focus-visible {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(30, 227, 207, 0.3);
}

/* Sliders */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
    cursor: pointer;
    margin: 10px 0;
}

input[type="range"]:focus {
    outline: none;
}

input[type="range"]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px rgba(30, 227, 207, 0.5), 0 2px 4px rgba(0, 0, 0, 0.3);
    border-color: var(--accent-primary);
}

input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: var(--border-soft);
    border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 20px;
    /* Larger touch target */
    width: 20px;
    border-radius: 50%;
    background: var(--text-main);
    margin-top: -7px;
    border: 2px solid var(--bg-elevated);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s, background-color 0.2s;
}

/* Radio Buttons */
.radio-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-main);
}

input[type="radio"] {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-muted);
    border-radius: 50%;
    margin-right: 12px;
    position: relative;
    display: grid;
    place-content: center;
}

input[type="radio"]:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(30, 227, 207, 0.3);
}

input[type="radio"]::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    background-color: var(--accent-primary);
}

input[type="radio"]:checked {
    border-color: var(--accent-primary);
}

input[type="radio"]:checked::before {
    transform: scale(1);
}

/* Buttons */
button {
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    border: none;
}

.primary-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-primary) 0%, #15c5b4 100%);
    color: #05070a;
    /* High contrast black on teal */
    font-weight: 700;
    padding: 12px 20px;
    border-radius: var(--radius-soft);
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(30, 227, 207, 0.2);
    margin-bottom: var(--gap-sm);
}

.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(30, 227, 207, 0.3);
}

.primary-btn:active {
    transform: translateY(1px);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.secondary-btn {
    background-color: var(--bg-input);
    color: var(--text-main);
    border: 1px solid var(--border-soft);
    border-radius: 4px;
    padding: 8px 14px;
    font-size: 0.9rem;
    font-weight: 500;
}

.secondary-btn:hover:not(:disabled) {
    border-color: var(--text-muted);
    background-color: #1a2029;
}

.secondary-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.icon-btn {
    background: transparent;
    color: var(--text-muted);
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 4px;
    border: 1px solid transparent;
}

.icon-btn:hover {
    color: var(--text-main);
    background-color: rgba(255, 255, 255, 0.05);
}

.icon-btn:focus-visible {
    border-color: var(--accent-primary);
}

.button-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* Action Area */
.action-area {
    margin-top: auto;
    padding-top: var(--gap-lg);
    border-top: 1px solid var(--border-soft);
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.toggle-row input[type="checkbox"] {
    accent-color: var(--accent-primary);
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* Preview Panel */
#preview-panel {
    display: flex;
    flex-direction: column;
}

.preview-card {
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-soft);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.preview-toolbar {
    min-height: 56px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--gap-md);
    background-color: rgba(0, 0, 0, 0.2);
    flex-wrap: wrap;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

#zoom-display {
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
    width: 4ch;
    text-align: center;
    font-weight: 600;
}

.canvas-container {
    flex: 1;
    position: relative;
    overflow: auto;
    display: grid;
    place-items: center;
    background-image:
        radial-gradient(circle at 1px 1px, #1a2029 1px, transparent 0);
    background-size: 20px 20px;
    background-color: #080a0f;
}

canvas {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    background-color: black;
    display: block;
}

.placeholder-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    pointer-events: none;
    max-width: 80%;
}

.instructions-overlay {
    position: absolute;
    bottom: var(--gap-lg);
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(5, 7, 10, 0.95);
    backdrop-filter: blur(4px);
    border: 1px solid var(--border-highlight);
    padding: 12px 24px;
    border-radius: var(--radius-pill);
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 10;
}

.instructions-overlay.hidden {
    opacity: 0;
}

.instructions-overlay p {
    margin: 0;
    color: var(--accent-primary);
    font-size: 1rem;
    font-weight: 600;
}

/* Status Text */
.status-text {
    font-family: monospace;
    color: var(--accent-secondary);
    font-size: 0.9rem;
    margin: 12px 0;
    font-weight: 600;
    min-height: 1.5em;
    display: flex;
    align-items: center;
}

/* FAQ & AEO Utils */
.sr-only-visually {
    /* Style for intro content that should be visible but distinct */
    margin-bottom: 2rem;
    color: var(--text-muted);
    font-size: 1rem;
}

/* Standard sr-only for purely screen reader content if needed */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.faq-section {
    width: 100%;
    max-width: 1200px;
    margin: 4rem auto 2rem auto;
    padding: 0 var(--gap-md);
}

.faq-section h2 {
    color: var(--text-main);
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    border-bottom: 1px solid var(--border-soft);
    padding-bottom: 0.5rem;
}

.faq-item {
    margin-bottom: 2rem;
}

.faq-item h3 {
    color: var(--accent-primary);
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.faq-item p {
    line-height: 1.7;
    color: var(--text-muted);
}

/* Footer */
footer {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border-soft);
    background-color: var(--bg-elevated);
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {

    *,
    ::before,
    ::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}


.force-visible {
    display: block !important;
}