:root {
  --primary: #3b5bdb;
  --primary-dark: #2846b0;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --text: #1a1d29;
  --muted: #6b7280;
  --border: #e2e5ec;
  --success: #2f9e44;
  --danger: #e03131;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* Login */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card-bg);
  padding: 36px;
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 380px;
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 24px; }

/* Language switch */
.lang-switch { display: flex; gap: 4px; margin-bottom: 16px; }
.lang-switch-small { margin-bottom: 0; }
.lang-btn { background: var(--border); color: var(--text); padding: 4px 10px; font-size: 12px; font-weight: 500; }
.lang-btn.active { background: var(--primary); color: white; }

label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
input[type=text], input[type=password], textarea, select {
  width: 100%;
  padding: 10px 12px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  font-family: inherit;
}
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--primary);
  color: white;
  font-size: 15px;
  font-weight: 600;
}
button:hover { background: var(--primary-dark); }
button.btn-danger { background: var(--danger); }
button.btn-success { background: var(--success); }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; }
.status { color: var(--muted); font-size: 13px; margin-top: 8px; }

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}
.brand { font-weight: 700; font-size: 18px; color: var(--primary); }
#tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  padding: 8px 14px;
}
.tab.active { background: var(--primary); color: white; }
.userbox { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); }
#logout-btn { background: var(--border); color: var(--text); padding: 6px 12px; font-weight: 500; }

main { padding: 24px; max-width: 1100px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 800px) { .panel-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.card h2 { margin-top: 0; font-size: 17px; }

.list { list-style: none; padding: 0; margin: 0; }
.list li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.list li:hover { background: var(--bg); }
.list .meta { color: var(--muted); font-size: 12px; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.list li .item-main { flex: 1; min-width: 0; }
.btn-icon-delete { flex-shrink: 0; background: transparent; color: var(--danger); font-size: 12px; padding: 4px 10px; font-weight: 500; }
.btn-icon-delete:hover { background: #fdeaea; }

#material-subject-filter { margin-bottom: 12px; }

.note-content { line-height: 1.7; font-size: 14px; }
.note-content h2, .note-content h3, .note-content h4 { margin: 14px 0 6px; }
.note-content ul, .note-content ol { margin: 6px 0 6px 20px; padding: 0; }
.note-content p { margin: 6px 0; }

/* Flashcards */
.flashcard-viewer { margin-top: 16px; }
.flashcard {
  border: 2px solid var(--primary);
  border-radius: 12px;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  font-size: 18px;
  cursor: pointer;
  background: #f8f9ff;
}
.flashcard-controls { display: flex; gap: 10px; margin-top: 14px; justify-content: center; }

/* Quiz */
.quiz-question { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.quiz-question h4 { margin-bottom: 10px; }
.quiz-choice { display: block; margin-bottom: 6px; font-size: 14px; }
.quiz-choice.correct-choice { color: var(--success); font-weight: 700; }
.quiz-choice.wrong-choice { color: var(--danger); font-weight: 700; }
.quiz-explanation { font-size: 13px; color: var(--muted); margin-top: 8px; padding: 10px 12px; background: var(--bg); border-radius: 8px; }

/* Chat */
.chat-card { display: flex; flex-direction: column; height: 520px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 8px; }
.chat-msg { margin-bottom: 12px; padding: 10px 14px; border-radius: 10px; max-width: 80%; font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.chat-msg.user { background: var(--primary); color: white; margin-left: auto; }
.chat-msg.assistant { background: var(--bg); }
.chat-msg.assistant p { margin: 4px 0; }
.chat-msg.assistant h2, .chat-msg.assistant h3, .chat-msg.assistant h4 { margin: 8px 0 4px; }
.chat-msg.assistant ul, .chat-msg.assistant ol { margin: 4px 0 4px 18px; padding: 0; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { flex: 1; margin-top: 0; }

/* Progress */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-tile { background: var(--bg); border-radius: 10px; padding: 16px; text-align: center; }
.stat-tile .num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat-tile .label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Settings */
.settings-form { max-width: 380px; }
.success-text { color: var(--success); }
.error-text { color: var(--danger); }
