:root {
    --bg-primary: #FBEFEF;
    --bg-secondary: #fdfaf5;
    --accent-color: #D3D4C0;
    --primary-action: #0A2947;
    --text-main: #0A2947;
    --text-muted: #8B5E3C;
    --border-radius: 12px;
    --box-shadow: 0 4px 12px rgba(10, 41, 71, 0.10);
    --shadow-3d: 0 4px 0 #0A2947, 0 6px 12px rgba(10, 41, 71, 0.15);
    --card-border: var(--accent-color);
    --highlight-bg: #e8e9de;
    --highlight-border: #8B5E3C;
    --badge-bg: #F3E4C9;
    --btn-text: #FBEFEF;
    --transition-speed: 0.3s;
}

body.dark-mode {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --accent-color: #333333;
    --primary-action: #4fa3f7;
    --text-main: #f0f0f0;
    --text-muted: #aaaaaa;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    --shadow-3d: 0 4px 0 #111111, 0 6px 12px rgba(0, 0, 0, 0.8);
    --card-border: #333333;
    --highlight-bg: #2a2a2a;
    --highlight-border: #555555;
    --badge-bg: #2a2a2a;
    --btn-text: #121212;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-main);
    line-height: 1.6;
    display: flex;
    justify-content: center;
    padding: 2rem;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

.container {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

header {
    text-align: center;
    margin-bottom: 1rem;
    position: relative;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-action);
    margin-bottom: 0.5rem;
    text-shadow: 2px 3px 0px rgba(0, 0, 0, 0.1), 4px 5px 10px rgba(0, 0, 0, 0.05);
}

.theme-btn {
    position: absolute;
    top: 0;
    right: 0;
    background: none;
    border: none;
    color: var(--primary-action);
    cursor: pointer;
    box-shadow: none;
    padding: 0.25rem;
    transition: transform 0.2s, color var(--transition-speed);
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-btn:hover {
    transform: scale(1.1);
}

.theme-btn:active {
    transform: scale(0.95);
}

header p {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.card {
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    box-shadow: var(--box-shadow);
    border: 1px solid var(--card-border);
    transition: background-color var(--transition-speed), border-color var(--transition-speed), box-shadow var(--transition-speed);
}



/* Live feed frame */
.video-container.card {
    margin-bottom: 1.25rem;
}

button {
    font-family: inherit;
    font-weight: 600;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.1s, background-color var(--transition-speed);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

button:active {
    transform: scale(0.98);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.primary-btn {
    background-color: var(--primary-action);
    color: var(--btn-text);
}

.primary-btn:hover:not(:disabled) {
    background-color: #0d3460;
}

.action-btn {
    background-color: var(--primary-action);
    color: var(--btn-text);
    font-size: 1.2rem;
    padding: 1rem 2rem;
    width: 100%;
    box-shadow: var(--shadow-3d);
    transition: transform 0.1s, box-shadow 0.1s, background-color var(--transition-speed), color var(--transition-speed);
}

.action-btn:hover:not(:disabled) {
    filter: brightness(1.1);
    box-shadow: var(--shadow-3d);
}

.action-btn:active:not(:disabled) {
    transform: translateY(3px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.2);
}

.status-msg {
    font-size: 0.9rem;
    font-weight: 600;
}

.success {
    color: #2e7d32;
}

.error {
    color: #c62828;
}

.video-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background-color: #000;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

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

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}

.controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

#capture-status {
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 600;
}

.results-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
}

@media (max-width: 768px) {
    body {
        padding: 1.5rem 1rem;
    }

    header h1 {
        font-size: 2.2rem;
    }
}

@media (max-width: 600px) {
    body {
        padding: 1rem 0.75rem;
    }

    .container {
        gap: 1rem;
    }

    header {
        margin-bottom: 0.5rem;
    }

    header h1 {
        font-size: 1.85rem;
    }

    header p {
        font-size: 0.95rem;
    }

    .card {
        padding: 1rem;
        border-radius: 10px;
    }

    .video-container {
        aspect-ratio: auto;
        height: clamp(180px, 35vh, 260px);
    }

    .action-btn {
        font-size: 1.05rem;
        padding: 0.8rem 1.5rem;
    }

    .results-panel {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    #live-sign-display {
        font-size: 2rem;
    }

    #signs-output,
    #translation-output {
        font-size: 1rem;
        min-height: 2.5rem;
    }
}

/* Extra small devices (very small phones like iPhone SE) */
@media (max-width: 400px) {
    body {
        padding: 0.75rem 0.5rem;
    }

    header h1 {
        font-size: 1.6rem;
    }

    header p {
        font-size: 0.85rem;
    }

    .card {
        padding: 0.75rem;
    }

    .video-container {
        height: clamp(160px, 30vh, 220px);
    }

    .action-btn {
        font-size: 0.95rem;
        padding: 0.7rem 1rem;
    }

    #live-sign-display {
        font-size: 1.65rem;
    }

    #capture-status {
        font-size: 0.82rem;
        text-align: center;
    }
}

.recognized-signs h3,
.translation-result h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.recognized-signs {
    /* Uses standard card styles */
}

.translation-result {
    /* Uses standard card styles */
}

.highlight-card {
    background-color: var(--highlight-bg);
    border-color: var(--highlight-border);
}

/* Sign badge styling for recognized signs */
#signs-output {
    font-size: 1.1rem;
    min-height: 5.5rem;
    max-height: 8rem;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-content: flex-start;
    align-items: flex-start;
    padding-top: 0.25rem;
}

.sign-badge {
    display: inline-block;
    background-color: var(--badge-bg);
    border: 1.5px solid var(--primary-action);
    color: var(--primary-action);
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.2rem 0.6rem;
    border-radius: 6px;
    box-shadow: 0 2px 0 var(--primary-action), 0 3px 6px rgba(0, 0, 0, 0.1);
    animation: badgePop 0.2s ease-out;
    white-space: nowrap;
}

@keyframes badgePop {
    from {
        transform: scale(0.7);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

#translation-output {
    font-size: 1.1rem;
    min-height: 3rem;
    font-weight: 600;
    color: var(--primary-action);
}

/* Spinner animation for buttons */
.spinner {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 3px solid white;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    margin-left: 10px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.live-detection {
    text-align: center;
    border-color: var(--accent-color);
    padding: 0.75rem 1.5rem;
}

.live-stats {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 0.25rem;
}

#live-sign-display {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--primary-action);
    line-height: 1.2;
}

#live-confidence-display {
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 0.25rem;
}

.action-btn.active {
    background-color: #333333;
}

.action-btn.active:hover:not(:disabled) {
    background-color: #222222;
}