/* ========================================
   CSS Variables & Reset
   ======================================== */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a2e;
    --bg-card-hover: #222240;
    --surface: #16213e;
    --border: rgba(255, 255, 255, 0.06);
    --border-glow: rgba(239, 68, 68, 0.3);

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent-red: #ef4444;
    --accent-green: #22c55e;
    --accent-yellow: #eab308;
    --accent-orange: #f97316;
    --gradient-1: linear-gradient(135deg, #ef4444, #f97316);
    --gradient-2: linear-gradient(135deg, #22c55e, #16a34a);
    --gradient-hero: linear-gradient(135deg, #ef4444 0%, #f97316 50%, #22c55e 100%);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(239, 68, 68, 0.15);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ========================================
   Navbar
   ======================================== */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 32px;
    background: rgba(10, 10, 15, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-emoji {
    font-size: 24px;
}

.nav-title {
    font-weight: 700;
    font-size: 18px;
    letter-spacing: -0.5px;
}

.nav-links {
    display: flex;
    gap: 16px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.nav-link:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border);
}

/* ========================================
   Hero Section
   ======================================== */
.hero {
    padding: 140px 32px 80px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: -200px;
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
    height: 800px;
    background: radial-gradient(circle, rgba(239, 68, 68, 0.08) 0%, transparent 70%);
    pointer-events: none;
}

.hero-badge {
    display: inline-block;
    padding: 6px 20px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 100px;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent-red);
    margin-bottom: 24px;
    animation: fadeInUp 0.6s ease;
}

.hero h1 {
    font-size: clamp(40px, 7vw, 72px);
    font-weight: 900;
    line-height: 1.1;
    letter-spacing: -2px;
    margin-bottom: 20px;
    animation: fadeInUp 0.6s ease 0.1s both;
}

.gradient-text {
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    font-size: 18px;
    color: var(--text-secondary);
    max-width: 560px;
    margin: 0 auto;
    animation: fadeInUp 0.6s ease 0.2s both;
}

/* ========================================
   App Section
   ======================================== */
.app-section {
    padding: 0 32px 80px;
    max-width: 1200px;
    margin: 0 auto;
}

.app-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* ========================================
   Panels
   ======================================== */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    transition: border-color 0.3s ease;
}

.panel:hover {
    border-color: rgba(255, 255, 255, 0.1);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.panel-header h2 {
    font-size: 18px;
    font-weight: 700;
}

/* ========================================
   Mode Toggle
   ======================================== */
.mode-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg-primary);
    padding: 3px;
    border-radius: var(--radius-sm);
}

.mode-btn {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s ease;
    font-family: var(--font);
}

.mode-btn.active {
    background: var(--accent-red);
    color: white;
}

/* ========================================
   Media Container (Webcam / Upload)
   ======================================== */
.media-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.media-container.hidden {
    display: none;
}

#webcam {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.webcam-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 15, 0.7);
    backdrop-filter: blur(4px);
}

.webcam-overlay.hidden {
    display: none;
}

.start-webcam-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 40px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-md);
    color: var(--accent-red);
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font);
    transition: all 0.3s ease;
}

.start-webcam-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    transform: scale(1.03);
}

/* Upload Zone */
.upload-zone {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.3s ease;
}

.upload-zone:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.02);
}

.upload-zone.dragover {
    background: rgba(239, 68, 68, 0.05);
    border: 2px dashed var(--accent-red);
}

.upload-zone p {
    font-size: 14px;
}

#upload-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: absolute;
    inset: 0;
    background: var(--bg-primary);
}

#upload-preview.hidden {
    display: none;
}

/* ========================================
   Controls
   ======================================== */
.controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 16px;
}

.detect-btn {
    flex: 1;
    padding: 14px 24px;
    font-size: 15px;
    font-weight: 700;
    font-family: var(--font);
    border: none;
    border-radius: var(--radius-md);
    background: var(--gradient-1);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.detect-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 25px rgba(239, 68, 68, 0.4);
}

.detect-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-text, .btn-loader {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-loader.hidden {
    display: none;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Auto-detect Toggle */
.auto-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.auto-toggle input {
    display: none;
}

.toggle-slider {
    width: 40px;
    height: 22px;
    background: var(--bg-primary);
    border-radius: 11px;
    position: relative;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all 0.3s ease;
}

.auto-toggle input:checked + .toggle-slider {
    background: rgba(239, 68, 68, 0.2);
    border-color: var(--accent-red);
}

.auto-toggle input:checked + .toggle-slider::after {
    left: 20px;
    background: var(--accent-red);
}

.toggle-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ========================================
   Results
   ======================================== */
.fps-badge {
    padding: 4px 12px;
    background: rgba(34, 197, 94, 0.15);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 100px;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-green);
    font-variant-numeric: tabular-nums;
}

.fps-badge.hidden {
    display: none;
}

.result-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.result-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
    font-size: 14px;
}

.result-placeholder.hidden {
    display: none;
}

.result-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.result-image.hidden {
    display: none;
}

.result-card {
    position: absolute;
    bottom: 12px;
    left: 12px;
    right: 12px;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    text-align: center;
}

.result-card.hidden {
    display: none;
}

.result-label {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.result-label.ripe { color: var(--accent-green); }
.result-label.unripe { color: var(--accent-yellow); }
.result-label.damaged { color: var(--accent-red); }
.result-label.none { color: var(--text-muted); }

.result-info {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ========================================
   About Section
   ======================================== */
.about-section {
    padding: 40px 32px 80px;
    max-width: 1200px;
    margin: 0 auto;
}

.about-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.about-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
    transition: all 0.3s ease;
}

.about-card:hover {
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.card-icon {
    font-size: 36px;
    margin-bottom: 16px;
}

.about-card h3 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
}

.about-card p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ========================================
   Footer
   ======================================== */
.footer {
    text-align: center;
    padding: 32px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
}

.footer a {
    color: var(--accent-red);
    text-decoration: none;
    font-weight: 600;
}

.footer a:hover {
    text-decoration: underline;
}

.footer-sub {
    margin-top: 6px;
    font-size: 12px;
}

/* ========================================
   Animations
   ======================================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 20px 4px rgba(239, 68, 68, 0.15); }
}

.detecting {
    animation: pulse-glow 1.5s ease infinite;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 900px) {
    .app-container {
        grid-template-columns: 1fr;
    }
    .about-grid {
        grid-template-columns: 1fr;
    }
    .navbar {
        padding: 12px 16px;
    }
    .hero {
        padding: 120px 16px 60px;
    }
    .app-section, .about-section {
        padding-left: 16px;
        padding-right: 16px;
    }
}

@media (max-width: 600px) {
    .hero h1 {
        letter-spacing: -1px;
    }
    .nav-links {
        display: none;
    }
    .controls {
        flex-direction: column;
    }
    .detect-btn {
        width: 100%;
    }
}
