/* ============================================================
   เกมตอบคำถามจากบทเรียน — สไตล์หลัก
   ============================================================ */
:root {
  --bg: #f2f4fb;
  --card: #ffffff;
  --ink: #1e2433;
  --muted: #6b7280;
  --border: #e5e7f0;
  --primary: #7c3aed;
  --primary-2: #4f46e5;
  --danger: #e11d48;
  --success: #16a34a;
  --warn: #f59e0b;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(31, 38, 82, .10);
  --shadow-lg: 0 18px 50px rgba(31, 38, 82, .18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Prompt', 'Tahoma', sans-serif;
  background:
    radial-gradient(1200px 500px at 85% -10%, #ede9fe 0%, transparent 60%),
    radial-gradient(900px 460px at -10% 10%, #e0f2fe 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 16px;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { font-family: 'Kanit', 'Prompt', sans-serif; letter-spacing: .2px; }

a { color: var(--primary); text-decoration: none; }

.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 20px; }
.container.narrow { max-width: 640px; }
.container.wide { max-width: 1280px; }

.main { flex: 1; display: flex; flex-direction: column; }
.main > .container:first-child { padding-top: 28px; }

/* ---------- Navbar ---------- */
.navbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-family: 'Kanit', sans-serif; font-weight: 700; font-size: 20px; color: var(--ink); }
.brand span { background: linear-gradient(90deg, var(--primary), var(--primary-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.nav-links { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.nav-links > a {
  padding: 8px 14px; border-radius: 999px; font-size: 14.5px; color: var(--ink);
  border: 1px solid transparent; transition: .15s;
}
.nav-links > a:hover { background: #eee9ff; }
.nav-links > a.active { background: var(--primary); color: #fff; }
.nav-links a.nav-admin { background: #fff7ed; border-color: #fed7aa; color: #c2410c; }
.nav-links a.nav-admin:hover { background: #ffedd5; }

/* Block ผู้ใช้ (ขวา) */
.nav-user-block { display: flex; align-items: center; gap: 8px; padding-left: 14px; margin-left: 4px; border-left: 1px solid var(--border); flex-wrap: wrap; }
.nav-user { display: inline-flex; align-items: center; gap: 8px; padding: 4px 14px 4px 4px; border-radius: 999px; border: 1px solid var(--border); background: #faf9ff; color: var(--ink); font-size: 14.5px; transition: .15s; }
.nav-user:hover { border-color: var(--primary); background: #f3efff; }
.nav-user .avatar-nav { width: 28px; height: 28px; font-size: 16px; border-radius: 9px; margin: 0; vertical-align: 0; box-shadow: inset 0 0 0 1px rgba(109, 40, 217, .08); }
.nav-user-name { font-weight: 600; line-height: 1.3; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-role { font-size: 11px; font-weight: 700; color: #6d28d9; background: #f3e8ff; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.nav-logout { padding: 8px 14px; border-radius: 999px; font-size: 14px; color: #dc2626; border: 1px solid #fecaca; background: #fff; transition: .15s; white-space: nowrap; }
.nav-logout:hover { background: #fef2f2; border-color: #fca5a5; }
.nav-login { padding: 8px 14px; border-radius: 999px; font-size: 14.5px; color: var(--ink); border: 1px solid var(--border); }
.nav-login:hover { background: #eee9ff; }
.nav-register { padding: 8px 16px; border-radius: 999px; font-size: 14.5px; color: #fff; background: var(--primary); }
.nav-register:hover { background: var(--primary-2); }

/* ---------- Flash ---------- */
.flash { padding: 12px 20px; font-size: 15px; }
.flash-success { background: #dcfce7; color: #166534; border-bottom: 1px solid #bbf7d0; }
.flash-error { background: #fee2e2; color: #991b1b; border-bottom: 1px solid #fecaca; }
.flash-info { background: #e0f2fe; color: #075985; border-bottom: 1px solid #bae6fd; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: 'Prompt', sans-serif; font-weight: 500; font-size: 15px;
  padding: 10px 20px; border-radius: 14px; border: 1px solid transparent;
  cursor: pointer; transition: .18s; background: #f0f1f8; color: var(--ink); line-height: 1.2;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border: 2px solid #d5d8e6; color: var(--ink); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-dark { background: #1f2937; color: #fff; }
.btn-danger { background: #fee2e2; border-color: #fecaca; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }
.btn-lg { padding: 14px 32px; font-size: 17px; border-radius: 16px; }
.btn-xs { padding: 5px 10px; font-size: 12.5px; border-radius: 9px; }
.btn-block { width: 100%; }
.btn-time {
  background: #fff; border: 2px solid #d8dbea; border-radius: 14px;
  padding: 10px 18px; font-size: 18px; font-weight: 600; color: var(--primary);
}
.btn-time:hover { border-color: var(--primary); background: #f5f0ff; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
@media (min-width: 600px) { .grid-cards { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }

.card-btn {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 22px 14px; text-align: center; color: var(--ink);
  border-top: 4px solid var(--card-color, var(--primary));
  transition: .2s;
}
.card-btn:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--card-color, var(--primary)); }
.card-btn.chosen { outline: 3px solid var(--card-color, var(--primary)); background: #f7f6ff; }
.card-emoji { font-size: 34px; line-height: 1; }
.card-name { font-weight: 700; font-size: 16px; }
.card-sub { color: var(--muted); font-size: 13px; }
.card-badge { margin-top: 4px; font-size: 12px; color: var(--muted); }

.grid-sets { display: grid; gap: 16px; }
.set-card { display: flex; flex-direction: column; gap: 14px; }
.set-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.set-name { font-size: 19px; }
.set-desc { color: var(--muted); font-size: 14px; margin-top: 2px; }
.set-count { flex-shrink: 0; background: #f3e8ff; color: #6d28d9; font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px; }
.set-times { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border-top: 1px dashed var(--border); padding-top: 14px; }
.set-times-label { font-size: 14px; color: var(--muted); margin-right: 2px; }

.empty-state { text-align: center; padding: 34px 22px; color: var(--muted); }
.empty-state p { margin-bottom: 14px; }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #2b0e5c 0%, #6d28d9 55%, #4f46e5 100%);
  color: #fff; padding: 72px 0 56px;
}
.hero-inner { position: relative; z-index: 2; text-align: center; }
.hero-badge {
  display: inline-block; padding: 8px 18px; border-radius: 999px;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.3);
  font-size: 14px; margin-bottom: 22px;
}
.hero-title { font-size: clamp(30px, 6vw, 52px); font-weight: 900; line-height: 1.15; }
.hero-title .dot { color: #fbbf24; }
.hero-sub { margin: 18px auto 28px; color: #e9e2ff; font-size: 17px; max-width: 560px; }
.hero-actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.hero-stats { display: flex; gap: 34px; justify-content: center; margin-top: 44px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stat-num { font-family: 'Kanit', sans-serif; font-weight: 900; font-size: 30px; color: #fbbf24; }
.stat-label { font-size: 13px; opacity: .85; }
.hero-shapes { position: absolute; inset: 0; pointer-events: none; }
.shape { position: absolute; font-size: 44px; opacity: .18; animation: floaty 9s ease-in-out infinite; }
.s1 { top: 12%; left: 8%; } .s2 { top: 20%; right: 10%; animation-delay: 1.5s; }
.s3 { bottom: 14%; left: 14%; animation-delay: 3s; } .s4 { top: 55%; right: 22%; animation-delay: 2s; }
.s5 { bottom: 20%; right: 8%; animation-delay: 4s; } .s6 { top: 10%; left: 42%; animation-delay: 2.5s; }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-18px); } }

/* ---------- Features ---------- */
.features { display: grid; gap: 18px; margin: -30px 0 10px; position: relative; z-index: 5; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.feature-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 26px 22px; box-shadow: var(--shadow); }
.feature-icon { font-size: 34px; margin-bottom: 10px; }
.feature-card h3 { font-size: 18px; margin-bottom: 6px; }
.feature-card p { color: var(--muted); font-size: 14.5px; }

.section { margin: 40px 0; }
.section-title { font-size: 24px; margin-bottom: 18px; }

/* ---------- Leaderboard ---------- */
.leaderboard { display: grid; gap: 10px; }
.lb-row {
  display: flex; align-items: center; gap: 14px; background: #fff;
  border: 1px solid var(--border); border-radius: 14px; padding: 13px 18px; box-shadow: var(--shadow);
}
.lb-rank { font-size: 24px; width: 34px; text-align: center; }
.lb-name { font-weight: 700; flex: 1; }
.lb-acc { font-size: 13.5px; color: var(--muted); }
.lb-best { font-weight: 700; color: var(--primary); white-space: nowrap; }
.lb-games { font-weight: 400; color: var(--muted); font-size: 13px; }

/* ---------- CTA ---------- */
.cta-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  background: linear-gradient(120deg, #1f2937, #374151); color: #fff;
  border-radius: 20px; padding: 30px 34px; margin-bottom: 46px;
}
.cta-banner h2 { font-size: 24px; }
.cta-banner p { color: #d1d5db; margin-top: 4px; }

/* ---------- Page head / breadcrumb ---------- */
.page-head { margin: 8px 0 22px; }
.page-head-actions { margin-bottom: 10px; }
.page-head h1 { font-size: 28px; }
.page-head p { color: var(--muted); margin-top: 4px; }
.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 22px; font-size: 14px; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; box-shadow: var(--shadow); }
.crumb-current { color: var(--primary); font-weight: 700; }
.crumb-ok { color: var(--success); }
.crumb-dim { color: var(--muted); }
.crumb-sep { color: #c3c8d8; }

.select-body { display: grid; gap: 30px; }
.select-step { display: grid; gap: 14px; }
.select-label { font-size: 17px; color: #4b5563; display: flex; align-items: center; gap: 10px; }
.select-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---------- Forms ---------- */
.form { display: grid; gap: 16px; }
.form-inline { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 13.5px; font-weight: 600; color: #4b5563; }
.field small { color: var(--muted); font-size: 12px; }
.field input, .field select, .field textarea {
  font-family: 'Prompt', sans-serif; font-size: 15px; padding: 11px 14px;
  border: 2px solid #dde0ec; border-radius: 12px; background: #fff; color: var(--ink); transition: .15s; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124,58,237,.14); }
.field-sm { flex: 0 1 200px; }
.field-grow { flex: 1 1 240px; }
.form-grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.auth-card { text-align: center; margin: 34px 0; }
.auth-icon { font-size: 46px; }
.auth-title { font-size: 26px; margin: 6px 0 2px; }
.auth-sub { color: var(--muted); margin-bottom: 20px; font-size: 15px; }
.auth-card .form { text-align: left; }
.auth-alt { margin-top: 18px; font-size: 14.5px; }
.auth-tip { margin-top: 12px; font-size: 13px; color: var(--muted); }
.auth-tip code { background: #f1f2f8; padding: 2px 6px; border-radius: 6px; }

.filter-bar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); margin-bottom: 18px; }
.filter-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; flex: 1; }
.filter-context { font-size: 14px; color: var(--muted); background: #fff; border: 1px dashed var(--border); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; }
.filter-context strong { color: var(--ink); }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); margin: 4px 0 30px; font-size: 14.5px; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid #eef0f6; vertical-align: top; }
.table th { background: #f9f9ff; font-weight: 700; color: #4b5563; font-size: 13.5px; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #faf9ff; }
.ta-right { text-align: right !important; white-space: nowrap; }
.td-dim { color: var(--muted); }
.td-list { font-size: 13.5px; }
.opt-inline { color: var(--muted); padding: 1px 0; }
.opt-inline.correct { color: var(--success); font-weight: 600; }
.badge { display: inline-block; background: #f3e8ff; color: #6d28d9; font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #b91c1c; }
.badge-dim { background: #f3f4f6; color: #4b5563; }
.badge-link:hover { background: var(--primary); color: #fff; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tab { padding: 8px 16px; border-radius: 999px; background: #fff; border: 1px solid var(--border); color: var(--ink); font-size: 14px; }
.tab:hover { border-color: var(--primary); }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.subject-chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; padding: 5px 12px; border-radius: 999px; background: color-mix(in srgb, var(--sc) 14%, white); color: var(--sc); }

.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.admin-card {
  display: flex; flex-direction: column; gap: 6px; padding: 24px 20px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--ink); transition: .2s;
}
.admin-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--ac); }
.admin-card .ad-icon { font-size: 32px; }
.admin-card strong { font-size: 17px; }
.admin-card small { color: var(--muted); }

.form-card h3 { font-size: 18px; margin-bottom: 16px; }
.inline-form { display: inline-block; }

/* ============================================================
   หน้าเล่นเกม
   ============================================================ */
.game-shell {
  position: relative; min-height: 100vh;
  background: linear-gradient(160deg, #1e1035 0%, #3b1d78 45%, #4f2ba1 100%);
  color: #fff; display: flex; flex-direction: column;
}
.game-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 22px; flex-wrap: wrap;
}
.game-topbar .left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.game-title { display: flex; flex-direction: column; min-width: 0; }
.game-title strong { font-size: 17px; }
.game-title small { color: #cfc3f2; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer-box {
  display: flex; align-items: baseline; gap: 8px;
  background: rgba(255,255,255,.1); border: 2px solid rgba(255,255,255,.25);
  padding: 8px 18px; border-radius: 16px;
}
.timer-box.danger { border-color: #fb7185; background: rgba(225,29,72,.25); animation: pulse .6s infinite alternate; }
.timer-num { font-family: 'Kanit', sans-serif; font-size: 30px; font-weight: 900; min-width: 74px; text-align: center; font-variant-numeric: tabular-nums; }
.timer-label { font-size: 13px; color: #d7cdf6; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.05); } }

.timebar-wrap { height: 8px; background: rgba(255,255,255,.12); }
.timebar {
  height: 100%; width: 100%;
  background: linear-gradient(90deg, #34d399, #fbbf24);
  border-radius: 0 8px 8px 0; transition: width .12s linear;
}
.timebar.danger { background: linear-gradient(90deg, #fb7185, #f43f5e); }

.game-container { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px 40px; }

.question-card {
  background: #fff; color: var(--ink); border-radius: 22px;
  box-shadow: 0 24px 70px rgba(0,0,0,.32);
  padding: 28px; max-width: 780px; width: 100%;
  transition: opacity .18s ease, transform .18s ease;
}
.q-meta { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.q-count { background: var(--primary); color: #fff; font-size: 13px; font-weight: 700; padding: 5px 12px; border-radius: 999px; }
.q-total { color: var(--muted); font-size: 13px; align-self: center; }
.q-text { font-size: 21px; line-height: 1.45; margin-bottom: 22px; }

.options { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .options { grid-template-columns: 1fr 1fr; } }
.option {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: #f6f7fc; border: 2px solid #e4e6f2; border-radius: 14px;
  padding: 13px 16px; font-family: 'Prompt', sans-serif; font-size: 15.5px;
  color: var(--ink); cursor: pointer; transition: .15s; width: 100%;
}
.option:hover:not(:disabled) { border-color: var(--primary); background: #f4f0ff; transform: translateY(-1px); }
.option:disabled { cursor: default; }
.opt-letter {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff; border: 2px solid #d3d7e6; font-weight: 700; color: #4b5563;
}
.opt-text { flex: 1; }
.option-selected { border-color: var(--primary); background: #eee9ff; }
.option-correct { border-color: var(--success); background: #dcfce7; }
.option-correct .opt-letter { background: var(--success); color: #fff; border-color: var(--success); }
.option-wrong { border-color: var(--danger); background: #fee2e2; }
.option-wrong .opt-letter { background: var(--danger); color: #fff; border-color: var(--danger); }

.feedback-banner {
  position: fixed; left: 50%; top: 86px; transform: translate(-50%, -30px);
  z-index: 60; background: #fff; padding: 14px 26px; border-radius: 999px;
  font-weight: 700; font-size: 18px; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; transition: .22s;
}
.feedback-banner.show { opacity: 1; transform: translate(-50%, 0); }
.feedback-banner.good { background: #16a34a; color: #fff; }
.feedback-banner.bad { background: #e11d48; color: #fff; }
.feedback-banner.info { background: #1f2937; color: #fff; }

/* ---------- Overlay นับถอยหลัง / หมดเวลา ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 8, 48, .92); backdrop-filter: blur(8px);
  opacity: 0; pointer-events: none; transition: opacity .3s;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.countdown-inner { text-align: center; }
.countdown-label { font-size: 22px; letter-spacing: 2px; color: #d7cdf6; margin-bottom: 10px; }
.countdown-num {
  font-family: 'Kanit', sans-serif; font-size: clamp(120px, 30vw, 220px);
  font-weight: 900; line-height: 1; color: #fff;
  text-shadow: 0 0 60px rgba(251,191,36, .8);
}
.countdown-num.pop-in { animation: popIn .8s cubic-bezier(.2,1.4,.3,1); }
.countdown-num.go { color: #fbbf24; animation: popIn .6s cubic-bezier(.2,1.4,.3,1); }
@keyframes popIn {
  0% { transform: scale(.2); opacity: 0; }
  55% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.timeup-inner { text-align: center; }
.timeup-title {
  font-family: 'Kanit', sans-serif; font-weight: 900; font-size: clamp(40px, 9vw, 88px);
  color: #ffe4e6; text-shadow: 0 0 60px rgba(244,63,94, .9);
  animation: shake .8s infinite alternate;
}
.timeup-sub { margin-top: 14px; font-size: 18px; color: #fecdd3; }
@keyframes shake { from { transform: rotate(-1.2deg) scale(1); } to { transform: rotate(1.2deg) scale(1.08); } }

/* ---------- จอ พร้อมลุย? ---------- */
.ready-inner { text-align: center; max-width: 560px; }
.ready-emoji { font-size: 64px; animation: floaty 2.4s ease-in-out infinite; }
.ready-title { font-size: 40px; margin-top: 8px; color: #fff; }
.ready-set {
  display: inline-block; margin-top: 12px; padding: 6px 18px; border-radius: 999px;
  background: rgba(251,191,36,.16); border: 1px solid rgba(251,191,36,.5);
  color: #fbbf24; font-weight: 700; font-size: 17px;
}
.ready-sub { color: #e9e2ff; margin-top: 12px; font-size: 15.5px; }
.ready-tip { color: #d7cdf6; margin: 14px 0 26px; font-size: 14.5px; }

.audio-toggle {
  position: fixed; bottom: 18px; right: 18px; z-index: 70;
  width: 48px; height: 48px; border-radius: 50%; border: 2px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.14); color: #fff; font-size: 21px; cursor: pointer;
  backdrop-filter: blur(6px); transition: .15s;
}
.audio-toggle:hover { background: rgba(255,255,255,.26); transform: scale(1.06); }

/* ============================================================
   หน้าสรุปผล
   ============================================================ */
.result-page {
  position: relative; min-height: 100vh;
  background: linear-gradient(160deg, #1e1035 0%, #3b1d78 55%, #4f2ba1 100%);
  padding: 50px 0; overflow: hidden;
}
.result-card { text-align: center; color: var(--ink); }
.result-icon { font-size: 52px; }
.result-title { font-size: 30px; margin: 4px 0; }
.result-set { color: var(--muted); font-size: 14.5px; margin-bottom: 18px; }
.result-score { margin: 20px auto; }
.score-big {
  font-family: 'Kanit', sans-serif; font-size: 86px; font-weight: 900; line-height: 1;
  background: linear-gradient(135deg, #fbbf24, #f97316); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.score-label { color: var(--muted); }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 22px 0; }
.res-item { background: #f7f8fc; border: 1px solid var(--border); border-radius: 14px; padding: 14px 8px; display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; color: var(--muted); }
.res-num { font-family: 'Kanit', sans-serif; font-size: 26px; font-weight: 900; color: var(--ink); }
.result-grade { border-radius: 14px; padding: 14px; font-size: 15px; margin-bottom: 22px; }
.grade-great { background: #dcfce7; color: #166534; }
.grade-good { background: #dbeafe; color: #1e40af; }
.grade-ok { background: #fef3c7; color: #92400e; }
.grade-low { background: #fee2e2; color: #991b1b; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.result-actions form { margin: 0; }

.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti-piece {
  position: absolute; top: -16px; width: 10px; height: 16px; border-radius: 2px;
  opacity: .8; animation: fall linear infinite;
}
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

/* ============================================================
   ประวัติการเล่น
   ============================================================ */
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.history-card { display: flex; flex-direction: column; gap: 8px; color: var(--ink); transition: .2s; }
.history-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.history-top { display: flex; justify-content: space-between; align-items: center; }
.history-icon { font-size: 30px; }
.history-score { font-family: 'Kanit', sans-serif; font-size: 24px; font-weight: 900; color: var(--primary); }
.history-score small { font-size: 12px; font-weight: 400; color: var(--muted); }
.history-name { font-size: 17px; }
.history-topic { color: var(--muted); font-size: 13.5px; }
.history-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.history-meta span { background: #f2f3f9; padding: 3px 8px; border-radius: 8px; }
.history-date { font-size: 12.5px; color: var(--muted); }
.history-cta { margin-top: auto; font-size: 13.5px; font-weight: 600; color: var(--primary); padding-top: 6px; }

.detail-summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 22px; }
.detail-summary .res-item { flex: 1; min-width: 110px; }
.detail-list { display: grid; gap: 16px; margin-bottom: 24px; }
.review-card { border-left: 6px solid var(--success); }
.review-card.review-bad { border-left-color: var(--danger); }
.review-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.review-badge { font-size: 13.5px; font-weight: 700; }
.review-good .review-badge { color: var(--success); }
.review-bad .review-badge { color: var(--danger); }
.review-no { color: var(--muted); font-size: 13px; }
.review-bonus { background: #fef3c7; color: #92400e; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.review-q { font-size: 16.5px; font-weight: 600; margin-bottom: 12px; }
.review-answers { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 12px; }
.review-opt {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 2px solid #e4e6f2; border-radius: 12px; padding: 9px 12px; background: #fafbfe; font-size: 14.5px;
}
.review-opt.is-answer { border-color: var(--success); background: #f0fdf4; }
.review-opt.is-wrong { border-color: var(--danger); background: #fef2f2; }
.tag-correct { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--success); }
.tag-wrong { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--danger); }
.review-explanation {
  background: #fffbe9; border: 1px solid #fde68a; color: #713f12;
  border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.6;
}
.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Footer ---------- */
.footer { text-align: center; padding: 22px; color: var(--muted); font-size: 14px; border-top: 1px solid var(--border); background: rgba(255,255,255,.6); }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .q-text { font-size: 18px; }
  .form-inline .btn { flex: 1; }
  .nav-inner { justify-content: center; }
  .nav-user-block { border-left: none; padding-left: 0; }
  .nav-user-name { max-width: 100px; }
  .game-topbar { padding: 10px 12px; }
  .question-card { padding: 20px; }
}

/* ---------- ระบบ Rank ---------- */
.btn-sm { padding: 8px 16px; font-size: 14px; border-radius: 12px; }
.page-title { font-size: 28px; margin-top: 6px; }
.page-sub { color: var(--muted); margin-top: 4px; }
.card-title { font-size: 19px; margin-bottom: 10px; }
.form-note { font-size: 13px; color: var(--muted); margin: -4px 0 14px; }
.field-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 560px) { .field-grid { grid-template-columns: repeat(3, 1fr); } }
.flash-warn { background: #fef3c7; color: #92400e; border-bottom: 1px solid #fde68a; }
.flash-warn .btn { margin-left: 10px; }

/* หน้า import ข้อคำถาม */
.import-summary { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; font-size: 13px; }
.import-confirm { margin-bottom: 22px; }
.import-err-txt { color: #b91c1c; font-size: 12.5px; margin-top: 3px; }
tr.import-err td { background: #fff8f8; }
tr.import-dup td { background: #fffcf0; }

.rank-badge {
  display: inline-block; font-size: 12px; font-weight: 700; line-height: 1.4;
  padding: 3px 10px; border-radius: 999px; margin-left: 6px;
  color: rgba(255,255,255,.95); background: var(--tier); vertical-align: 2px;
  white-space: nowrap;
}
.lb-tier { display: block; margin-top: 4px; }

/* Tabs ขอบเขต */
.lb-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 18px 0 12px; }
.lb-tab {
  padding: 9px 16px; border-radius: 12px; background: #fff; border: 2px solid #e4e6f2;
  font-weight: 600; color: var(--ink); transition: .15s;
}
.lb-tab:hover { border-color: var(--primary); transform: translateY(-1px); }
.lb-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.lb-panel { background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 18px; box-shadow: var(--shadow-sm); }
.lb-period { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.lb-period-btn { padding: 7px 14px; border-radius: 99px; background: #f1f3f8; font-size: 13.5px; color: var(--muted); }
.lb-period-btn:hover { color: var(--ink); }
.lb-period-btn.active { background: var(--ink); color: #fff; }

/* การ์ดอันดับของฉัน */
.rank-me {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
  border: 2px solid var(--primary); background: linear-gradient(135deg, #f5f0ff, #fff);
}
.rank-me.muted { border-color: var(--border); background: #fafbfe; }
.rank-me-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.rank-me-pos { font-size: 24px; font-weight: 900; color: var(--primary); }
.rank-me-in { font-size: 13.5px; color: var(--muted); }

/* ตารางอันดับ */
.lb-table-wrap { overflow-x: auto; }
.lb-table { width: 100%; border-collapse: collapse; min-width: 520px; }
.lb-table th { text-align: left; font-size: 12.5px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.lb-table td { padding: 11px 10px; border-bottom: 1px solid #f0f1f7; vertical-align: middle; }
.lb-table tr.me td { background: #f7f3ff; }
.lb-table .num { text-align: right; white-space: nowrap; }
.lb-table .lb-rank { font-size: 20px; font-weight: 800; width: 48px; }
.lb-table .lb-name { font-weight: 700; display: flex; flex-wrap: wrap; align-items: center; }
.lb-table .lb-you { font-size: 11px; background: var(--primary); color: #fff; padding: 2px 9px; border-radius: 999px; margin-left: 6px; }
.lb-places { font-size: 12.5px; color: var(--muted); }
.lb-places span { display: block; }
.lb-score { color: var(--primary); }

.lb-more { margin-top: 14px; font-size: 14.5px; }
.lb-more a { color: var(--primary); font-weight: 600; }

/* ระดับยศ */
.tier-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tier-card {
  text-align: center; background: #fff; border: 1px solid var(--border);
  border-top: 4px solid var(--tier); border-radius: 14px; padding: 16px 10px;
  transition: .18s;
}
.tier-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.tier-emoji { font-size: 30px; }
.tier-title { font-weight: 700; margin-top: 6px; }
.tier-pts { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

/* โปรไฟล์ */
.profile-head { display: flex; gap: 14px; align-items: center; }
.profile-avatar {
  width: 58px; height: 58px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 800;
}
.profile-user { color: var(--muted); font-size: 14px; }
.profile-rank { background: #fafbff; border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; margin: 16px 0; }
.rank-main { font-weight: 700; font-size: 17px; }
.rank-pts { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.rank-bar { height: 10px; background: #ececf6; border-radius: 99px; overflow: hidden; margin-top: 10px; }
.rank-bar-fill { height: 100%; border-radius: 99px; transition: width .6s; }
.rank-next { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* บนหน้าสรุปผล */
.result-rank { margin-top: 14px; text-align: center; border: 1px solid var(--border); background: #fafbfe; border-radius: 14px; padding: 12px 14px; }
.rank-current { font-weight: 800; font-size: 17px; }
.result-rank .rank-bar { max-width: 300px; margin: 10px auto 12px; }

/* ---------- Avatar ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; font-size: 18px; flex-shrink: 0;
  background: #f1eaff; border-radius: 10px; margin-right: 6px; vertical-align: -5px;
  border: 1px solid #e2d9f7;
}
.avatar-nav { width: 26px; height: 26px; font-size: 15px; border-radius: 8px; margin-right: 4px; vertical-align: -4px; }
.avatar-sm { width: 26px; height: 26px; font-size: 15px; border-radius: 8px; }
.avatar-lg { width: 56px; height: 56px; font-size: 34px; border-radius: 16px; }
.profile-avatar {
  width: 58px; height: 58px; border-radius: 16px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  border: 1px solid #d6c9f5;
  display: flex; align-items: center; justify-content: center; font-size: 34px;
}

/* เลือก avatar */
.avatar-pick { margin-bottom: 16px; }
.avatar-pick-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 10px; }
.avatar-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-opt input { position: absolute; opacity: 0; pointer-events: none; }
.avatar-opt span {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; font-size: 24px; border-radius: 12px; cursor: pointer;
  background: #f4f2fc; border: 2px solid transparent; transition: .15s;
}
.avatar-opt:hover span { background: #e9e2ff; transform: translateY(-2px); }
.avatar-opt.active span { border-color: var(--primary); background: #f0e9ff; }

.profile-streak { color: var(--primary); font-size: 14px; margin-top: 6px; font-weight: 600; }
.profile-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.trophy-count { background: #fff; color: var(--primary); border-radius: 999px; padding: 1px 9px; font-size: 12.5px; margin-left: 4px; }

.lb-flame { font-size: 12.5px; margin-left: 8px; font-weight: 700; }

/* ---------- ห้องรางวัล ---------- */
.trophy-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.trophy-head h2 { font-size: 20px; }
.trophy-head-info { color: var(--muted); font-size: 14px; margin-top: 5px; }
.trophy-progress { margin-left: auto; text-align: center; }
.trophy-count-big { display: block; font-size: 26px; font-weight: 800; color: var(--primary); }
.trophy-progress span { font-size: 12.5px; color: var(--muted); }
.trophy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 14px; }
.trophy-card {
  text-align: center; background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 18px 12px; transition: .2s;
}
.trophy-card.unlocked { border-color: #fde68a; box-shadow: 0 0 0 1px #fde68a; background: linear-gradient(180deg,#fffdf5,#fff); }
.trophy-card.locked { opacity: .55; background: #f6f7fa; }
.trophy-card.unlocked:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.trophy-emoji { font-size: 34px; }
.trophy-name { font-weight: 700; margin-top: 8px; font-size: 15px; }
.trophy-desc { font-size: 12.5px; color: var(--muted); margin-top: 4px; line-height: 1.5; }