* { box-sizing: border-box; }
:root {
  --blue: #2563eb; --blue-dark: #1d4ed8; --green: #16a34a; --red: #dc2626;
  --bg: #f4f6fb; --card: #ffffff; --text: #1e293b; --muted: #64748b; --border: #e2e8f0;
  font-family: "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
}
body { margin: 0; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); padding: 10px 16px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; }
.nav { display: flex; align-items: center; gap: 8px; }
.navbtn {
  background: none; border: none; padding: 8px 12px; border-radius: 8px; font-size: 15px;
  cursor: pointer; color: var(--text);
}
.navbtn:hover { background: var(--bg); }
.whoami { color: var(--muted); font-size: 14px; margin: 0 4px; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }
.view { display: none; }
.view.active { display: block; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; margin-bottom: 16px;
}
.card.narrow { max-width: 380px; margin: 60px auto; }

h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 20px 0 8px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 14px; margin-top: 16px; }

form label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
form input {
  display: block; width: 100%; margin-top: 6px; padding: 12px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 10px;
}
.btn {
  display: inline-block; border: none; border-radius: 10px; padding: 12px 20px;
  font-size: 16px; cursor: pointer; background: var(--border); color: var(--text);
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.big { width: 100%; padding: 16px; font-size: 18px; font-weight: 600; margin-top: 6px; }
.btn:disabled { opacity: .5; cursor: default; }
.error { color: var(--red); min-height: 20px; font-size: 14px; }

/* รายวิชา */
.subjectCard {
  border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.subjectCard .name { font-weight: 600; font-size: 17px; }
.badge { font-size: 13px; padding: 4px 10px; border-radius: 999px; }
.badge.done { background: #dcfce7; color: var(--green); }
.badge.todo { background: #fef3c7; color: #92400e; }

/* ทำข้อสอบ */
.quizbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.timer { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer.low { color: var(--red); }
.progress { color: var(--muted); font-size: 14px; }
.aiNote { font-size: 12px; color: var(--muted); background: var(--bg); padding: 8px 12px; border-radius: 8px; margin-bottom: 14px; }
.aiNote a { color: var(--blue); text-decoration: none; margin-left: 6px; }

.question { font-size: 18px; line-height: 1.6; margin-bottom: 16px; white-space: pre-wrap; }
.choice {
  display: block; width: 100%; text-align: left; padding: 14px 16px; margin-bottom: 10px;
  border: 2px solid var(--border); border-radius: 12px; background: #fff; font-size: 16px; cursor: pointer;
}
.choice:hover { border-color: var(--blue); }
.choice.chosen { border-color: var(--blue); background: #eff6ff; }
.choice.correct { border-color: var(--green); background: #f0fdf4; }
.choice.wrong { border-color: var(--red); background: #fef2f2; }
.choice:disabled { cursor: default; }

.feedback { border-radius: 12px; padding: 14px; margin: 14px 0; }
.feedback.correct { background: #f0fdf4; border: 1px solid #bbf7d0; }
.feedback.wrong { background: #fef2f2; border: 1px solid #fecaca; }
.feedback h3 { margin: 0 0 6px; font-size: 15px; }
.feedback p { margin: 4px 0; font-size: 15px; line-height: 1.5; }

/* สถิติ */
.statRow { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.statRow .k { color: var(--muted); }
.statRow .v { font-weight: 600; }
.bar { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.bar .label { width: 200px; font-size: 14px; flex-shrink: 0; }
.bar .track { flex: 1; background: var(--bg); border-radius: 999px; height: 14px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--blue); }
.bar .pct { width: 44px; text-align: right; font-size: 13px; color: var(--muted); }

table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th, table.simple td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }
input.emailInput { padding: 6px 8px; font-size: 14px; border: 1px solid var(--border); border-radius: 6px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex;
  align-items: center; justify-content: center; padding: 16px; z-index: 20;
}
.modalbox { background: #fff; border-radius: 12px; padding: 20px; max-width: 640px; max-height: 80vh; overflow: auto; position: relative; }
.modalclose { position: absolute; top: 12px; right: 12px; }
#promptText { white-space: pre-wrap; font-size: 13px; color: var(--muted); }

@media (max-width: 480px) {
  .bar .label { width: 120px; }
  .nav { gap: 2px; }
  .navbtn { padding: 8px 8px; font-size: 14px; }
}
