:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --ink: #171923;
  --ink-soft: #5b6478;
  --line: #e8eaf0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0fe;
  --accent: #7c3aed;
  --danger: #e11d48;
  --success: #059669;
  --warning: #d97706;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow-sm: 0 1px 2px rgba(23,25,35,.06), 0 1px 3px rgba(23,25,35,.05);
  --shadow: 0 4px 12px rgba(23,25,35,.06), 0 12px 32px rgba(23,25,35,.06);
  --shadow-lg: 0 8px 24px rgba(23,25,35,.08), 0 24px 60px rgba(60,66,120,.14);
  --ring: 0 0 0 4px rgba(79,70,229,.16);
  --grad: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);

  --bs-primary: #4f46e5;
  --bs-primary-rgb: 79,70,229;
  --bs-primary-text-emphasis: #4338ca;
  --bs-primary-bg-subtle: #eef0fe;
  --bs-primary-border-subtle: #d6d9fb;
  --bs-link-color: #4f46e5;
  --bs-link-color-rgb: 79,70,229;
  --bs-link-hover-color: #4338ca;
  --bs-body-color: #171923;
  --bs-border-radius: 11px;
}
* { font-family: 'Anuphan', system-ui, -apple-system, sans-serif; }
body { background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
h1,h2,h3,h4,h5,h6 { font-weight: 600; letter-spacing: -.01em; }

::selection { background: rgba(79,70,229,.16); }

.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--grad);
  display: grid; place-items: center; color: #fff; font-size: 1.05rem; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(79,70,229,.35);
}

/* avatars */
.avatar-sm { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; background: var(--grad); display: inline-grid; place-items: center; color: #fff; font-size: .8rem; font-weight: 600; overflow: hidden; flex-shrink: 0; }
.avatar-sm img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: var(--grad); display: grid; place-items: center; color: #fff; font-size: 1.9rem; font-weight: 700; overflow: hidden; flex-shrink: 0; box-shadow: var(--shadow-sm); }
.avatar-lg img { width: 100%; height: 100%; object-fit: cover; }

/* media thumbnails in editor */
.media-thumb { max-width: 100%; max-height: 160px; border-radius: 10px; border: 1px solid var(--line); }
.media-thumb-sm { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.choice-row .input-group-text label, .choice-row label.input-group-text { cursor: pointer; }
.choice-row label.input-group-text:hover { background: var(--primary-soft); color: var(--primary); }

/* media inside exam / review question cards */
.q-image { max-width: 100%; max-height: 340px; border-radius: 12px; border: 1px solid var(--line); margin: .25rem 0 .75rem; display: block; }
.q-audio { width: 100%; margin: .25rem 0 .75rem; }
.choice-img { max-width: 100%; max-height: 160px; border-radius: 8px; margin-top: .4rem; display: block; }

/* ---------- Navbar ---------- */
.app-navbar {
  background: rgba(255,255,255,.82);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1030;
  min-height: 60px;
}
.app-navbar .navbar-brand {
  color: var(--ink); font-weight: 700; font-size: 1.05rem;
  display: flex; align-items: center; gap: .55rem; letter-spacing: -.02em;
}
.app-navbar .navbar-brand img { height: 30px; width: auto; border-radius: 7px; }
.app-navbar .navbar-brand .brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--grad);
  display: grid; place-items: center; color: #fff; font-size: 1.05rem;
  box-shadow: 0 4px 12px rgba(79,70,229,.35);
}
.app-navbar .btn-outline-light { color: var(--ink-soft); border-color: var(--line); background: #fff; }
.app-navbar .btn-outline-light:hover { color: var(--ink); background: var(--bg); border-color: var(--line); }

/* ---------- Layout ---------- */
.app-layout { display: flex; min-height: calc(100vh - 61px); }
.app-sidebar { width: 256px; background: var(--surface); flex-shrink: 0; border-right: 1px solid var(--line); }
.app-sidebar .nav { padding: .85rem .7rem; gap: 2px; }
.app-sidebar .nav-link {
  color: var(--ink-soft); padding: .62rem .85rem; border-radius: 10px;
  font-size: .93rem; font-weight: 500; display: flex; align-items: center;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}
.app-sidebar .nav-link i { transition: transform .16s ease; }
.app-sidebar .nav-link:hover { background: var(--bg); color: var(--ink); }
.app-sidebar .nav-link:hover i { transform: translateX(1px); }
.app-sidebar .nav-link.active { background: var(--primary-soft); color: var(--primary-hover); font-weight: 600; }
.app-content { flex: 1; padding: 1.9rem; max-width: 100%; overflow-x: auto; animation: fadeUp .4s ease both; }

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--line); background: var(--surface);
  box-shadow: var(--shadow-sm); border-radius: var(--radius);
  transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease;
}
.card:hover { box-shadow: var(--shadow); }
.app-content .row .card:hover { transform: translateY(-2px); border-color: #dde0ee; }

/* ---------- Buttons ---------- */
.btn { border-radius: 10px; font-weight: 600; transition: transform .14s ease, box-shadow .18s ease, background .18s ease; }
.btn:active { transform: translateY(1px); }
.btn-brand, .btn-primary { background: var(--grad); border: none; color: #fff; box-shadow: 0 6px 18px rgba(79,70,229,.28); }
.btn-brand:hover, .btn-primary:hover { color: #fff; box-shadow: 0 10px 26px rgba(79,70,229,.38); transform: translateY(-1px); }
.btn-outline-primary { --bs-btn-color:#4f46e5; --bs-btn-border-color:#d6d9fb; --bs-btn-hover-bg:#4f46e5; --bs-btn-hover-border-color:#4f46e5; --bs-btn-active-bg:#4338ca; }
.btn-outline-secondary { --bs-btn-color:#5b6478; --bs-btn-border-color:#e0e3ee; --bs-btn-hover-bg:#f6f7fb; --bs-btn-hover-border-color:#d3d7e6; --bs-btn-hover-color:#171923; }

/* ---------- Forms ---------- */
.form-control, .form-select { border-radius: 10px; border-color: var(--line); padding: .55rem .8rem; transition: border-color .16s ease, box-shadow .16s ease; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: var(--ring); }
.form-control-lg, .form-select-lg { border-radius: 12px; }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.form-check-input:focus { box-shadow: var(--ring); border-color: var(--primary); }
.form-label { font-weight: 500; font-size: .9rem; color: var(--ink); margin-bottom: .35rem; }

/* ---------- Tables ---------- */
.table { --bs-table-border-color: var(--line); }
.table thead th { background: var(--bg); color: var(--ink-soft); border: none; font-weight: 600; font-size: .82rem; text-transform: none; letter-spacing: .01em; }
.table td { border-color: var(--line); }
.table > :not(caption) > * > * { padding: .7rem .75rem; }

/* ---------- Badges ---------- */
.badge { font-weight: 600; border-radius: 7px; padding: .34em .6em; }
.badge.bg-primary-subtle { background: var(--primary-soft) !important; color: var(--primary-hover) !important; }

/* ---------- Stat tiles ---------- */
.stat-tile .stat-value { font-size: 1.8rem; font-weight: 700; letter-spacing: -.02em; }
.stat-tile .stat-label { color: var(--ink-soft); font-size: .85rem; }

/* ---------- Alerts ---------- */
.alert { border: 1px solid transparent; border-radius: 12px; }
.alert-success { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.alert-danger { background: #fff1f2; color: #9f1239; border-color: #fecdd3; }
.alert-warning { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--primary-soft); color: var(--primary-hover); border-color: #d6d9fb; }

/* ---------- Footer ---------- */
.app-footer { text-align: center; padding: 1.2rem; font-size: .78rem; color: #9098ad; border-top: 1px solid var(--line); }

/* ---------- Public (login / entry) ---------- */
body.public-body { background: #0c0e1a; min-height: 100vh; position: relative; overflow-x: hidden; }
body.public-body::before, body.public-body::after {
  content: ''; position: fixed; border-radius: 50%; filter: blur(90px); z-index: 0; opacity: .55;
}
body.public-body::before { width: 60vw; height: 60vw; background: #4f46e5; top: -18vw; left: -12vw; animation: float1 16s ease-in-out infinite; }
body.public-body::after { width: 46vw; height: 46vw; background: #7c3aed; bottom: -14vw; right: -8vw; animation: float2 20s ease-in-out infinite; }
.entry-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.1rem; position: relative; z-index: 1; }
.entry-card {
  background: rgba(255,255,255,.96); border: 1px solid rgba(255,255,255,.5);
  border-radius: 22px; padding: 2.4rem 2rem; width: 100%; max-width: 430px;
  box-shadow: var(--shadow-lg); backdrop-filter: blur(8px);
  animation: popIn .5s cubic-bezier(.2,.8,.2,1) both;
}
.entry-card .brand-mark {
  width: 56px; height: 56px; border-radius: 16px; background: var(--grad); margin: 0 auto;
  display: grid; place-items: center; color: #fff; font-size: 1.7rem;
  box-shadow: 0 10px 26px rgba(79,70,229,.45);
}
.entry-card h4 { font-weight: 700; letter-spacing: -.02em; }
.entry-footer { color: rgba(255,255,255,.6); font-size: .76rem; text-align: center; margin-top: 1.4rem; position: relative; z-index: 1; }

/* ---------- Exam taking (mobile) ---------- */
.exam-body { background: var(--bg); }
.exam-body, .exam-body * { -webkit-user-select: none; user-select: none; }
.exam-body input, .exam-body textarea { -webkit-user-select: text; user-select: text; }
.exam-shell { max-width: 720px; margin: 0 auto; padding: .75rem; }
.exam-timer {
  position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,.85);
  backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 14px;
  padding: .7rem 1rem; display: flex; justify-content: space-between; align-items: center;
  margin-top: .5rem; box-shadow: var(--shadow-sm);
}
.exam-timer.low-time { background: #fff1f2; color: var(--danger); border-color: #fecdd3; }
.exam-timer .time-value { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.12rem; color: var(--primary); }
.exam-timer.low-time .time-value { color: var(--danger); }
.question-card { margin: 1rem 0; animation: fadeUp .3s ease both; }
.choice-option {
  display: block; border: 1.5px solid var(--line); border-radius: 13px;
  padding: .85rem 1rem; margin-bottom: .6rem; cursor: pointer; background: #fff;
  transition: border-color .15s ease, background .15s ease, transform .1s ease;
}
.choice-option:hover { border-color: #c9cdf5; }
.choice-option:active { transform: scale(.99); }
.choice-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice-option input:checked ~ .choice-label { font-weight: 600; color: var(--primary-hover); }
.violation-toast {
  position: fixed; bottom: 1.1rem; left: 50%; transform: translateX(-50%) translateY(0);
  background: #171923; color: #fff; padding: .65rem 1.05rem; border-radius: 12px;
  font-size: .88rem; z-index: 2000; box-shadow: var(--shadow-lg); animation: toastIn .3s ease both;
}
.result-badge { width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto; font-size: 2.2rem; animation: popIn .5s cubic-bezier(.2,.8,.2,1) both; }
.result-badge.ok { background: #ecfdf5; color: var(--success); }
.result-badge.bad { background: #fff1f2; color: var(--danger); }
.result-badge.neutral { background: var(--bg); color: var(--ink-soft); }

/* ---------- Animations ---------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes float1 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(4vw,3vw); } }
@keyframes float2 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(-3vw,-4vw); } }
@media (prefers-reduced-motion: reduce) { *, ::before, ::after { animation: none !important; transition: none !important; } }

@media print {
  .app-navbar, .app-sidebar, .no-print { display: none !important; }
  .app-content { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
