/* ==========================================================================
   Trường Học Kết Nối – Hệ thống giao diện (CSS thuần, không cần build)
   Tông cam chủ đạo, vui tươi, dễ đọc trên điện thoại.
   ========================================================================== */

:root {
  --orange-50: #fff7ed;
  --orange-100: #ffedd5;
  --orange-200: #fed7aa;
  --orange-300: #fdba74;
  --orange-400: #fb923c;
  --orange-500: #ff7a00;
  --orange-600: #ea580c;
  --orange-700: #c2410c;
  --orange-800: #9a3412;

  --sun: #ffc83d;
  --sun-soft: #fff3c4;
  --teal: #0fa3a3;
  --teal-soft: #d5f5f2;
  --sky: #3b82f6;
  --sky-soft: #dbeafe;
  --berry: #e11d74;
  --berry-soft: #fde2ee;
  --leaf: #16a34a;
  --leaf-soft: #dcfce7;
  --grape: #7c3aed;
  --grape-soft: #ede9fe;

  --ink: #23180f;
  --ink-2: #4a3a2c;
  --muted: #7a6a5c;
  --line: #f1e3d3;
  --line-strong: #e7cfb6;
  --bg: #fffaf4;
  --card: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --success: #15803d;
  --success-soft: #dcfce7;
  --warning: #b45309;
  --warning-soft: #fef3c7;

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 24px;
  --shadow-sm: 0 1px 2px rgba(124, 58, 0, .06), 0 1px 1px rgba(124, 58, 0, .04);
  --shadow: 0 6px 20px -8px rgba(154, 52, 18, .22);
  --shadow-lg: 0 18px 40px -16px rgba(154, 52, 18, .35);

  --font-body: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Baloo 2", "Be Vietnam Pro", system-ui, sans-serif;
  --container: 1200px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg, video { max-width: 100%; height: auto; }
a { color: var(--orange-700); text-decoration-thickness: 1.5px; text-underline-offset: 3px; }
a:hover { color: var(--orange-600); }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.2; margin: 0 0 .5em; color: var(--ink); font-weight: 700; }
h1 { font-size: clamp(1.75rem, 1.2rem + 2.2vw, 2.6rem); }
h2 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.8rem); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1em; }
hr { border: 0; border-top: 1px dashed var(--line-strong); margin: 1.5rem 0; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: 0 16px; }
.section { padding: 40px 0; }
.section-sm { padding: 24px 0; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.grid-6 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); }
.layout-side { display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
@media (max-width: 960px) { .layout-side { grid-template-columns: minmax(0, 1fr); } }
.text-muted { color: var(--muted); }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .78rem; }
.text-center { text-align: center; }
.mt-0 { margin-top: 0 !important; } .mb-0 { margin-bottom: 0 !important; }
.w-full { width: 100%; }
.nowrap { white-space: nowrap; }

/* ---------- Đầu trang ---------- */
.topbar { background: var(--orange-600); color: #fff; font-size: .82rem; }
.topbar .container { display: flex; justify-content: space-between; gap: 12px; padding-top: 6px; padding-bottom: 6px; }
.topbar a { color: #fff; text-decoration: none; }
@media (max-width: 640px) { .topbar .hide-sm { display: none; } }

.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; gap: 16px; height: 68px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.brand-mark { width: 42px; height: 42px; flex-shrink: 0; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.22rem; line-height: 1; letter-spacing: -.01em; }
.brand-name small { display: block; font-family: var(--font-body); font-size: .68rem; font-weight: 600; color: var(--orange-600); letter-spacing: .04em; margin-top: 3px; }
.brand-name .k { color: var(--orange-500); }

.main-nav { display: flex; align-items: center; gap: 2px; margin-left: 8px; }
.main-nav > a, .nav-drop > button {
  font: 600 .93rem/1 var(--font-body); color: var(--ink-2); text-decoration: none;
  padding: 10px 12px; border-radius: 999px; background: none; border: 0; cursor: pointer; white-space: nowrap;
}
.main-nav > a:hover, .nav-drop > button:hover, .main-nav > a.active { background: var(--orange-50); color: var(--orange-700); }
.nav-drop { position: relative; }
.nav-drop-panel {
  display: none; position: absolute; top: calc(100% + 8px); left: 0; min-width: 560px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 16px;
}
.nav-drop:hover .nav-drop-panel, .nav-drop:focus-within .nav-drop-panel { display: block; }
.nav-drop::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 10px; }
.grade-mega { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grade-mega h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 6px; font-family: var(--font-body); }
.grade-mega a { display: block; padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); font-weight: 600; }
.grade-mega a:hover { background: var(--orange-50); color: var(--orange-700); }

.header-search { flex: 1; max-width: 340px; margin-left: auto; position: relative; }
.header-search input {
  width: 100%; height: 42px; border-radius: 999px; border: 2px solid var(--line); background: var(--orange-50);
  padding: 0 44px 0 16px; font: inherit; font-size: .92rem;
}
.header-search input:focus { border-color: var(--orange-400); background: #fff; outline: none; }
.header-search button { position: absolute; right: 4px; top: 4px; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--orange-500); color: #fff; cursor: pointer; display: grid; place-items: center; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.nav-toggle { display: none; background: var(--orange-50); border: 0; width: 42px; height: 42px; border-radius: 12px; cursor: pointer; }
.user-chip { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 600; padding: 4px 10px 4px 4px; border-radius: 999px; border: 1px solid var(--line); background: #fff; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, var(--orange-400), var(--orange-600)); color: #fff; display: grid; place-items: center; font-weight: 800; font-family: var(--font-display); flex-shrink: 0; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.6rem; }

@media (max-width: 1180px) {
  .main-nav { display: none; position: absolute; top: 68px; left: 0; right: 0; background: #fff; flex-direction: column; align-items: stretch; padding: 12px 16px 20px; border-bottom: 1px solid var(--line); box-shadow: var(--shadow); margin: 0; max-height: calc(100vh - 68px); overflow: auto; }
  .main-nav.open { display: flex; }
  .main-nav > a, .nav-drop > button { width: 100%; text-align: left; padding: 12px; }
  .nav-drop-panel { position: static; display: block; min-width: 0; box-shadow: none; border: 0; padding: 0 0 8px 12px; }
  .grade-mega { grid-template-columns: repeat(2, 1fr); }
  .nav-toggle { display: grid; place-items: center; }
  .header-search { max-width: none; }
}
@media (max-width: 640px) {
  .header-inner { gap: 8px; }
  .brand-name small { display: none; }
  .header-search { position: absolute; left: 0; right: 0; top: 68px; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line); display: none; }
  .header-search.open { display: block; }
  .header-search button { right: 20px; top: 12px; }
  .search-toggle { display: grid !important; }
  .user-chip span { display: none; }
}
.search-toggle { display: none; place-items: center; background: var(--orange-50); border: 0; width: 42px; height: 42px; border-radius: 12px; cursor: pointer; margin-left: auto; }

/* ---------- Nút ---------- */
.btn {
  --btn-bg: var(--orange-500); --btn-fg: #fff; --btn-edge: var(--orange-700);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: 14px; border: 0;
  background: var(--btn-bg); color: var(--btn-fg); font: 700 .95rem/1 var(--font-body);
  text-decoration: none; cursor: pointer; white-space: nowrap;
  box-shadow: 0 4px 0 var(--btn-edge); transform: translateY(0); transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { color: var(--btn-fg); filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-edge); }
.btn[disabled], .btn.disabled { opacity: .55; pointer-events: none; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: .85rem; border-radius: 11px; box-shadow: 0 3px 0 var(--btn-edge); }
.btn-lg { min-height: 54px; padding: 0 28px; font-size: 1.08rem; border-radius: 18px; }
.btn-sun { --btn-bg: var(--sun); --btn-fg: var(--ink); --btn-edge: #d99a00; }
.btn-teal { --btn-bg: var(--teal); --btn-edge: #087575; }
.btn-dark { --btn-bg: var(--ink); --btn-edge: #000; }
.btn-danger { --btn-bg: var(--danger); --btn-edge: #991b1b; }
.btn-success { --btn-bg: var(--leaf); --btn-edge: #166534; }
.btn-ghost { --btn-bg: #fff; --btn-fg: var(--ink-2); --btn-edge: var(--line-strong); border: 1px solid var(--line-strong); }
.btn-ghost:hover { --btn-fg: var(--orange-700); }
.btn-link { background: none; border: 0; padding: 0; color: var(--orange-700); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }
.btn-block { width: 100%; }

/* ---------- Thẻ ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-body { padding: 20px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head h2, .card-head h3 { margin: 0; font-size: 1.1rem; }
.card-link { display: block; text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s, border-color .15s; }
.card-link:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--orange-200); color: inherit; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700; background: var(--orange-100); color: var(--orange-800); white-space: nowrap; }
.badge-teal { background: var(--teal-soft); color: #075e5e; }
.badge-sky { background: var(--sky-soft); color: #1e40af; }
.badge-berry { background: var(--berry-soft); color: #9d174d; }
.badge-leaf { background: var(--leaf-soft); color: #166534; }
.badge-grape { background: var(--grape-soft); color: #5b21b6; }
.badge-gray { background: #f1ede8; color: var(--ink-2); }
.badge-danger { background: var(--danger-soft); color: #991b1b; }
.badge-sun { background: var(--sun-soft); color: #854d0e; }

/* ---------- Hero trang chủ ---------- */
.hero {
  position: relative; overflow: hidden;
  background:
    radial-gradient(circle at 85% 20%, rgba(255, 200, 61, .55) 0 120px, transparent 121px),
    radial-gradient(circle at 8% 90%, rgba(255, 255, 255, .18) 0 160px, transparent 161px),
    linear-gradient(135deg, #ff8a1f 0%, #ff6a00 55%, #f04d00 100%);
  color: #fff;
}
.hero::before {
  content: ""; position: absolute; inset: 0; opacity: .14; pointer-events: none;
  background-image: radial-gradient(#fff 1.5px, transparent 1.6px); background-size: 22px 22px;
}
.hero-inner { position: relative; display: grid; grid-template-columns: 1.15fr .85fr; gap: 32px; align-items: center; padding: 48px 16px 64px; }
.hero h1 { color: #fff; font-size: clamp(2rem, 1.3rem + 3vw, 3.3rem); margin-bottom: 12px; }
.hero h1 .hl { color: var(--sun); display: inline-block; transform: rotate(-2deg); }
.hero p.lead { font-size: 1.12rem; opacity: .95; max-width: 560px; }
.hero-search { display: flex; gap: 8px; background: #fff; padding: 6px; border-radius: 18px; box-shadow: var(--shadow-lg); max-width: 560px; margin: 22px 0 16px; }
.hero-search input { flex: 1; border: 0; font: inherit; font-size: 1rem; padding: 0 12px; min-width: 0; color: var(--ink); background: transparent; }
.hero-search input:focus { outline: none; }
.hero-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.hero-chips a { color: #fff; background: rgba(255, 255, 255, .18); border: 1px solid rgba(255, 255, 255, .35); padding: 6px 14px; border-radius: 999px; text-decoration: none; font-size: .88rem; font-weight: 600; }
.hero-chips a:hover { background: rgba(255, 255, 255, .3); }
.hero-art { position: relative; min-height: 320px; }
.hero-card {
  position: absolute; background: #fff; color: var(--ink); border-radius: 20px; padding: 14px 16px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 12px; font-weight: 700; animation: bob 5s ease-in-out infinite;
}
.hero-card .ic { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 1.5rem; }
.hero-card small { display: block; font-weight: 500; color: var(--muted); font-size: .78rem; }
.hero-card.c1 { top: 6%; left: 6%; }
.hero-card.c2 { top: 38%; right: 0; animation-delay: -1.6s; }
.hero-card.c3 { bottom: 4%; left: 14%; animation-delay: -3.2s; }
.hero-blob { position: absolute; inset: 14% 12%; border-radius: 42% 58% 55% 45% / 48% 42% 58% 52%; background: rgba(255, 255, 255, .16); border: 2px dashed rgba(255, 255, 255, .45); }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-1deg); } 50% { transform: translateY(-10px) rotate(1deg); } }
@media (prefers-reduced-motion: reduce) { .hero-card { animation: none; } }
@media (max-width: 860px) { .hero-inner { grid-template-columns: 1fr; padding-bottom: 40px; } .hero-art { display: none; } }
.wave { display: block; width: 100%; height: 40px; margin-top: -39px; position: relative; }

/* ---------- Khối lớp ---------- */
.grade-tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
@media (max-width: 860px) { .grade-tiles { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 520px) { .grade-tiles { grid-template-columns: repeat(3, 1fr); } }
.grade-tile {
  --c: var(--orange-500);
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  aspect-ratio: 1 / 1; border-radius: 22px; text-decoration: none; color: #fff; background: var(--c);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .14), var(--shadow-sm); transition: transform .15s;
  font-family: var(--font-display);
}
.grade-tile:hover { transform: translateY(-4px) rotate(-1.5deg); color: #fff; }
.grade-tile .n { font-size: clamp(2rem, 1.4rem + 2.4vw, 3rem); font-weight: 800; line-height: 1; }
.grade-tile .l { font-size: .9rem; font-weight: 600; opacity: .95; font-family: var(--font-body); }

.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.section-head p { margin: 4px 0 0; color: var(--muted); }
.eyebrow { display: inline-block; font-size: .78rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--orange-600); margin-bottom: 4px; }

/* ---------- Thẻ tính năng / môn học ---------- */
.feature { padding: 22px; border-radius: var(--radius-lg); background: #fff; border: 1px solid var(--line); position: relative; overflow: hidden; }
.feature .ic { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 1.6rem; margin-bottom: 12px; }
.feature h3 { margin-bottom: 6px; }
.feature p { color: var(--muted); font-size: .93rem; margin: 0; }
.bg-orange { background: var(--orange-100); } .bg-sun { background: var(--sun-soft); } .bg-teal { background: var(--teal-soft); }
.bg-sky { background: var(--sky-soft); } .bg-berry { background: var(--berry-soft); } .bg-leaf { background: var(--leaf-soft); } .bg-grape { background: var(--grape-soft); }

.subject-pill { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 16px; background: #fff; border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 700; transition: border-color .15s, transform .15s; }
.subject-pill:hover { border-color: var(--orange-300); transform: translateY(-2px); color: var(--orange-700); }
.subject-pill .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 1.35rem; flex-shrink: 0; }
.subject-pill small { display: block; font-weight: 500; color: var(--muted); font-size: .78rem; }

/* ---------- Danh sách học liệu ---------- */
.res-item { display: flex; gap: 14px; padding: 16px; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s; }
.res-item:hover { border-color: var(--orange-300); box-shadow: var(--shadow); color: inherit; }
.res-item .ic { width: 46px; height: 46px; flex-shrink: 0; border-radius: 14px; display: grid; place-items: center; font-size: 1.35rem; background: var(--orange-100); }
.res-item h3 { font-size: 1.02rem; margin: 0 0 4px; font-family: var(--font-body); font-weight: 700; color: var(--ink); }
.res-item p { margin: 0; color: var(--muted); font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.res-list { display: grid; gap: 10px; }

.chapter { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; overflow: hidden; }
.chapter + .chapter { margin-top: 12px; }
.chapter > summary { list-style: none; cursor: pointer; padding: 14px 18px; font-weight: 800; display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--orange-50); font-family: var(--font-display); font-size: 1.08rem; }
.chapter > summary::-webkit-details-marker { display: none; }
.chapter > summary::after { content: "＋"; color: var(--orange-600); font-weight: 800; }
.chapter[open] > summary::after { content: "－"; }
.chapter ul { list-style: none; margin: 0; padding: 6px 0; }
.chapter li a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 18px; text-decoration: none; color: var(--ink); }
.chapter li a:hover { background: var(--orange-50); color: var(--orange-700); }
.chapter .lesson-name { font-weight: 700; padding: 10px 18px 2px; font-size: .9rem; color: var(--ink-2); }

.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line-strong); background: #fff; color: var(--ink-2); font-weight: 600; font-size: .88rem; text-decoration: none; cursor: pointer; }
.chip:hover { border-color: var(--orange-400); color: var(--orange-700); }
.chip.active { background: var(--orange-500); border-color: var(--orange-500); color: #fff; }

/* ---------- Bài viết / lời giải ---------- */
.breadcrumb { display: flex; flex-wrap: wrap; gap: 6px; font-size: .86rem; color: var(--muted); padding: 14px 0 0; margin: 0; list-style: none; }
.breadcrumb li + li::before { content: "›"; margin-right: 6px; color: var(--line-strong); }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--orange-700); }

.prose { font-size: 1.05rem; line-height: 1.8; overflow-wrap: anywhere; }
.prose h2 { margin-top: 1.6em; padding-left: 12px; border-left: 5px solid var(--orange-500); }
.prose h3 { margin-top: 1.4em; color: var(--orange-800); }
.prose img { border-radius: 12px; display: block; margin: 1em auto; }
.prose table { width: 100%; border-collapse: collapse; margin: 1em 0; font-size: .95rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line-strong); padding: 8px 10px; text-align: left; }
.prose th { background: var(--orange-50); }
.prose blockquote { margin: 1em 0; padding: 12px 16px; background: var(--sun-soft); border-radius: 12px; border-left: 5px solid var(--sun); }
.prose pre { background: #2b1d12; color: #ffe8cc; padding: 14px; border-radius: 12px; overflow-x: auto; }
.prose iframe { width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; border-radius: 12px; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.solution-box { border: 2px dashed var(--orange-300); background: var(--orange-50); border-radius: var(--radius); padding: 16px 18px; }

.locked-box { text-align: center; padding: 32px 20px; border-radius: var(--radius-lg); background: linear-gradient(180deg, #fff, var(--orange-50)); border: 2px dashed var(--orange-300); }
.locked-box .ic { font-size: 2.6rem; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.pager a { display: block; padding: 14px 16px; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.pager a:hover { border-color: var(--orange-300); }
.pager small { display: block; color: var(--muted); font-size: .78rem; }
.pager .next { text-align: right; grid-column: 2; }

/* ---------- Biểu mẫu ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-weight: 700; margin-bottom: 6px; font-size: .92rem; color: var(--ink-2); }
.form-hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.form-control, select.form-control, textarea.form-control {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line-strong);
  background: #fff; font: inherit; color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
textarea.form-control { min-height: 120px; resize: vertical; line-height: 1.6; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; }
.form-control:focus { outline: none; border-color: var(--orange-400); box-shadow: 0 0 0 4px var(--orange-100); }
.form-control.is-invalid { border-color: var(--danger); }
.invalid-feedback { color: var(--danger); font-size: .82rem; margin-top: 4px; font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--orange-500); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 0 16px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding-top: 8px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; }
legend { font-weight: 800; padding: 0 6px; font-family: var(--font-display); }

.auth-wrap { min-height: calc(100vh - 220px); display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 460px; }
.btn-google { --btn-bg: #fff; --btn-fg: #1f1f1f; --btn-edge: #c7c7c7; border: 1px solid #c7c7c7; gap: 10px; }
.btn-google:hover { --btn-fg: #1f1f1f; background: #f8f9fa; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: .85rem; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.role-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.role-picker label { display: block; cursor: pointer; }
.role-picker input { position: absolute; opacity: 0; }
.role-picker span { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px; border-radius: 14px; border: 2px solid var(--line-strong); font-weight: 700; font-size: .88rem; text-align: center; }
.role-picker span b { font-size: 1.6rem; }
.role-picker input:checked + span { border-color: var(--orange-500); background: var(--orange-50); color: var(--orange-800); }
.role-picker input:focus-visible + span { outline: 3px solid var(--sun); }

/* ---------- Thông báo ---------- */
.alert { padding: 12px 16px; border-radius: 14px; margin-bottom: 16px; font-weight: 600; display: flex; gap: 10px; align-items: flex-start; }
.alert-success { background: var(--success-soft); color: #14532d; border: 1px solid #bbf7d0; }
.alert-error { background: var(--danger-soft); color: #7f1d1d; border: 1px solid #fecaca; }
.alert-info { background: var(--sky-soft); color: #1e3a8a; border: 1px solid #bfdbfe; }
.alert-warning { background: var(--warning-soft); color: #78350f; border: 1px solid #fde68a; }
.flash-stack { position: fixed; top: 84px; right: 16px; z-index: 80; width: min(380px, calc(100vw - 32px)); }
.flash-stack .alert { box-shadow: var(--shadow-lg); animation: slidein .25s ease-out; }
@keyframes slidein { from { transform: translateY(-8px); opacity: 0; } }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .ic { font-size: 2.6rem; display: block; margin-bottom: 8px; }
.empty h3 { color: var(--ink-2); }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: var(--orange-50); font-weight: 700; color: var(--ink-2); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fffcf8; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.rank-medal { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; font-weight: 800; font-family: var(--font-display); background: #f4ece4; }
.rank-1 { background: linear-gradient(135deg, #ffe066, #f5b700); color: #5c4200; }
.rank-2 { background: linear-gradient(135deg, #eef2f7, #b9c3d0); color: #2b3440; }
.rank-3 { background: linear-gradient(135deg, #ffd0a8, #d9822b); color: #4d2600; }

/* ---------- Phân trang ---------- */
.pagination { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; list-style: none; padding: 0; margin: 24px 0 0; }
.pagination a, .pagination span { display: grid; place-items: center; min-width: 40px; height: 40px; padding: 0 10px; border-radius: 12px; border: 1px solid var(--line-strong); background: #fff; text-decoration: none; color: var(--ink-2); font-weight: 700; }
.pagination a:hover { border-color: var(--orange-400); color: var(--orange-700); }
.pagination .active span { background: var(--orange-500); border-color: var(--orange-500); color: #fff; }
.pagination .disabled span { opacity: .45; }

/* ---------- Dashboard ---------- */
.dash-hero { background: linear-gradient(120deg, var(--orange-500), #ff9a3d); color: #fff; border-radius: var(--radius-lg); padding: 24px; display: flex; gap: 20px; align-items: center; flex-wrap: wrap; position: relative; overflow: hidden; }
.dash-hero h1 { color: #fff; font-size: 1.7rem; margin: 0; }
.dash-hero::after { content: ""; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px; border-radius: 50%; background: rgba(255, 255, 255, .15); }
.stat { padding: 18px; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); }
.stat .v { font-family: var(--font-display); font-size: 1.9rem; font-weight: 800; line-height: 1.1; color: var(--ink); }
.stat .k { color: var(--muted); font-size: .84rem; font-weight: 600; }
.stat .ic { float: right; font-size: 1.6rem; }
.progress { height: 10px; background: var(--orange-100); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--orange-400), var(--orange-600)); border-radius: 999px; }
.progress.teal > span { background: linear-gradient(90deg, #36c6c6, var(--teal)); }
.progress.red > span { background: linear-gradient(90deg, #f87171, var(--danger)); }
.badge-tile { text-align: center; padding: 16px 10px; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); }
.badge-tile .e { font-size: 2.2rem; display: block; }
.badge-tile.locked { filter: grayscale(1); opacity: .45; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 12px; text-decoration: none; color: var(--ink-2); font-weight: 600; }
.side-nav a:hover, .side-nav a.active { background: var(--orange-50); color: var(--orange-700); }

/* ---------- Kỳ thi ---------- */
.comp-card { overflow: hidden; }
.comp-banner { aspect-ratio: 16 / 7; background: linear-gradient(135deg, var(--orange-500), var(--sun)); display: grid; place-items: center; font-size: 3rem; position: relative; }
.comp-banner img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 18px 34px; }
.timeline li::before { content: ""; position: absolute; left: 10px; top: 6px; bottom: -6px; width: 2px; background: var(--orange-200); }
.timeline li:last-child::before { display: none; }
.timeline li::after { content: attr(data-n); position: absolute; left: 0; top: 0; width: 22px; height: 22px; border-radius: 50%; background: var(--orange-500); color: #fff; font-size: .75rem; font-weight: 800; display: grid; place-items: center; }

/* ---------- Chân trang ---------- */
.site-footer { background: #2a1a0d; color: #f5e6d6; margin-top: 48px; }
.site-footer a { color: #ffd3a6; text-decoration: none; }
.site-footer a:hover { color: #fff; }
.footer-grid { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; gap: 28px; padding: 44px 16px 28px; }
.site-footer h4 { color: #fff; font-size: 1rem; margin-bottom: 12px; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: .92rem; }
.footer-bottom { border-top: 1px solid rgba(255, 255, 255, .1); padding: 16px; font-size: .82rem; color: #c7b29d; text-align: center; }
@media (max-width: 860px) { .footer-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .footer-grid { grid-template-columns: 1fr; } }

/* ---------- Công cụ lớp học ---------- */
.tool-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 20px 12px; border-radius: 22px; background: #fff; border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 700; transition: transform .15s, box-shadow .15s; }
.tool-card:hover { transform: translateY(-4px) rotate(-1deg); box-shadow: var(--shadow); color: var(--orange-700); }
.tool-card .e { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; font-size: 2rem; }
.tool-card small { font-weight: 500; color: var(--muted); font-size: .8rem; }
.tool-stage { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 24px; text-align: center; }
.big-display { font-family: var(--font-display); font-weight: 800; font-size: clamp(3rem, 2rem + 8vw, 8rem); line-height: 1; color: var(--orange-600); font-variant-numeric: tabular-nums; }
.result-pop { animation: pop .4s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.dice { display: inline-grid; place-items: center; width: 110px; height: 110px; border-radius: 24px; background: #fff; border: 3px solid var(--ink); font-size: 4.5rem; box-shadow: 0 6px 0 var(--ink); margin: 8px; }
.score-team { border-radius: 22px; padding: 18px; color: #fff; text-align: center; }
.score-team .pts { font-family: var(--font-display); font-size: 4rem; font-weight: 800; line-height: 1; }
.score-team form { display: inline; }
.score-team .btn { --btn-bg: rgba(255, 255, 255, .25); --btn-edge: rgba(0, 0, 0, .2); }
.xw-grid { display: inline-grid; gap: 2px; background: transparent; margin: 0 auto; }
.xw-cell { width: 36px; height: 36px; position: relative; }
.xw-cell.on { background: #fff; border: 2px solid var(--ink); border-radius: 6px; }
.xw-cell input { width: 100%; height: 100%; border: 0; text-align: center; font: 800 1.1rem var(--font-display); text-transform: uppercase; background: transparent; padding: 0; }
.xw-cell.ok { background: var(--leaf-soft); }
.xw-cell.bad { background: var(--danger-soft); }
.xw-cell .no { position: absolute; top: 0; left: 2px; font-size: .58rem; font-weight: 800; color: var(--orange-700); line-height: 1; }
.xw-cell.key { background: var(--sun-soft); }
@media (max-width: 520px) { .xw-cell { width: 26px; height: 26px; } .xw-cell input { font-size: .85rem; } }
.caro-board { display: inline-grid; gap: 2px; background: var(--line-strong); padding: 2px; border-radius: 8px; }
.caro-board button { width: 32px; height: 32px; border: 0; background: #fff; font: 800 1.1rem var(--font-display); cursor: pointer; padding: 0; }
.caro-board button.x { color: var(--orange-600); } .caro-board button.o { color: var(--sky); }
.caro-board button.win { background: var(--sun-soft); }
@media (max-width: 520px) { .caro-board button { width: 22px; height: 22px; font-size: .8rem; } }
.hang-word { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; font: 800 2rem var(--font-display); }
.hang-word span { min-width: 34px; border-bottom: 4px solid var(--ink); text-align: center; }
.kbd-grid { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 640px; margin: 0 auto; }
.kbd-grid button { width: 42px; height: 42px; border-radius: 10px; border: 2px solid var(--line-strong); background: #fff; font-weight: 800; cursor: pointer; }
.kbd-grid button:disabled { opacity: .3; }

/* ---------- Tiện ích in ---------- */
@media print {
  .site-header, .site-footer, .topbar, .no-print, .flash-stack { display: none !important; }
  body { background: #fff; }
  .card { border: 0; box-shadow: none; }
}

/* ---------- Trang quản trị ---------- */
.admin-body { background: #f8f4ef; }
.admin-shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.admin-side { background: #2a1a0d; color: #f5e6d6; padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.admin-side .brand { color: #fff; margin: 0 6px 18px; }
.admin-side h6 { font: 700 .7rem var(--font-body); text-transform: uppercase; letter-spacing: .1em; color: #b39a82; margin: 16px 10px 6px; }
.admin-side a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 10px; color: #f5e6d6; text-decoration: none; font-size: .9rem; font-weight: 500; }
.admin-side a:hover, .admin-side a.active { background: rgba(255, 122, 0, .18); color: #fff; }
.admin-side a .badge { margin-left: auto; }
.admin-main { min-width: 0; }
.admin-top { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 30; }
.admin-content { padding: 24px; }
.admin-content > * + * { margin-top: 18px; }
.page-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-title h1 { font-size: 1.55rem; margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.filters .form-control { min-height: 40px; padding: 6px 12px; width: auto; min-width: 140px; }
.admin-toggle { display: none; }
@media (max-width: 960px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-side { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 90; transform: translateX(-100%); transition: transform .2s; }
  .admin-side.open { transform: none; box-shadow: var(--shadow-lg); }
  .admin-toggle { display: inline-grid; place-items: center; }
  .admin-content { padding: 16px; }
}
.status-draft { background: #f1ede8; color: var(--ink-2); }
.status-pending { background: var(--sun-soft); color: #854d0e; }
.status-published, .status-approved, .status-open, .status-graded { background: var(--leaf-soft); color: #166534; }
.status-archived, .status-closed, .status-rejected, .status-cancelled, .status-voided { background: var(--danger-soft); color: #991b1b; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px; border: 2px solid var(--line-strong); border-bottom: 0; border-radius: 12px 12px 0 0; background: var(--orange-50); }
.editor-toolbar button { border: 1px solid var(--line-strong); background: #fff; border-radius: 8px; padding: 4px 10px; cursor: pointer; font-weight: 700; font-size: .85rem; }
.editor-toolbar + textarea.form-control { border-radius: 0 0 12px 12px; }
.bar-chart { display: flex; gap: 6px; align-items: flex-end; height: 140px; }
.bar-chart div { flex: 1; background: linear-gradient(180deg, var(--orange-400), var(--orange-600)); border-radius: 6px 6px 2px 2px; min-height: 2px; position: relative; }
.bar-chart span { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: .68rem; color: var(--muted); white-space: nowrap; }

/* ---------- Tinh chỉnh responsive ---------- */
html, body { overflow-x: hidden; }
.hero-inner > * { min-width: 0; }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
@media (max-width: 1280px) and (min-width: 641px) {
  .header-search { display: none; position: absolute; right: 16px; top: 68px; width: 360px; padding: 8px; background: #fff; border-radius: 0 0 16px 16px; box-shadow: var(--shadow); }
  .header-search.open { display: block; }
  .header-search button { right: 12px; top: 12px; }
  .search-toggle { display: grid; margin-left: auto; }
}
@media (max-width: 860px) { .hero-inner { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) {
  .brand-name { font-size: 1.02rem; }
  .brand-mark { width: 36px; height: 36px; }
  .header-actions .btn-sm { padding: 0 10px; font-size: .8rem; }
  .hero-inner { padding-top: 32px; }
  .hero-search { flex-wrap: wrap; }
  .hero-search input { min-height: 44px; flex-basis: 100%; }
  .hero-search .btn { width: 100%; }
}
@media (max-width: 400px) {
  .header-inner { gap: 6px; }
  .brand-name { font-size: .92rem; }
  .nav-toggle, .search-toggle { width: 38px; height: 38px; }
}

.import-cell { max-height: 170px; overflow: auto; }
.import-cell img { max-width: 160px; max-height: 110px; display: block; margin: 4px 0; }
/* Màn hình laptop nhỏ: ẩn tên trên nút tài khoản để menu không tràn */
@media (max-width: 1360px) and (min-width: 1181px) { .header-actions .user-chip > span:last-child { display: none; } .header-actions .user-chip { padding: 4px; } }
