/* ── Reset & Base ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #f0f2f5 0%, #e8ecf1 100%);
    color: #1a1a2e;
    line-height: 1.6;
    min-height: 100vh;
}
#app { max-width: 800px; margin: 0 auto; padding: 16px 20px; }

/* ── Loading Overlay ───────────────────────────────── */
.loading-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(4px);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 16px;
    transition: opacity 0.3s;
}
.loading-overlay.hidden { display: none; }
.spinner {
    width: 40px; height: 40px;
    border: 4px solid #e0e0e0;
    border-top: 4px solid #1a73e8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: #666; font-size: 0.9rem; }

/* ── Toast Notifications ───────────────────────────── */
.toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 2000;
    display: flex; flex-direction: column; gap: 8px;
    max-width: 360px;
}
.toast {
    padding: 14px 18px; border-radius: 10px;
    color: white; font-size: 0.9rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    animation: slideIn 0.3s ease;
    display: flex; align-items: center; gap: 10px;
}
.toast.success { background: #34a853; }
.toast.error { background: #ea4335; }
.toast.info { background: #1a73e8; }
.toast .toast-icon { font-size: 1.1rem; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }
.toast.removing { animation: slideOut 0.3s ease forwards; }

/* ── Screens ──────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Cards ────────────────────────────────────────── */
.card {
    background: white;
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
    transition: box-shadow 0.2s;
}
.card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06); }
.auth-card { max-width: 420px; margin: 80px auto; }

/* ── Logo ──────────────────────────────────────────── */
.logo { text-align: center; margin-bottom: 12px; }
.logo-icon-wrapper { margin-bottom: 12px; display: flex; justify-content: center; }
h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
.brand-subtitle { font-size: 0.75rem; color: #1a73e8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.screen-header { margin-bottom: 8px; }
.screen-step { font-size: 0.75rem; color: #1a73e8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
h2 { font-size: 1.25rem; font-weight: 600; margin-top: 4px; }
.subtitle { color: #666; font-size: 0.9rem; margin-bottom: 20px; }

/* ── Tabs ─────────────────────────────────────────── */
.tab-bar { display: flex; gap: 0; margin-bottom: 16px; border-radius: 10px; overflow: hidden; border: 1px solid #e0e0e0; background: #f8f9fa; }
.tab { flex: 1; padding: 10px; border: none; background: transparent; cursor: pointer; font-size: 0.9rem; font-weight: 500; transition: all 0.2s; }
.tab.active { background: #1a73e8; color: white; }
.tab:hover:not(.active) { background: #e8f0fe; }
.tab-content { display: none; }
.tab-content.active { display: flex; flex-direction: column; gap: 12px; }

/* ── Forms ────────────────────────────────────────── */
input, textarea, select {
    width: 100%; padding: 12px 14px; border: 1.5px solid #e0e0e0; border-radius: 10px;
    font-size: 0.95rem; font-family: inherit; transition: all 0.2s; background: #fafafa;
}
input:focus, textarea:focus { outline: none; border-color: #1a73e8; background: white; box-shadow: 0 0 0 3px rgba(26,115,232,0.1); }
textarea { resize: vertical; min-height: 60px; }

/* ── Buttons ──────────────────────────────────────── */
.btn {
    padding: 12px 24px; border: none; border-radius: 10px; font-size: 0.9rem;
    font-weight: 600; cursor: pointer; transition: all 0.2s;
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: #1a73e8; color: white; }
.btn.primary:hover { background: #1557b0; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(26,115,232,0.3); }
.btn.primary:active { transform: translateY(0); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.secondary { background: #e8f0fe; color: #1a73e8; }
.btn.secondary:hover { background: #d2e3fc; }
.btn.ghost { background: transparent; color: #666; padding: 8px 16px; }
.btn.ghost:hover { background: #f0f2f5; color: #333; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn-full { width: 100%; }

/* ── Badges ───────────────────────────────────────── */
.badge {
    display: inline-block; padding: 4px 12px; border-radius: 20px;
    font-size: 0.8rem; font-weight: 600;
}
.badge.level-badge { background: #e8f0fe; color: #1a73e8; }
.badge.streak { background: #fff3e8; color: #e37400; margin-left: 6px; }

/* ── Dashboard Header ─────────────────────────────── */
.dashboard-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.header-right { display: flex; align-items: center; gap: 6px; }

/* ── Section Labels ───────────────────────────────── */
.section-label {
    font-size: 0.8rem; font-weight: 600; color: #666;
    text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 8px;
}

/* ── Progress ─────────────────────────────────────── */
.progress-card { background: linear-gradient(135deg, #f8f9ff 0%, #ffffff 100%); }
.progress-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.progress-label { font-size: 0.85rem; font-weight: 600; color: #444; }
.progress-count { font-size: 0.8rem; color: #666; }
.progress-bar { height: 8px; background: #e8f0fe; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #1a73e8, #4a9eff); border-radius: 4px; transition: width 0.5s ease; }
.progress-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.level-desc { font-size: 0.8rem; color: #888; }
.level-up { font-size: 0.85rem; color: #1a73e8; font-weight: 600; }

/* ── Diagnosis ────────────────────────────────────── */
.question-item { }
.q-number { font-size: 0.75rem; color: #1a73e8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.q-text { font-weight: 600; margin-bottom: 10px; font-size: 1rem; }
.q-input {
    min-height: 80px; margin-bottom: 12px;
    transition: all 0.3s;
}
.q-input:focus { min-height: 100px; }
.diagnosis-nav { display: flex; gap: 8px; }
.diagnosis-progress { max-width: 420px; margin: 0 auto; }
.dprog-bar { height: 3px; background: #e0e0e0; border-radius: 2px; overflow: hidden; margin-bottom: 8px; }
.dprog-fill { height: 100%; background: #1a73e8; transition: width 0.3s ease; }
.dprog-steps { display: flex; justify-content: center; gap: 24px; }
.dprog-dot {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 600;
    background: #e0e0e0; color: #999; cursor: pointer;
    transition: all 0.2s;
}
.dprog-dot.active { background: #1a73e8; color: white; }
.dprog-dot.done { background: #34a853; color: white; }

/* ── Exercise Grid ────────────────────────────────── */
.exercise-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.exercise-card {
    text-align: center; cursor: pointer;
    transition: all 0.2s; border: 2px solid transparent;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 20px 16px;
}
.exercise-card:hover:not(.disabled) {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.1);
    border-color: #1a73e8;
}
.exercise-card:focus:not(.disabled) { outline: none; border-color: #1a73e8; }
.exercise-card.disabled { opacity: 0.5; cursor: default; }
.exercise-icon { font-size: 2rem; }
.exercise-card h3 { font-size: 1rem; margin-bottom: 2px; }
.exercise-card p { font-size: 0.8rem; color: #666; }
.card-action { font-size: 0.8rem; font-weight: 600; color: #1a73e8; margin-top: 4px; }
.card-action.coming-soon { color: #999; }

/* ── Chat ─────────────────────────────────────────── */
.conv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.conv-topic { font-size: 0.8rem; color: #888; margin-top: 2px; }
.chat-log {
    max-height: 450px; overflow-y: auto; padding: 16px; background: #f8f9fa;
    border-radius: 12px; margin-bottom: 12px;
    display: flex; flex-direction: column; gap: 12px;
    min-height: 200px;
}
.chat-empty { text-align: center; color: #bbb; padding: 40px 0; font-size: 0.9rem; }
.message {
    max-width: 85%; padding: 12px 16px; border-radius: 16px; font-size: 0.9rem;
    line-height: 1.5; animation: fadeIn 0.3s ease;
}
.message.teacher {
    align-self: flex-start; background: white; border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
}
.message.student {
    align-self: flex-end; background: #1a73e8; color: white;
    border-bottom-right-radius: 4px;
}
.message .msg-role { font-size: 0.7rem; font-weight: 600; margin-bottom: 4px; opacity: 0.6; }
.message .msg-content { word-wrap: break-word; }
.message .msg-feedback {
    font-size: 0.8rem; margin-top: 8px; padding: 8px 12px; border-radius: 8px;
    background: #fff8e1; color: #795548; border-left: 3px solid #ffc107;
}
.typing-indicator {
    align-self: flex-start; display: flex; gap: 4px; padding: 12px 16px;
    background: white; border: 1px solid #e8e8e8; border-radius: 16px;
    border-bottom-left-radius: 4px;
}
.typing-indicator span {
    width: 8px; height: 8px; border-radius: 50%;
    background: #bbb; animation: typing 1.4s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%,60%,100% { opacity: 0.3; transform: scale(0.8); } 30% { opacity: 1; transform: scale(1); } }
.chat-input-area { display: flex; gap: 8px; }
.chat-input-area textarea { flex: 1; resize: none; }
.chat-input-area .btn { align-self: flex-end; }

/* ── Quiz ─────────────────────────────────────────── */
.quiz-progress-bar { height: 4px; background: #e8f0fe; border-radius: 2px; margin-bottom: 20px; overflow: hidden; }
.quiz-progress-fill { height: 100%; background: #1a73e8; border-radius: 2px; transition: width 0.3s; }
.quiz-question { font-size: 1.05rem; font-weight: 600; margin-bottom: 20px; line-height: 1.5; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.quiz-option {
    padding: 14px 16px; border: 2px solid #e0e0e0; border-radius: 12px;
    cursor: pointer; transition: all 0.2s; text-align: left; background: white;
    font-size: 0.95rem; font-family: inherit;
}
.quiz-option:hover { border-color: #1a73e8; background: #f8fbff; }
.quiz-option.selected { border-color: #1a73e8; background: #e8f0fe; }
.quiz-option.correct { border-color: #34a853; background: #e6f4ea; }
.quiz-option.incorrect { border-color: #ea4335; background: #fce8e6; }
.quiz-option:disabled { cursor: default; }
.quiz-feedback-box {
    padding: 14px 16px; border-radius: 12px; margin-bottom: 12px;
    font-size: 0.9rem; background: #f8f9fa; border-left: 4px solid #1a73e8;
    animation: fadeIn 0.3s ease;
}
.quiz-actions { text-align: center; }
#btn-next-question { margin-top: 8px; }

/* ── History ──────────────────────────────────────── */
.history-section { margin-top: 4px; }
.history-section summary {
    cursor: pointer; font-weight: 600; padding: 12px 0;
    font-size: 0.9rem; display: flex; align-items: center; gap: 8px;
    color: #555; user-select: none;
}
.history-section summary:hover { color: #1a73e8; }
.history-list { padding: 0; }
.history-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 12px; border-radius: 8px;
    border-bottom: 1px solid #f0f0f0; font-size: 0.85rem;
    transition: background 0.2s;
}
.history-item:hover { background: #f8f9fa; }
.history-item:last-child { border-bottom: none; }
.history-empty { color: #bbb; font-size: 0.85rem; text-align: center; padding: 20px; }

/* ── Utilities ────────────────────────────────────── */
.hidden { display: none !important; }
.error { color: #ea4335; font-size: 0.85rem; margin-top: 8px; padding: 8px 12px; background: #fce8e6; border-radius: 8px; }

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 640px) {
    #app { padding: 12px; }
    .exercise-grid { grid-template-columns: 1fr; }
    .dashboard-header { flex-direction: column; align-items: flex-start; }
    .auth-card { margin: 40px auto; }
    .message { max-width: 92%; }
    .toast-container { left: 20px; right: 20px; max-width: none; }
}
