:root {
    --primary: #168451;
    --primary-hover: #0f6c40;
    --primary-light: #e8f6f1;
    --accent-warning: #f59e0b;
    --accent-success: #16a34a;
    --accent-danger: #ef4444;
    --card-bg: #ffffff;
    --text-main: #174d36;
    --text-muted: #4b6b5b;
    --border-color: #cbd5e1;
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 6px 20px rgba(18, 56, 38, 0.08);
    --shadow-lg: 0 12px 30px rgba(0, 0, 0, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--primary-light);
    color: var(--text-main);
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1050px;
    margin: 12px auto;
    padding: 0 16px;
}

/* Header & Scoreboard */
header {
    background: var(--card-bg);
    padding: 14px 22px;
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(22, 132, 81, 0.08);
}

h1 {
    margin: 0;
    color: var(--primary);
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.scoreboard {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.score-pill {
    background: #f0fdf4;
    border: 1.5px solid #bbf7d0;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 700;
    color: #1f5139;
}

.score-pill span {
    color: var(--primary);
    font-size: 20px;
    font-variant-numeric: tabular-nums;
}

/* Controls Bar */
.controls {
    margin: 12px 0;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

button {
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    padding: 10px 18px;
    background: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(22, 132, 81, 0.22);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

button:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 5px 12px rgba(22, 132, 81, 0.32);
}

button:active:not(:disabled) {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(22, 132, 81, 0.2);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

#pauseBtn {
    background: #d97706;
    box-shadow: 0 3px 8px rgba(217, 119, 6, 0.25);
}
#pauseBtn:hover:not(:disabled) {
    background: #b45309;
}

#restartBtn {
    background: #4b5563;
    box-shadow: 0 3px 8px rgba(75, 85, 99, 0.25);
}
#restartBtn:hover:not(:disabled) {
    background: #374151;
}

#teacherBtn {
    background: #4338ca;
    box-shadow: 0 3px 8px rgba(67, 56, 202, 0.25);
    margin-left: auto;
}
#teacherBtn:hover:not(:disabled) {
    background: #3730a3;
}

/* Main Game Card */
.game-card {
    background: var(--card-bg);
    padding: 18px 22px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(22, 132, 81, 0.08);
}

/* Labels centered above each column */
.labels {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: clamp(24px, 6vw, 80px);
    padding: 0 2%;
    text-align: center;
    font-weight: 800;
    font-size: 16px;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 12px;
}

/* Game Board with 2 clear vertical columns for exactly 3 items */
#gameBoard {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: clamp(24px, 6vw, 80px);
    padding: 0 2%;
    min-height: 360px;
    align-items: center;
}

.column {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 14px;
    z-index: 4;
}

/* Word and Picture Cards */
.item {
    width: 100%;
    min-width: 0;
    height: clamp(85px, 12vh, 115px);
    background: #ffffff;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    touch-action: none;
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.2s ease, background-color 0.2s ease;
    overflow: hidden;
    position: relative;
}

.item.word {
    cursor: grab;
    background: #fdfdfd;
}

.item.word:hover:not(.matched) {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(22, 132, 81, 0.16);
}

.word {
    font-size: clamp(20px, 2.4vw, 26px);
    font-weight: 800;
    text-transform: capitalize;
    color: var(--text-main);
    padding: 8px 14px;
    text-align: center;
}

.picture {
    background: #f8fafc;
    cursor: default;
}

.picture img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 8px;
    border-radius: 12px;
    transition: transform 0.2s ease;
}

.picture:hover img {
    transform: scale(1.04);
}

.emoji {
    font-size: clamp(55px, 7vw, 75px);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Card State Transitions (No border width jump, constant 2px border) */
.selected {
    border-color: var(--accent-warning) !important;
    background: #fffbeb !important;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.35) !important;
    transform: scale(1.02);
}

.matched {
    border-color: var(--accent-success) !important;
    background: #dcfce7 !important;
    box-shadow: 0 3px 10px rgba(22, 163, 74, 0.2) !important;
    cursor: default !important;
}

.wrong {
    border-color: var(--accent-danger) !important;
    background: #fee2e2 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3) !important;
    animation: shake 0.4s ease-in-out;
}

/* SVG Line Layer */
#lines {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 3;
    overflow: visible;
}

.match-line {
    stroke: var(--accent-success);
    stroke-width: 5;
    stroke-linecap: round;
    filter: drop-shadow(0 2px 4px rgba(22, 163, 74, 0.35));
}

.preview-line {
    stroke: var(--accent-warning);
    stroke-width: 4;
    stroke-dasharray: 8 6;
    stroke-linecap: round;
    filter: drop-shadow(0 2px 4px rgba(245, 158, 11, 0.35));
}

.wrong-line {
    stroke: var(--accent-danger) !important;
    stroke-width: 5;
    stroke-linecap: round;
    filter: drop-shadow(0 2px 4px rgba(239, 68, 68, 0.4));
}

/* Real-Time Hand Skeleton Overlay Canvas */
#handCanvas {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 5;
}

/* Feedback message */
#feedback {
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    margin-top: 16px;
    min-height: 40px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    background: #f8fafc;
    border: 1px dashed var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s ease;
}

/* Camera & Hand Tracking Section */
.camera-section {
    background: var(--card-bg);
    padding: 16px 22px;
    margin-top: 14px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(22, 132, 81, 0.08);
}

.camera-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.camera-header h3 {
    margin: 0;
    color: #1f2937;
    font-size: 18px;
}

.camera-buttons {
    display: flex;
    gap: 10px;
}

#disableCameraBtn {
    background: #6b7280;
    box-shadow: 0 3px 8px rgba(107, 114, 128, 0.25);
}
#disableCameraBtn:hover:not(:disabled) {
    background: #4b5563;
}

#cameraStatus {
    margin: 10px 0 0;
    font-size: 14px;
    font-weight: 500;
    color: #4b6b5b;
}

/* Small Webcam Preview with mini skeleton canvas */
.webcam-container {
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    background: #f8fafc;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    border: 1px solid #e2e8f0;
}

.video-wrapper {
    position: relative;
    width: 180px;
    height: 135px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #000;
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

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

#webcamMiniCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.camera-hint {
    flex: 1;
    min-width: 200px;
    font-size: 13px;
    color: #334155;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
}

/* Teacher Settings Panel */
.teacher-panel {
    background: var(--card-bg);
    padding: 22px;
    margin-top: 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    border: 2px solid #a7f3d0;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 10px;
}

.panel-header h2 {
    margin: 0;
    color: #1e3a2b;
    font-size: 22px;
}

.btn-icon {
    background: transparent;
    border: none;
    font-size: 18px;
    color: #64748b;
    cursor: pointer;
    box-shadow: none;
    padding: 4px 8px;
}
.btn-icon:hover {
    color: #1e293b;
    background: #f1f5f9;
}

.teacher-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 22px;
}

.teacher-box {
    background: #f8fafc;
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid #e2e8f0;
}

.teacher-box h3 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 16px;
    color: #0f766e;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 6px;
}

.teacher-panel label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    color: #334155;
    margin-top: 10px;
    margin-bottom: 4px;
}

.teacher-panel input[type="text"],
.teacher-panel input[type="url"],
.teacher-panel input[type="file"],
.teacher-panel select {
    display: block;
    width: 100%;
    padding: 8px 12px;
    margin-bottom: 6px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    background: #ffffff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.teacher-panel input:focus,
.teacher-panel select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(22, 132, 81, 0.15);
}

.divider-text {
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: #94a3b8;
    margin: 6px 0;
    position: relative;
}

/* Image Preview Box */
.preview-area {
    margin: 12px 0;
}

.preview-label {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
}

.preview-box {
    width: 100%;
    height: 90px;
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius-sm);
    margin-top: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    overflow: hidden;
    position: relative;
}

.preview-box img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.preview-emoji {
    font-size: 44px;
}

#previewPlaceholder {
    font-size: 13px;
    color: #94a3b8;
}

/* Fruit Library List */
.fruit-list-container {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm);
    background: #ffffff;
    margin-bottom: 12px;
}

.fruit-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
}

.fruit-list-item:last-child {
    border-bottom: none;
}

.fruit-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.fruit-thumb {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.fruit-emoji-thumb {
    font-size: 24px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fruit-title {
    font-weight: 700;
    font-size: 14px;
    text-transform: capitalize;
    color: #1e293b;
}

.btn-delete-fruit {
    background: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fca5a5;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 6px;
    box-shadow: none;
}
.btn-delete-fruit:hover {
    background: #fecaca;
    color: #991b1b;
}

.teacher-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
    width: 100%;
}

.btn-secondary {
    background: #64748b;
    color: #ffffff;
    box-shadow: 0 3px 8px rgba(100, 116, 139, 0.25);
}
.btn-secondary:hover:not(:disabled) {
    background: #475569;
}

.hidden {
    display: none !important;
}

/* Result Modal Screen */
#result {
    background: var(--card-bg);
    text-align: center;
    padding: 30px 20px;
    border-radius: var(--radius-lg);
    margin-top: 16px;
    box-shadow: var(--shadow-lg);
    border: 2px solid #86efac;
    animation: popIn 0.3s ease-out;
}

#result h2 {
    margin-top: 0;
    color: var(--accent-success);
    font-size: 28px;
}

.result-stats {
    margin: 16px 0;
}

.result-highlight {
    font-size: 24px;
    font-weight: 800;
    color: #15803d;
    margin: 6px 0;
}

#result p {
    font-size: 16px;
    color: #334155;
    margin: 4px 0;
}

#playAgainBtn {
    font-size: 16px;
    padding: 12px 30px;
    margin-top: 10px;
}

/* Keyframes */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@keyframes popIn {
    0% { transform: scale(0.96); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Responsive Media Queries */
@media (max-width: 820px) {
    .teacher-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 650px) {
    .container {
        margin: 8px auto;
        padding: 0 8px;
    }

    header {
        padding: 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    h1 {
        font-size: 20px;
    }

    .scoreboard {
        width: 100%;
        justify-content: space-between;
    }

    .score-pill {
        padding: 4px 8px;
        font-size: 12px;
    }

    .score-pill span {
        font-size: 16px;
    }

    .controls button {
        padding: 8px 12px;
        font-size: 13px;
        flex: 1 1 calc(50% - 8px);
    }

    #teacherBtn {
        margin-left: 0;
    }

    .game-card {
        padding: 14px 10px;
    }

    .labels {
        gap: 12px;
        padding: 0;
        font-size: 13px;
        margin-bottom: 8px;
    }

    #gameBoard {
        gap: 14px;
        padding: 0;
        min-height: 300px;
    }

    .item {
        height: 78px;
    }

    .word {
        font-size: 16px;
        padding: 4px;
    }

    .emoji {
        font-size: 46px;
    }

    #feedback {
        font-size: 15px;
        padding: 6px 10px;
        min-height: 36px;
    }
}

