:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a2e;
    --text-primary: #ffffff;
    --text-secondary: #8888aa;
    --accent: #00f5ff;
    --random-color: #ff6b35;
    --luxury-color: #ffd700;
    --ugly-color: #39ff14;
    --cursed-color: #ff00ff;
    --success: #00ff88;
    --danger: #ff3333;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

.hidden { display: none !important; }

/* ============================================
   LOADER
============================================ */
.loader {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s;
}

.loader.fade-out { opacity: 0; pointer-events: none; }

.loader-content { text-align: center; }

.scan-icon {
    width: 100px; height: 100px;
    margin: 0 auto 20px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scan-emoji { font-size: 48px; }

.scan-line {
    position: absolute;
    top: 0; left: 10%; width: 80%; height: 2px;
    background: var(--accent);
    box-shadow: 0 0 20px var(--accent);
    animation: scanMove 2s infinite;
}

@keyframes scanMove {
    0%, 100% { top: 10%; }
    50% { top: 90%; }
}

.glitch {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    color: var(--accent);
    text-shadow: 0 0 20px var(--accent);
}

.loading-bar {
    width: 250px; height: 4px;
    background: var(--bg-card);
    border-radius: 2px;
    margin: 20px auto;
    overflow: hidden;
}

.loading-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #0088ff);
    animation: loadingAnim 2s forwards;
}

@keyframes loadingAnim {
    0% { width: 0; }
    100% { width: 100%; }
}

/* ============================================
   HEADER
============================================ */
.header {
    padding: 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid #2a2a3e;
    text-align: center;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.logo-icon { font-size: 2rem; }

.logo-text {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
}

.accent { color: var(--accent); }

/* ============================================
   MAIN CONTENT
============================================ */
.main-content {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
}

section {
    margin-bottom: 30px;
}

section h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.1rem;
    color: var(--accent);
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

/* ============================================
   CODE SECTION
============================================ */
.code-section {
    text-align: center;
    padding: 25px;
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid #2a2a3e;
}

.btn-generate {
    width: 100%;
    padding: 18px 30px;
    background: linear-gradient(135deg, #00f5ff, #0088ff);
    border: none;
    border-radius: 14px;
    color: #000;
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s;
}

.btn-generate:hover {
    transform: scale(1.02);
    box-shadow: 0 0 30px #00f5ff44;
}

.btn-generate:active {
    transform: scale(0.98);
}

.btn-icon { font-size: 1.4rem; }

/* Code Display */
.code-display {
    margin-top: 25px;
    padding: 20px;
    background: var(--bg-primary);
    border-radius: 12px;
    border: 2px solid var(--accent);
    animation: fadeIn 0.5s;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.code-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.code-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 20px var(--accent);
    letter-spacing: 8px;
    margin: 10px 0;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { text-shadow: 0 0 20px var(--accent); }
    50% { text-shadow: 0 0 40px var(--accent), 0 0 60px var(--accent); }
}

.btn-copy {
    padding: 10px 25px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: 8px;
    color: var(--accent);
    font-family: 'Orbitron', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-copy:hover {
    background: var(--accent);
    color: #000;
}

.btn-copy.copied {
    background: var(--success);
    border-color: var(--success);
    color: #000;
}

.code-timer {
    margin-top: 15px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

#codeTimer {
    color: var(--luxury-color);
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
}

.code-instruction {
    margin-top: 15px;
    padding: 12px;
    background: rgba(255, 215, 0, 0.1);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--luxury-color);
}

/* ============================================
   CAMERA SECTION
============================================ */
.camera-section {
    text-align: center;
}

.camera-container {
    width: 100%;
    aspect-ratio: 4/3;
    background: #000;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    border: 2px solid #2a2a3e;
    margin-bottom: 15px;
}

.camera-container video,
.camera-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
}

.corner {
    position: absolute;
    width: 30px; height: 30px;
    border-color: var(--accent);
    border-style: solid;
}

.corner.tl { top: 10px; left: 10px; border-width: 3px 0 0 3px; }
.corner.tr { top: 10px; right: 10px; border-width: 3px 3px 0 0; }
.corner.bl { bottom: 10px; left: 10px; border-width: 0 0 3px 3px; }
.corner.br { bottom: 10px; right: 10px; border-width: 0 3px 3px 0; }

.scan-line-camera {
    position: absolute;
    left: 10px; right: 10px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    box-shadow: 0 0 10px var(--accent);
    animation: scanCamera 3s infinite;
}

@keyframes scanCamera {
    0%, 100% { top: 10px; }
    50% { top: calc(100% - 10px); }
}

.camera-placeholder {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    background: var(--bg-card);
}

.placeholder-icon {
    font-size: 4rem;
    opacity: 0.5;
}

.camera-placeholder p {
    color: var(--text-secondary);
}

.btn-start-camera {
    padding: 12px 25px;
    background: linear-gradient(135deg, var(--accent), #0088ff);
    border: none;
    border-radius: 10px;
    color: #000;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-start-camera:disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
}

.btn-start-camera:not(:disabled):hover {
    transform: scale(1.05);
}

.capture-preview {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 5;
}

/* Camera Controls */
.camera-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
}

.btn-capture {
    width: 70px; height: 70px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 0;
}

.btn-capture:disabled { opacity: 0.3; cursor: not-allowed; }

.capture-ring {
    width: 100%; height: 100%;
    border-radius: 50%;
    border: 4px solid var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.btn-capture:not(:disabled):hover .capture-ring {
    border-color: #fff;
    box-shadow: 0 0 20px var(--accent);
}

.capture-inner {
    width: 50px; height: 50px;
    border-radius: 50%;
    background: var(--accent);
    transition: all 0.3s;
}

.btn-capture:not(:disabled):hover .capture-inner {
    background: #fff;
}

.btn-control {
    width: 45px; height: 45px;
    border-radius: 50%;
    border: 1px solid #2a2a3e;
    background: var(--bg-card);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-control:hover {
    border-color: var(--accent);
}

/* Analyze Button */
.btn-analyze {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--accent), #6600ff);
    border: none;
    border-radius: 14px;
    color: #fff;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s;
}

.btn-analyze:hover {
    transform: scale(1.02);
    box-shadow: 0 0 30px #00f5ff44;
}

/* ============================================
   RESULTS SECTION
============================================ */
.results-section {
    text-align: center;
}

.result-code-reminder {
    background: var(--bg-card);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 0.9rem;
}

.result-code {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent);
}

.detected-object {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
}

.object-name {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.object-description {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Categories Grid */
.categories-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.category-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
}

.category-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 10px;
}

.category-emoji { font-size: 1.3rem; }

.category-name {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.75rem;
    font-weight: bold;
}

.score-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.score-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 1s ease-out;
    width: 0;
}

.random-fill { background: var(--random-color); }
.luxury-fill { background: var(--luxury-color); }
.ugly-fill { background: var(--ugly-color); }
.cursed-fill { background: var(--cursed-color); }

.score-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    font-weight: bold;
}

#cardRandom .score-value { color: var(--random-color); }
#cardLuxury .score-value { color: var(--luxury-color); }
#cardUgly .score-value { color: var(--ugly-color); }
#cardCursed .score-value { color: var(--cursed-color); }

/* Best Category */
.best-category {
    background: linear-gradient(135deg, var(--bg-card), #22223a);
    border: 2px solid var(--accent);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 0 20px #00f5ff22;
}

.best-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.best-name {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.4rem;
    font-weight: bold;
    color: var(--accent);
}

.best-level {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.btn-new-scan {
    width: 100%;
    padding: 15px;
    background: var(--bg-card);
    border: 2px solid var(--accent);
    border-radius: 12px;
    color: var(--accent);
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-new-scan:hover {
    background: var(--accent);
    color: #000;
}

/* ============================================
   MODAL
============================================ */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 40px;
    text-align: center;
    max-width: 350px;
    width: 90%;
}

.modal-content h2 {
    font-family: 'Orbitron', sans-serif;
    color: var(--accent);
    margin-bottom: 10px;
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.analyzing-animation {
    position: relative;
    width: 80px; height: 80px;
    margin: 0 auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.analyzing-ring {
    position: absolute;
    width: 100%; height: 100%;
    border: 3px solid transparent;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1.5s linear infinite;
}

.analyzing-ring.r2 {
    width: 60%; height: 60%;
    border-top-color: var(--luxury-color);
    animation-direction: reverse;
}

@keyframes spin { to { transform: rotate(360deg); } }

.analyzing-icon { font-size: 1.5rem; z-index: 2; }

.analyzing-progress {
    width: 100%;
    height: 4px;
    background: var(--bg-primary);
    border-radius: 2px;
    overflow: hidden;
}

.analyzing-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--cursed-color));
    width: 0;
    transition: width 0.5s;
}

/* ============================================
   RESPONSIVE
============================================ */
@media (max-width: 400px) {
    .code-value {
        font-size: 2.2rem;
        letter-spacing: 5px;
    }
    
    .categories-grid {
        grid-template-columns: 1fr;
    }
}