/*
 * กิจกรรมประจำเดือน: ส่วนกลางที่ใช้ทั้งหน้านักเรียน (index.html) และหน้าครู (admin.html)
 * สีทั้งหมดคิดจากเฉดสีหลัก --h (ตั้งใน theme.js ตามธีมสีที่เลือก) และ --pl (ความสว่างของสีหลักโหมดสว่าง)
 * ไฟล์อื่น: ui.css = popup / dropdown / ปฏิทิน / การแสดงผล / เอฟเฟกต์, app.css = หน้านักเรียน (landing + แอปมือถือ)
 */
:root {
  --h: 225;
  --pl: 48%;
  --bg: hsl(var(--h), 45%, 97.5%);
  --bg-2: hsl(var(--h), 40%, 95%);
  --surface: #ffffff;
  --surface-2: hsl(var(--h), 40%, 96.5%);
  --ink: hsl(var(--h), 32%, 13%);
  --muted: hsl(var(--h), 12%, 41%);
  --line: hsl(var(--h), 28%, 89%);
  --primary: hsl(var(--h), 72%, var(--pl));
  --primary-hover: hsl(var(--h), 72%, calc(var(--pl) - 6%));
  --primary-2: hsl(calc(var(--h) + 40), 88%, 62%);
  --primary-ink: #ffffff;
  --primary-soft: hsl(var(--h), 90%, 95%);
  --primary-glow: hsla(var(--h), 85%, 55%, .28);
  --accent: #e2a300;
  --accent-2: #f6c443;
  --accent-soft: #fff4d4;
  --ok: #17804e;
  --ok-soft: #e1f5ea;
  --warn: #8f5600;
  --warn-soft: #fff1d6;
  --danger: #c43333;
  --danger-soft: #fde8e8;
  --top-bg: hsla(var(--h), 45%, 98%, .82);
  --radius: 22px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px hsla(var(--h), 40%, 20%, .05), 0 12px 32px hsla(var(--h), 40%, 25%, .08);
  --shadow-lg: 0 30px 70px hsla(var(--h), 50%, 25%, .16);
  --font: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: 'Mitr', 'IBM Plex Sans Thai', system-ui, sans-serif;
  --nav-h: 66px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.2, .9, .3, 1.35);
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: hsl(var(--h), 28%, 7.5%);
  --bg-2: hsl(var(--h), 24%, 10%);
  --surface: hsl(var(--h), 24%, 11.5%);
  --surface-2: hsl(var(--h), 22%, 15.5%);
  --ink: hsl(var(--h), 25%, 94%);
  --muted: hsl(var(--h), 14%, 68%);
  --line: hsl(var(--h), 20%, 21%);
  --primary: hsl(var(--h), 95%, 74%);
  --primary-hover: hsl(var(--h), 95%, 80%);
  --primary-2: hsl(calc(var(--h) + 40), 92%, 72%);
  --primary-ink: hsl(var(--h), 45%, 9%);
  --primary-soft: hsl(var(--h), 38%, 19%);
  --primary-glow: hsla(var(--h), 95%, 70%, .25);
  --accent: #f6c443;
  --accent-soft: #3a3016;
  --ok: #62d29c;
  --ok-soft: #153126;
  --warn: #f0b759;
  --warn-soft: #382a12;
  --danger: #ff8080;
  --danger-soft: #3d1c1e;
  --top-bg: hsla(var(--h), 28%, 8%, .78);
  --shadow: 0 1px 0 hsla(0, 0%, 100%, .03) inset, 0 14px 34px rgba(0, 0, 0, .3);
  --shadow-lg: 0 30px 70px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 84px; }
body {
  margin: 0; min-height: 100vh;
  background: var(--bg); color: var(--ink);
  font: 16px/1.65 var(--font);
  overflow-x: hidden;
  transition: background-color .35s, color .35s;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-head); font-weight: 500; line-height: 1.35; margin: 0; }
h1 { font-size: clamp(1.45rem, 4.5vw, 2rem); }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--primary); color: var(--primary-ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.grad-text { background: linear-gradient(100deg, var(--primary), var(--primary-2) 55%, var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.wrap-wide { max-width: 1120px; }
.page { display: grid; gap: 16px; padding-top: 20px; padding-bottom: 32px; }
.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 16px; }

.demo-bar { margin: 0; padding: 7px 16px; background: var(--accent-soft); color: var(--warn); font-size: .82rem; text-align: center; }

/* ---------- แถบบน ---------- */
.top {
  position: sticky; top: 0; z-index: 30;
  background: var(--top-bg);
  -webkit-backdrop-filter: blur(14px) saturate(1.4); backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.top-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--font-head); font-size: 1.05rem; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { width: 36px; height: 36px; flex: none; color: var(--primary); filter: drop-shadow(0 6px 12px var(--primary-glow)); transition: transform .4s var(--spring); }
.brand:hover .brand-mark { transform: rotate(-10deg) scale(1.08); }
.top-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); cursor: pointer;
  transition: border-color .15s, color .15s, transform .2s var(--spring), background-color .2s;
}
.icon-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.icon-btn:active:not(:disabled) { transform: scale(.9); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn:focus-visible { outline: 3px solid var(--primary-glow); outline-offset: 2px; }
[data-theme-toggle] .ic { color: var(--accent); transition: transform .5s var(--spring); }
[data-theme-toggle]:active .ic { transform: rotate(90deg) scale(.8); }
[data-appearance] .ic { color: var(--primary); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--muted); white-space: nowrap; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 70%, 100% { box-shadow: 0 0 0 8px transparent; } }

/* ---------- การ์ด ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; transition: background-color .35s, border-color .35s; }
.hero { display: grid; gap: 12px; padding: 24px 20px; position: relative; overflow: hidden; }
.hero::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 5px; background: linear-gradient(90deg, var(--primary), var(--primary-2), var(--accent-2)); background-size: 200% 100%; animation: slide-grad 6s linear infinite; }
@keyframes slide-grad { to { background-position: -200% 0; } }
.hero-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.countdown { font-size: .9rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.question { font-size: clamp(1.1rem, 3.6vw, 1.3rem); line-height: 1.6; white-space: pre-line; padding: 14px 16px; background: var(--primary-soft); border-radius: var(--radius-sm); overflow-wrap: anywhere; }
.question.is-pending { background: var(--surface-2); color: var(--muted); font-size: 1rem; }
.note { color: var(--muted); font-size: .92rem; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px; border-radius: 999px; font-size: .82rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-open { background: var(--ok-soft); color: var(--ok); }
.chip-open::before { animation: pulse-dot 1.6s infinite; }
@keyframes pulse-dot { 50% { opacity: .35; transform: scale(.7); } }
.chip-upcoming, .chip-draft { background: var(--warn-soft); color: var(--warn); }
.eyebrow { font-size: .8rem; font-weight: 600; letter-spacing: .02em; color: var(--muted); }

/* ---------- ฟอร์ม ---------- */
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: .9rem; font-weight: 500; }
.field small { font-size: .8rem; }
input:not([type=checkbox]):not([type=range]), select, textarea {
  width: 100%; min-width: 0;
  padding: 11px 14px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-2); color: var(--ink);
  transition: border-color .15s, box-shadow .2s, background-color .2s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
textarea { resize: vertical; line-height: 1.55; }
input:hover:not(:disabled):not(:focus), textarea:hover:not(:focus) { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 4px var(--primary-glow); }
input:disabled { opacity: .6; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.hint { font-size: .88rem; padding: 8px 12px; border-radius: var(--radius-sm); }
.hint-warn { background: var(--warn-soft); color: var(--warn); }
.hint-error { background: var(--danger-soft); color: var(--danger); }
.hint:not([hidden]) { animation: hint-in .3s var(--ease); }
@keyframes hint-in { from { opacity: 0; transform: translateY(-4px); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 10px 20px;
  border: 1.5px solid transparent; border-radius: 14px;
  font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s, transform .15s, box-shadow .2s, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .chip-btn:focus-visible, .link:focus-visible, .tabs button:focus-visible { outline: 3px solid var(--primary-glow); outline-offset: 2px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 70%, var(--primary-2))); color: var(--primary-ink); box-shadow: 0 8px 20px var(--primary-glow); }
.btn-primary:hover:not(:disabled) { box-shadow: 0 12px 28px var(--primary-glow); transform: translateY(-1px); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.btn-gold { background: linear-gradient(135deg, #ffd66b, #f2a51f); color: #4a2a00; box-shadow: 0 8px 22px rgba(242, 165, 31, .35); }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .88rem; border-radius: 11px; }
.btn-sm .ic { width: 17px; height: 17px; }
.btn-lg { min-height: 54px; padding: 12px 26px; font-size: 1.05rem; border-radius: 16px; }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: .9rem; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.tag .ic { width: 14px; height: 14px; }
.tag-mine { background: var(--primary); color: var(--primary-ink); }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-win { background: linear-gradient(135deg, #ffd66b, #f2a51f); color: #4a2a00; }
.tag-muted { background: var(--surface-2); color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 18px 8px; }

.result-icon { width: 56px; height: 56px; flex: none; border-radius: 18px; display: grid; place-items: center; background: linear-gradient(145deg, #ffd66b, #f2a51f); color: #4a2a00; box-shadow: 0 10px 24px rgba(242, 165, 31, .35); }
.result-icon .ic { width: 30px; height: 30px; }
.result-icon.is-none { background: var(--surface-2); color: var(--muted); box-shadow: none; }

/* ---------- toast + modal ---------- */
.toasts { position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 130; display: grid; justify-items: center; gap: 8px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 440px;
  padding: 10px 16px 10px 10px; border-radius: 16px; background: var(--ink); color: var(--bg);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .25); font-size: .92rem; animation: toast-in .45s var(--spring);
}
.toast i { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 10px; background: rgba(255, 255, 255, .14); flex: none; }
.toast i .ic { width: 18px; height: 18px; }
.toast-success i { background: #22a86a; color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast.is-leaving { opacity: 0; transform: translateY(10px) scale(.96); transition: opacity .3s, transform .3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(18px) scale(.9); } }

.modal { border: 0; padding: 0; border-radius: var(--radius); background: var(--surface); color: var(--ink); width: min(420px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: rgba(10, 12, 24, .5); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.modal[open] { animation: modal-in .35s var(--spring); }
@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(.94); } }
.modal-box { padding: 24px; display: grid; gap: 10px; }
.modal-box p { color: var(--muted); }
.modal-icon { width: 50px; height: 50px; border-radius: 16px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); animation: icon-pop .5s .1s var(--spring) backwards; }
@keyframes icon-pop { from { transform: scale(.3) rotate(-25deg); opacity: 0; } }
.modal-warning .modal-icon { background: var(--warn-soft); color: var(--warn); }
.modal-danger .modal-icon { background: var(--danger-soft); color: var(--danger); }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ---------- แผ่นเมนู (มือถือ) ---------- */
.sheet { border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 85vh; background: transparent; color: var(--ink); }
.sheet::backdrop { background: rgba(10, 12, 24, .55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.sheet[open] .sheet-box { animation: sheet-up .35s cubic-bezier(.2, .9, .25, 1); }
@keyframes sheet-up { from { transform: translateY(100%); } }
.sheet-box { background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 26px 26px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 6px; max-width: 560px; margin: 0 auto; }
.sheet-grip { justify-self: center; display: block; width: 42px; height: 5px; border-radius: 99px; background: var(--line); margin-bottom: 8px; }
.sheet-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 54px; padding: 10px 14px; border-radius: 16px; border: 0; background: var(--bg-2); color: var(--ink); text-decoration: none; font-weight: 500; text-align: left; cursor: pointer; }
.sheet-item .ic { color: var(--primary); }
.sheet-item.is-danger, .sheet-item.is-danger .ic { color: var(--danger); }
.sheet-item:hover { background: var(--surface-2); }
.sheet .btn { margin-top: 6px; }

/* ---------- เมนูล่าง (แบบแอปมือถือ) มีปุ่ม Home วงกลมเด่นตรงกลาง ---------- */
.bottom-nav { display: none; }
@media (max-width: 899px) {
  body.has-nav { padding-bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); }
  .desktop-only { display: none !important; }
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; align-items: flex-end;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding: 0 6px env(safe-area-inset-bottom);
    background: var(--top-bg); -webkit-backdrop-filter: blur(16px) saturate(1.4); backdrop-filter: blur(16px) saturate(1.4);
    border-top: 1px solid var(--line); box-shadow: 0 -10px 30px hsla(var(--h), 40%, 20%, .08);
  }
  .bottom-nav > a, .bottom-nav > button {
    position: relative; flex: 1; min-width: 0; height: var(--nav-h);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    border: 0; background: none; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; cursor: pointer;
    -webkit-tap-highlight-color: transparent; transition: color .2s;
  }
  .bottom-nav > * > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .bottom-nav .ic { width: 23px; height: 23px; transition: transform .35s var(--spring); }
  .bottom-nav .is-current { color: var(--primary); }
  .bottom-nav > .is-current:not(.nav-home) .ic { transform: translateY(-3px) scale(1.12); }
  .bottom-nav > .is-current:not(.nav-home)::before { content: ''; position: absolute; top: 6px; left: 50%; width: 5px; height: 5px; margin-left: -2.5px; border-radius: 50%; background: var(--primary); animation: icon-pop .4s var(--spring); }
  .bottom-nav .badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; display: grid; place-items: center; background: var(--danger); color: #fff; font-size: .66rem; font-weight: 700; font-style: normal; animation: icon-pop .4s var(--spring); }
  .bottom-nav .nav-home { justify-content: flex-end; padding-bottom: 9px; color: var(--ink); }
  .nav-home i {
    position: absolute; top: -28px; left: 50%; transform: translateX(-50%);
    width: 66px; height: 66px; border-radius: 50%; display: grid; place-items: center;
    background: linear-gradient(145deg, var(--primary-2), var(--primary)); color: #fff;
    border: 5px solid var(--bg); box-shadow: 0 12px 26px var(--primary-glow);
    transition: transform .25s var(--spring), box-shadow .3s;
  }
  .nav-home i::after { content: ''; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--primary); opacity: 0; }
  .nav-home.is-current i::after { animation: ring 2.4s ease-out infinite; }
  @keyframes ring { 0% { transform: scale(.95); opacity: .6; } 80%, 100% { transform: scale(1.35); opacity: 0; } }
  .nav-home i .ic { width: 29px; height: 29px; stroke-width: 2.3; }
  .nav-home:active i { transform: translateX(-50%) scale(.9); }
  .nav-home.is-current { color: var(--primary); }
  .bottom-nav > :focus-visible { outline: 3px solid var(--primary-glow); outline-offset: -4px; border-radius: 14px; }
  .toasts { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); }
  .has-nav .toasts { bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); }
}

/* ================= หน้าครู ================= */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; position: relative; overflow: hidden; }
.login-bg { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.login-bg::before, .login-bg::after { content: ''; position: absolute; width: 480px; height: 480px; border-radius: 50%; filter: blur(80px); opacity: .45; animation: blob 14s ease-in-out infinite alternate; }
.login-bg::before { background: var(--primary); top: -160px; left: -120px; }
.login-bg::after { background: var(--primary-2); bottom: -180px; right: -140px; animation-delay: -6s; }
@keyframes blob { to { transform: translate(60px, 40px) scale(1.15); } }
.login-card { position: relative; width: min(400px, 100%); padding: 30px 24px; text-align: center; animation: modal-in .6s var(--spring); }
.login-card .field { text-align: left; }
.login-logo { width: 62px; height: 62px; color: var(--primary); justify-self: center; filter: drop-shadow(0 10px 18px var(--primary-glow)); animation: bob 3s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-4deg); } }
.login-tools { position: absolute; top: 16px; right: 16px; display: flex; gap: 6px; z-index: 2; }
.demo-hint { font-size: .85rem; color: var(--muted); background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px; }
.back-link { font-size: .9rem; }
.is-shake, .fx-shake { animation: shake .45s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; display: inline-flex; align-items: center; gap: 8px; flex: none;
  padding: 10px 14px 12px; border: 0; background: none;
  color: var(--muted); font-weight: 600; cursor: pointer; transition: color .2s;
}
.tabs button::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transform: scaleX(0); transition: transform .35s var(--spring); }
.tabs button:hover { color: var(--ink); }
.tabs button.is-active { color: var(--primary); }
.tabs button.is-active::after { transform: none; }

.panel-in > * { animation: panel-in .5s var(--ease) backwards; }
.panel-in > :nth-child(2) { animation-delay: .06s; }
.panel-in > :nth-child(3) { animation-delay: .12s; }
.panel-in > :nth-child(4) { animation-delay: .18s; }
.panel-in > :nth-child(n+5) { animation-delay: .24s; }
@keyframes panel-in { from { opacity: 0; transform: translateY(16px); } }

.admin-hero { background: radial-gradient(600px 220px at 100% 0%, var(--primary-soft), transparent 70%), var(--surface); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.announce-state { font-size: .88rem; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { position: relative; overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; display: grid; gap: 2px; min-width: 0; box-shadow: var(--shadow); transition: transform .25s var(--spring), border-color .2s; }
.tile:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); }
.tile-ic { position: absolute; right: 12px; top: 12px; width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.tile-ic .ic { width: 18px; height: 18px; }
.tile-label { font-size: .82rem; color: var(--muted); padding-right: 40px; }
.tile-value { font-family: var(--font-head); font-weight: 500; font-size: 1.7rem; line-height: 1.2; font-variant-numeric: tabular-nums; }

.winner { display: flex; align-items: center; gap: 16px; }
.winner h2 { font-size: 1.4rem; overflow-wrap: anywhere; }
.winner.is-found { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%); }
.winner.is-found .result-icon { animation: trophy 2.6s ease-in-out infinite; }
@keyframes trophy { 0%, 100% { transform: rotate(0); } 8% { transform: rotate(-12deg) scale(1.08); } 16% { transform: rotate(10deg) scale(1.08); } 24% { transform: rotate(0) scale(1); } }

.table-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { position: relative; border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 13px; font-size: .85rem; font-weight: 600; cursor: pointer; color: var(--muted); transition: background-color .2s, color .2s, border-color .2s, transform .2s var(--spring); }
.chip-btn:hover { border-color: var(--primary); color: var(--primary); }
.chip-btn:active { transform: scale(.94); }
.chip-btn span { font-variant-numeric: tabular-nums; opacity: .8; }
.chip-btn.is-active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); box-shadow: 0 6px 14px var(--primary-glow); }
.table-wrap { margin-top: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .8rem; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr { transition: background-color .2s; animation: row-in .4s var(--ease) backwards; animation-delay: calc(var(--i, 0) * 30ms); }
@keyframes row-in { from { opacity: 0; transform: translateX(-8px); } }
.table tbody tr:hover td { background: var(--surface-2); }
.table td time { font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.is-win td { background: var(--accent-soft); }
.table tr.is-hidden td { color: var(--muted); }
.table tr.is-hidden .t-answer { text-decoration: line-through; }
.t-answer { font-weight: 600; overflow-wrap: anywhere; }
.t-actions { text-align: right; width: 1%; white-space: nowrap; }
.t-result { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; }
.mark { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: .85rem; }
.mark .ic { width: 16px; height: 16px; }
.mark-ok { color: var(--ok); }
.mark-no { color: var(--muted); }

.save-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.save-bar [data-dirty] { margin-right: auto; }
.save-bar .is-dirty { color: var(--warn); font-weight: 600; animation: hint-in .3s var(--ease); }

.history { display: grid; gap: 10px; margin-top: 14px; }
.h-item { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); transition: border-color .2s, box-shadow .2s; }
.h-item:hover, .h-item[open] { border-color: color-mix(in srgb, var(--primary) 40%, var(--line)); box-shadow: var(--shadow); }
.h-item summary { display: grid; grid-template-columns: 150px 1fr auto auto; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; list-style: none; }
.h-item summary::-webkit-details-marker { display: none; }
.h-item summary > .ic { color: var(--muted); transition: transform .3s var(--spring); }
.h-item[open] summary > .ic { transform: rotate(180deg); }
.h-month { font-size: .85rem; font-weight: 600; color: var(--muted); }
.h-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-win { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: .9rem; }
.h-win .ic { color: var(--accent); width: 18px; height: 18px; }
.h-body { padding: 0 16px 14px; display: grid; gap: 8px; }
.h-item[open] .h-body { animation: hint-in .35s var(--ease); }
.h-answers { margin: 0; padding-left: 22px; display: grid; gap: 4px; font-size: .92rem; }
.h-answers li.is-correct b { color: var(--ok); }

@media (max-width: 899px) {
  .admin .top-in { min-height: 58px; }
  .admin .tabs { display: none; }
  .admin .top-actions [data-logout] { display: none; }
  .admin .top .live { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
}
@media (max-width: 720px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { border: 1px solid var(--line); border-radius: 16px; padding: 6px 4px; margin-bottom: 10px; }
  .table-cards tr.is-win { background: var(--accent-soft); }
  .table-cards td { border: 0; padding: 5px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; background: transparent !important; }
  .table-cards td[data-label]::before { content: attr(data-label); flex: 0 0 76px; font-size: .78rem; color: var(--muted); font-weight: 600; }
  .table-cards .t-actions { text-align: left; width: 100%; }
  .h-item summary { grid-template-columns: 1fr auto auto; }
  .h-item .h-title { grid-column: 1 / -1; grid-row: 2; white-space: normal; }
}
@media (max-width: 480px) {
  .card { padding: 16px; }
  .hero { padding: 20px 16px; }
  .actions .btn { width: 100%; }
  .winner { align-items: flex-start; }
  .result-icon { width: 46px; height: 46px; border-radius: 14px; }
  .modal-actions .btn { flex: 1; }
  .save-bar .btn { flex: 1; }
  .save-bar [data-dirty] { flex-basis: 100%; }
}

/* ---------- ปิดแอนิเมชัน (ผู้ใช้ปิดเอง หรือเครื่องตั้งลดการเคลื่อนไหว) ---------- */
[data-fx="off"] *, [data-fx="off"] *::before, [data-fx="off"] *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
