:root {
  --brand: #0ea5e9;
  --brand-dark: #0369a1;
  --bg: #f8fafc;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", "Sarabun", sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand-dark); }
.container { max-width: 880px; margin: 0 auto; padding: 24px; }
.wide { max-width: 1200px; }
h1 { margin: 0 0 4px; font-size: 28px; }
h2 { margin: 24px 0 8px; font-size: 20px; }
p.sub { color: var(--muted); margin: 0 0 24px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.04); }
label { display: block; font-size: 14px; font-weight: 500; margin: 10px 0 4px; }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; font-family: inherit; background: #fff; }
input:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,165,233,0.15); }
textarea { resize: vertical; min-height: 80px; }
button { background: var(--brand); color: #fff; border: 0; padding: 10px 16px; border-radius: 8px; font-size: 15px; font-weight: 500; cursor: pointer; }
button:hover { background: var(--brand-dark); }
button.ghost { background: transparent; color: var(--brand-dark); border: 1px solid var(--border); }
button.ghost:hover { background: #f1f5f9; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 200px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.pill.green { background: #dcfce7; color: #166534; }
.pill.gray  { background: #f1f5f9; color: #475569; }
.pill.blue  { background: #dbeafe; color: #1e40af; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.topbar .logo { font-weight: 700; font-size: 18px; }
.topbar nav a { margin-left: 16px; text-decoration: none; font-size: 14px; color: var(--muted); }
.topbar nav a:hover { color: var(--ink); }

/* Chat */
.chat { max-height: 60vh; overflow-y: auto; padding: 8px; margin-bottom: 16px; }
.msg { margin: 10px 0; display: flex; gap: 10px; }
.msg.ai { justify-content: flex-start; }
.msg.user { justify-content: flex-end; }
.bubble { padding: 12px 16px; border-radius: 16px; max-width: 78%; line-height: 1.5; font-size: 15px; }
.msg.ai .bubble  { background: #eff6ff; color: #1e3a8a; border-bottom-left-radius: 4px; }
.msg.user .bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.progress { height: 6px; background: #e2e8f0; border-radius: 999px; margin-bottom: 16px; overflow: hidden; }
.progress > div { height: 100%; background: var(--brand); transition: width 0.3s; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.empty { color: var(--muted); font-style: italic; text-align: center; padding: 32px; }

/* Division grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.div-card {
  background: #fff; border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; cursor: pointer; text-decoration: none; color: inherit;
  display: flex; flex-direction: column; gap: 8px;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  border-top: 4px solid var(--brand);
}
.div-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15,23,42,0.08); }
.div-card .icon { font-size: 32px; }
.div-card .name { font-size: 18px; font-weight: 600; }
.div-card .meta { color: var(--muted); font-size: 13px; }
.div-card.add {
  border-top-color: var(--muted);
  border-style: dashed;
  align-items: center; justify-content: center; text-align: center;
  color: var(--muted);
}
.div-card.add:hover { color: var(--brand); border-top-color: var(--brand); }
.breadcrumb { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--ink); }

/* Example page */
.ex-q {
  background: #f8fafc;
  border-left: 4px solid var(--brand);
  padding: 14px 18px;
  border-radius: 8px;
  margin: 16px 0 10px;
  font-weight: 600;
  font-size: 16px;
}
.ex-bad, .ex-good {
  padding: 12px 16px;
  border-radius: 10px;
  margin: 8px 0;
  font-size: 14.5px;
  line-height: 1.6;
}
.ex-bad { background: #fef2f2; border: 1px solid #fecaca; }
.ex-good { background: #f0fdf4; border: 1px solid #bbf7d0; }
.ex-tip  { background: #fffbeb; border: 1px solid #fde68a; padding: 10px 14px; border-radius: 8px; font-size: 14px; margin: 8px 0 4px; }
.ex-label { display:inline-block; font-weight: 600; margin-right: 6px; }
.ex-section { border-top: 2px dashed var(--border); margin: 32px 0 12px; padding-top: 16px; }
.ex-section h2 { margin: 0 0 4px; }
