/* ============================================================
   Virtual Teacher — Main Stylesheet
   ============================================================ */

:root {
    --vt-primary: #5B4FCF;
    --vt-primary-light: #7B6FE0;
    --vt-accent: #FF6B8A;
    --vt-bg: #F8F7FF;
    --vt-board: #FFFEF5;
    --vt-board-border: #D4C9A8;
    --vt-text: #2D2B3D;
    --vt-text-light: #6B6880;
    --vt-success: #4CAF50;
    --vt-warning: #FF9800;
    --vt-error: #F44336;
    --vt-card-bg: #FFFFFF;
    --vt-card-hover: #F0EEFF;
    --vt-card-selected: #E8E4FF;
    --vt-card-correct: #E8F5E9;
    --vt-card-incorrect: #FFEBEE;
    --vt-shadow: 0 2px 8px rgba(0,0,0,0.08);
    --vt-shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
    --vt-radius: 12px;
    --vt-radius-sm: 8px;
    --vt-font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--vt-font);
    background: var(--vt-bg);
    color: var(--vt-text);
    user-select: none;
    -webkit-user-select: none;
}

#vt-app {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: 1fr 56px;
    grid-template-areas:
        "teacher teaching"
        "control control";
    width: 100%;
    height: 100vh;
    max-width: 1280px;
    margin: 0 auto;
    gap: 0;
}

/* ============================================================
   Teacher Stage
   ============================================================ */

#teacher-stage {
    grid-area: teacher;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px 16px;
    background: linear-gradient(180deg, #F0EEFF 0%, #F8F7FF 100%);
    border-right: 1px solid #E8E4FF;
    position: relative;
}

#avatar-container {
    width: 180px;
    height: 260px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#avatar-svg {
    width: 100%;
    height: 100%;
}

#teacher-speech-bubble {
    margin-top: 12px;
    background: white;
    border-radius: var(--vt-radius);
    padding: 10px 14px;
    box-shadow: var(--vt-shadow);
    max-width: 220px;
    position: relative;
    transition: opacity var(--transition-normal);
}

#teacher-speech-bubble::before {
    content: '';
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid white;
}

#teacher-speech-text {
    font-size: 13px;
    line-height: 1.4;
    color: var(--vt-text);
}

#teacher-name-badge {
    position: absolute;
    bottom: 12px;
    background: var(--vt-primary);
    color: white;
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ============================================================
   Teaching Area (Blackboard + Interaction)
   ============================================================ */

#teaching-area {
    grid-area: teaching;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 12px;
    overflow-y: auto;
}

#blackboard-container {
    position: relative;
    background: var(--vt-board);
    border: 2px solid var(--vt-board-border);
    border-radius: var(--vt-radius);
    box-shadow: var(--vt-shadow-lg);
    flex: 1;
    min-height: 300px;
    overflow: hidden;
}

#blackboard-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#blackboard-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#blackboard-overlay.interactive {
    pointer-events: auto;
}

/* ============================================================
   Interaction Zone
   ============================================================ */

#interaction-zone {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 80px;
    align-items: center;
    justify-content: center;
}

#answer-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.answer-card {
    background: var(--vt-card-bg);
    border: 2px solid #E0DDE8;
    border-radius: var(--vt-radius-sm);
    padding: 12px 20px;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--vt-shadow);
    min-width: 60px;
    text-align: center;
}

.answer-card:hover {
    background: var(--vt-card-hover);
    border-color: var(--vt-primary-light);
    transform: translateY(-2px);
    box-shadow: var(--vt-shadow-lg);
}

.answer-card:active {
    transform: translateY(0);
}

.answer-card.selected {
    background: var(--vt-card-selected);
    border-color: var(--vt-primary);
}

.answer-card.correct {
    background: var(--vt-card-correct);
    border-color: var(--vt-success);
    animation: pulse-green 0.5s ease;
}

.answer-card.incorrect {
    background: var(--vt-card-incorrect);
    border-color: var(--vt-error);
    animation: shake 0.4s ease;
}

.answer-card.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Draggable Counters */
.counter-object {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    font-size: 28px;
    cursor: grab;
    transition: transform var(--transition-fast);
    border-radius: 50%;
    background: white;
    box-shadow: var(--vt-shadow);
    user-select: none;
}

.counter-object:active {
    cursor: grabbing;
    transform: scale(1.1);
}

.counter-object.dragging {
    opacity: 0.7;
    transform: scale(1.1);
    box-shadow: var(--vt-shadow-lg);
    z-index: 100;
}

.drop-zone {
    border: 2px dashed #D4C9A8;
    border-radius: var(--vt-radius-sm);
    min-width: 60px;
    min-height: 60px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    background: rgba(255,255,255,0.5);
    transition: all var(--transition-fast);
}

.drop-zone.highlight {
    border-color: var(--vt-primary);
    background: rgba(91,79,207,0.05);
}

.drop-zone.filled {
    border-style: solid;
    border-color: var(--vt-success);
}

/* ============================================================
   Control Bar
   ============================================================ */

#control-bar {
    grid-area: control;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: white;
    border-top: 1px solid #E8E4FF;
    box-shadow: 0 -1px 4px rgba(0,0,0,0.04);
}

#control-bar button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid #E0DDE8;
    background: white;
    font-size: 18px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

#control-bar button:hover {
    background: var(--vt-card-hover);
    border-color: var(--vt-primary-light);
}

#control-bar button:active {
    transform: scale(0.95);
}

#control-bar button.active {
    background: var(--vt-primary);
    color: white;
    border-color: var(--vt-primary);
}

#lang-select {
    height: 40px;
    padding: 0 12px;
    border-radius: 20px;
    border: 1px solid #E0DDE8;
    background: white;
    font-size: 14px;
    font-family: var(--vt-font);
    color: var(--vt-text);
    cursor: pointer;
    transition: all var(--transition-fast);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%236B6880'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
    min-width: 120px;
}

#lang-select:hover {
    border-color: var(--vt-primary-light);
    background: var(--vt-card-hover);
}

#lang-select:focus {
    outline: none;
    border-color: var(--vt-primary);
    box-shadow: 0 0 0 2px rgba(91,79,207,0.15);
}

#lesson-progress {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 12px;
}

#progress-bar {
    flex: 1;
    height: 6px;
    background: #E8E4FF;
    border-radius: 3px;
    overflow: hidden;
    max-width: 200px;
}

#progress-fill {
    height: 100%;
    background: var(--vt-primary);
    border-radius: 3px;
    width: 0%;
    transition: width var(--transition-normal);
}

#progress-label {
    font-size: 12px;
    color: var(--vt-text-light);
    white-space: nowrap;
}

#teacher-state-badge {
    font-size: 11px;
    color: var(--vt-text-light);
    white-space: nowrap;
    padding: 4px 10px;
    background: #F0EEFF;
    border-radius: 12px;
}

/* ============================================================
   Evidence Dashboard
   ============================================================ */

#evidence-panel {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 280px;
    max-height: calc(100vh - 100px);
    background: white;
    border-radius: var(--vt-radius);
    box-shadow: var(--vt-shadow-lg);
    z-index: 900;
    overflow: hidden;
    font-size: 12px;
    display: none; /* HIDDEN by default — internal teacher tool */
}

#evidence-panel.visible {
    display: block;
}

.ev-dashboard {
    padding: 0;
}

.ev-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: linear-gradient(135deg, #5B4FCF, #7B6FE0);
    color: white;
}

.ev-header h3 {
    font-size: 13px;
    font-weight: 600;
    margin: 0;
}

.ev-header span {
    font-size: 10px;
    opacity: 0.85;
}

.ev-flash {
    padding: 8px 14px;
    background: #F0EEFF;
    border-bottom: 1px solid #E8E4FF;
    font-size: 11px;
    display: flex;
    gap: 6px;
    align-items: center;
    transition: all 0.3s ease;
}

.ev-flash-anim {
    animation: slide-in-right 0.3s ease;
}

@keyframes slide-in-right {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.ev-flash-icon {
    font-size: 16px;
}

.ev-dimensions {
    padding: 8px 0;
}

.ev-dim-row {
    display: grid;
    grid-template-columns: 24px 52px 1fr 36px;
    align-items: center;
    gap: 4px;
    padding: 5px 14px;
    transition: background 0.2s;
}

.ev-dim-row:hover {
    background: #F8F7FF;
}

.ev-dim-row.ev-unprobed {
    opacity: 0.45;
}

.ev-dim-row.ev-covered {
    background: #E8F5E9;
    animation: flash-green-bg 1s ease;
}

@keyframes flash-green-bg {
    0% { background: #C8E6C9; }
    100% { background: transparent; }
}

.ev-dim-icon {
    font-size: 14px;
    text-align: center;
}

.ev-dim-label {
    font-size: 11px;
    color: var(--vt-text);
    font-weight: 500;
}

.ev-dim-bar-bg {
    height: 6px;
    background: #E8E4FF;
    border-radius: 3px;
    overflow: hidden;
}

.ev-dim-bar-fill {
    height: 100%;
    border-radius: 3px;
    width: 0%;
    transition: width 0.5s ease, background 0.3s ease;
    background: #CCC;
}

.ev-dim-bar-fill.ev-strong { background: #4CAF50; }
.ev-dim-bar-fill.ev-moderate { background: #FF9800; }
.ev-dim-bar-fill.ev-weak { background: #F44336; }

.ev-dim-score {
    font-size: 10px;
    text-align: right;
    color: var(--vt-text-light);
    font-weight: 600;
}

.ev-statement {
    padding: 10px 14px;
    border-top: 1px solid #E8E4FF;
    font-size: 11px;
    line-height: 1.4;
    color: var(--vt-text-light);
    max-height: 80px;
    overflow-y: auto;
}

.ev-statement.ev-strong { color: #2E7D32; }
.ev-statement.ev-moderate { color: #E65100; }
.ev-statement.ev-weak { color: #C62828; }

/* ============================================================
   Debug Panel
   ============================================================ */

#debug-panel {
    position: fixed;
    bottom: 60px;
    right: 16px;
    width: 320px;
    max-height: 400px;
    background: #1E1E2E;
    color: #CDD6F4;
    border-radius: var(--vt-radius-sm);
    box-shadow: var(--vt-shadow-lg);
    font-size: 11px;
    font-family: 'Consolas', 'Courier New', monospace;
    overflow: hidden;
    z-index: 1000;
}

#debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: #181825;
    border-bottom: 1px solid #313244;
}

#debug-content {
    padding: 8px 10px;
    max-height: 340px;
    overflow-y: auto;
}

#debug-content > div {
    margin-bottom: 8px;
    padding: 6px;
    background: #181825;
    border-radius: 4px;
}

/* ============================================================
   Animations
   ============================================================ */

@keyframes pulse-green {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-6px); }
    75% { transform: translateX(6px); }
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slide-up {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pop-in {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

.fade-in { animation: fade-in 0.3s ease forwards; }
.slide-up { animation: slide-up 0.4s ease forwards; }
.pop-in { animation: pop-in 0.3s ease forwards; }

/* ============================================================
   Utility
   ============================================================ */

.hidden { display: none !important; }
.invisible { visibility: hidden; }

/* ============================================================
   Responsive — Tablet (≤900px)
   ============================================================ */
@media (max-width: 900px) {
    #vt-app {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr 56px;
        grid-template-areas:
            "teacher"
            "teaching"
            "control";
        max-width: 100%;
    }

    #teacher-stage {
        flex-direction: row;
        align-items: center;
        padding: 8px 12px;
        border-right: none;
        border-bottom: 1px solid #E8E4FF;
        gap: 10px;
    }

    #avatar-container {
        width: 60px;
        height: 90px;
        flex-shrink: 0;
    }

    #teacher-speech-bubble {
        flex: 1;
        margin-top: 0;
        max-width: none;
        font-size: 12px;
        padding: 8px 10px;
    }

    #teacher-speech-bubble::before {
        top: 50%;
        left: -6px;
        transform: translateY(-50%);
        border-top: 6px solid transparent;
        border-bottom: 6px solid transparent;
        border-right: 6px solid white;
        border-left: none;
    }

    #teacher-name-badge {
        position: static;
        font-size: 10px;
        padding: 3px 10px;
    }

    #teaching-area {
        padding: 8px;
    }

    #blackboard-container {
        min-height: 200px;
    }

    .answer-card {
        padding: 10px 14px;
        font-size: 16px;
        min-width: 50px;
    }

    #evidence-panel {
        position: fixed;
        bottom: 60px;
        right: 8px;
        width: 240px;
        max-height: 40vh;
        font-size: 11px;
    }

    .ev-dim-row {
        grid-template-columns: 20px 44px 1fr 30px;
        padding: 4px 10px;
    }

    .ev-dim-icon { font-size: 12px; }
    .ev-dim-label { font-size: 10px; }
    .ev-dim-score { font-size: 9px; }

    #control-bar {
        gap: 4px;
        padding: 6px 8px;
    }

    #control-bar button {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    #lang-select {
        height: 36px;
        font-size: 12px;
        min-width: 100px;
        padding: 0 24px 0 8px;
    }

    #control-bar #voice-select {
        max-width: 130px;
        height: 36px;
        font-size: 12px;
    }

    #control-bar #btn-mute, #control-bar #btn-test-voice {
        font-size: 12px;
        padding: 0 8px;
    }

    #lesson-progress {
        margin: 0 4px;
    }

    .counter-object {
        width: 40px;
        height: 40px;
        font-size: 22px;
    }

    .drop-zone {
        min-width: 50px;
        min-height: 50px;
    }
}

/* ============================================================
   Responsive — Phone (≤500px)
   ============================================================ */
@media (max-width: 500px) {
    #vt-app {
        grid-template-rows: auto 1fr auto;
    }

    #teacher-stage {
        padding: 6px 8px;
        gap: 6px;
    }

    #avatar-container {
        width: 44px;
        height: 64px;
    }

    #teacher-speech-bubble {
        font-size: 11px;
        padding: 6px 8px;
    }

    #teacher-name-badge {
        font-size: 9px;
        padding: 2px 8px;
    }

    #teaching-area {
        padding: 6px;
        gap: 6px;
    }

    #blackboard-container {
        min-height: 160px;
        border-radius: var(--vt-radius-sm);
    }

    #interaction-zone {
        gap: 6px;
        min-height: 60px;
    }

    #answer-cards {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        width: 100%;
    }

    .answer-card {
        padding: 10px 8px;
        font-size: 15px;
        min-width: 0;
        text-align: center;
    }

    #evidence-panel {
        bottom: 52px;
        right: 4px;
        width: 200px;
        max-height: 35vh;
        border-radius: var(--vt-radius-sm);
    }

    .ev-header {
        padding: 6px 10px;
    }
    .ev-header h3 { font-size: 11px; }
    .ev-dim-row {
        grid-template-columns: 18px 38px 1fr 26px;
        padding: 3px 8px;
        gap: 2px;
    }
    .ev-statement {
        padding: 6px 8px;
        font-size: 10px;
        max-height: 50px;
    }

    #control-bar {
        gap: 3px;
        row-gap: 5px;
        padding: 4px 6px;
        flex-wrap: wrap;
    }

    #control-bar button {
        width: 32px;
        height: 32px;
        font-size: 14px;
        border-radius: 50%;
    }

    /* Test voice is redundant on phones (voice select already previews) */
    #control-bar #btn-test-voice { display: none; }

    #lang-select {
        height: 32px;
        font-size: 11px;
        min-width: 80px;
        padding: 0 20px 0 6px;
        background-position: right 6px center;
    }

    #control-bar #voice-select {
        min-width: 90px;
        max-width: 110px;
        height: 32px;
        font-size: 11px;
    }

    #control-bar #btn-mute {
        font-size: 11px;
        padding: 0 8px;
    }

    #lesson-progress {
        margin: 0 2px;
        gap: 4px;
    }

    #progress-bar {
        max-width: 80px;
        height: 4px;
    }

    #progress-label {
        font-size: 10px;
    }

    #teacher-state-badge {
        font-size: 9px;
        padding: 2px 6px;
    }

    /* Drag-drop: stack zones vertically on mobile */
    #draggable-area {
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        justify-content: center;
    }

    #drop-zones {
        display: flex;
        flex-direction: column;
        gap: 6px;
        width: 100%;
    }

    .counter-object {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    .drop-zone {
        min-width: 100%;
        min-height: 44px;
        flex-direction: row;
        justify-content: flex-start;
        padding: 6px;
    }

    /* Debug panel smaller on mobile */
    #debug-panel {
        width: 260px;
        max-height: 300px;
        right: 4px;
        bottom: 52px;
    }
}

/* ============================================================
   Global Navbar + Voice Controls + Diagnostics (DEC-045)
   ============================================================ */

body { display: flex; flex-direction: column; }
#vt-app { height: calc(100vh - 48px); flex: 0 0 auto; }

.vt-nav {
    height: 48px;
    flex: 0 0 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: linear-gradient(135deg, var(--vt-primary), #7C3AED);
    color: #fff;
    box-shadow: var(--vt-shadow);
    position: relative;
    z-index: 30;
}
.vt-brand { font-weight: 700; font-size: 15px; }
.vt-nav-links { display: flex; align-items: center; gap: 4px; }
.vt-nav-links a {
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 999px;
    transition: background var(--transition-fast);
}
.vt-nav-links a:hover { background: rgba(255,255,255,.18); }
.vt-nav-links a.active { background: rgba(255,255,255,.28); }
.vt-nav-btn {
    width: 34px; height: 34px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,.18);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--transition-fast);
}
.vt-nav-btn:hover, .vt-nav-btn.active { background: rgba(255,255,255,.34); }

/* Voice controls (math-practice style) */
#voice-select {
    height: 40px;
    min-width: 110px;
    max-width: 180px;
    padding: 0 26px 0 12px;
    border-radius: 20px;
    border: 1px solid #E0DDE8;
    background: white;
    font-size: 13px;
    font-family: var(--vt-font);
    color: var(--vt-text);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%236B6880'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}
#control-bar #btn-mute, #control-bar #btn-test-voice { width: auto; padding: 0 12px; border-radius: 20px; font-size: 13px; }
#control-bar #btn-mute.muted { background: var(--vt-error); color: #fff; border-color: var(--vt-error); }

/* STT live status pill (floats above the control bar, out of the app grid) */
#stt-status {
    position: fixed;
    bottom: 64px;
    left: 16px;
    z-index: 25;
    padding: 6px 12px;
    border-radius: 999px;
    background: #101223;
    color: #E6E6F0;
    font-size: 12px;
    box-shadow: var(--vt-shadow);
}
#stt-status:empty { display: none; }

/* Diagnostics ("data for nerds") panel */
#nerd-panel {
    position: fixed;
    top: 56px;
    right: 12px;
    width: 300px;
    max-height: calc(100vh - 70px);
    overflow: auto;
    background: #101223;
    color: #E6E6F0;
    border: 1px solid #2A2D45;
    border-radius: 12px;
    box-shadow: var(--vt-shadow-lg);
    font-family: 'Cascadia Code', 'SF Mono', Consolas, monospace;
    font-size: 12px;
    z-index: 50;
    display: none;
}
#nerd-panel.open { display: block; }
.nerd-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    font-weight: 700;
    border-bottom: 1px solid #2A2D45;
    position: sticky;
    top: 0;
    background: #101223;
}
.nerd-header button {
    background: transparent;
    border: none;
    color: #9A9AB0;
    cursor: pointer;
    font-size: 14px;
}
#nerd-content { padding: 8px 12px 12px; }
.nerd-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.nerd-k { color: #9A9AB0; }
.nerd-v { color: #7BE0A3; text-align: right; word-break: break-all; }
.nerd-hr { border: none; border-top: 1px solid #2A2D45; margin: 6px 0; }
