:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --good: #16a34a;
  --warn: #d97706;
  --error: #b91c1c;
  --border: #e2e8f0;
  --radius: 12px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
/* Visually hidden but readable by screen readers, e.g. the live chat-status announcement. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar h1 { font-size: 1.25rem; margin: 0; }
.progress { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; }
.progress-track { width: 160px; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--good); transition: width 0.3s; }

main { padding: 16px 20px; }
.message-screen, .access-form { max-width: 480px; margin: 60px auto; padding: 24px; background: var(--panel); border-radius: var(--radius); border: 1px solid var(--border); text-align: center; }
.message-screen button { margin-top: 16px; }
.access-form { display: flex; flex-direction: column; gap: 12px; }
.form-error { color: var(--error); font-size: 0.9rem; margin: 0; }

.question-view { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); gap: 20px; }
.question-prompt { font-size: 1.1rem; line-height: 1.5; margin-top: 0; }
.board { width: 100%; aspect-ratio: 1 / 1; max-height: 70vh; border-radius: var(--radius); border: 1px solid var(--border); background: #fff; }
.hint { color: var(--muted); font-size: 0.9rem; }

.question-right { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 0; }
.chip { padding: 6px 10px; border-radius: 999px; background: var(--border); font-size: 0.85rem; }
.chip-partial { background: #fef3c7; color: var(--warn); }
.chip-mastered { background: #dcfce7; color: var(--good); }

.chat-log { flex: 1; min-height: 240px; max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 12px; line-height: 1.45; white-space: pre-wrap; }
.bubble-assistant { align-self: flex-start; background: var(--accent-soft); }
.bubble-user { align-self: flex-end; background: var(--accent); color: #fff; }
.bubble-thinking { align-self: flex-start; color: var(--muted); font-style: italic; }
.bubble-error { align-self: center; background: #fee2e2; color: #b91c1c; }

.chat-form { display: flex; gap: 8px; }
.chat-form textarea { flex: 1; font: inherit; padding: 8px; border-radius: 8px; border: 1px solid var(--border); resize: vertical; }
button { font: inherit; padding: 8px 16px; border: none; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary { background: var(--border); color: var(--text); }
.nav-buttons { display: flex; justify-content: space-between; }

@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; }
  .question-view { grid-template-columns: minmax(0, 1fr); }
}
