/* ธีมโทนฟ้ามินิมอล + กลิ่นอายคณิตศาสตร์ (พื้นกระดาษกราฟ สัญลักษณ์ + − × ÷ และน้องพาย) */
:root {
  --font: "Noto Sans Thai Looped", "Leelawadee UI", Thonburi, Sarabun, system-ui, sans-serif;
  --math: "Cambria Math", "STIX Two Math", "Times New Roman", serif;
  --bg: #f3f7fe;
  --grid: rgb(31 111 229 / .05);
  --surface: #fff;
  --surface-2: #f5f9ff;
  --border: #e2eaf6;
  --border-strong: #cad8ee;
  --text: #10213f;
  --text-2: #4b5d7d;
  --text-3: #6b7c9c;
  --primary: #1f6fe5;
  --primary-hover: #185fd0;
  --primary-ink: #1559c7;
  --primary-soft: #e8f1ff;
  --primary-tint: #cfe2ff;
  --sky: #6cc6ff;
  --accent: #ffc845;
  --danger: #c62f2f;
  --danger-soft: #fdecec;
  --warn: #9a5800;
  --warn-soft: #fff3d9;
  --ok: #0e7a4f;
  --ok-soft: #e2f5eb;
  --info: #1559c7;
  --info-soft: #e8f1ff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgb(16 33 63 / .04), 0 3px 12px rgb(31 76 160 / .06);
  --shadow-lg: 0 18px 44px rgb(16 33 63 / .16);
  --topbar-h: 64px;
  --sidebar-w: 264px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); font-size: 15px; line-height: 1.6; color: var(--text);
  background-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
::selection { background: var(--primary-tint); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid rgb(31 111 229 / .45); outline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 600; letter-spacing: -.005em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 .6em; }
button, input, select, textarea { font: inherit; color: inherit; }
svg.ic { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--text-3); }
.muted { color: var(--text-2); } .faint { color: var(--text-3); } .small { font-size: .86rem; }
.pre { white-space: pre-wrap; word-break: break-word; }
.row { display: flex; align-items: center; gap: 10px; } .wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; } .spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- ปุ่มและฟอร์ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; padding: 0 18px;
  border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none !important;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); border-color: #b8cbea; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgb(31 111 229 / .24); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: #f2c4c4; }
.btn-danger:hover { background: var(--danger-soft); border-color: #eaa9a9; }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--primary-soft); border-color: transparent; color: var(--primary-ink); }
.btn-sm { min-height: 34px; padding: 0 14px; font-size: .9rem; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: transparent; color: var(--text-2); cursor: pointer; flex: none; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--primary-soft); color: var(--primary-ink); }
.icon-btn:disabled { opacity: .4; cursor: default; background: transparent; }
.link-btn { border: 0; background: none; padding: 0; color: var(--primary); font-weight: 500; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .9rem; font-weight: 500; color: var(--text-2); }
.input, .field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 9px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input::placeholder, .field input::placeholder, .field textarea::placeholder { color: #9aa8c2; }
textarea.input, .field textarea { min-height: 90px; resize: vertical; line-height: 1.55; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgb(31 111 229 / .14); }
.input:disabled, .field textarea:disabled { background: var(--surface-2); color: var(--text-2); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
input[type="checkbox"] { accent-color: var(--primary); }
.error-box { padding: 11px 14px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: .92rem; }
.note-box { padding: 11px 14px; border-radius: var(--radius-sm); background: var(--info-soft); color: var(--primary-ink); font-size: .92rem; border: 1px solid var(--primary-tint); }

/* ---------- ป้ายสถานะ ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 500; white-space: nowrap; background: #edf2fa; color: var(--text-2); }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-danger { background: var(--danger-soft); color: var(--danger); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-primary { background: var(--primary-soft); color: var(--primary-ink); }

/* ---------- โครงหน้า ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 30; display: flex; align-items: center; gap: 6px;
  padding: 0 14px; background: rgb(255 255 255 / .88); -webkit-backdrop-filter: saturate(1.4) blur(12px); backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; color: var(--text); font-weight: 600; font-size: 1.08rem; min-width: 0; text-decoration: none !important; }
.brand-logo { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex: none; box-shadow: 0 4px 10px rgb(31 111 229 / .25); }
.brand-logo svg { width: 100%; height: 100%; display: block; }
.crumb { color: var(--text-2); font-size: .98rem; min-width: 0; }
.crumb::before { content: "›"; margin: 0 8px; color: var(--text-3); }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--primary); color: #fff; font-weight: 600; font-size: .92rem; border: 0; cursor: pointer;
}
.avatar.sm { width: 30px; height: 30px; font-size: .8rem; }
.avatar.student { background: #dcebff; color: var(--primary-ink); }
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 25; overflow-y: auto;
  padding: 14px 12px 30px; background: var(--surface); border-right: 1px solid var(--border); transition: transform .2s;
}
.nav-item {
  display: flex; align-items: center; gap: 13px; padding: 9px 14px; border-radius: 14px; color: var(--text-2);
  font-weight: 500; text-decoration: none !important; margin-bottom: 3px; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.nav-sep { height: 1px; background: var(--border); margin: 12px 4px; }
.nav-label { padding: 4px 14px; font-size: .8rem; color: var(--text-3); font-weight: 500; }
.nav-dot { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: .8rem; font-weight: 600; flex: none; background: var(--cc); }
.main { padding: calc(var(--topbar-h) + 24px) 26px 60px calc(var(--sidebar-w) + 26px); min-height: 100vh; }
.page { max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.scrim { position: fixed; inset: 0; background: rgb(16 33 63 / .35); z-index: 24; }
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-102%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .main { padding-left: 16px; padding-right: 16px; }
}
@media (min-width: 1024px) { .menu-btn, .scrim { display: none; } }
@media (max-width: 600px) { .crumb { display: none; } h1 { font-size: 1.35rem; } }

/* แถบเมนูด้านล่าง (มือถือ) */
.bottom-nav { display: none; }
@media (max-width: 760px) {
  .bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 28; display: flex; gap: 2px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    background: rgb(255 255 255 / .94); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-top: 1px solid var(--border);
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 2px; border: 0; background: none;
    color: var(--text-3); font-size: .74rem; font-weight: 500; text-decoration: none !important; cursor: pointer;
  }
  .bn-ic { display: grid; place-items: center; width: 52px; height: 30px; border-radius: 999px; transition: background .15s; }
  .bottom-nav .on { color: var(--primary-ink); }
  .bottom-nav .on .bn-ic { background: var(--primary-soft); }
  .sidebar { bottom: calc(66px + env(safe-area-inset-bottom)); }
  .main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom)) !important; }
}

/* ---------- การ์ดและรายการ ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.card-head > .ic { color: var(--primary); }
.list-item { display: flex; align-items: center; gap: 14px; padding: 13px 20px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none !important; transition: background .12s; }
.list-item:first-child { border-top: 0; }
a.list-item:hover, button.list-item:hover { background: var(--surface-2); }
button.list-item { width: 100%; border: 0; border-top: 1px solid var(--border); background: none; text-align: left; cursor: pointer; }
.type-icon { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; flex: none; color: var(--cc, var(--primary)); background: var(--cc-soft, var(--primary-soft)); }
.type-icon.material { color: #50648a; background: #edf1f8; }
.type-icon.announcement { color: var(--primary-ink); background: var(--primary-soft); }
.empty { padding: 36px 20px; text-align: center; color: var(--text-2); }
.empty .ic { width: 42px; height: 42px; color: var(--primary-tint); margin-bottom: 6px; }
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; padding: 30px 20px; color: var(--text-2); }
.empty-state .mascot { margin-bottom: 6px; }
.empty-state h3 { font-size: 1.05rem; color: var(--text); }
.empty-state.compact { padding: 18px 16px 20px; }
.section-head { display: flex; align-items: center; gap: 10px; margin: 4px 2px 12px; }
.section-head h2 { font-size: 1.15rem; }

/* ---------- การ์ดรายวิชา ---------- */
.course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.course-card { display: flex; flex-direction: column; overflow: hidden; min-height: 226px; color: var(--text); text-decoration: none !important; transition: box-shadow .18s, transform .18s; }
.course-card:hover { box-shadow: 0 14px 30px rgb(31 76 160 / .16); transform: translateY(-3px); }
.course-card .cover, .course-banner {
  position: relative; overflow: hidden; color: #fff; background: var(--cc);
  background: linear-gradient(135deg, var(--cc) 30%, color-mix(in srgb, var(--cc) 62%, #8fd3ff));
}
.course-card .cover::before, .course-banner::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgb(255 255 255 / .12) 1px, transparent 1px), linear-gradient(90deg, rgb(255 255 255 / .12) 1px, transparent 1px);
  background-size: 18px 18px;
}
.course-card .cover { padding: 16px 18px; min-height: 106px; }
.course-card .cover h3 { font-size: 1.15rem; position: relative; }
.course-card .cover .sub { position: relative; opacity: .92; font-size: .9rem; }
.course-card .cover .teacher { margin-top: 6px; }
.cover-sym { position: absolute; right: 12px; bottom: -22px; font-family: var(--math); font-size: 96px; font-weight: 700; font-style: italic; line-height: 1; color: rgb(255 255 255 / .2); pointer-events: none; user-select: none; }
.course-card:hover .cover-sym { color: rgb(255 255 255 / .3); }
.course-card .body { flex: 1; padding: 12px 18px; font-size: .92rem; color: var(--text-2); }
.course-card .foot { display: flex; align-items: center; gap: 8px; padding: 8px 12px 10px 18px; border-top: 1px solid var(--border); font-size: .88rem; color: var(--text-2); }
.course-card .foot .ic { color: var(--cc); }
.c-teal { --cc: #0b7c87; --cc-soft: #e3f4f5; }
.c-blue { --cc: #1f6fe5; --cc-soft: #e8f1ff; }
.c-indigo { --cc: #4f57d6; --cc-soft: #ecedfc; }
.c-purple { --cc: #7b4fe0; --cc-soft: #f1ebfd; }
.c-pink { --cc: #c43a75; --cc-soft: #fbe9f1; }
.c-red { --cc: #c9423a; --cc-soft: #fbeceb; }
.c-orange { --cc: #b8570c; --cc-soft: #fdf0e4; }
.c-green { --cc: #16804f; --cc-soft: #e4f4ec; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 12px; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--border-strong); background: var(--cc); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 2px var(--text); }

/* ---------- หน้ารายวิชา ---------- */
.course-banner { border-radius: 22px; padding: 26px 28px 22px; min-height: 156px; display: flex; flex-direction: column; justify-content: flex-end; box-shadow: 0 10px 26px rgb(31 76 160 / .14); }
.course-banner h1 { position: relative; font-size: 1.9rem; }
.course-banner .sub { position: relative; opacity: .92; }
.course-banner .cover-sym { font-size: 170px; right: 26px; bottom: -42px; }
.course-banner .banner-actions { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; z-index: 1; }
.course-banner .banner-actions .btn { background: rgb(255 255 255 / .94); border: 0; color: var(--text); box-shadow: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 8px 0 20px; overflow-x: auto; scrollbar-width: none; }
.tab { position: relative; padding: 12px 16px; border: 0; background: none; cursor: pointer; font-weight: 500; color: var(--text-2); white-space: nowrap; text-decoration: none !important; border-radius: 12px 12px 0 0; }
.tab:hover { color: var(--text); background: rgb(31 111 229 / .05); }
.tab.on { color: var(--cc, var(--primary)); font-weight: 600; }
.tab.on::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--cc, var(--primary)); }
.two-col { display: grid; grid-template-columns: 250px 1fr; gap: 20px; align-items: start; }
@media (max-width: 820px) { .two-col { grid-template-columns: 1fr; } .course-banner h1 { font-size: 1.45rem; } .course-banner .cover-sym { font-size: 120px; } }
.code-box { font-size: 1.6rem; font-weight: 600; letter-spacing: .12em; color: var(--cc, var(--primary)); font-variant-numeric: tabular-nums; }
.post-card { padding: 0; overflow: hidden; }
.post-card .post-head { display: flex; gap: 14px; align-items: center; padding: 14px 18px; color: var(--text); text-decoration: none !important; }
a.post-head:hover { background: var(--surface-2); }
.post-card .post-body { padding: 0 18px 16px 72px; }
@media (max-width: 600px) { .post-card .post-body { padding-left: 18px; } }
.topic-title { font-size: 1.15rem; color: var(--cc, var(--primary)); padding: 6px 4px 8px; border-bottom: 2px solid var(--cc-soft, var(--primary-soft)); margin: 18px 0 10px; }

/* ---------- ไฟล์แนบ ---------- */
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.file-chip {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 8px; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); text-decoration: none !important; min-width: 0; cursor: pointer; text-align: left; width: 100%;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.file-chip:hover { border-color: var(--primary-tint); background: var(--surface-2); box-shadow: var(--shadow); }
.file-thumb { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; flex: none; background: #edf1f8; color: var(--text-2); }
.file-thumb.pdf { background: #fdeceb; color: #c9423a; }
.file-thumb.img { background: var(--primary-soft); color: var(--primary-ink); }
.file-thumb.link { background: #e3f4f5; color: #0b7c87; }
.file-chip .meta { min-width: 0; flex: 1; line-height: 1.35; }
.file-chip .meta b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.video-embed { position: relative; width: 100%; max-width: 640px; aspect-ratio: 16 / 9; border-radius: 14px; overflow: hidden; background: #000; }
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.dropzone { border: 2px dashed var(--border-strong); border-radius: 14px; padding: 18px; text-align: center; color: var(--text-2); cursor: pointer; background: var(--surface-2); transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-soft); }

/* ---------- หน้าโพสต์และงาน ---------- */
.post-layout { display: grid; grid-template-columns: 1fr 330px; gap: 22px; align-items: start; }
@media (max-width: 900px) { .post-layout { grid-template-columns: 1fr; } }
.post-title-row { display: flex; gap: 16px; align-items: flex-start; }
.work-panel { position: sticky; top: calc(var(--topbar-h) + 16px); }
.score-big { font-size: 2rem; font-weight: 600; color: var(--primary); line-height: 1.1; }
.feedback { padding: 11px 14px; border-radius: 12px; background: var(--primary-soft); color: var(--text); border-left: 4px solid var(--primary); }
.comment { display: flex; gap: 10px; padding: 8px 0; }
.comment .bubble { flex: 1; min-width: 0; padding: 8px 12px; border-radius: 4px 14px 14px 14px; background: var(--surface-2); border: 1px solid var(--border); }
.result { display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: 16px; background: linear-gradient(135deg, #eaf2ff, #f7fbff); border: 1px solid var(--border); }
.result b { display: block; font-size: 1.05rem; color: var(--primary-ink); }
.ring { display: block; flex: none; }
.ring-track { fill: none; stroke: var(--primary-soft); stroke-width: 10; }
.ring-bar { fill: none; stroke: var(--primary); stroke-width: 10; stroke-linecap: round; }
.ring-num { font-family: var(--font); font-size: 25px; font-weight: 600; fill: var(--text); }
.ring-sub { font-family: var(--font); font-size: 13px; fill: var(--text-3); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.stat-ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; flex: none; background: var(--primary-soft); color: var(--primary-ink); }
.stat-num { font-size: 1.5rem; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) {
  .work-item { flex-wrap: wrap; padding: 13px 16px; }
  .work-item > .grow { flex-basis: calc(100% - 56px); }
  .work-item > .stack { flex-direction: row; align-items: center !important; justify-content: flex-end; width: 100%; padding-left: 56px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px; gap: 10px; }
  .stat-ic { width: 38px; height: 38px; border-radius: 12px; }
  .stat-num { font-size: 1.3rem; }
}

/* ---------- ตาราง ---------- */
.table-wrap { overflow: auto; border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .93rem; }
.table th, .table td { padding: 11px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; font-size: .86rem; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #f8fbff; }
.table .num { text-align: center; font-variant-numeric: tabular-nums; }
.grades th.sticky, .grades td.sticky { position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: 1px 0 0 var(--border); }
.grades th.sticky { background: var(--surface-2); }
.grade-cell { display: block; min-width: 86px; text-align: center; color: var(--text); text-decoration: none !important; border-radius: 8px; padding: 3px; }
.grade-cell:hover { background: var(--primary-soft); }

/* ---------- หน้าต่างและแจ้งเตือน ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; background: rgb(16 33 63 / .42); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto; }
.modal { width: 100%; max-width: 560px; background: var(--surface); border-radius: 22px; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 16px 8px 24px; }
.modal-body { padding: 8px 24px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 24px 20px; flex-wrap: wrap; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 11px 20px; border-radius: 999px; background: var(--text); color: #fff; font-weight: 500; box-shadow: var(--shadow-lg); max-width: min(92vw, 520px); animation: pop .18s ease-out; }
.toast.err { background: var(--danger); border-radius: 16px; }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; z-index: 40; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 6px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-radius: 10px; background: none; cursor: pointer; text-align: left; color: var(--text); text-decoration: none !important; }
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }

/* ---------- หน้าเข้าสู่ระบบ ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; }
.auth-shell { width: 100%; max-width: 940px; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--surface); border: 1px solid var(--border); border-radius: 28px; box-shadow: var(--shadow-lg); overflow: hidden; }
.auth-shell.solo { max-width: 460px; grid-template-columns: 1fr; }
.auth-art { position: relative; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 14px; padding: 36px 30px; text-align: center; background: linear-gradient(160deg, #e1edff 0%, #f2f8ff 60%, #e5f4ff 100%); }
.auth-art::before { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgb(31 111 229 / .07) 1px, transparent 1px), linear-gradient(90deg, rgb(31 111 229 / .07) 1px, transparent 1px); background-size: 22px 22px; }
.auth-art > * { position: relative; }
.auth-art h2 { font-size: 1.5rem; }
.auth-art p { color: var(--text-2); margin: 0; max-width: 340px; }
.auth-card { width: 100%; padding: 40px 36px; display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.auth-title h1 { font-size: 1.45rem; }
.pw-wrap { position: relative; }
.pw-wrap .icon-btn { position: absolute; right: 3px; top: 2px; }
@media (max-width: 760px) {
  .auth-wrap { padding: 16px 12px; align-items: start; }
  .auth-shell { grid-template-columns: 1fr; border-radius: 24px; }
  .auth-art { padding: 20px 18px 4px; gap: 4px; }
  .auth-art .buddies { max-width: 230px; }
  .auth-art p { display: none; }
  .auth-art h2 { font-size: 1.2rem; }
  .auth-card { padding: 20px 20px 26px; }
}

/* ---------- หน้าหลัก ---------- */
.hero {
  position: relative; overflow: hidden; display: flex; align-items: center; gap: 16px; min-height: 170px; padding: 24px 28px; margin-bottom: 22px;
  border-radius: 24px; border: 1px solid var(--border); background: linear-gradient(120deg, #e1edff 0%, #f3f8ff 55%, #e6f5ff 100%);
}
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgb(31 111 229 / .07) 1px, transparent 1px), linear-gradient(90deg, rgb(31 111 229 / .07) 1px, transparent 1px);
  background-size: 24px 24px; -webkit-mask-image: linear-gradient(90deg, transparent 10%, #000 75%); mask-image: linear-gradient(90deg, transparent 10%, #000 75%);
}
.hero-text { position: relative; z-index: 1; flex: 1; min-width: 0; }
.hero-kicker { display: inline-block; padding: 3px 12px; margin-bottom: 8px; border-radius: 999px; background: #fff; color: var(--primary-ink); font-size: .85rem; font-weight: 600; box-shadow: var(--shadow); }
.hero h1 { font-size: 1.75rem; }
.hero-sub { color: var(--text-2); margin: 2px 0 14px; }
.hero-mascot { position: relative; z-index: 1; width: 140px; height: 140px; margin: -12px 6px -22px 0; filter: drop-shadow(0 10px 14px rgb(31 76 160 / .18)); }
.float-sym { position: absolute; z-index: 0; font-family: var(--math); font-size: 26px; font-weight: 700; color: rgb(31 111 229 / .2); pointer-events: none; user-select: none; }
@media (max-width: 600px) {
  .hero { padding: 18px 16px; min-height: 0; border-radius: 20px; }
  .hero h1 { font-size: 1.3rem; }
  .hero-mascot { width: 92px; height: 92px; margin: -4px -4px -12px 0; }
}
.dash { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.dash-main { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.dash-side { display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 900px) { .dash { grid-template-columns: minmax(0, 1fr); } }
.fun-card { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.fun-head { display: flex; align-items: center; gap: 10px; }
.fun-ic { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; flex: none; background: var(--primary-soft); color: var(--primary-ink); font-family: var(--math); font-size: 1.15rem; font-weight: 700; }
.quiz { display: flex; align-items: center; gap: 12px; }
.quiz-q { font-size: 1.5rem; font-weight: 600; margin-bottom: 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.quiz-blank { color: var(--primary); }
.quiz-in { min-height: 40px; max-width: 130px; text-align: center; font-size: 1.05rem; }
.quiz-msg { min-height: 1.5em; font-size: .92rem; font-weight: 500; color: var(--text-2); }
.quiz-msg.ok { color: var(--ok); } .quiz-msg.no { color: var(--warn); } .quiz-msg.skip { color: var(--primary-ink); }
.fact-text { margin: 0; color: var(--text-2); }
.fun-card .link-btn { align-self: flex-start; }

/* ---------- ตัวการ์ตูน ภาพประกอบ และแอนิเมชัน ---------- */
.mascot { display: block; flex: none; overflow: visible; }
.buddies { display: block; width: 100%; max-width: 340px; height: auto; overflow: visible; }
.loading { display: flex; justify-content: center; gap: 10px; padding: 40px 20px; font-family: var(--math); font-size: 1.5rem; font-weight: 700; color: var(--primary); }
.loading span:nth-child(2) { color: #3d8bfd; } .loading span:nth-child(3) { color: var(--sky); } .loading span:nth-child(4) { color: #9cc7ff; }
.confetti { position: fixed; inset: 0; z-index: 95; pointer-events: none; overflow: hidden; }
.confetti span { position: absolute; top: -40px; font-family: var(--math); font-weight: 700; animation: confetti-fall 2s cubic-bezier(.3, .2, .6, 1) forwards; }
@keyframes confetti-fall { to { transform: translate(var(--dx), 108vh) rotate(var(--r)); } }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes floaty { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-8px) rotate(8deg); } }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-9px); } }
@keyframes ring-in { from { stroke-dasharray: 0 999; } }
@media (prefers-reduced-motion: no-preference) {
  .bob { animation: bob 3.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center bottom; }
  .b2 { animation-delay: -1.1s; } .b3 { animation-delay: -2.2s; }
  .fl { animation: floaty 5s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
  .f2 { animation-delay: -1.7s; } .f3 { animation-delay: -3.3s; }
  .hero-mascot { animation: bob 3.4s ease-in-out infinite; }
  .float-sym { animation: floaty 6s ease-in-out infinite; }
  .loading span { animation: hop 1s ease-in-out infinite; }
  .loading span:nth-child(2) { animation-delay: .12s; } .loading span:nth-child(3) { animation-delay: .24s; } .loading span:nth-child(4) { animation-delay: .36s; }
  .ring-bar { animation: ring-in 1s ease-out; }
}

/* ---------- พิมพ์บัตรรหัสผ่าน ---------- */
.slips { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.slip { border: 1px dashed var(--border-strong); border-radius: 10px; padding: 10px 12px; font-size: .9rem; }
@media print {
  body { background: #fff; }
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; inset: 0; padding: 10mm; }
  .slip { break-inside: avoid; }
}
