* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: #0f172a; color: #e2e8f0; min-height: 100vh; }

/* Screens */
.screen { display: none; }
.screen.active { display: flex; }

/* Login */
#login-screen { justify-content: center; align-items: center; min-height: 100vh; }
.login-box { background: #1e293b; border-radius: 16px; padding: 3rem; text-align: center; max-width: 400px; width: 90%; box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
.login-box h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.login-box h2 { font-size: 1.1rem; color: #94a3b8; margin-bottom: 0.5rem; }
.login-box p { color: #64748b; margin-bottom: 2rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label { text-align: left; font-size: 0.9rem; color: #94a3b8; }
.login-form input { padding: 0.8rem 1rem; border-radius: 8px; border: 2px solid #334155; background: #0f172a; color: #e2e8f0; font-size: 1.2rem; text-align: center; outline: none; }
.login-form input:focus { border-color: #3b82f6; }
#login-btn { padding: 0.8rem; border-radius: 8px; border: none; background: #3b82f6; color: white; font-size: 1.1rem; cursor: pointer; transition: background 0.2s; }
#login-btn:hover { background: #2563eb; }
.hint { font-size: 0.8rem; color: #475569; }
.changelog { margin-top: 1.5rem; text-align: left; font-size: 0.82rem; color: #94a3b8; }
.changelog summary { cursor: pointer; color: #64748b; font-size: 0.85rem; text-align: center; }
.changelog summary:hover { color: #e2e8f0; }
.changelog ul { margin-top: 0.6rem; padding-left: 1.2rem; display: flex; flex-direction: column; gap: 0.4rem; }
.changelog li { line-height: 1.4; }
.changelog-date { color: #64748b; font-size: 0.75rem; }

/* Top Bar */
#topbar { display: flex; align-items: center; padding: 0.8rem 1.2rem; background: #1e293b; border-bottom: 1px solid #334155; gap: 1rem; position: sticky; top: 0; z-index: 50; }
#topbar-left { display: flex; gap: 1rem; align-items: center; min-width: 200px; }
#student-label { color: #64748b; font-size: 0.85rem; }
#unit-label { font-weight: 600; color: #3b82f6; }
#progress-bar-container { flex: 1; height: 8px; background: #334155; border-radius: 4px; overflow: hidden; }
#progress-bar { height: 100%; background: linear-gradient(90deg, #3b82f6, #10b981); width: 0%; transition: width 0.5s ease; border-radius: 4px; }
#topbar-right { min-width: 50px; text-align: right; }
#gemini-toggle { background: none; border: 2px solid #334155; border-radius: 8px; padding: 0.4rem 0.6rem; font-size: 1.2rem; cursor: pointer; transition: all 0.2s; }
#gemini-toggle:hover { border-color: #3b82f6; }
#gemini-toggle.active { border-color: #10b981; background: #10b98120; }

/* Content */
#app-screen { flex-direction: column; min-height: 100vh; }
#content-wrapper { display: flex; flex: 1; }
#content-area { flex: 1; padding: 2rem; overflow-y: auto; max-width: 800px; margin: 0 auto; }

/* Units */
.unit-intro { margin-bottom: 2rem; }
.unit-intro h2 { font-size: 1.6rem; margin-bottom: 1rem; color: #f1f5f9; }
.explanation { background: #1e293b; border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; border-left: 4px solid #3b82f6; line-height: 1.7; }
.example { background: #1a2332; border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; border-left: 4px solid #10b981; }
.example h3 { color: #10b981; margin-bottom: 0.8rem; }

/* Tasks */
.task-card { background: #1e293b; border-radius: 12px; padding: 1.5rem; margin-bottom: 1rem; border: 2px solid #334155; transition: border-color 0.3s; }
.task-card.correct { border-color: #10b981; }
.task-card.incorrect { border-color: #ef4444; }
.task-card h3 { color: #94a3b8; margin-bottom: 1rem; font-size: 0.9rem; }
.task-question { font-size: 1.1rem; margin-bottom: 1rem; line-height: 1.6; }
.md-table { border-collapse: collapse; margin: 0.8rem 0; width: auto; }
.md-table th, .md-table td { border: 1px solid #475569; padding: 0.4rem 0.8rem; text-align: center; }
.md-table th { background: #1e293b; font-weight: 600; color: #94a3b8; }
.md-table td { background: #0f172a; }
.task-input-row { display: flex; gap: 0.8rem; align-items: center; margin-bottom: 0.5rem; }
.task-input-row input { flex: 1; min-width: 0; padding: 0.6rem 1rem; border-radius: 8px; border: 2px solid #334155; background: #0f172a; color: #e2e8f0; font-size: 1rem; outline: none; font-family: 'Courier New', monospace; }
.task-input-row input:focus { border-color: #3b82f6; }
.task-input-row .check-btn { padding: 0.6rem 1.2rem; border-radius: 8px; border: none; background: #3b82f6; color: white; cursor: pointer; font-size: 0.95rem; white-space: nowrap; }
.task-input-row .check-btn:hover { background: #2563eb; }
.task-feedback { margin-top: 0.8rem; padding: 0.8rem 1rem; border-radius: 8px; font-size: 0.95rem; line-height: 1.5; display: none; }
.task-feedback.show { display: block; }
.task-feedback.correct { background: #10b98120; color: #6ee7b7; }
.task-feedback.wrong { background: #ef444420; color: #fca5a5; }
.task-feedback.hint { background: #f59e0b20; color: #fcd34d; }

/* Math input area */
.math-input-area { display: flex; flex-direction: column; gap: 0.5rem; }

/* Live preview */
.math-preview { min-height: 2.2rem; padding: 0.5rem 1rem; background: #0f172a; border: 1px solid #334155; border-radius: 8px; font-size: 1.2rem; display: flex; align-items: center; }
.preview-placeholder { color: #475569; font-size: 0.85rem; font-style: italic; }

/* Math keyboard */
.math-keyboard { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; padding: 0.5rem 0; }
.math-key { padding: 0.5rem 0.2rem; border-radius: 6px; border: 1px solid #334155; background: #1e293b; color: #e2e8f0; font-size: 1rem; cursor: pointer; text-align: center; transition: all 0.15s; min-height: 38px; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.math-key:hover, .math-key:active { background: #334155; border-color: #3b82f6; }
.math-key.key-op { color: #3b82f6; font-weight: 600; }
.math-key.key-fn { color: #10b981; font-size: 0.8rem; font-weight: 600; }
.math-key.key-num { color: #94a3b8; }
.math-key.key-del { color: #ef4444; font-weight: 600; }

/* Hint Steps */
.hint-btn { background: #f59e0b30; border: 1px solid #f59e0b50; color: #fcd34d; padding: 0.4rem 0.8rem; border-radius: 6px; cursor: pointer; font-size: 0.85rem; margin-top: 0.5rem; }
.hint-btn:hover { background: #f59e0b40; }

/* Mastery Check */
.mastery-result { text-align: center; padding: 2rem; }
.mastery-result h2 { font-size: 1.8rem; margin-bottom: 1rem; }
.mastery-score { font-size: 3rem; font-weight: 700; margin: 1rem 0; }
.mastery-score.pass { color: #10b981; }
.mastery-score.fail { color: #f59e0b; }
.mastery-msg { color: #94a3b8; margin-bottom: 1.5rem; line-height: 1.6; }

/* Sync section */
.sync-section { display: flex; justify-content: center; gap: 1rem; margin: 1.5rem 0; flex-wrap: wrap; }

/* Buttons */
.btn-primary { padding: 0.8rem 2rem; border-radius: 8px; border: none; background: #3b82f6; color: white; font-size: 1rem; cursor: pointer; }
.btn-primary:hover { background: #2563eb; }
.btn-secondary { padding: 0.8rem 2rem; border-radius: 8px; border: 2px solid #334155; background: transparent; color: #e2e8f0; font-size: 1rem; cursor: pointer; }
.btn-secondary:hover { border-color: #3b82f6; }

/* Navigation */
.nav-buttons { display: flex; justify-content: center; gap: 1rem; margin-top: 2rem; padding: 1rem 0; }

/* Structure Quiz */
.structure-quiz { margin: 1rem 0; }
.structure-options { display: flex; flex-direction: column; gap: 0.5rem; }
.structure-options button { padding: 0.8rem 1.2rem; border-radius: 8px; border: 2px solid #334155; background: #0f172a; color: #e2e8f0; text-align: left; cursor: pointer; transition: all 0.2s; font-size: 1rem; }
.structure-options button:hover { border-color: #3b82f6; }
.structure-options button.selected-correct { border-color: #10b981; background: #10b98120; }
.structure-options button.selected-wrong { border-color: #ef4444; background: #ef444420; }

/* Checkpoint notice */
.checkpoint-notice { background: #7c3aed20; border: 2px solid #7c3aed50; border-radius: 12px; padding: 1.5rem; text-align: center; margin: 1.5rem 0; }
.checkpoint-notice h3 { color: #a78bfa; margin-bottom: 0.5rem; }

/* Gemini Panel — draggable floating overlay */
#gemini-panel {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 380px;
    max-height: 500px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    z-index: 200;
    overflow: hidden;
    resize: both;
}
#gemini-panel.hidden { display: none; }
#gemini-header { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 1rem; border-bottom: 1px solid #334155; font-weight: 600; background: #1e293b; border-radius: 16px 16px 0 0; cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none; }
#gemini-header:active { cursor: grabbing; }
#gemini-header button { background: none; border: none; color: #94a3b8; font-size: 1.2rem; cursor: pointer; }
#gemini-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.8rem; min-height: 200px; max-height: 340px; }
.gemini-msg { padding: 0.8rem 1rem; border-radius: 12px; max-width: 90%; line-height: 1.5; font-size: 0.95rem; word-wrap: break-word; }
.gemini-msg.user { background: #3b82f6; align-self: flex-end; border-bottom-right-radius: 4px; }
.gemini-msg.ai { background: #334155; align-self: flex-start; border-bottom-left-radius: 4px; }
#gemini-input-area { display: flex; gap: 0.5rem; padding: 0.8rem; border-top: 1px solid #334155; align-items: center; }
#gemini-input-area input { flex: 1; min-width: 0; padding: 0.6rem; border-radius: 8px; border: 1px solid #334155; background: #0f172a; color: #e2e8f0; outline: none; }
#gemini-input-area .send-btn { padding: 0.6rem 1rem; border-radius: 8px; border: none; background: #10b981; color: white; cursor: pointer; font-size: 1.1rem; }
.gemini-hint { text-align: center; padding: 0.4rem; font-size: 0.75rem; color: #64748b; }

/* Draw pad */
.draw-btn {
    width: 2.3rem; min-width: 2.3rem; height: 2.3rem;
    border-radius: 999px; border: 1px solid #475569;
    background: #0f172a; color: #cbd5e1; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1rem; line-height: 1; transition: all 0.2s ease;
}
.draw-btn:hover { border-color: #8b5cf6; color: #f8fafc; }
.draw-wrap {
    display: none; margin: 0.5rem 0;
    border: 2px solid #475569; border-radius: 12px;
    overflow: hidden; background: #fff;
    position: relative;
}
.draw-close-btn {
    position: absolute; top: 6px; right: 6px; z-index: 10;
    width: 44px; height: 44px; min-width: 44px; min-height: 44px;
    border-radius: 50%; border: 2px solid #475569;
    background: rgba(30,41,59,0.9); color: #e2e8f0;
    font-size: 1.2rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; line-height: 1;
}
.draw-close-btn:hover { background: #ef4444; border-color: #ef4444; color: #fff; }
.draw-wrap.visible { display: block; }
.draw-canvas {
    display: block; width: 100%; height: 200px;
    touch-action: none; cursor: crosshair;
    -webkit-user-select: none; user-select: none;
    -webkit-touch-callout: none;
}
.draw-buttons {
    display: flex; gap: 0.5rem; padding: 0.4rem;
    background: #1e293b; border-top: 1px solid #334155;
}
.draw-buttons button {
    padding: 0.35rem 0.75rem; border-radius: 8px; border: 1px solid #475569;
    background: #0f172a; color: #cbd5e1; cursor: pointer; font-size: 0.85rem;
}
.draw-buttons button:hover { border-color: #3b82f6; color: #f8fafc; }
.draw-recognize-btn { background: #8b5cf6 !important; color: #fff !important; border-color: #8b5cf6 !important; }

/* Speech input */
.mic-btn {
    width: 2.3rem;
    min-width: 2.3rem;
    height: 2.3rem;
    border-radius: 999px;
    border: 1px solid #475569;
    background: #0f172a;
    color: #cbd5e1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    transition: all 0.2s ease;
}
.mic-btn:hover { border-color: #3b82f6; color: #f8fafc; }
.mic-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.task-input-row input.converting { border-color: #f59e0b; animation: convert-pulse 0.8s ease-in-out infinite; }
@keyframes convert-pulse { 0%,100% { border-color: #f59e0b; } 50% { border-color: #334155; } }
.mic-btn.recording {
    background: #b91c1c;
    border-color: #ef4444;
    color: #fff;
    animation: mic-pulse 1.2s ease-out infinite;
}

@keyframes mic-pulse {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    70% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
.speech-status {
    display: none; font-size: 0.8rem; color: #fbbf24;
    margin-left: 0.4rem; white-space: nowrap;
    animation: speech-status-fade 1.5s ease-in-out infinite;
}
@keyframes speech-status-fade {
    0%,100% { opacity: 1; } 50% { opacity: 0.5; }
}

/* Responsive */
@media (max-width: 600px) {
    #gemini-panel { left: 0.5rem; right: 0.5rem; bottom: 0.5rem; width: auto; max-height: 60vh; }
    #content-area { padding: 1rem; }
    #topbar-left { min-width: auto; }
    .math-keyboard { grid-template-columns: repeat(7, 1fr); gap: 3px; }
    .math-key { padding: 0.6rem 0.1rem; font-size: 0.95rem; min-height: 42px; }
    .mic-btn, .draw-btn { width: 2.15rem; min-width: 2.15rem; height: 2.15rem; font-size: 0.95rem; }
    .task-input-row { gap: 0.5rem; }
    .draw-canvas { height: 170px; }
}
