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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #e0e0e0;
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
}

header {
    text-align: center;
    margin-bottom: 10px;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(90deg, #00d9ff, #00ff88);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.subtitle {
    color: #888;
    font-size: 0.95rem;
}

/* Main layout - side by side */
.main-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

.video-section {
    flex: 1;
    min-width: 0;
}

.video-container {
    position: relative;
    width: 100%;
    max-width: 400px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    background: #0f0f1a;
    aspect-ratio: 4/3;
}

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

#canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform: scaleX(-1);
}

.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(0, 217, 255, 0.2);
    border-top-color: #00d9ff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading p {
    color: #00d9ff;
    font-size: 1rem;
}

.no-face {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 100, 100, 0.2);
    padding: 12px 24px;
    border-radius: 8px;
    border: 1px solid rgba(255, 100, 100, 0.4);
    z-index: 5;
}

.no-face p {
    color: #ff6464;
    font-size: 0.95rem;
}

.hidden {
    display: none !important;
}

.controls {
    text-align: center;
    margin: 15px 0;
}

.btn {
    background: linear-gradient(135deg, #00d9ff, #00ff88);
    color: #1a1a2e;
    border: none;
    padding: 14px 32px;
    font-size: 1.1rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(0, 217, 255, 0.3);
}

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

.btn.active {
    background: linear-gradient(135deg, #ff6464, #ff8888);
}

.btn.btn-snapshot {
    background: linear-gradient(135deg, #aa66ff, #ff66aa);
}

.btn.btn-snapshot:hover:not(:disabled) {
    box-shadow: 0 10px 30px rgba(170, 102, 255, 0.3);
}

.btn-icon {
    font-size: 0.9rem;
}

.emotions-panel {
    flex: 0 0 320px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.emotions-panel h2 {
    text-align: center;
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: #fff;
}

.emotions-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.emotion-card {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
    border: 2px solid transparent;
}

.emotion-card.dominant {
    border-color: #00d9ff;
    background: rgba(0, 217, 255, 0.15);
}

.emotion-emoji {
    font-size: 1.4rem;
    flex-shrink: 0;
}

.emotion-label {
    font-size: 0.85rem;
    color: #aaa;
    width: 70px;
    flex-shrink: 0;
}

.emotion-bar {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.emotion-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.2s ease;
}

.emotion-card[data-emotion="happy"] .emotion-fill {
    background: linear-gradient(90deg, #ffdd00, #ffaa00);
}

.emotion-card[data-emotion="sad"] .emotion-fill {
    background: linear-gradient(90deg, #5588ff, #3366cc);
}

.emotion-card[data-emotion="angry"] .emotion-fill {
    background: linear-gradient(90deg, #ff4444, #cc2222);
}

.emotion-card[data-emotion="fearful"] .emotion-fill {
    background: linear-gradient(90deg, #aa66ff, #8844cc);
}

.emotion-card[data-emotion="disgusted"] .emotion-fill {
    background: linear-gradient(90deg, #44cc44, #228822);
}

.emotion-card[data-emotion="surprised"] .emotion-fill {
    background: linear-gradient(90deg, #ff88cc, #ff44aa);
}

.emotion-card[data-emotion="neutral"] .emotion-fill {
    background: linear-gradient(90deg, #888888, #666666);
}

.emotion-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    width: 35px;
    text-align: right;
    flex-shrink: 0;
}

.dominant-emotion {
    margin-top: 10px;
    text-align: center;
    background: rgba(0, 217, 255, 0.1);
    padding: 10px 20px;
    border-radius: 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    border: 1px solid rgba(0, 217, 255, 0.3);
}

.dominant-label {
    color: #888;
    font-size: 0.95rem;
}

.dominant-emoji {
    font-size: 1.8rem;
}

.dominant-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: #00d9ff;
    text-transform: capitalize;
}

footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    color: #666;
    font-size: 0.9rem;
}

/* ==================== */
/* Graph Section        */
/* ==================== */

.graph-section {
    margin-top: 15px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.graph-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 15px;
}

.graph-header h2 {
    font-size: 1.3rem;
    color: #fff;
    margin: 0;
}

.graph-controls {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-small {
    background: linear-gradient(135deg, #00d9ff, #00ff88);
    color: #1a1a2e;
    border: none;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-small:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(0, 217, 255, 0.3);
}

.btn-small.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #aaa;
}

.btn-small.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    box-shadow: none;
}

.btn-small.recording {
    background: linear-gradient(135deg, #ff4444, #ff6666);
    animation: pulse-rec 1.5s infinite;
}

.rec-icon {
    font-size: 0.7rem;
}

.btn-small.recording .rec-icon {
    color: #fff;
}

@keyframes pulse-rec {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.graph-container {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 15px;
    height: 200px;
    position: relative;
}

.graph-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.stat-item {
    text-align: center;
}

.stat-label {
    font-size: 0.8rem;
    color: #666;
    display: block;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: #00d9ff;
}

/* ==================== */
/* Heatmap Section      */
/* ==================== */

.heatmap-section {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.heatmap-section h3 {
    color: #fff;
    font-size: 1.1rem;
    margin-bottom: 15px;
    text-align: center;
}

.heatmap-container {
    display: flex;
    gap: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 15px;
}

.heatmap-labels {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    font-size: 0.75rem;
    color: #888;
    min-width: 70px;
    text-align: right;
    padding-right: 8px;
}

#heatmapCanvas {
    flex: 1;
    height: 140px;
    border-radius: 4px;
}

.heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
    font-size: 0.8rem;
    color: #888;
}

.legend-gradient {
    width: 150px;
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg,
        #1a1a2e 0%,
        #2d1f5e 25%,
        #6b2d8e 50%,
        #d94444 75%,
        #ffdd00 100%
    );
}

/* ==================== */
/* Modal Styles         */
/* ==================== */

.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: 2000;
    backdrop-filter: blur(5px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: #1a1a2e;
    border-radius: 16px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: rgba(0, 217, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.modal-header h3 {
    color: #fff;
    font-size: 1.1rem;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #fff;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: 60vh;
}

#snapshotCanvas {
    width: 100%;
    border-radius: 8px;
    display: block;
}

.snapshot-emotions {
    margin-top: 15px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.snapshot-emotion-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 8px;
    text-align: center;
}

.snapshot-emotion-item .emoji {
    font-size: 1.3rem;
    display: block;
    margin-bottom: 4px;
}

.snapshot-emotion-item .label {
    font-size: 0.7rem;
    color: #888;
    display: block;
}

.snapshot-emotion-item .value {
    font-size: 0.9rem;
    font-weight: 600;
    color: #00d9ff;
}

.snapshot-emotion-item.dominant {
    background: rgba(0, 217, 255, 0.15);
    border: 1px solid rgba(0, 217, 255, 0.3);
}

.modal-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ==================== */
/* How It Works Section */
/* ==================== */

.explanation {
    margin-top: 60px;
    padding-top: 40px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.section-title {
    text-align: center;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 40px;
    background: linear-gradient(90deg, #00d9ff, #00ff88);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.explanation-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 50px;
}

.explanation-card {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    padding: 24px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: all 0.3s ease;
}

.explanation-card:hover {
    border-color: rgba(0, 217, 255, 0.3);
    transform: translateY(-4px);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.card-icon {
    font-size: 1.8rem;
}

.card-header h3 {
    font-size: 1.2rem;
    color: #fff;
}

.card-content p {
    color: #aaa;
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.card-content ul {
    list-style: none;
    padding: 0;
}

.card-content li {
    color: #888;
    font-size: 0.9rem;
    padding: 6px 0;
    padding-left: 20px;
    position: relative;
}

.card-content li::before {
    content: ">";
    position: absolute;
    left: 0;
    color: #00d9ff;
    font-weight: bold;
}

.card-content strong {
    color: #e0e0e0;
}

/* Code Section */
.code-section {
    margin-bottom: 50px;
}

.code-title {
    font-size: 1.5rem;
    color: #fff;
    margin-bottom: 24px;
    text-align: center;
}

.code-block {
    background: #0d0d1a;
    border-radius: 12px;
    margin-bottom: 24px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(0, 217, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.code-label {
    font-weight: 600;
    color: #00d9ff;
    font-size: 0.95rem;
}

.code-file {
    font-size: 0.8rem;
    color: #666;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
}

.code-block pre {
    padding: 20px;
    overflow-x: auto;
    margin: 0;
}

.code-block code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    color: #e0e0e0;
    line-height: 1.6;
}

.code-explanation {
    padding: 16px 20px;
    background: rgba(255, 255, 255, 0.02);
    color: #888;
    font-size: 0.9rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    margin: 0;
}

.code-explanation code {
    background: rgba(0, 217, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #00d9ff;
}

/* Architecture Section */
.architecture-section {
    margin-bottom: 50px;
}

.architecture-title {
    font-size: 1.5rem;
    color: #fff;
    margin-bottom: 24px;
    text-align: center;
}

.architecture-diagram {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    padding: 30px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow-x: auto;
}

.arch-flow {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.arch-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 16px 20px;
    border-radius: 12px;
    min-width: 100px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.arch-node.highlight {
    background: rgba(0, 217, 255, 0.1);
    border-color: rgba(0, 217, 255, 0.3);
}

.arch-icon {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.arch-label {
    font-size: 0.75rem;
    color: #aaa;
    text-align: center;
}

.arch-arrow {
    color: #00d9ff;
    font-size: 1.2rem;
    padding: 0 4px;
}

.architecture-note {
    text-align: center;
    color: #00ff88;
    font-size: 0.9rem;
    margin-top: 20px;
    padding: 12px;
    background: rgba(0, 255, 136, 0.05);
    border-radius: 8px;
}

/* Models Section */
.models-section {
    margin-bottom: 30px;
}

.models-title {
    font-size: 1.5rem;
    color: #fff;
    margin-bottom: 24px;
    text-align: center;
}

.models-table {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.model-row {
    display: grid;
    grid-template-columns: 1fr 100px 1fr;
    padding: 16px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    align-items: center;
}

.model-row:last-child {
    border-bottom: none;
}

.model-row.header {
    background: rgba(0, 217, 255, 0.1);
    font-weight: 600;
    color: #00d9ff;
    font-size: 0.9rem;
}

.model-row span {
    color: #aaa;
    font-size: 0.9rem;
}

.model-row code {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.8rem;
    color: #00ff88;
    background: rgba(0, 255, 136, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
}

/* Responsive for main layout */
@media (max-width: 900px) {
    .main-layout {
        flex-direction: column;
    }

    .emotions-panel {
        flex: none;
        width: 100%;
        max-height: none;
    }

    .emotions-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
    }

    .emotion-card {
        flex-direction: column;
        text-align: center;
        padding: 12px;
    }

    .emotion-label {
        width: auto;
    }

    .emotion-bar {
        width: 100%;
    }

    .emotion-value {
        width: auto;
        text-align: center;
    }
}

/* Responsive for explanation section */
@media (max-width: 768px) {
    .explanation-grid {
        grid-template-columns: 1fr;
    }

    .arch-flow {
        flex-direction: column;
    }

    .arch-arrow {
        transform: rotate(90deg);
    }

    .model-row {
        grid-template-columns: 1fr;
        gap: 8px;
        text-align: center;
    }

    .model-row.header {
        display: none;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .emotions-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .emotion-card {
        padding: 10px;
    }

    .emotion-emoji {
        font-size: 1.3rem;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.95rem;
    }

    .section-title {
        font-size: 1.5rem;
    }

    .code-block code {
        font-size: 0.75rem;
    }

    .explanation-card {
        padding: 16px;
    }
}
