:root {
  --bg: #f5f6f8;
  --panel: #fff;
  --ink: #1c1e22;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --ok: #16a34a;
  --bad: #dc2626;
  --border: #e5e7eb;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
header {
  background: var(--panel);
  padding: 1.2rem 2rem 0;
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 1.4rem; }
.sub { color: var(--muted); margin: 0.2rem 0 1rem; font-size: 0.9rem; }
nav { display: flex; gap: 0.5rem; }
.tab {
  background: none; border: none; padding: 0.7rem 1rem;
  cursor: pointer; font-size: 0.95rem; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--accent); border-color: var(--accent); font-weight: 600; }
main { max-width: 900px; margin: 0 auto; padding: 1.5rem; }
.panel { display: none; background: var(--panel); padding: 1.5rem; border-radius: 8px; border: 1px solid var(--border); }
.panel.active { display: block; }
label { display: block; margin: 0.5rem 0; font-size: 0.9rem; color: var(--muted); }
input:not([type=radio]):not([type=checkbox]), select, textarea {
  width: 100%; padding: 0.6rem; border: 1px solid var(--border);
  border-radius: 4px; font: inherit; margin-top: 0.25rem; background: #fff;
}
input[type=radio], input[type=checkbox] { width: auto; margin: 0; cursor: pointer; accent-color: var(--accent); }
textarea { resize: vertical; font-family: inherit; }
button {
  background: var(--accent); color: #fff; border: none;
  padding: 0.6rem 1.2rem; border-radius: 4px; cursor: pointer;
  font-size: 0.95rem; margin-top: 0.5rem;
}
button:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.box {
  background: #f9fafb; padding: 0.8rem; border-radius: 4px;
  margin: 0.5rem 0; border-left: 3px solid var(--accent);
  white-space: pre-wrap;
}
.box:empty { display: none; }
.q-toolbar { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.8rem; }
.q-toolbar button { margin: 0; }
button.secondary { background: #e5e7eb; color: var(--ink); }
button.secondary:hover { background: #d1d5db; }
.muted { color: var(--muted); font-size: 0.85rem; margin-left: auto; }
.quelle-tag { display:inline-block; background:#eef2ff; color:var(--accent); padding:0.15rem 0.5rem; border-radius:10px; font-size:0.75rem; margin-bottom:0.3rem; }
.topic { display:flex; align-items:center; gap:0.6rem; padding:0.5rem 0; border-bottom:1px solid var(--border); }
.topic.archived { opacity:0.5; }
.topic .bar { flex:0 0 120px; height:8px; background:var(--border); border-radius:4px; overflow:hidden; }
.topic .bar > span { display:block; height:100%; background:var(--accent); transition:width .3s; }
.topic.archived .bar > span { background: var(--ok); }
.topic .label { flex:1; font-size:0.9rem; }
.topic .counts { color:var(--muted); font-size:0.8rem; white-space:nowrap; }
.topic-pill { display:inline-block; background:#fef3c7; color:#92400e; padding:0.15rem 0.6rem; border-radius:10px; font-size:0.75rem; margin:0 0 0.5rem; }
.quiz-q > .topic-pill { display: block; width: fit-content; }
.result { margin-top: 1rem; }
.score {
  display: inline-block; padding: 0.3rem 0.8rem; border-radius: 20px;
  font-weight: 600; color: #fff; margin-bottom: 0.8rem;
}
.score.good { background: var(--ok); }
.score.mid  { background: #eab308; }
.score.bad  { background: var(--bad); }
.result h4 { margin: 0.8rem 0 0.3rem; }
.result ul { margin: 0.3rem 0 0.8rem 1.2rem; padding: 0; }
.muster { background: #eff6ff; padding: 0.8rem 1rem; border-radius: 4px; border-left: 3px solid var(--accent); }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 0.8rem 0 0.3rem; line-height: 1.3; }
.markdown h1 { font-size: 1.1rem; }
.markdown h2 { font-size: 1.05rem; }
.markdown h3 { font-size: 1rem; }
.markdown h4 { font-size: 0.95rem; }
.markdown p { margin: 0.4rem 0; }
.markdown ul, .markdown ol { margin: 0.3rem 0 0.6rem 1.2rem; padding: 0; }
.markdown li { margin: 0.15rem 0; }
.markdown li > p { margin: 0.15rem 0; }
.markdown code { background: #eef2ff; padding: 0.05rem 0.3rem; border-radius: 3px; font-size: 0.9em; }
.markdown strong { font-weight: 600; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.quiz-q { background: #f9fafb; padding: 1rem 1.2rem; border-radius: 6px; margin: 0.8rem 0; }
.quiz-q .frage { margin-top: 0.4rem; font-weight: 500; }
.quiz-q .options { margin-top: 0.6rem; display: flex; flex-direction: column; gap: 0.2rem; }
.quiz-q .option {
  display: flex; align-items: flex-start; gap: 0.6rem;
  padding: 0.55rem 0.7rem; cursor: pointer; border-radius: 4px;
  border: 1px solid transparent;
}
.quiz-q .option:hover { background: #eef2ff; }
.quiz-q .option.correct { background: #dcfce7; }
.quiz-q .option.wrong   { background: #fee2e2; }
.quiz-q .erklaerung { margin-top: 0.6rem; font-size: 0.9rem; color: var(--muted); }
#chat-log { min-height: 300px; max-height: 500px; overflow-y: auto; padding: 0.5rem 0; }
.msg { padding: 0.7rem 1rem; border-radius: 8px; margin: 0.5rem 0; max-width: 80%; white-space: pre-wrap; }
.msg.user { background: var(--accent); color: #fff; margin-left: auto; }
.msg.assistant { background: #f3f4f6; }
#chat-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
#chat-form textarea { flex: 1; }
#chat-form button { align-self: stretch; }
#progress-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin: 1rem 0; }
.stat { background: #f9fafb; padding: 1rem; border-radius: 4px; text-align: center; }
.stat .num { font-size: 1.6rem; font-weight: 600; color: var(--accent); }
.stat .lbl { font-size: 0.85rem; color: var(--muted); }
.row {
  display: flex; justify-content: space-between; padding: 0.6rem 0;
  border-bottom: 1px solid var(--border); font-size: 0.9rem;
}
.row .date { color: var(--muted); font-size: 0.8rem; }
.loading { color: var(--muted); font-style: italic; }

.answer-wrap { position: relative; }
.answer-wrap textarea { padding-right: 3rem; }
.mic-btn {
  position: absolute; top: 0.5rem; right: 0.5rem;
  width: 2.2rem; height: 2.2rem; padding: 0; margin: 0;
  border-radius: 50%; background: #fff; color: var(--ink);
  border: 1px solid var(--border); font-size: 1rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.mic-btn:hover { background: #f3f4f6; }
.mic-btn.recording { background: var(--bad); color: #fff; border-color: var(--bad); animation: pulse 1.2s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.55); }
  50%      { box-shadow: 0 0 0 8px rgba(220,38,38,0); }
}
.mic-status { min-height: 1.1em; margin: 0.2rem 0 0.4rem; font-size: 0.85rem; color: var(--muted); }
.chat-input-wrap { flex: 1; }
.chat-input-wrap textarea { margin-top: 0; }

.grade-loader {
  display: flex; flex-direction: column; gap: 0.7rem;
  background: #f9fafb; padding: 1rem 1.2rem; border-radius: 6px;
  border-left: 3px solid var(--accent);
}
.grade-loader .row1 { display: flex; align-items: center; gap: 0.7rem; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid #e5e7eb; border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; flex: 0 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.grade-loader .status { font-weight: 500; color: var(--ink); }
.grade-loader .elapsed { color: var(--muted); font-size: 0.85rem; margin-left: auto; font-variant-numeric: tabular-nums; }
.progress-track {
  height: 5px; background: #e5e7eb; border-radius: 3px; overflow: hidden; position: relative;
}
.progress-track::before {
  content: ""; position: absolute; left: -40%; top: 0; bottom: 0; width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: slide 1.4s ease-in-out infinite;
}
@keyframes slide {
  0%   { left: -40%; }
  100% { left: 100%; }
}

.header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.user-box { display: flex; align-items: center; gap: 0.6rem; font-size: 0.9rem; color: var(--muted); }
.user-box button { margin: 0; padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.user-box #user-name { font-weight: 600; color: var(--ink); }

.login-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 1rem;
}
.login-overlay[hidden], .user-box[hidden] { display: none !important; }
.login-card {
  background: var(--panel); padding: 1.8rem; border-radius: 8px;
  border: 1px solid var(--border); width: 100%; max-width: 360px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.15);
}
.login-card h2 { margin: 0 0 0.2rem; }
.login-card .sub { margin: 0 0 1rem; }
.login-card button { width: 100%; margin-top: 0.8rem; }
.login-error { color: var(--bad); font-size: 0.85rem; min-height: 1.2em; margin-top: 0.4rem; }
