/* --- Theme: Utopian Futuristic Pixel Art --- */
:root {
    --bg-page: #0f1419;
    --bg-container: #1a2332;
    --bg-card: #243447;
    --bg-input: #2d3f52;
    --border: #4da6ff;
    --border-dim: #4da6ff40;
    --accent: #4da6ff;
    --accent-glow: #4da6ff80;
    --text: #e6edf3;
    --text-muted: #8b9cb3;
    --success: #4da6ff;
    --warn: #ffb347;
    --error: #ff6b6b;
    --pixel: 4px;
    --font-sans: 'Outfit', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --shadow: 0 0 0 2px var(--border-dim), 0 8px 0 var(--border-dim);
}

[data-theme="light"] {
    --bg-page: #e8f0f8;
    --bg-container: #ffffff;
    --bg-card: #f0f6fc;
    --bg-input: #e0ecf8;
    --border: #0077b6;
    --border-dim: #0077b630;
    --accent: #0077b6;
    --accent-glow: #0077b650;
    --text: #1a2836;
    --text-muted: #5a6a7a;
    --success: #0077b6;
    --warn: #c97600;
    --error: #c53030;
    --shadow: 0 0 0 2px var(--border-dim), 0 6px 0 var(--border-dim);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-page);
    min-height: 100vh;
    padding: 20px;
    color: var(--text);
    background-image:
        linear-gradient(var(--border-dim) 1px, transparent 1px),
        linear-gradient(90deg, var(--border-dim) 1px, transparent 1px);
    background-size: var(--pixel) var(--pixel);
    transition: background 0.3s, color 0.3s;
}

/* Theme toggle */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100;
    width: 48px;
    height: 48px;
    border: 2px solid var(--border);
    background: var(--bg-container);
    border-radius: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 4px 0 var(--border-dim);
}
.theme-toggle:hover {
    background: var(--accent);
    color: var(--bg-page);
    transform: translateY(-2px);
    box-shadow: 0 6px 0 var(--border-dim);
}
.theme-toggle .theme-icon {
    width: 24px;
    height: 24px;
    display: none;
}
.theme-toggle .theme-icon svg {
    width: 100%;
    height: 100%;
}
body:not([data-theme="light"]) .theme-toggle .moon { display: block; }
body[data-theme="light"] .theme-toggle .sun { display: block; }

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--bg-container);
    border: 2px solid var(--border);
    border-radius: 0;
    padding: 40px;
    box-shadow: var(--shadow);
    position: relative;
}

header {
    text-align: center;
    margin-bottom: 40px;
}

header h1 {
    font-size: 2.2em;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--accent);
    font-family: var(--font-mono);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

header h1 .version {
    font-size: 0.45em;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0.02em;
    opacity: 0.8;
    margin-left: 0.5em;
    vertical-align: middle;
}

header p {
    color: var(--text-muted);
    font-size: 1em;
}

header .subtitle {
    font-size: 0.95em;
    color: var(--text-muted);
    line-height: 1.6;
    max-width: 900px;
    margin: 0 auto 15px;
    font-style: italic;
}

header .intro-line {
    font-size: 1em;
    color: var(--text);
    font-weight: 500;
    margin-bottom: 8px;
    line-height: 1.5;
}

header .upload-hint {
    font-size: 1em;
    color: var(--text-muted);
    margin-top: 0;
}

/* Icons */
.upload-icon {
    width: 48px;
    height: 48px;
    display: block;
    margin: 0 auto 10px;
}
.upload-icon svg {
    width: 100%;
    height: 100%;
    stroke: var(--accent);
}
[data-theme="light"] .upload-icon svg { stroke: var(--accent); }

.icon-warn {
    display: inline-flex;
    width: 14px;
    height: 14px;
    margin-right: 4px;
    vertical-align: -2px;
}
.icon-warn svg { stroke: var(--warn); }

.btn-icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    margin-right: 8px;
    vertical-align: -3px;
}
.btn-icon.small { width: 16px; height: 16px; margin-right: 6px; }
.btn-icon svg { width: 100%; height: 100%; }

.icon-arrow, .icon-loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-right: 6px;
    vertical-align: -4px;
}
.icon-arrow svg, .icon-loading svg { stroke: var(--text-muted); }

.upload-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.upload-box {
    border: 2px solid var(--border);
    border-radius: 0;
    padding: 28px;
    text-align: center;
    transition: all 0.2s;
    background: var(--bg-card);
    box-shadow: 0 4px 0 var(--border-dim);
}

.upload-box:hover {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow), 0 6px 0 var(--border-dim);
    transform: translateY(-2px);
}

.upload-box.dragover {
    border-color: var(--accent);
    background: var(--bg-input);
    transform: translateY(-2px);
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    gap: 10px;
}

.upload-text {
    color: var(--accent);
    font-weight: 600;
    font-size: 0.95em;
    font-family: var(--font-mono);
}

.file-name {
    margin-top: 10px;
    color: var(--success);
    font-weight: 600;
    font-size: 0.85em;
    font-family: var(--font-mono);
}

.upload-warning {
    margin-top: 10px;
    color: var(--warn);
    font-size: 0.75em;
    line-height: 1.4;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 24px;
    border: 2px solid var(--border);
    border-radius: 0;
    font-size: 0.95em;
    font-weight: 600;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 0 var(--border-dim);
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-page);
    border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 0 20px var(--accent-glow), 0 6px 0 var(--border-dim);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text);
    border-color: var(--border-dim);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--bg-input);
    border-color: var(--border);
    transform: translateY(-2px);
}

.btn-success {
    background: var(--success);
    color: var(--bg-page);
    border-color: var(--success);
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 0 20px var(--accent-glow), 0 6px 0 var(--border-dim);
}

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

.recording-status {
    text-align: center;
    padding: 16px;
    margin: 16px 0;
    background: var(--bg-card);
    border: 2px solid var(--warn);
    border-radius: 0;
    color: var(--text);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.recording-status small {
    display: block;
    width: 100%;
    margin-top: 6px;
    font-size: 0.85em;
    opacity: 0.8;
}

.recording-status.hidden {
    display: none;
}

.recording-dot {
    width: 12px;
    height: 12px;
    background: var(--accent);
    border-radius: 0;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--accent-glow); }
    50% { opacity: 0.6; }
}

.canvas-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto 30px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 0;
    overflow: hidden;
    box-shadow: 0 6px 0 var(--border-dim);
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

#animationCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

#selectionCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
    z-index: 1;
}

#selectionCanvas.hidden {
    display: none;
}

.instructions {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    font-size: 1.1em;
    pointer-events: none;
}

.instructions-sub {
    font-size: 0.9em;
    margin-top: 10px;
    opacity: 0.8;
}

.instructions.hidden {
    display: none;
}

.canvas-progress {
    max-width: 800px;
    margin: -8px auto 24px;
    padding: 12px 0;
}

.canvas-progress.hidden {
    display: none;
}

.canvas-progress .progress-bar-wrapper {
    margin-bottom: 0;
}

.selection-mode {
    max-width: 900px;
    margin: 0 auto 30px;
    padding: 28px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 0;
    box-shadow: 0 6px 0 var(--border-dim);
}

.selection-mode.hidden {
    display: none;
}

.selection-instructions {
    display: flex;
    gap: 30px;
    align-items: flex-start;
}

.instructions-sidebar {
    flex: 0 0 220px;
    text-align: left;
    padding-right: 20px;
    border-right: 2px solid var(--border-dim);
}

.instructions-sidebar h4 {
    margin-bottom: 12px;
    color: var(--accent);
    font-size: 1em;
    font-weight: 700;
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.instruction-steps {
    margin: 0;
    padding-left: 20px;
    color: var(--text-muted);
    font-size: 0.9em;
    line-height: 1.8;
}

.instruction-steps li {
    margin-bottom: 8px;
    padding: 6px 10px;
    margin-left: -10px;
    padding-left: 14px;
    border-left: 3px solid transparent;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.instruction-steps li.current {
    border-left-color: var(--accent);
    background: var(--bg-input);
    color: var(--accent);
    font-weight: 600;
}

.selection-main {
    flex: 1;
    text-align: center;
}

.selection-instructions h3.step-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    color: var(--text);
    font-size: 1.2em;
    font-family: var(--font-mono);
}

.step-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--accent);
}

.step-icon .step-icon-svg,
.step-icon-svg {
    width: 24px;
    height: 24px;
}

.selection-instructions h3 {
    margin-bottom: 10px;
    color: var(--text);
    font-size: 1.2em;
    font-family: var(--font-mono);
}

.selection-instructions p {
    margin-bottom: 18px;
    color: var(--text-muted);
    font-size: 0.95em;
    line-height: 1.5;
}

.selection-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.selection-buttons .btn {
    margin: 0;
}

.skip-preview-option {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--border-dim);
}

.checkbox-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9em;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

.background-progress {
    max-width: 800px;
    margin: 0 auto 30px;
    padding: 28px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: 0;
    text-align: center;
    box-shadow: 0 6px 0 var(--border-dim);
}

.background-progress.hidden {
    display: none;
}

.progress-container h3 {
    margin-bottom: 20px;
    color: var(--text);
    font-size: 1.1em;
    font-family: var(--font-mono);
}

.progress-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.progress-bar {
    flex: 1;
    height: 28px;
    background: var(--bg-input);
    border: 2px solid var(--border-dim);
    border-radius: 0;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    min-width: 48px;
    font-weight: 700;
    color: var(--accent);
    font-size: 1em;
    font-family: var(--font-mono);
}

.progress-hint {
    color: var(--text-muted);
    font-size: 0.85em;
    margin-top: 10px;
    font-style: italic;
}

.model-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--accent);
    font-weight: 600;
    z-index: 2;
}

.model-loading .icon-loading svg {
    stroke: var(--accent);
    animation: spin 0.8s linear infinite;
}

.model-loading.hidden {
    display: none;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    margin: 16px auto 0;
    border: 3px solid var(--border-dim);
    border-top-color: var(--accent);
    border-radius: 0;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.settings {
    background: var(--bg-card);
    padding: 28px;
    border: 2px solid var(--border-dim);
    border-radius: 0;
    margin-top: 24px;
}

.settings h3 {
    margin-bottom: 20px;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 1em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.setting-group {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.setting-group label {
    min-width: 140px;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.95em;
}

.setting-group input[type="range"] {
    flex: 1;
    height: 8px;
    border-radius: 0;
    background: var(--bg-input);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.setting-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border: 2px solid var(--border);
    cursor: pointer;
    border-radius: 0;
    box-shadow: 0 2px 0 var(--border-dim);
}

.setting-group input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent);
    border: 2px solid var(--border);
    cursor: pointer;
    border-radius: 0;
}

.setting-group span {
    min-width: 40px;
    text-align: right;
    font-weight: 700;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.95em;
}

.beta-warning {
    text-align: center;
    font-size: 0.75em;
    color: var(--text-muted);
    margin: 24px 0 16px;
    padding: 0 20px;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.5;
}

@media (max-width: 768px) {
    .container {
        padding: 24px;
    }

    header h1 {
        font-size: 1.8em;
    }

    header .subtitle {
        font-size: 0.9em;
        padding: 0 10px;
    }

    .upload-section {
        grid-template-columns: 1fr;
    }

    .controls {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .theme-toggle {
        top: 12px;
        right: 12px;
        width: 44px;
        height: 44px;
    }

    .selection-instructions {
        flex-direction: column;
        gap: 20px;
    }

    .instructions-sidebar {
        flex: none;
        border-right: none;
        border-bottom: 2px solid var(--border-dim);
        padding-right: 0;
        padding-bottom: 20px;
    }
}
