:root {
  --bg: #f3f7ff;
  --ink: #1e293b;
  --muted: #64748b;
  --card: #ffffff;
  --ring: rgba(59, 130, 246, 0.35);
  --shadow: 0 10px 30px -12px rgba(30, 58, 138, 0.25);
  --radius: 20px;
  /* ลูกศร dropdown ของ <select> (แทน native OS arrow) — chevron สี --muted, inline SVG (CSP-safe) */
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

/* attribute hidden ต้องซ่อนเสมอ — กัน display ที่ตั้งเอง (เช่น .container.manage, .ud-item) มาทับ
   ป้องกันส่วนจัดการ/เมนู admin หลุดมาโผล่ทั้งที่ตั้ง hidden ไว้ */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

/* ---------- Form controls: baseline กันหลุดธีม + ลูกศร <select> เอง (ทั้งแอป) ----------
   :where() = specificity 0 → "ไม่มีทาง" override กฎเดิม (.field/.rec-toolbar/.rec-report-controls ฯลฯ)
   ทำหน้าที่รับเฉพาะ control ที่ไม่มีใคร style ให้ตกมาใช้ธีมนี้แทน browser default (กันหลุดในอนาคต)
   checkbox/radio/color/file/range/hidden เว้นไว้ (มีสไตล์เฉพาะของตัวเอง) */
:where(
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]):not([type="range"]):not([type="hidden"]),
  select, textarea
) {
  padding: 9px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background-color: #fff;
}
:where(
  input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]):not([type="range"]):not([type="hidden"]),
  select, textarea
):focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--ring);
}
/* <select> ทุกตัวในแอป: ตัด native OS dropdown chrome ทิ้ง (appearance ไม่มีใคร set → กฎนี้ชนะเสมอ)
   chevron/padding เป็น fallback สำหรับ select ที่ไม่มี container rule; ตัวที่มี container (พื้น #fff)
   จะได้ chevron จากกฎท้าย records.css ที่ specificity ตรงกันแทน */
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 8px;
  padding-right: 34px;
  cursor: pointer;
}

/* ---------- สถานะกำลังโหลดของปุ่ม/ลิงก์ (แสดงเฉพาะตอนรอเครือข่ายจริง) ---------- */
.ui-spinner {
  display: inline-block;
  width: 1.05em;
  height: 1.05em;
  border: 2px solid currentColor;   /* สีตามข้อความปุ่ม → คอนทราสต์กับทุกสไตล์ปุ่ม */
  border-right-color: transparent;
  border-radius: 50%;
  animation: ui-spin 0.6s linear infinite;
  vertical-align: -0.15em;
}
@keyframes ui-spin { to { transform: rotate(360deg); } }
.is-loading { cursor: default; pointer-events: none; }
/* พื้นที่ที่กำลังรอ (เช่น ปุ่ม Google ที่เป็น iframe ครอบ spinner ไม่ได้) — หรี่+กันคลิก */
.is-loading-area { position: relative; opacity: 0.55; pointer-events: none; }
.is-loading-area::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border: 2px solid #6366f1; border-right-color: transparent; border-radius: 50%; animation: ui-spin 0.6s linear infinite;
}
@media (prefers-reduced-motion: reduce) { .ui-spinner, .is-loading-area::after { animation-duration: 1.3s; } }

body {
  margin: 0;
  font-family: "Sarabun", system-ui, sans-serif;
  color: var(--ink);
  background: #f6f3fb; /* ฐานครีมม่วงของธีมพาสเทล — เลเยอร์ไล่เฉด/ลายอยู่ที่ body::before */
  line-height: 1.6;
  overflow-x: hidden;
}

/* ---------- ธีมพื้นหลังพาสเทล "กระดาษสมุดครู" (ทั้งแอป รวมหน้าเข้าระบบ) ----------
   ชั้นบน→ล่าง: doodle อุปกรณ์ครู (7%) → เส้นตารางกระดาษสมุด → ไล่เฉดชมพู/ลาเวนเดอร์/ฟ้า/มินต์ตามมุม
   ใช้ ::before แบบ fixed แทน background-attachment: fixed ที่มือถือ (Safari) ไม่รองรับ */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    url("/assets/bg-doodle.svg"),
    linear-gradient(rgba(99, 102, 241, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99, 102, 241, 0.045) 1px, transparent 1px),
    radial-gradient(58% 52% at 8% 0%, #fbdfee 0%, rgba(251, 223, 238, 0) 64%),
    radial-gradient(52% 48% at 92% 6%, #dceafc 0%, rgba(220, 234, 252, 0) 62%),
    radial-gradient(52% 46% at 52% 32%, #e8e3fa 0%, rgba(232, 227, 250, 0) 66%),
    radial-gradient(56% 52% at 6% 96%, #dcf5e8 0%, rgba(220, 245, 232, 0) 60%),
    radial-gradient(52% 52% at 94% 92%, #fbdfee 0%, rgba(251, 223, 238, 0) 58%);
  background-size: 280px 280px, 56px 56px, 56px 56px, 100% 100%, 100% 100%, 100% 100%, 100% 100%, 100% 100%;
}

.container {
  width: min(1120px, 92vw);
  margin-inline: auto;
}

/* ---------- navbar ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(99, 102, 241, 0.12);
}
.navbar-inner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
}
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); margin-right: auto; }
.brand-logo { border-radius: 50%; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-family: "Prompt", sans-serif; font-weight: 600; font-size: 1.05rem; }
.brand-text small { color: var(--muted); font-size: 0.78rem; display: none; }

/* ---- top-bar menu (mobile-first: base = dropdown ใต้ hamburger) ---- */
.nav-menu {
  list-style: none; margin: 0;
  display: none;
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  flex-direction: column; align-items: stretch; gap: 2px;
  background: #fff; border: 1px solid rgba(99, 102, 241, 0.14);
  border-radius: 16px; padding: 10px;
  box-shadow: 0 18px 36px -18px rgba(15, 23, 42, 0.45);
}
.nav-menu.open { display: flex; }
.nav-link {
  font-family: "Prompt", sans-serif;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover { background: rgba(99, 102, 241, 0.1); }
.nav-link.is-current { color: #4338ca; background: rgba(99, 102, 241, 0.1); }
.nav-link.is-soon { color: var(--muted); cursor: default; }
.nav-link.is-soon:hover { background: none; }
.nav-link em {
  font-style: normal;
  font-size: 0.62rem;
  font-weight: 600;
  background: #fde68a;
  color: #92400e;
  padding: 1px 7px;
  border-radius: 999px;
  letter-spacing: 0.2px;
}

.nav-right { display: flex; align-items: center; gap: 10px; }
/* ปุ่มกลับเข้าโซนสมาชิก (โชว์เมื่อล็อกอินแล้วและอยู่หน้าเว็บสาธารณะ) */
.btn-member-home {
  font-family: "Prompt", sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  padding: 8px 16px;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 6px 14px -6px rgba(99, 102, 241, 0.65);
  transition: filter 0.15s ease;
}
.btn-member-home:hover { filter: brightness(1.07); }
body.is-member #btn-member-home { display: none; }
.btn-login {
  font-family: "Prompt", sans-serif;
  font-weight: 600;
  font-size: 0.88rem;
  color: #4338ca;
  background: #fff;
  border: 1.5px solid rgba(99, 102, 241, 0.4);
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}
.btn-login:hover { background: rgba(99, 102, 241, 0.08); }

/* ---- hamburger (mobile-first: base = แสดง, เดสก์ท็อปซ่อน) ---- */
.nav-toggle {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1.5px solid rgba(99, 102, 241, 0.25);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.nav-toggle span { display: block; width: 18px; height: 2px; margin: 0 auto; background: var(--ink); border-radius: 2px; transition: transform 0.2s ease, opacity 0.2s ease; }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* เดสก์ท็อป: เมนูเป็นแถวแนวนอนใน topbar, ซ่อน hamburger */
@media (min-width: 1025px) {
  .nav-toggle { display: none; }
  .nav-menu {
    display: flex;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }
  .nav-link { padding: 8px 14px; }
  .nav-link.is-current { background: rgba(99, 102, 241, 0.12); }
}

/* ---------- animated background ---------- */
.bg-blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.55;
  animation: float 18s ease-in-out infinite;
}
.blob-1 { width: 420px; height: 420px; background: #60a5fa; top: -120px; left: -80px; }
.blob-2 { width: 360px; height: 360px; background: #f0abfc; top: 120px; right: -100px; animation-delay: -6s; }
.blob-3 { width: 340px; height: 340px; background: #6ee7b7; bottom: -120px; left: 30%; animation-delay: -12s; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(20px, -30px) scale(1.08); }
}

/* ---------- hero (เวทีเกมพาสเทล — พื้นหลังคือ .hg-stage จาก hero-game.css/js) ---------- */
.hero {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  /* เต็มหน้าจอแรก (ลบความสูง topbar ~64px) — dvh กัน address bar มือถือ; มี fallback vh */
  min-height: calc(100vh - 64px);
  min-height: calc(100dvh - 64px);
  text-align: center;
  padding: 40px 0 44px;
  color: var(--ink);
  border-radius: 0 0 36px 36px;
  border-bottom: 1px solid rgba(99, 102, 241, 0.16);
  box-shadow: 0 20px 50px -30px rgba(99, 102, 241, 0.45);
}
.hero-content { position: relative; z-index: 1; }
.hero-logo {
  display: block;
  width: 80px;
  height: 80px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: #fff;
  padding: 6px;
  box-shadow: 0 10px 28px -14px rgba(15, 23, 42, 0.45);
}
.hero-badge {
  display: inline-block;
  font-family: "Prompt", sans-serif;
  font-weight: 500;
  color: #4338ca;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(99, 102, 241, 0.25);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  backdrop-filter: blur(6px);
}
.hero-title {
  font-family: "Prompt", sans-serif;
  font-weight: 700;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  margin: 16px 0 8px;
  letter-spacing: -0.5px;
  /* headline ไล่เฉดฟ้า→ม่วง→ชมพู โทนเดียวกับเวทีเกมด้านหลัง
     — สีทึบเป็น fallback ก่อน, เบราว์เซอร์ที่รองรับ background-clip:text ค่อยทับด้วยไล่เฉด */
  color: #7c3aed;
  background: linear-gradient(90deg, #0284c7 0%, #7c3aed 55%, #db2777 100%);
  padding-bottom: 0.1em;
}
/* ทาไล่เฉดลงตัวอักษรเฉพาะเบราว์เซอร์ที่รองรับจริง — ที่ไม่รองรับจะเห็นสีทึบด้านบนแทน (ไม่โปร่งใสหาย) */
@supports ((-webkit-background-clip: text) or (background-clip: text)) {
  .hero-title {
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}
.hero-sub { font-size: clamp(1rem, 2vw, 1.18rem); margin: 0 auto; max-width: 640px; color: #334155; }
.hero-sub strong { font-weight: 600; }
/* สีเข้มพอผ่าน AA บนพื้นพาสเทลสว่างของเวทีเกม (พื้นเดิมเข้ม/ตัวอักษรขาว เปลี่ยนเป็นพื้นสว่างแล้ว) */
.hero-sem { margin: 10px 0 0; font-size: 0.95rem; color: #475569; }
.hero-hint {
  margin: 16px 0 0;
  font-family: "Prompt", sans-serif;
  font-size: 0.8rem;
  color: #6d28d9;
  opacity: 0.9;
}
/* จอสัมผัส (ไม่มีเมาส์): สลับคำชวนจาก "กวาดเมาส์" เป็น "แตะ" — แตะจับลูกแก้วได้เลย */
.hero-hint .hint-touch { display: none; }
@media (hover: none) {
  .hero-hint .hint-mouse { display: none; }
  .hero-hint .hint-touch { display: inline; }
}

.search-wrap {
  position: relative;
  width: min(560px, 90%);
  margin: 28px auto 0;
}
.search-wrap .search-icon {
  position: absolute; left: 18px; top: 50%; transform: translateY(-50%);
  width: 20px; height: 20px; color: var(--muted);
}
#search {
  width: 100%;
  padding: 16px 20px 16px 50px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  box-shadow: var(--shadow);
  outline: none;
}
#search:focus { box-shadow: 0 0 0 4px var(--ring), var(--shadow); }

/* ---------- section heading ---------- */
.forms-section { scroll-margin-top: 76px; padding-top: 18px; }
.section-head { text-align: center; margin-top: 24px; }
.section-title {
  font-family: "Prompt", sans-serif;
  font-weight: 700;
  font-size: clamp(1.5rem, 3vw, 2rem);
  margin: 0 0 6px;
  color: var(--ink);
}
.section-desc { color: var(--muted); margin: 0; }
.section-desc strong { color: var(--ink); font-weight: 600; }

/* ---------- chips ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 28px 0 28px;
}
.chip {
  font-family: "Prompt", sans-serif;
  font-size: 0.92rem;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1.5px solid #e2e8f0;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}
.chip:hover { transform: translateY(-2px); border-color: var(--accent, #3b82f6); color: var(--ink); }
.chip.active {
  background: var(--accent, #3b82f6);
  border-color: var(--accent, #3b82f6);
  color: #fff;
  box-shadow: 0 8px 18px -8px var(--accent, #3b82f6);
}

/* ---------- grid & cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 22px;
  padding-bottom: 60px;
}
.card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 22px 20px;
  box-shadow: var(--shadow);
  border: 1px solid #eef2ff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: rise 0.5s ease backwards;
}
.card::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 5px;
  background: var(--accent);
}
.card:hover { transform: translateY(-5px); box-shadow: 0 22px 40px -18px rgba(30, 58, 138, 0.4); }
.card { transition: transform 0.2s ease, box-shadow 0.2s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.card-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.card-icon {
  font-size: 1.5rem;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: var(--accent-soft);
  flex-shrink: 0;
}
.card-code {
  font-family: "Prompt", sans-serif;
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 999px;
}
.card-title {
  font-family: "Prompt", sans-serif;
  font-weight: 600;
  font-size: 1.06rem;
  margin: 0 0 6px;
  color: var(--ink);
  line-height: 1.35;
}
.card-desc { font-size: 0.92rem; color: var(--muted); margin: 0 0 18px; flex: 1; }

.card-actions { display: grid; grid-template-columns: 1fr; gap: 9px; }
.card-actions .btn-view { grid-column: 1 / -1; }
.btn {
  font-family: "Prompt", sans-serif;
  font-weight: 500;
  font-size: 0.9rem;
  text-align: center;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: all 0.16s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.btn:hover { transform: translateY(-2px); }
.btn-view { background: var(--accent); color: #fff; }
.btn-view:hover { filter: brightness(1.06); box-shadow: 0 10px 20px -10px var(--accent); }
.btn-pdf { background: #fee2e2; color: #b91c1c; }
.btn-pdf:hover { background: #fecaca; }
.btn-docx { background: #dbeafe; color: #1d4ed8; }
.btn-docx:hover { background: #bfdbfe; }
/* ไฟล์ที่ยังไม่มี — แสดงเป็นปุ่ม disabled ชัดเจน (สีเทาทึบ + cursor ห้ามกด) */
.btn[data-missing="true"] {
  background: #eef2f6;
  color: #9aa6b2;
  box-shadow: none;
  cursor: not-allowed;
}
.btn[data-missing="true"]:hover { transform: none; filter: none; background: #eef2f6; box-shadow: none; }

/* ---------- empty ---------- */
.empty { text-align: center; color: var(--muted); font-size: 1.1rem; padding: 50px 0; }

/* ---------- footer (พื้นขาวแบบ topbar) ---------- */
.footer {
  text-align: center;
  padding: 40px 0 48px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(99, 102, 241, 0.14);
  margin-top: 40px;
}
.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  margin-bottom: 14px;
}
.footer-brand img { border-radius: 50%; }
.footer-brand strong { display: block; font-family: "Prompt", sans-serif; font-weight: 600; color: var(--ink); font-size: 1rem; }
.footer-brand span { font-size: 0.85rem; }
.footer p { margin: 4px 0; }
.footer-copy { font-size: 0.9rem; }
.footer-powered { font-size: 0.85rem; opacity: 0.9; }
.footer-powered a { color: #4338ca; font-weight: 600; text-decoration: none; }
.footer-powered a:hover { text-decoration: underline; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 4vw; }
.modal[hidden] { display: none; }
/* ย้อมม่วงลาเวนเดอร์ให้ธีมพาสเทลเรืองผ่าน blur (เดิมเป็นเทาหินเข้ม) */
.modal-backdrop { position: absolute; inset: 0; background: rgba(74, 62, 138, 0.42); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  background: #fff;
  width: min(860px, 96vw);
  height: min(88vh, 1000px);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.5);
  animation: pop 0.25s ease;
}
@keyframes pop { from { opacity: 0; transform: scale(0.96); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid #eef2ff;
}
.modal-head h3 { font-family: "Prompt", sans-serif; font-size: 1.05rem; margin: 0; padding-right: 12px; }
.icon-btn {
  background: #f1f5f9; border: none; border-radius: 10px;
  width: 36px; height: 36px; font-size: 1rem; cursor: pointer; color: var(--muted);
  flex-shrink: 0;
}
.icon-btn:hover { background: #e2e8f0; }
#modal-frame { flex: 1; border: none; width: 100%; background: #f8fafc; }
.modal-foot { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid #eef2ff; }
.modal-foot .btn { flex: 1; }

/* ===== mobile-first: ขยายขึ้นจอใหญ่ ===== */
@media (min-width: 481px) {
  .hero { padding: 48px 0 40px; }
  .hero-logo { width: 96px; height: 96px; }
  .card-actions { grid-template-columns: 1fr 1fr; }
  .brand-text small { display: block; }
}
