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

:root {
    --primary-color: #004c8c;
    --secondary-color: #64b5f6;
    --success-color: #4caf50;
    --warning-color: #ff9800;
    --danger-color: #f44336;
    --dark-bg: #1a2332;
    --card-bg: #2d3e50;
    --text-primary: #ffffff;
    --text-secondary: #b0bec5;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a2332 0%, #2d3e50 100%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Header */
header {
    background: var(--primary-color);
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
    font-size: 1.5em;
    font-weight: bold;
}

.logo .icon {
    font-size: 1.8em;
    animation: wave 2s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(20deg); }
    75% { transform: rotate(-20deg); }
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 25px;
}

.status-indicator .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--danger-color);
    animation: pulse 2s ease-in-out infinite;
}

.status-indicator.online .dot {
    background: var(--success-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.tutorial-btn-header {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tutorial-btn-header:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--secondary-color);
    transform: translateY(-2px);
}

/* Main Container */
.main-container {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 30px;
    padding: 30px;
    max-width: 1800px;
    margin: 0 auto;
}

/* Webcam Section */
.webcam-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.video-container {
    position: relative;
    background: #000;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    aspect-ratio: 16/9;
    display: flex;
    justify-content: center;
}

#webcam {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

/* Info Overlay */
.info-overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    padding: 20px;
    border-radius: 15px;
    min-width: 250px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-size: 0.9em;
}

.info-item .label {
    color: var(--text-secondary);
}

.info-item .value {
    font-weight: bold;
    color: var(--secondary-color);
}

/* Velocity Bar */
.velocity-bar {
    margin-top: 15px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--success-color), var(--warning-color), var(--danger-color));
    border-radius: 4px;
    transition: width 0.2s ease;
    width: 0%;
}

.threshold-line {
    position: absolute;
    left: 30%;
    top: 0;
    width: 2px;
    height: 100%;
    background: white;
}

/* Result Display */
.result-display {
    position: absolute;
    top: 50%;
    right: 30px;
    transform: translateY(-50%);
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.95), rgba(56, 142, 60, 0.95));
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: all 0.5s ease;
    pointer-events: none;
}

.result-display.show {
    opacity: 1;
    transform: translateY(-50%) scale(1.1);
}

.result-label {
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 10px;
    opacity: 0.9;
}

.result-number {
    font-size: 4em;
    font-weight: bold;
    margin: 10px 0;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.result-confidence {
    font-size: 0.9em;
    opacity: 0.9;
}

/* Controls */
.controls {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.control-btn {
    flex: 1;
    min-width: 120px;
    background: var(--primary-color);
    border: none;
    padding: 15px 20px;
    border-radius: 12px;
    color: white;
    font-size: 1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 76, 140, 0.3);
}

.control-btn:hover:not(:disabled) {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(100, 181, 246, 0.4);
}

.control-btn:active:not(:disabled) {
    transform: translateY(0);
}

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

.control-btn .icon {
    font-size: 1.3em;
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.card {
    background: var(--card-bg);
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.card h2 {
    font-size: 1.2em;
    margin-bottom: 20px;
    color: var(--secondary-color);
}

/* Instructions */
.instructions {
    list-style-position: inside;
    line-height: 2;
}

.instructions li {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.instructions li:last-child {
    border-bottom: none;
}

/* Numbers Grid */
.numbers-detected-container {
    min-height: 100px;
}

.numbers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px;
}

.number-badge {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(100, 181, 246, 0.3);
    border-radius: 10px;
    padding: 15px;
    text-align: center;
    font-size: 1.5em;
    font-weight: bold;
    color: var(--secondary-color);
    transition: all 0.3s ease;
    cursor: default;
}

.number-badge:hover {
    background: rgba(100, 181, 246, 0.1);
    transform: translateY(-2px);
}

.number-badge.active {
    background: var(--success-color);
    border-color: var(--success-color);
    color: white;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.4);
    transform: scale(1.1);
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 30px 20px;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.95em;
}

/* Stats */
.stats {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.stat-label {
    color: var(--text-secondary);
}

.stat-value {
    font-weight: bold;
    color: var(--secondary-color);
    font-size: 1.1em;
}

/* Settings */
.settings {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.setting-item label {
    color: var(--text-secondary);
}

.setting-item span {
    font-weight: bold;
    color: var(--secondary-color);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--card-bg);
    padding: 20px 30px;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(150%);
    transition: transform 0.3s ease;
    z-index: 2000;
    max-width: 400px;
}

.toast.show {
    transform: translateY(0);
}

.toast-message {
    color: white;
    font-size: 1em;
}

/* Responsive */
@media (max-width: 1200px) {
    .main-container {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        order: 2;
    }
}

@media (max-width: 768px) {
    header {
        padding: 15px 20px;
    }
    
    .logo {
        font-size: 1.2em;
    }
    
    .main-container {
        padding: 20px;
        gap: 20px;
    }
    
    .controls {
        grid-template-columns: 1fr 1fr;
    }
    
    .control-btn {
        min-width: auto;
    }
    
    .control-btn .text {
        display: none;
    }
    
    .result-display {
        right: 20px;
        padding: 20px;
    }
    
    .result-number {
        font-size: 3em;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card {
    animation: fadeIn 0.6s ease forwards;
}

.card:nth-child(1) { animation-delay: 0.1s; }
.card:nth-child(2) { animation-delay: 0.2s; }
.card:nth-child(3) { animation-delay: 0.3s; }
.card:nth-child(4) { animation-delay: 0.4s; }

/* Tutorial Modal */
.tutorial-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 20px;
    overflow-y: auto;
}

.tutorial-modal.show {
    opacity: 1;
    visibility: visible;
}

.tutorial-content {
    background: linear-gradient(135deg, #1a2332 0%, #2d3e50 100%);
    border-radius: 20px;
    max-width: 1000px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.5s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.tutorial-header {
    background: var(--primary-color);
    padding: 30px;
    text-align: center;
    border-radius: 20px 20px 0 0;
}

.tutorial-header h1 {
    font-size: 2em;
    margin-bottom: 10px;
}

.tutorial-header p {
    color: var(--text-secondary);
    font-size: 1.1em;
}

.tutorial-body {
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.tutorial-section {
    background: rgba(255, 255, 255, 0.05);
    padding: 25px;
    border-radius: 15px;
    border: 1px solid rgba(100, 181, 246, 0.2);
}

.tutorial-section h2 {
    font-size: 1.5em;
    margin-bottom: 15px;
    color: var(--secondary-color);
}

.tutorial-subtitle {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.step {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    background: rgba(255, 255, 255, 0.03);
    padding: 20px;
    border-radius: 12px;
    border-left: 4px solid var(--secondary-color);
    transition: all 0.3s ease;
}

.step:hover {
    background: rgba(100, 181, 246, 0.1);
    transform: translateX(5px);
}

.step-number {
    background: var(--secondary-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.2em;
    flex-shrink: 0;
}

.step-content strong {
    display: block;
    font-size: 1.1em;
    margin-bottom: 5px;
    color: var(--text-primary);
}

.step-content p {
    color: var(--text-secondary);
    line-height: 1.6;
}

.numbers-tutorial-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
}

.number-tutorial-card {
    background: rgba(100, 181, 246, 0.2);
    padding: 25px;
    border-radius: 12px;
    text-align: center;
    font-size: 2em;
    font-weight: bold;
    color: var(--secondary-color);
    border: 2px solid var(--secondary-color);
    transition: all 0.3s ease;
}

.number-tutorial-card:hover {
    background: rgba(100, 181, 246, 0.3);
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(100, 181, 246, 0.4);
}

.tips-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tips-list li {
    padding: 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    border-left: 4px solid var(--success-color);
    line-height: 1.6;
}

.tips-list li strong {
    color: var(--success-color);
}

.tutorial-footer {
    padding: 25px 30px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 20px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.tutorial-btn-close {
    background: var(--success-color);
    color: white;
    border: none;
    padding: 15px 40px;
    border-radius: 12px;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(76, 175, 80, 0.3);
}

.tutorial-btn-close:hover {
    background: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.4);
}

.tutorial-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    user-select: none;
}

.tutorial-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* Scrollbar do modal */
.tutorial-content::-webkit-scrollbar {
    width: 10px;
}

.tutorial-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.tutorial-content::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 5px;
}

.tutorial-content::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Responsive Tutorial */
@media (max-width: 768px) {
    .tutorial-content {
        max-height: 95vh;
    }

    .tutorial-header {
        padding: 20px;
    }

    .tutorial-header h1 {
        font-size: 1.5em;
    }

    .tutorial-body {
        padding: 20px;
        gap: 20px;
    }

    .tutorial-section {
        padding: 15px;
    }

    .numbers-tutorial-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .tutorial-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .tutorial-btn-close {
        width: 100%;
    }

    .numbers-grid {
        grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    }
}
