:root {
    --bg-color: #050505;
    --panel-bg: rgba(0, 255, 64, 0.02);
    --panel-border: rgba(0, 255, 64, 0.2);
    --text-primary: #e0f2e9;
    --text-secondary: #4ade80;
    --accent-color: #10b981;
    --accent-hover: #059669;
    --error-color: #ef4444;
    --success-color: #10b981;
    --font-ui: 'Inter', sans-serif;
    --font-hacker: 'Tomorrow', monospace;
}

@font-face {
    font-family: 'Tomorrow';
    src: url('font/Tomorrow-Regular.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Orbitron';
    src: url('font/Orbitron-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: normal;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-ui);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    /* Stop scrolling entirely */
    position: relative;
    padding: 1rem;
    /* Reduced padding slightly to give more room */
}

/* CRT Scanline Overlay */
body::after {
    content: " ";
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 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));
    z-index: 2;
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    opacity: 0.15;
}

.background-radials {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    background:
        radial-gradient(circle at 15% 50%, rgba(16, 185, 129, 0.1), transparent 30%),
        radial-gradient(circle at 85% 30%, rgba(34, 197, 94, 0.08), transparent 30%);
    filter: blur(40px);
}

.matrix-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -2;
    opacity: 0.6;
}

.app-container {
    width: 100%;
    max-width: 900px;
    /* Slightly wider for better landscape scaling */
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    /* Tighter gap */
    max-height: 100%;
    /* Keep within viewport */
}

header {
    text-align: center;
    margin-bottom: 0.5rem;
    animation: fadeInDown 0.8s ease-out;
    flex-shrink: 0;
}

header h1 {
    font-family: var(--font-hacker);
    font-size: 2.5rem;
    /* Slightly smaller */
    font-weight: 700;
    margin-bottom: 0.2rem;
    color: #4ade80;
    text-shadow: 0 0 10px rgba(74, 222, 128, 0.5), 0 0 20px rgba(74, 222, 128, 0.3);
    letter-spacing: 2px;
    text-transform: uppercase;
}

header p {
    color: var(--text-secondary);
    font-size: 1rem;
    letter-spacing: 1px;
}

.glass-panel {
    background: rgba(0, 20, 5, 0.6);
    border: 1px solid var(--panel-border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 12px;
    padding: 1.5rem;
    /* Reduced padding to fit 1 frame */
    box-shadow: 0 0 30px rgba(0, 255, 64, 0.05), inset 0 0 20px rgba(0, 255, 64, 0.05);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    animation: fadeInUp 0.8s ease-out;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Ensure inner contents flex properly */
    max-height: 100%;
}

.glass-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-color));
    animation: scanline 4s linear infinite;
}

@keyframes scanline {
    0% {
        left: -100%;
    }

    100% {
        left: 200%;
    }
}

.glass-panel:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 40px rgba(0, 255, 64, 0.1), inset 0 0 30px rgba(0, 255, 64, 0.05);
    border-color: rgba(0, 255, 64, 0.4);
}

.search-section form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.input-group input {
    width: 100%;
    padding: 1rem 1.2rem;
    border-radius: 12px;
    background: rgba(0, 10, 0, 0.4);
    border: 1px solid rgba(0, 255, 64, 0.3);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: var(--font-hacker);
    transition: all 0.3s ease;
    outline: none;
    letter-spacing: 1px;
}

.input-group input:focus {
    border-color: var(--accent-color);
    background: rgba(0, 20, 0, 0.6);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.2);
}

button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.primary-btn {
    background: var(--accent-color);
    color: white;
}

.primary-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

.secondary-btn {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--panel-border);
}

.secondary-btn:hover {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.5);
}

.glow-btn {
    position: relative;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
}

.glow-btn:hover {
    box-shadow: 0 0 30px rgba(16, 185, 129, 0.6);
}

.status-message {
    margin-top: 1rem;
    padding: 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-message.error {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-message.success {
    background: rgba(16, 185, 129, 0.1);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.hidden {
    display: none !important;
}

.preview-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
    max-height: calc(100vh - 120px);
    /* Fit within viewport */
}

.preview-section h2 {
    font-weight: 600;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.canvas-wrapper {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    max-width: 100%;
    max-height: 45vh;
    /* Direct constraint to fit viewport without scrolling */
    width: auto;
    height: auto;
    object-fit: contain;
    /* ensures scaling respects aspect ratio without cropping */
    display: block;
    border-radius: 12px;
}

.actions {
    display: flex;
    gap: 1rem;
    width: 100%;
    background: rgba(0, 10, 0, 0.4);
    border: 1px solid var(--panel-border);
    padding: 1rem;
    border-radius: 12px;
    box-shadow: inset 0 0 15px rgba(0, 255, 64, 0.05);
    flex-shrink: 0;
}

.actions button {
    flex: 1;
    padding: 0.8rem 1.2rem;
    font-size: 0.95rem;
}

/* Load the custom font implicitly but render offscreen so it's ready for canvas */
.font-preload {
    font-family: 'Tomorrow';
    position: absolute;
    left: -9999px;
    visibility: hidden;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 600px) {
    .actions {
        flex-direction: column;
    }

    .glass-panel {
        padding: 1.5rem;
    }
}

/* Maintenance Mode Styles */
#maintenancePanel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    padding: 2rem;
    background: rgba(5, 5, 5, 0.8);
}

.maintenance-content {
    max-width: 500px;
    width: 100%;
    text-align: center;
    padding: 3rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.maintenance-icon {
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 0 15px rgba(74, 222, 128, 0.4));
    animation: pulse 2s infinite ease-in-out;
}

.maintenance-content h1 {
    font-family: var(--font-hacker);
    color: #4ade80;
    font-size: 2rem;
    margin: 0;
}

.maintenance-content p {
    color: var(--text-primary);
    opacity: 0.8;
}

.status-bar {
    width: 100%;
    height: 4px;
    background: rgba(74, 222, 128, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 1rem;
}

.status-progress {
    height: 100%;
    width: 30%;
    background: #4ade80;
    box-shadow: 0 0 10px #4ade80;
    animation: progressMove 3s infinite linear;
}

.status-text {
    font-family: var(--font-hacker);
    font-size: 0.8rem;
    color: #4ade80;
    letter-spacing: 2px;
    opacity: 0.6;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.8;
    }
}

@keyframes progressMove {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(400%);
    }
}