/* Giao diện dùng chung cho cổng game và mọi game */

/* Font nằm sẵn trong repo (chơi offline được): Be Vietnam Pro cho nội dung, Nunito cho tiêu đề.
   Tải lại hoặc đổi font: python tools/fetch_fonts.py "Tên font" 400,700 */
@import url("../fonts/be-vietnam-pro/font.css");
@import url("../fonts/nunito/font.css");

:root {
  --bg: #f5f3ff;
  --surface: #ffffff;
  --surface-2: #f1eefc;
  --text: #1f1b3d;
  --text-soft: #625d82;
  --primary: #6252e8;
  --primary-2: #8b74f7;
  --primary-dark: #4636c2;
  --accent: #ff7a59;
  --accent-2: #ffa26b;
  --accent-dark: #d9542f;
  --success: #1fae7a;
  --danger: #ef4f5f;
  --star: #ffb800;
  --border: #e6e1f7;
  --shadow: 0 1px 2px rgba(31, 27, 61, 0.06), 0 12px 32px -12px rgba(31, 27, 61, 0.25);
  --shadow-lg: 0 2px 4px rgba(31, 27, 61, 0.06), 0 24px 48px -16px rgba(31, 27, 61, 0.35);

  /* Màu nhóm game */
  --cat-hoc-tap: #1fae7a;
  --cat-cong-nghe: #3a7bde;
  --cat-ai: #9b51e0;

  --radius: 22px;
  --radius-sm: 14px;
  --font: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Nunito", "Be Vietnam Pro", "Segoe UI", system-ui, sans-serif;
  --fs-base: 20px;
  --tap: 48px;
}

/* Chữ to để chiếu lên màn hình lớp học (nút 🔍 trên thanh trên) */
:root[data-size="big"] { --fs-base: 25px; --tap: 56px; }
.btn[aria-pressed="true"] { box-shadow: inset 0 0 0 3px var(--primary), 0 4px 0 var(--primary-dark); }

/* Chế độ tương phản cao (bật trong cài đặt) */
:root[data-contrast="high"] {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f0f0;
  --text: #000000;
  --text-soft: #1a1a1a;
  --primary: #0039a6;
  --primary-2: #0039a6;
  --primary-dark: #002270;
  --border: #000000;
  --shadow: 0 0 0 2px #000000;
  --shadow-lg: 0 0 0 2px #000000;
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: var(--fs-base); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  background:
    radial-gradient(1100px 560px at 8% -8%, #e6e0ff 0, transparent 62%),
    radial-gradient(900px 520px at 105% 0%, #ffe6da 0, transparent 58%),
    radial-gradient(800px 600px at 50% 120%, #dff4ff 0, transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
:root[data-contrast="high"] body { background: var(--bg); }

h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; letter-spacing: -0.01em; font-family: var(--font-display); }
/* nút và ô nhập dùng cùng font với trang (trình duyệt mặc định dùng font hệ thống) */
button, input, select, textarea { font-family: inherit; }
a { color: var(--primary); }
img, svg { max-width: 100%; display: block; }

:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }

/* Thuộc tính hidden luôn thắng mọi kiểu hiển thị (ví dụ .btn dùng display: inline-flex) */
[hidden] { display: none !important; }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0.4em 1.2em;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--primary-2), var(--primary));
  color: #fff;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 0 var(--primary-dark), 0 10px 22px -8px rgba(98, 82, 232, 0.6);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
  user-select: none;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 1px 0 var(--primary-dark); }
.btn[disabled], .btn[aria-disabled="true"] {
  background: #d6d2e6; color: #fff; box-shadow: 0 4px 0 #b9b4cc; cursor: not-allowed; transform: none; filter: none;
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 0 0 1.5px var(--border), 0 4px 0 var(--border), 0 8px 18px -10px rgba(31, 27, 61, 0.3);
}
.btn-secondary:active { box-shadow: inset 0 0 0 1.5px var(--border), 0 1px 0 var(--border); }
.btn-accent {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 0 var(--accent-dark), 0 10px 22px -8px rgba(255, 122, 89, 0.65);
}
.btn-accent:active { box-shadow: 0 1px 0 var(--accent-dark); }
.btn-icon { padding: 0; width: var(--tap); font-size: 1.1rem; }
.btn-lg { font-size: 1.2rem; min-height: 60px; padding: 0.4em 1.8em; }

/* ---------- Thẻ ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Thanh trên của màn game ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.topbar .btn-icon { min-height: 44px; width: 44px; min-width: 44px; }
.topbar-title {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { display: flex; gap: 8px; }

/* ---------- Hộp thoại ---------- */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(31, 27, 61, 0.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in 0.15s ease-out;
}
.dialog {
  width: 100%;
  max-width: 540px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 28px 28px 24px;
  text-align: center;
  border-radius: 28px;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.22s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.dialog-title { font-size: 1.5rem; }
.dialog-body { margin-bottom: 22px; color: var(--text-soft); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }

.input-lg {
  width: 100%;
  min-height: 64px;
  padding: 0 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
}
.input-lg:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 4px rgba(98, 82, 232, 0.15); }

/* ---------- Sao & phần thưởng ---------- */
.stars { display: inline-flex; gap: 6px; font-size: 2.6rem; line-height: 1; }
.star { color: #e2ddef; }
.star.on {
  color: var(--star);
  text-shadow: 0 2px 0 #e59a00, 0 6px 16px rgba(255, 184, 0, 0.45);
  animation: star-pop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both;
}
.star.on:nth-child(2) { animation-delay: 0.15s; }
.star.on:nth-child(3) { animation-delay: 0.3s; }

.confetti-layer { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 200; }
.confetti {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  animation: confetti-fall linear forwards;
}

/* ---------- Chứng nhận (chỉ hiện khi in) ---------- */
.certificate-print { display: none; }
@media print {
  body.printing > *:not(.certificate-print) { display: none !important; }
  body.printing .certificate-print { display: flex !important; }
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.9) translateY(8px); } }
@keyframes star-pop { 0% { transform: scale(0) rotate(-30deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes confetti-fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition: none !important; }
}

/* ---------- Bản quyền ---------- */
.mini-footer { padding: 24px 16px 32px; color: var(--text-soft); font-size: 0.7rem; line-height: 1.7; text-align: center; }
.mini-footer a { color: var(--primary); font-weight: 800; }
.copyright-note { margin: 16px 0 0; padding-top: 12px; border-top: 1px solid var(--border); color: var(--text-soft); font-size: 0.68rem; line-height: 1.6; }
@media print { .mini-footer { padding: 12px 0 0; } }

/* ---------- Dòng thông báo chạy và nút Góp ý (shared/js/notice.js) ---------- */
.notice-bar { position: sticky; z-index: 49; display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: linear-gradient(90deg, #fff3c4, #ffe6d6); border-bottom: 1px solid #f2d27a; color: #6a4400; font-size: 0.78rem; font-weight: 800; }
.notice-tag { flex: none; padding: 3px 10px; border-radius: 999px; background: #e8613c; color: #fff; font-size: 0.72rem; white-space: nowrap; }
.notice-track { flex: 1; overflow: hidden; mask-image: linear-gradient(90deg, transparent, #000 3%, #000 97%, transparent); }
.notice-move { display: flex; width: max-content; animation: notice-run 45s linear infinite; }
.notice-move span { padding-right: 80px; white-space: nowrap; }
.notice-bar:hover .notice-move { animation-play-state: paused; }
@keyframes notice-run { to { transform: translateX(-50%); } }
@media (prefers-reduced-motion: reduce) {
  .notice-move { animation: none; width: auto; }
  .notice-move span { white-space: normal; padding: 0; }
  .notice-move span + span { display: none; }
}
.fb-dock { position: fixed; right: 18px; bottom: 18px; z-index: 90; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.fb-btn { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 20px 0 14px; border: 0; border-radius: 999px; background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: #fff; font: inherit; font-size: 0.9rem; font-weight: 900; box-shadow: 0 4px 0 var(--accent-dark), 0 12px 28px -8px rgba(255, 122, 89, 0.7); cursor: pointer; }
.fb-btn span { font-size: 1.2rem; }
.fb-btn:hover { filter: brightness(1.06); }
.fb { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.fb p { margin: 0; }
.fb-text { width: 100%; padding: 12px; border: 2px solid var(--border); border-radius: 12px; font: inherit; font-size: 0.9rem; resize: vertical; }
.fb-text:focus { border-color: var(--primary); outline: none; }
.fb-note { color: var(--text-soft); font-size: 0.72rem; }
.fb-done { min-height: 1.2em; color: #14805a; font-size: 0.8rem; font-weight: 800; }
@media print { .notice-bar, .fb-dock { display: none !important; } }
.fb-label { font-weight: inherit; }
@media (max-width: 640px) {
  .fb-dock { right: 12px; bottom: 12px; }
  .fb-btn { justify-content: center; width: 52px; padding: 0; }
  .fb-btn .fb-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}
.dn-btn { background: linear-gradient(180deg, #ff8fb1, #e0507e); box-shadow: 0 4px 0 #b3305a, 0 12px 28px -8px rgba(224, 80, 126, 0.7); }
.ct-btn { background: linear-gradient(180deg, #5ec8f2, #2f86d6); box-shadow: 0 4px 0 #1f64a8, 0 12px 28px -8px rgba(47, 134, 214, 0.7); }
.fb-qr { display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: 14px; background: var(--surface-2); }
.fb-qr img { width: 120px; height: 120px; object-fit: contain; border-radius: 10px; background: #fff; }
.fb-qr small { display: block; color: var(--text-soft); font-size: 0.75rem; }
.fb-center { align-items: center; text-align: center; }
.dn-qr { width: min(260px, 70vw); height: auto; border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.dn-qr-empty { display: grid; place-items: center; aspect-ratio: 1; padding: 20px; border: 3px dashed var(--border); box-shadow: none; color: var(--text-soft); font-size: 0.85rem; font-weight: 700; text-align: center; }

/* ---------- Nhập thông tin người lớn trước khi chơi (shared/js/visitor-gate.js) ---------- */
.vg-back { z-index: 300; }
.vg { display: flex; flex-direction: column; gap: 12px; width: min(480px, calc(100vw - 32px)); text-align: left; }
.vg .dialog-title { text-align: center; }
.vg-lead { margin: 0; color: var(--text-soft); text-align: center; }
.vg-label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 900; }
.vg-name { min-height: 52px; padding: 0 14px; border: 2px solid var(--border); border-radius: 14px; font: inherit; font-size: 1rem; font-weight: 700; }
.vg-name:focus { border-color: var(--primary); outline: none; }
.vg-roles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.vg-role { min-height: 56px; border: 0; border-radius: 14px; background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--border); font: inherit; font-size: 0.95rem; font-weight: 900; cursor: pointer; }
.vg-role.on { background: color-mix(in srgb, var(--primary) 14%, #fff); box-shadow: inset 0 0 0 3px var(--primary); color: var(--primary-dark); }
.vg-err { min-height: 1.2em; margin: 0; color: var(--danger); font-size: 0.82rem; font-weight: 800; }
.vg-note { color: var(--text-soft); font-size: 0.72rem; line-height: 1.5; }
.vg .dialog-actions { justify-content: center; }
