:root {
    --bg-dark: #24273a;
    --bg-card: #181926;
    --primary: #c6a0f6;
    --secondary: #8bd5ca;
    --accent: #eed49f;
    --text-main: #cad3f5;
    --text-muted: #a5adcb;
    --border: #cad3f5;
    --font-heading: 'Press Start 2P', cursive;
    --font-body: 'VT323', monospace;
}

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

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 20px;
    line-height: 1.4;
    overflow-x: hidden;
    image-rendering: pixelated;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
        linear-gradient(90deg, rgba(255, 0, 0, 0.06), rgba(0, 255, 0, 0.02), rgba(0, 0, 255, 0.06));
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    z-index: 999;
}

.background-glow {
    position: fixed;
    inset: 0;
    background-image: linear-gradient(var(--bg-card) 1px, transparent 1px),
        linear-gradient(90deg, var(--bg-card) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: center;
    opacity: 0.3;
    z-index: -1;
}

.hidden {
    display: none !important;
}

.generate-main {
    padding: 2rem 5%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.generate-container {
    width: 100%;
    max-width: 1400px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.step-header {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.step-eyebrow {
    font-size: 1rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.2em;
}

.step-title {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    color: var(--text-main);
}

.step-subtitle {
    font-size: 1.2rem;
    color: var(--text-muted);
}

.upload-group,
.resolution-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.input-label {
    font-size: 1rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.input-hint {
    font-size: 1rem;
    color: var(--text-muted);
}

.file-input-label {
    border: 2px dashed var(--secondary);
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    color: var(--secondary);
    background: rgba(139, 213, 202, 0.08);
}

.file-input-label:hover {
    background: rgba(139, 213, 202, 0.2);
}

.file-input {
    display: none;
}

.resolution-dropdown {
    position: relative;
    width: 100%;
}

.resolution-toggle {
    width: 100%;
    background: rgba(24, 25, 38, 0.8);
    border: 2px solid var(--secondary);
    color: var(--text-main);
    padding: 0.75rem 1rem;
    font-family: var(--font-body);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

.resolution-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    width: 100%;
    background: var(--bg-card);
    border: 2px solid var(--border);
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-5px);
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 5;
}

.resolution-dropdown[data-open="true"] .resolution-menu {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.resolution-menu button {
    background: transparent;
    border: none;
    padding: 0.8rem 1.2rem;
    text-align: left;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 1.2rem;
    cursor: pointer;
}

.resolution-menu button:hover,
.resolution-menu button[aria-selected="true"] {
    background: rgba(198, 160, 246, 0.2);
    color: var(--primary);
}

.character-actions {
    display: flex;
    width: 100%;
}

.character-generate-block {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.character-cta-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 0 1rem;
}

.character-status-actions {
    margin: 0;
    width: 100%;
}

.character-next-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-left: auto;
    align-self: stretch;
    align-items: flex-end;
}

.btn-secondary {
    background: transparent;
    border: 3px solid var(--border);
    padding: 0.9rem 1rem;
    color: var(--text-main);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: 4px 4px 0 var(--bg-card);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    text-transform: uppercase;
    flex: 1;
}

.btn-secondary:hover:enabled {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 var(--bg-card);
}

.btn-secondary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: 0 0 0 transparent;
}

.character-preview-panel {
    justify-content: flex-start;
    gap: 0.25rem;
}

#characterFrameNav {
    gap: 4rem;
    margin-bottom: -1.6rem;
}

#characterFrameNav .preview-nav-button {
    min-width: 2.4rem;
}

.character-preview-panel .canvas-area {
    min-height: 400px;
    padding: 1rem;
}

.character-preview {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 360px;
}

.preview-placeholder {
    text-align: center;
    padding: 1rem;
}

.character-preview-image {
    max-width: 100%;
    width: 100%;
    max-height: 360px;
    object-fit: contain;
    border: 3px solid var(--border);
    background: #0d0d0d;
    image-rendering: pixelated;
}

.btn-next {
    width: auto;
    min-width: 150px;
    background: var(--primary);
    border: 3px solid var(--border);
    padding: 0.9rem 1rem;
    color: var(--bg-card);
    font-family: var(--font-heading);
    font-size: 0.9rem;
    cursor: pointer;
    text-transform: uppercase;
    box-shadow: 4px 4px 0 var(--bg-card);
}

.btn-next:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.generator-layout {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 2rem;
    background: var(--bg-card);
    border: 4px solid var(--border);
    padding: 2rem;
    box-shadow: 8px 8px 0 var(--bg-card);
}

.input-panel {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    width: 100%;
}

.input-container {
    position: relative;
}

.prompt-input {
    width: 100%;
    min-height: 120px;
    background: rgba(24, 25, 38, 0.8);
    border: 2px solid var(--secondary);
    padding: 1.5rem;
    font-family: var(--font-body);
    font-size: 1.4rem;
    color: var(--secondary);
    resize: vertical;
    outline: none;
    box-shadow: 4px 4px 0 rgba(24, 25, 38, 0.5);
}

.prompt-input::placeholder {
    color: var(--text-muted);
}

.prompt-input:focus {
    border-color: var(--accent);
    box-shadow: 6px 6px 0 rgba(24, 25, 38, 0.5);
}

.btn-generate {
    background: var(--accent);
    border: 3px solid var(--border);
    padding: 1rem 1.4rem;
    color: var(--bg-card);
    font-family: var(--font-heading);
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 4px 4px 0 var(--bg-card);
    transition: transform 0.1s ease, box-shadow 0.1s ease;
    text-transform: uppercase;
    width: 100%;
}

.btn-generate:hover {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 var(--bg-card);
}

.btn-generate:active {
    transform: translate(4px, 4px);
    box-shadow: 0 0 0 var(--bg-card);
}

.btn-generate.is-loading,
.btn-generate:disabled {
    background: var(--text-muted);
    color: var(--bg-card);
    cursor: not-allowed;
    opacity: 0.8;
    box-shadow: 0 0 0 var(--bg-card);
    transform: none;
}

.tag-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.tag-btn {
    background: rgba(165, 173, 203, 0.2);
    border: 2px solid var(--text-muted);
    padding: 0.6rem 1.2rem;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    text-align: left;
}

.tag-btn:hover {
    background: var(--text-muted);
    color: var(--bg-card);
    transform: translateY(-2px);
}

.animation-list-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.animation-template-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}

.animation-template-option {
    display: flex;
    gap: 0.65rem;
    align-items: center;
    justify-content: flex-start;
    padding: 0.6rem 0.85rem;
    border: 2px solid var(--border);
    background: rgba(12, 13, 23, 0.85);
    box-shadow: 3px 3px 0 rgba(24, 25, 38, 0.5);
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease, border 0.1s ease;
    font-family: var(--font-body);
    font-size: 1rem;
}

.animation-template-option:hover {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 rgba(24, 25, 38, 0.5);
}

.animation-template-option:active {
    transform: translate(4px, 4px);
    box-shadow: 0 0 0 rgba(24, 25, 38, 0.5);
}

.animation-template-option.is-selected {
    border-color: var(--accent);
    box-shadow: 3px 3px 0 rgba(220, 33, 99, 0.4);
}

.template-checkbox {
    appearance: none;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--text-muted);
    background: transparent;
    position: relative;
    flex-shrink: 0;
}

.template-checkbox::after {
    content: '';
    position: absolute;
    inset: 2px;
    background: transparent;
    transition: background 0.15s ease;
}

.template-checkbox:checked {
    border-color: var(--accent);
}

.template-checkbox:checked::after {
    background: var(--accent);
}

.template-text {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: 1;
}

.template-title {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    color: var(--text-light);
}

.animation-template-option.is-selected .template-title {
    color: var(--accent);
}


.preview-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.window-frame {
    background: var(--bg-card);
    border: 4px solid var(--border);
    box-shadow: 8px 8px 0 var(--bg-card);
}

.window-header {
    background: var(--text-muted);
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 4px solid var(--bg-card);
}

.dot {
    width: 12px;
    height: 12px;
    border: 2px solid var(--bg-card);
    border-radius: 50%;
}

.red {
    background: #ed8796;
}

.yellow {
    background: #eed49f;
}

.green {
    background: #a6da95;
}

.filename {
    margin-left: 1rem;
    font-size: 1.2rem;
    color: var(--bg-card);
    font-family: var(--font-body);
}

.canvas-area {
    min-height: 400px;
    background-color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 1rem;
}

.preview-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    width: 100%;
}

.preview-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    text-align: center;
}

.pixel-cursor {
    width: 60px;
    height: 60px;
    border: 3px solid var(--accent);
    position: relative;
    animation: pulse 1.5s ease-in-out infinite;
    display: none;
}

.pixel-cursor::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 20px;
    height: 20px;
    background: var(--accent);
    animation: pixelate 0.8s steps(4) infinite;
}

.preview-loading.is-active .pixel-cursor {
    display: block;
}

.status-text {
    font-size: 1.4rem;
    color: var(--text-main);
    font-family: var(--font-body);
    text-shadow: 2px 2px 0 #000;
    white-space: pre-line;
}

.status-text[data-state='error'] {
    color: #f38ba8;
}

.status-text[data-state='success'] {
    color: #a6da95;
}

.status-text[data-state='progress'] {
    color: var(--accent);
}

.results-preview {
    width: 100%;
    display: flex;
    justify-content: center;
}

.frames-canvas {
    display: none;
    width: 100%;
    max-width: 360px;
    border: 4px solid var(--border);
    background: #0d0d0d;
    image-rendering: pixelated;
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.4);
}

.frames-canvas.is-visible {
    display: block;
}

.control-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
    column-gap: 1rem;
    width: 100%;
    margin: 0 auto;
    padding: 0 1rem;
}

.control-fps,
.control-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    text-align: left;
    width: 100%;
}

.fps-label,
.status-label {
    font-family: var(--font-body);
    color: var(--text-muted);
    font-size: 1.2rem;
    letter-spacing: 0.05em;
    text-transform: lowercase;
    width: 100%;
}

.fps-inputs {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.8rem;
    width: 100%;
}

.fps-slider {
    width: 100%;
    max-width: 100%;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
}

.fps-slider::-webkit-slider-thumb {
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background: var(--primary);
    cursor: pointer;
}

.fps-slider::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background: var(--primary);
    border: none;
    cursor: pointer;
}

.fps-number {
    width: 2.6rem;
    height: 2.6rem;
    padding: 0;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 1.1rem;
    text-align: center;
    line-height: 2.6rem;
}

.fps-number::-webkit-outer-spin-button,
.fps-number::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.fps-number {
    -moz-appearance: textfield;
}

.fps-number:focus {
    outline: none;
    border-color: var(--primary);
}

.control-divider {
    width: 1px;
    height: 100%;
    background: var(--border);
    opacity: 0.6;
    align-self: stretch;
}

.status-content {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.8rem;
    width: 100%;
}

.control-btn {
    width: 50px;
    height: 50px;
    background: rgba(24, 25, 38, 0.8);
    border: 3px solid var(--border);
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 4px 4px 0 rgba(24, 25, 38, 0.5);
}

.control-btn:hover {
    background: var(--primary);
    color: var(--bg-card);
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 rgba(24, 25, 38, 0.5);
}

.control-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
    background: rgba(24, 25, 38, 0.8);
    color: var(--text-muted);
    box-shadow: 4px 4px 0 rgba(24, 25, 38, 0.5);
}

.control-btn:disabled:hover {
    transform: none;
    box-shadow: 4px 4px 0 rgba(24, 25, 38, 0.5);
    background: rgba(24, 25, 38, 0.8);
    color: var(--text-muted);
}

.download-status {
    min-height: 1.5rem;
    margin: 0;
    text-shadow: none;
    font-size: 1.1rem;
    text-align: left;
}

.preview-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border: 2px solid var(--border);
    background: rgba(12, 13, 23, 0.85);
    box-shadow: 3px 3px 0 var(--bg-card);
    width: fit-content;
    min-width: calc(3 * 2.4rem);
    margin: 0 auto;
}

.preview-nav-button {
    width: 2.2rem;
    height: 2.2rem;
    border: 2px solid var(--text-muted);
    background: rgba(18, 18, 28, 0.8);
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s ease, border 0.1s ease, background 0.1s ease;
    font-size: 1rem;
}

.preview-nav-button.is-active {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--bg-card);
    box-shadow: none;
}

.preview-nav-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.preview-nav-button.is-placeholder {
    border-style: dashed;
    opacity: 0.6;
}

@keyframes pulse {
    0%,
    100% {
        transform: scale(1);
        opacity: 0.8;
    }

    50% {
        transform: scale(1.1);
        opacity: 1;
    }
}

@keyframes pixelate {
    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

@media (max-width: 1024px) {
    .generator-layout {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
}

@media (max-width: 768px) {
    .generator-layout {
        padding: 1.5rem;
    }

    .control-bar {
        grid-template-columns: 1fr;
        row-gap: 1.5rem;
    }

    .control-divider {
        display: none;
    }
}
