/* =============================================
   ตาเบาวิทยา — ระบบสะสมคะแนนความดี
   ============================================= */

:root {
  --h: 145;
  --font: 'Kanit', sans-serif;
  --r-card: 16px;
  --g:    oklch(0.52 0.17 var(--h));
  --gd:   oklch(0.35 0.15 var(--h));
  --gl:   oklch(0.95 0.05 var(--h));
  --gm:   oklch(0.72 0.14 var(--h));
  --bg:   oklch(0.97 0.02 var(--h));
  --border: oklch(0.93 0.04 var(--h));
  --text: oklch(0.25 0.12 var(--h));
  --text-soft: oklch(0.6 0.05 var(--h));
}

*, *::before, *::after { box-sizing: border-box; font-family: var(--font); }
body { margin: 0; background: var(--bg); min-height: 100vh; }

/* ── Animations ── */
@keyframes slideUp   { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn    { from { opacity: 0; } to { opacity: 1; } }
@keyframes toastIn   { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes spin      { to { transform: rotate(360deg); } }
@keyframes pulse     { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }

.anim-slideup { animation: slideUp 0.25s ease; }
.anim-fadein  { animation: fadeIn 0.4s ease; }
.anim-pulse   { animation: pulse 2s infinite; display: inline-block; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: oklch(0.85 0.05 var(--h)); border-radius: 2px; }

/* ── Range input ── */
input[type=range] { -webkit-appearance: none; appearance: none; height: 6px; border-radius: 3px; cursor: pointer; width: 100%; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--g); cursor: pointer; }
select { appearance: none; -webkit-appearance: none; }


/* ── Login ── */
#login-view {
  min-height: 100dvh; position: relative; overflow: hidden;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 24px;
}
.login-box { width: 100%; max-width: 380px; position: relative; z-index: 1; }

/* ── Falling leaves (decorative, non-interactive) ── */
/* --dy = fall distance in px, computed in JS from the container's own height so the
   same animation works both full-page (login) and inside a short card (student hero) */
#leaf-field, .leaf-field { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.leaf {
  position: absolute; top: -10%; left: var(--x); font-size: var(--sz); opacity: 0;
  will-change: transform, opacity; animation: leafFall var(--dur) ease-in-out infinite; animation-delay: var(--del);
}
.hero-banner .leaf { filter: brightness(0) invert(1); }
@keyframes leafFall {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  12%  { opacity: var(--op); }
  50%  { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); }
  88%  { opacity: var(--op); }
  100% { transform: translate(calc(var(--dx) * 1.6), calc(var(--dy) * 2)) rotate(calc(var(--rot) * 1.7)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .leaf { display: none; }
}
.login-logo { text-align: center; margin-bottom: 20px; }
.logo-icon {
  width: 90px; height: 90px; font-size: 60px; margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  filter: drop-shadow(0 0 12px oklch(0.68 0.21 var(--h) / 0.6)) drop-shadow(0 0 28px oklch(0.6 0.22 var(--h) / 0.4));
}
.login-logo h1 { margin: 0; font-size: 26px; font-weight: 700; color: var(--text); }
.login-logo p  { margin: 6px 0 0; font-size: 14px; color: var(--text-soft); }
.login-tabs {
  display: flex; gap: 4px; background: oklch(0.95 0.03 var(--h)); border-radius: 14px;
  padding: 4px; margin-bottom: 22px;
}
.login-tab {
  flex: 1; padding: 11px 8px; border: none; border-radius: 10px; cursor: pointer;
  background: transparent; color: var(--text-soft); font-family:var(--font); font-size: 14px;
  font-weight: 600; transition: all 0.15s;
}
.login-tab.active { background: #fff; color: var(--gd); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.login-note { text-align: center; font-size: 12px; color: oklch(0.7 0.04 var(--h)); margin-top: 24px; }

.install-app-btn {
  display: block; width: 100%; margin-top: 14px; padding: 11px;
  background: #fff; border: 1.5px solid var(--border); border-radius: 12px;
  font-family:var(--font); font-weight: 600; font-size: 13px; color: var(--gd);
  cursor: pointer; transition: background 0.2s;
}
.install-app-btn:hover { background: var(--gl); }

/* ── App shell: header + bottom nav ── */
/* กว้างเต็มจอบนแท็บเล็ต — ค่า 480px ด้านล่างคือเพดานสำหรับมือถือเท่านั้น */
#app-a { display: none; max-width: 480px; margin: 0 auto; min-height: 100vh; position: relative; background: var(--bg); }
#header-a {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  max-width: 480px; width: 100%; background: #fff;
  border-bottom: 1px solid var(--border); z-index: 90;
  display: flex; align-items: center; padding: 0 16px; height: 56px;
  box-shadow: 0 1px 8px rgba(0,0,0,0.06);
}
@media (min-width: 640px) {
  #app-a, #header-a, .bottom-nav, .modal-sheet { max-width: 100%; }
}
.header-logo { width: 36px; height: 36px; background: var(--gl); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; margin: 0 10px; flex-shrink: 0; }
.header-title { font-size: 16px; font-weight: 700; color: var(--text); flex: 1; }
.header-right { display: flex; align-items: center; gap: 8px; }
.content-a { padding: 76px 16px 80px; }

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  max-width: 480px; width: 100%; background: #fff;
  border-top: 1px solid oklch(0.92 0.03 var(--h));
  display: flex; z-index: 100; box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}
.bnav-btn {
  flex: 1; padding: 10px 4px 8px; border: none; background: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: all 0.15s; border-top: 3px solid transparent;
}
.bnav-btn.active { background: var(--gl); border-top-color: var(--g); }
.bnav-icon { font-size: 19px; }
.bnav-label { font-size: 10px; color: #9ca3af; font-family: var(--font); }
/* ปุ่มกลางขนาดใหญ่ (ขอทำดี ของนักเรียน) ลอยเหนือแถบเมนู */
.bottom-nav { overflow: visible; }
.bnav-btn.bnav-fab { background: #fff; border-top-color: transparent; position: relative; padding-top: 38px; }
.bnav-btn.bnav-fab.active { background: #fff; border-top-color: transparent; }
.bnav-fab-circle {
  position: absolute; top: -24px; left: 50%; transform: translateX(-50%);
  width: 58px; height: 58px; border-radius: 50%;
  background: linear-gradient(135deg, var(--g), var(--gd)); border: 4px solid #fff;
  box-shadow: 0 4px 14px oklch(0.4 0.15 var(--h) / 0.45);
  display: flex; align-items: center; justify-content: center; font-size: 26px;
}
.bnav-btn.bnav-fab.active .bnav-fab-circle { box-shadow: 0 0 0 3px var(--gl), 0 4px 14px oklch(0.4 0.15 var(--h) / 0.45); }
.bnav-btn.bnav-fab .bnav-label { font-weight: 700; color: var(--g); }
.bnav-btn.active .bnav-label { color: var(--g); font-weight: 700; }

/* ── Drawer (full menu, slides in from the left over the app) ── */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 950; background: rgba(0,0,0,0.45);
  display: flex; animation: fadeIn 0.2s ease;
}
.drawer-panel {
  width: 240px; height: 100%; box-shadow: 4px 0 24px rgba(0,0,0,0.25);
  animation: drawerIn 0.25s ease;
}
@keyframes drawerIn { from { transform: translateX(-100%); } to { transform: translateX(0); } }

.sidebar {
  background: linear-gradient(180deg, var(--gd), oklch(0.28 0.13 var(--h)));
  display: flex; flex-direction: column;
}
.sidebar-brand { padding: 20px 18px 18px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-brand-name { font-size: 18px; font-weight: 700; color: #fff; }
.sidebar-brand-sub  { font-size: 11px; color: rgba(255,255,255,0.55); margin-top: 3px; }
.sidebar-nav { padding: 12px 0; flex: 1; overflow-y: auto; }
.snav-btn {
  display: flex; align-items: center; gap: 10px; padding: 10px 18px;
  width: 100%; border: none; background: transparent; cursor: pointer;
  color: rgba(255,255,255,0.65); font-family:var(--font); font-size: 14px;
  text-align: left; border-left: 3px solid transparent; transition: all 0.15s;
}
.snav-btn:hover, .snav-btn.active {
  background: rgba(255,255,255,0.14); color: #fff; border-left-color: #fff; font-weight: 700;
}
.snav-icon { font-size: 18px; }
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.08); }
.sidebar-logout {
  width: 100%; padding: 8px 12px; background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15); border-radius: 8px;
  color: rgba(255,255,255,0.7); font-family:var(--font); cursor: pointer; font-size: 12px;
}
.sidebar-logout:hover { background: rgba(255,255,255,0.15); }

/* ── Shared UI components ── */
.role-badge { background: var(--gl); border-radius: 20px; padding: 4px 10px; font-size: 11px; font-weight: 600; color: var(--gd); }
.mgmt-menu-btn { width: 32px; height: 32px; border: none; background: var(--gl); border-radius: 10px; color: var(--gd); font-size: 15px; cursor: pointer; flex-shrink: 0; }
.mgmt-menu-btn:hover { background: oklch(0.9 0.06 var(--h)); }
.avatar { width: 32px; height: 32px; background: linear-gradient(135deg, var(--g), var(--gd)); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px; cursor: pointer; flex-shrink: 0; }

/* Screen content wrapper */
.screen-wrap { display: flex; flex-direction: column; gap: 14px; }

/* Hero banner */
.hero-banner {
  background: linear-gradient(135deg, var(--gd), var(--g));
  border-radius: 18px; padding: 22px; color: #fff;
  position: relative; overflow: hidden;
}
.hero-banner::before {
  content: ''; position: absolute; top: -24px; right: -24px;
  width: 100px; height: 100px; background: rgba(255,255,255,0.07); border-radius: 50%;
}
.hero-banner::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: -60%;
  width: 45%;
  background: linear-gradient(115deg, transparent 0%, rgba(255,255,255,0.32) 50%, transparent 100%);
  transform: skewX(-20deg);
  animation: heroShine 4.5s ease-in-out infinite;
  z-index: 2; pointer-events: none;
}
@keyframes heroShine {
  0%  { left: -60%; }
  22% { left: 130%; }
  100% { left: 130%; }
}
@media (prefers-reduced-motion: reduce) {
  .hero-banner::after { animation: none; display: none; }
}

/* Card */
.card { background: #fff; border-radius: var(--r-card); padding: 20px; box-shadow: 0 2px 12px rgba(0,0,0,0.055); }

/* Stat boxes */
.stat-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.stat-box {
  background: #fff; border-radius: 14px; padding: 10px 8px;
  text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.stat-icon { font-size: 22px; }
.stat-val  { font-size: 20px; font-weight: 700; line-height: 1; margin-top: 3px; }
.stat-lbl  { font-size: 11px; color: #9ca3af; margin-top: 3px; }

/* List row */
.list-item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid oklch(0.96 0.02 var(--h)); }
.list-icon  { font-size: 22px; width: 32px; text-align: center; flex-shrink: 0; }
.list-body  { flex: 1; min-width: 0; }
.list-title { font-weight: 600; font-size: 14px; color: #1f2937; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-sub   { font-size: 12px; color: #9ca3af; margin-top: 1px; }
.list-right { font-weight: 700; color: var(--g); font-size: 13px; flex-shrink: 0; }

/* Green button */
.btn-green {
  padding: 13px 20px; background: linear-gradient(90deg, var(--gd), var(--g));
  color: #fff; border: none; border-radius: 12px; font-family:var(--font);
  font-weight: 700; font-size: 14px; cursor: pointer; transition: opacity 0.2s;
  display: block; width: 100%; text-align: center;
}
.btn-green:hover { opacity: 0.9; }
.btn-green:disabled { opacity: 0.5; cursor: not-allowed; }

.call-btn-cta {
  padding: 13px 20px; background: linear-gradient(90deg, #d97706, #f59e0b);
  color: #fff; border: none; border-radius: 12px; font-family:var(--font);
  font-weight: 700; font-size: 14px; cursor: pointer; transition: opacity 0.2s;
  display: block; width: 100%; text-align: center;
  box-shadow: 0 6px 16px rgba(245,129,31,0.3);
}
.call-btn-cta:hover { opacity: 0.9; }
.call-btn-cta:disabled { opacity: 0.5; cursor: not-allowed; }

/* Form */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 13px; font-weight: 600; color: #374151; display: block; margin-bottom: 6px; }
.form-input {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid oklch(0.88 0.07 var(--h)); border-radius: 10px;
  font-family:var(--font); font-size: 14px; color: #1f2937; outline: none;
  box-sizing: border-box; background: #fff;
}
.form-input:focus { border-color: var(--g); }
.form-input[readonly] { background: #f9fafb; }

.form-group input[type="file"] {
  width: 100%; box-sizing: border-box; font-family:var(--font); font-size: 12.5px;
  color: #9ca3af; padding: 9px 10px;
  border: 1.5px dashed oklch(0.88 0.07 var(--h)); border-radius: 10px;
  background: var(--gl); cursor: pointer;
}
.form-group input[type="file"]::file-selector-button,
.form-group input[type="file"]::-webkit-file-upload-button {
  font-family:var(--font); font-weight: 700; font-size: 13px; color: #fff;
  background: linear-gradient(90deg, var(--gd), var(--g));
  border: none; border-radius: 8px; padding: 8px 14px; margin-right: 10px;
  cursor: pointer; transition: opacity 0.2s;
}
.form-group input[type="file"]:hover::file-selector-button,
.form-group input[type="file"]:hover::-webkit-file-upload-button { opacity: 0.9; }

/* QR scanner */
.qr-scan-box {
  background: #111; border-radius: 14px; height: 230px;
  position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.qr-corner { position: absolute; width: 28px; height: 28px; border: 3px solid var(--g); }
.qr-tl { top:18px; left:18px;  border-right:none; border-bottom:none; border-radius:6px 0 0 0; }
.qr-tr { top:18px; right:18px; border-left:none;  border-bottom:none; border-radius:0 6px 0 0; }
.qr-bl { bottom:18px; left:18px;  border-right:none; border-top:none; border-radius:0 0 0 6px; }
.qr-br { bottom:18px; right:18px; border-left:none;  border-top:none; border-radius:0 0 6px 0; }
.scan-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ── QR ↔ camera flip card (student home) — double-tap toggles ──
   Only one face is ever rendered in the DOM at a time (see app.js) — a real 3D
   rotateY flip with backface-visibility:hidden looked good in testing but showed
   both faces' text superimposed on some mobile browsers where backface-visibility
   isn't respected reliably, so this trades the 3D flip for a plain scale/fade-in
   that works everywhere. */
.qr-flip-wrap {
  position: relative; cursor: pointer; touch-action: manipulation;
  display: flex; flex-direction: column; align-items: center;
  transition: transform 0.15s ease;
}
.qr-flip-wrap:active { transform: scale(0.96); }
.qr-flip-face {
  width: 100%; display: flex; flex-direction: column; align-items: center;
  animation: qrFaceIn 0.3s ease;
}
@keyframes qrFaceIn {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

/* แตะแล้วมีวงสีสันกระจายจากจุดกึ่งกลาง — ให้รู้สึกถึงการแตะทุกครั้ง ไม่ใช่แค่ตอนพลิกสำเร็จ */
.qr-tap-pulse {
  position: absolute; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, oklch(0.78 0.19 var(--h) / 0.55) 0%, oklch(0.8 0.16 85 / 0.4) 55%, transparent 75%);
  animation: qrTapPulse 0.5s ease-out forwards;
}
@keyframes qrTapPulse {
  from { transform: scale(0); opacity: 1; }
  to   { transform: scale(1); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .qr-flip-face { animation: none; }
  .qr-flip-wrap { transition: none; }
  .qr-flip-wrap:active { transform: none; }
  .qr-tap-pulse { display: none; }
}

/* Floating "+N" score popup — fixed to the viewport so re-renders mid-scan-result don't cut it off */
.float-points {
  position: fixed; transform: translate(-50%, -50%); pointer-events: none; z-index: 960;
  font-size: 34px; font-weight: 800; color: #facc15; font-family:var(--font);
  text-shadow: 0 2px 6px rgba(0,0,0,0.35), 0 0 14px rgba(250,204,21,0.65);
  animation: floatPointsUp 1.2s ease-out forwards;
}
@keyframes floatPointsUp {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
  15%  { opacity: 1; transform: translate(-50%, -65%) scale(1.2); }
  32%  { transform: translate(-50%, -78%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .float-points { animation: fadeIn 0.3s ease forwards; }
}

/* Unlockable avatar frame — ring style upgrades as the student climbs badge tiers */
.avatar-frame { position: relative; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.avatar-frame::before { content: ''; position: absolute; inset: 0; border-radius: 50%; z-index: 0; }
.avatar-frame > div { position: relative; z-index: 1; }
.avatar-frame-base::before { background: rgba(255,255,255,0.35); }
.avatar-frame-mid::before {
  background: conic-gradient(var(--frame-glow), #fff, var(--frame-glow));
  box-shadow: 0 0 10px 1px var(--frame-glow);
}
.avatar-frame-max::before {
  background: conic-gradient(var(--frame-glow), #fff8dc, var(--frame-glow), #fff, var(--frame-glow));
  box-shadow: 0 0 16px 3px var(--frame-glow);
  animation: avatarFrameSpin 3.5s linear infinite;
}
@keyframes avatarFrameSpin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .avatar-frame-max::before { animation: none; }
}

/* ── Badge page: มาสคอตวิวัฒนาการ ── */
.mascot-caption { text-align: center; font-size: 12.5px; font-weight: 700; color: var(--gd); letter-spacing: 0.03em; margin: 4px 0 12px; }

.mascot-scene-wrap { border-radius: 20px; overflow: hidden; box-shadow: 0 2px 14px rgba(0,0,0,0.08); }
.mascot-scene {
  position: relative; width: 100%; aspect-ratio: 1200 / 700; container-type: inline-size;
  background-size: cover; background-position: center; background-color: #cdeecb;
  overflow: hidden;
}

.mascot-bird { position: absolute; right: -8%; font-size: 13px; opacity: 0; animation: mascotBirdFly 9s linear infinite; z-index: 2; }
@keyframes mascotBirdFly {
  0% { opacity: 0; transform: translateX(0) translateY(0); }
  6% { opacity: 0.9; }
  50% { transform: translateX(-58cqw) translateY(-10px); }
  94% { opacity: 0.9; }
  100% { opacity: 0; transform: translateX(-118cqw) translateY(2px); }
}

.mascot-pulse-ring {
  position: absolute; left: 50%; bottom: 15%; transform: translateX(-50%);
  width: 15%; aspect-ratio: 1 / 1; border-radius: 50%; border: 2.5px solid var(--g); opacity: 0;
  animation: mascotPulse 2.6s ease-out infinite; z-index: 1;
}
@keyframes mascotPulse { 0% { transform: translateX(-50%) scale(0.75); opacity: 0.55; } 100% { transform: translateX(-50%) scale(1.9); opacity: 0; } }

.mascot-icon {
  position: absolute; left: 50%; bottom: 13%; transform: translateX(-50%);
  height: auto; filter: drop-shadow(0 6px 6px rgba(15,50,20,0.45));
  z-index: 2;
}
.mascot-icon[data-stage="1"] { width: 15cqw; }
.mascot-icon[data-stage="2"] { width: 18cqw; }
.mascot-icon[data-stage="3"] { width: 22cqw; }
.mascot-icon[data-stage="4"] { width: 27cqw; }
.mascot-icon[data-stage="5"] { width: 34cqw; }

.mascot-tag {
  position: absolute; top: 12px; left: 12px; background: #fff; color: var(--gd); font-size: 10.5px; font-weight: 700;
  padding: 5px 10px; border-radius: 20px; box-shadow: 0 2px 6px rgba(0,0,0,0.12); z-index: 2;
}

.mascot-scene-caption { padding: 8px 16px 10px; background: #fff; text-align: center; }
.mascot-scene-caption .msc-name { font-size: 14.5px; font-weight: 700; color: var(--text); }
.mascot-scene-caption .msc-sub { font-size: 11.5px; color: var(--text-soft); margin-top: 3px; }

/* Growth path */
.gpath-wrap { margin-top: 0; padding: 10px 12px 10px; border-radius: 20px; background: #fff; box-shadow: 0 2px 14px rgba(0,0,0,0.06); }
.gpath-title { font-size: 12px; font-weight: 700; color: var(--text); margin-bottom: 18px; padding-left: 2px; }
.gpath-row { display: flex; align-items: flex-start; position: relative; }
.gpath-line-bg { position: absolute; top: 21px; height: 3px; background: var(--border); border-radius: 2px; z-index: 0; }
.gpath-line-fill { position: absolute; top: 21px; height: 3px; background: var(--g); border-radius: 2px; z-index: 0; transition: width 0.9s cubic-bezier(0.3,0.7,0.3,1); }
.gnode { flex: 1; display: flex; flex-direction: column; align-items: center; position: relative; z-index: 1; text-align: center; }
.gnode-badge {
  width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 20px; background: #fff; border: 2.5px solid var(--border); box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.gnode-check {
  position: absolute; top: -3px; right: 4px; width: 15px; height: 15px; border-radius: 50%;
  background: var(--g); color: #fff; font-size: 9px; display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}
.gnode-lock {
  position: absolute; top: -3px; right: 4px; width: 15px; height: 15px; border-radius: 50%;
  background: #c3cbc4; color: #fff; font-size: 8px; display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff;
}
.gnode.done .gnode-badge { border-color: var(--g); background: var(--gl); }
.gnode.now .gnode-badge {
  width: 50px; height: 50px; font-size: 24px; border-color: var(--g); background: var(--gl);
  box-shadow: 0 0 0 5px rgba(26,122,61,0.16), 0 3px 8px rgba(15,77,36,0.2);
}
.gnode.future .gnode-badge { filter: grayscale(1); opacity: 0.65; }
.gnode-label { font-size: 9.5px; font-weight: 700; color: var(--text); margin-top: 6px; line-height: 1.2; max-width: 58px; }
.gnode.future .gnode-label { color: #a7b0a8; }
.gnode-pts { font-size: 8px; color: var(--text-soft); margin-top: 1px; }
.gnode-now-tag {
  position: absolute; top: -22px; left: 50%; transform: translateX(-50%);
  background: var(--gd); color: #fff; font-size: 8.5px; font-weight: 700; padding: 2px 8px; border-radius: 10px;
  white-space: nowrap;
}
.gnode-now-tag::after {
  content: ''; position: absolute; bottom: -3px; left: 50%; transform: translateX(-50%);
  width: 6px; height: 6px; background: var(--gd); rotate: 45deg;
}

@media (prefers-reduced-motion: reduce) {
  .mascot-icon, .mascot-pulse-ring, .mascot-bird { animation: none !important; }
}

/* Leaderboard podium */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 6px; padding: 0 4px; }
.podium-col { flex: 1; text-align: center; }
.podium-name { font-size: 10px; font-weight: 600; color: var(--gd); margin-bottom: 4px; line-height: 1.3; }
.podium-bar {
  border-radius: 10px 10px 0 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; transition: height 0.7s cubic-bezier(.34,1.56,.64,1);
}
.podium-bar-first { box-shadow: 0 0 16px 2px rgba(255,215,0,0.55); }
.podium-rank { font-size: 19px; }
.podium-pts  { font-size: 11px; margin-top: 2px; }
.podium-crown { font-size: 20px; margin-bottom: -2px; animation: podiumCrownBounce 1.6s ease-in-out infinite; }
@keyframes podiumCrownBounce {
  0%, 100% { transform: translateY(0) rotate(-4deg); }
  50%      { transform: translateY(-4px) rotate(4deg); }
}
@media (prefers-reduced-motion: reduce) {
  .podium-bar { transition: none; }
  .podium-crown { animation: none; }
}

/* Streak chip — consecutive-day good-deed streak, shown on the student hero card */
.streak-chip {
  display: inline-block; border-radius: 20px; padding: 2px 10px; font-size: 12px;
  font-weight: 700; color: #fff;
  background: linear-gradient(90deg, #f97316, #facc15);
  animation: streakPulse 1.6s ease-in-out infinite;
}
@keyframes streakPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(249,115,22,0.5); }
  50%      { box-shadow: 0 0 10px 3px rgba(249,115,22,0.5); }
}
@media (prefers-reduced-motion: reduce) {
  .streak-chip { animation: none; }
}

/* Weekly quests */
.quest-item { display: flex; flex-direction: column; }
.quest-icon { font-size: 19px; width: 26px; text-align: center; flex-shrink: 0; }
.quest-bar-track { height: 8px; border-radius: 6px; background: #f3f4f6; overflow: hidden; }
.quest-bar-fill {
  height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--gd), var(--g));
  transition: width 0.8s cubic-bezier(.34,1.2,.64,1);
}
.quest-done .quest-bar-fill { background: linear-gradient(90deg, #f59e0b, #facc15); }
@media (prefers-reduced-motion: reduce) {
  .quest-bar-fill { transition: none; }
}

/* Reward card */
.reward-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.reward-card { background: #fff; border-radius: 16px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.055); }
.reward-img  { height: 54px; display: flex; align-items: center; justify-content: center; font-size: 28px; }
.reward-body { padding: 8px 10px 10px; }
.reward-name { font-weight: 700; font-size: 13px; color: #1f2937; line-height: 1.3; }
.reward-stock { font-size: 10.5px; color: #9ca3af; margin-top: 1px; }
.reward-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.reward-pts { font-weight: 700; color: var(--g); font-size: 13px; }
.btn-redeem {
  padding: 5px 12px; border: none; border-radius: 8px;
  font-family:var(--font); font-size: 12px; font-weight: 600; cursor: pointer;
}
.btn-redeem.can   { background: var(--g); color: #fff; }
.btn-redeem.cant  { background: #e5e7eb; color: #9ca3af; }

/* Chart bars (reports) */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 130px; }
.bar-col  { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.bar-val  { font-size: 9px; color: var(--g); font-weight: 700; }
.bar-fill { width: 100%; border-radius: 4px 4px 0 0; transition: height 0.5s; }
.bar-lbl  { font-size: 10px; color: #9ca3af; }

/* Admin action buttons */
.action-btns { display: flex; gap: 6px; }
.btn-edit { padding: 4px 10px; background: #eff6ff; color: #3b82f6; border: none; border-radius: 6px; cursor: pointer; font-size: 12px; }
.btn-del  { padding: 4px 10px; background: #fee2e2; color: #ef4444; border: none; border-radius: 6px; cursor: pointer; font-size: 12px; }
.btn-tog  { padding: 4px 10px; border: none; border-radius: 6px; cursor: pointer; font-size: 12px; }

/* Deed selector chips */
.deed-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.deed-chip {
  padding: 10px 8px; background: #f9fafb; border: 2px solid #e5e7eb;
  border-radius: 10px; font-family:var(--font); font-size: 13px; cursor: pointer; color: #374151;
  transition: all 0.15s;
}
.deed-chip.selected { background: var(--gl); border-color: var(--g); color: var(--gd); font-weight: 700; }

/* Progress bar */
.progress-track { background: rgba(255,255,255,0.15); border-radius: 8px; height: 8px; overflow: hidden; }
.progress-fill  { height: 100%; background: #fff; border-radius: 8px; transition: width 1s; }

/* Toast */
#toast-container { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); z-index: 9999; pointer-events: none; }
.toast-msg {
  background: var(--gd); color: #fff; padding: 12px 22px; border-radius: 30px;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  box-shadow: 0 4px 24px rgba(0,0,0,0.2); animation: toastIn 0.3s ease;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 800;
  display: flex; align-items: flex-end; animation: fadeIn 0.2s ease;
}
.modal-sheet {
  position: relative;
  background: #fff; border-radius: 24px 24px 0 0; padding: 24px 20px;
  width: 100%; max-width: 480px; margin: 0 auto;
  animation: slideUp 0.3s ease; max-height: 90vh; overflow-y: auto;
}
.modal-handle { width: 40px; height: 4px; background: #e5e7eb; border-radius: 2px; margin: 0 auto 20px; }
.modal-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 16px; }
.modal-close-btn {
  position: absolute; top: 12px; right: 16px; background: none;
  border: none; font-size: 20px; cursor: pointer; color: #9ca3af;
}

/* Level-up celebration overlay — shown when a student's redeem pushes them into a new badge tier */
.levelup-overlay {
  position: fixed; inset: 0; z-index: 970; cursor: pointer;
  background: radial-gradient(circle at 50% 40%, oklch(0.4 0.15 var(--h) / 0.97), oklch(0.12 0.05 var(--h) / 0.99));
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  overflow: hidden; animation: fadeIn 0.25s ease; text-align: center; padding: 24px;
}
.levelup-confetti-field { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-piece {
  position: absolute; top: -8%; left: var(--x);
  width: var(--sz); height: calc(var(--sz) * 0.42); background: var(--col);
  border-radius: 2px; opacity: 0; will-change: transform, opacity;
  animation: confettiFall var(--dur) ease-in var(--del) forwards;
}
@keyframes confettiFall {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  8%   { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}
.levelup-badge-icon {
  font-size: 92px; line-height: 1; filter: drop-shadow(0 0 24px rgba(255,255,255,0.55));
  animation: levelUpPop 0.6s cubic-bezier(.34,1.56,.64,1);
}
@keyframes levelUpPop {
  0%   { transform: scale(0) rotate(-20deg); opacity: 0; }
  60%  { transform: scale(1.15) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}
.levelup-title {
  color: #fff; font-size: 15px; font-weight: 700; letter-spacing: 3px;
  text-transform: uppercase; margin-top: 18px; opacity: 0.85;
  animation: fadeIn 0.4s ease 0.2s both;
}
.levelup-name {
  color: #fff; font-size: 30px; font-weight: 700; margin-top: 6px;
  animation: fadeIn 0.4s ease 0.35s both;
}
.levelup-hint {
  color: rgba(255,255,255,0.7); font-size: 13px; margin-top: 26px;
  animation: fadeIn 0.4s ease 0.6s both;
}
@media (prefers-reduced-motion: reduce) {
  .confetti-piece { display: none; }
  .levelup-badge-icon, .levelup-title, .levelup-name, .levelup-hint { animation: none; opacity: 1; transform: none; }
}

/* Deed-call alert overlay — ครูเรียกหานักเรียนทำความดี (schema.sql §24), foreground-only via Realtime */
.deedcall-overlay {
  position: fixed; inset: 0; z-index: 970; cursor: pointer;
  background: radial-gradient(circle at 50% 26%, rgba(255,160,66,0.98), rgba(163,64,6,0.99) 78%);
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  overflow: hidden; animation: fadeIn 0.25s ease; text-align: center; padding: 24px;
}
.deedcall-beacon { position: relative; width: 112px; height: 112px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.deedcall-beacon-ring {
  position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(255,255,255,0.5);
  animation: deedcallBeacon 2s ease-out infinite;
}
.deedcall-beacon-ring:nth-child(2) { animation-delay: 0.65s; }
.deedcall-beacon-ring:nth-child(3) { animation-delay: 1.3s; }
@keyframes deedcallBeacon {
  0%   { transform: scale(0.65); opacity: 0.9; }
  100% { transform: scale(1.9); opacity: 0; }
}
.deedcall-ring {
  width: 92px; height: 92px; border-radius: 50%; position: relative; z-index: 1;
  background: radial-gradient(circle, rgba(255,255,255,0.4), rgba(255,255,255,0.12));
  display: flex; align-items: center; justify-content: center; font-size: 46px;
  filter: drop-shadow(0 0 18px rgba(255,255,255,0.5));
  animation: levelUpPop 0.5s cubic-bezier(.34,1.56,.64,1);
}
.deedcall-kicker {
  display: inline-flex; align-items: center; gap: 5px; color: #ad3e08; background: #fff;
  font-weight: 800; font-size: 12px; letter-spacing: 0.04em; margin-top: 18px; padding: 5px 15px;
  border-radius: 20px; box-shadow: 0 3px 12px rgba(0,0,0,0.2);
  animation: fadeIn 0.4s ease 0.15s both;
}
.deedcall-title { color: #fff; font-weight: 800; font-size: 25px; margin-top: 12px; text-shadow: 0 2px 12px rgba(0,0,0,0.18); animation: fadeIn 0.4s ease 0.25s both; }
.deedcall-msg-box {
  background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.28); border-radius: 14px;
  padding: 12px 16px; margin-top: 14px; max-width: 300px; animation: fadeIn 0.4s ease 0.35s both;
}
.deedcall-msg { color: #fff; font-size: 13.5px; line-height: 1.55; }
.deedcall-meta { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 14px; max-width: 300px; animation: fadeIn 0.4s ease 0.45s both; }
.deedcall-chip {
  background: rgba(255,255,255,0.16); color: #fff; font-size: 11.5px; font-weight: 600;
  padding: 5px 12px; border-radius: 20px; display: inline-flex; align-items: center; gap: 4px;
}
.deedcall-actions { display: flex; gap: 10px; margin-top: 24px; width: 100%; max-width: 300px; animation: fadeIn 0.4s ease 0.55s both; }
.deedcall-accept, .deedcall-dismiss {
  flex: 1; padding: 13px 8px; border-radius: 14px; font-family:var(--font); font-weight: 800;
  font-size: 14px; cursor: pointer; border: none;
}
.deedcall-accept { background: #fff; color: #c2540a; box-shadow: 0 4px 18px rgba(0,0,0,0.28); animation: deedcallAcceptPulse 1.6s ease-in-out infinite; }
.deedcall-dismiss { background: rgba(255,255,255,0.14); color: rgba(255,255,255,0.92); }
@keyframes deedcallAcceptPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.035); }
}
@media (prefers-reduced-motion: reduce) {
  .deedcall-ring, .deedcall-beacon-ring, .deedcall-accept { animation: none; }
  .deedcall-kicker, .deedcall-title, .deedcall-msg-box, .deedcall-meta, .deedcall-actions { animation: none; opacity: 1; }
}

/* Loading */
.loading-center { display: flex; align-items: center; justify-content: center; padding: 40px; }
.spinner { display: inline-block; width: 32px; height: 32px; border: 3px solid var(--gl); border-top-color: var(--g); border-radius: 50%; animation: spin 0.8s linear infinite; }

/* Student count badge */
.count-row { display: flex; gap: 10px; margin-bottom: 14px; }
.count-badge { padding: 6px 12px; background: var(--gl); border-radius: 8px; font-size: 12px; color: var(--gd); font-weight: 600; }

/* QR code display */
.qr-display { display: flex; justify-content: center; }
.qr-frame { padding: 8px; border: 2px solid var(--g); border-radius: 12px; display: inline-block; }


/* ── ธีมส่วนตัว (ตั้งค่าที่หน้าโปรไฟล์) ── */
/* ปรับความโค้งมนของการ์ดที่เขียน inline ไว้ 16px ทั่วแอป */
[style*="border-radius:16px"] { border-radius: var(--r-card) !important; }
.content-a { zoom: var(--ui-zoom, 1); }
body.theme-no-fx .leaf, body.theme-no-fx .mascot-bird, body.theme-no-fx .leaf-field { display: none !important; }
body.theme-no-fx .hero-banner::after { animation: none; display: none; }
body.theme-flat .card, body.theme-flat [style*="box-shadow:0 2px 12px"] { box-shadow: none !important; border: 1px solid var(--border); }
body.theme-gradient-bg { background: linear-gradient(180deg, var(--gl), var(--bg) 40%); background-attachment: fixed; }
.theme-chip { padding: 8px 14px; border-radius: 99px; border: 1.5px solid var(--border); background: #fff; font-size: 13px; cursor: pointer; color: #374151; }
.theme-chip.selected { background: var(--gl); border-color: var(--g); color: var(--gd); font-weight: 700; }
.theme-swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px #d1d5db; cursor: pointer; }
.theme-swatch.selected { box-shadow: 0 0 0 3px var(--g); }

/* ── ครู/แอดมิน: ย่อทุกหน้าให้กะทัดรัด (ใช้ !important เพราะหลายหน้ากำหนด padding แบบ inline) ── */
body.staff-compact .screen-wrap { gap: 10px !important; }
body.staff-compact .hero-banner { padding: 14px 16px !important; }
body.staff-compact .card { padding: 12px 14px !important; }
body.staff-compact .list-item { padding: 9px 14px !important; }
body.staff-compact .stat-box { padding: 10px 8px; }
body.staff-compact .stat-icon { font-size: 22px; }
body.staff-compact .stat-val { font-size: 20px; }
body.staff-compact .btn-green { padding-top: 11px !important; padding-bottom: 11px !important; }
body.staff-compact .form-group { margin-bottom: 10px; }
body.staff-compact .form-input { padding-top: 8px; padding-bottom: 8px; }
body.staff-compact .reward-img { height: 54px; font-size: 28px; }
body.staff-compact .reward-body { padding: 8px 10px 10px; }

#install-gate .gate-note { font-size: 12px; color: #9ca3af; }

.compact-form .form-group { margin-bottom: 10px; }
.compact-form .form-input { padding-top: 8px; padding-bottom: 8px; }
