/* ---------- Biến thiết kế ---------- */
:root {
  --bg: #15121f;
  --surface: #1f1a30;
  --surface-2: #2a2340;
  --line: #3b3259;
  --ink: #f2eef9;
  --muted: #a79fbf;
  --accent: #7c6cff;
  --accent-2: #4de3c1;
  --warm: #ffc857;
  --radius: 16px;
  --font-display: 'Bricolage Grotesque', 'Be Vietnam Pro', system-ui, sans-serif;
  --font-body: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
body.noscroll { overflow: hidden; }
img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; margin: 0; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 3px; }
main:focus { outline: none; }

.wrap { width: min(1200px, 100% - 40px); margin-inline: auto; }
.skip {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  background: var(--accent-2); color: #15121f; padding: 8px 14px; border-radius: 8px; font-weight: 600;
}
.skip:focus { top: 12px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 28px;
  padding: calc(14px + env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
  background: rgba(21, 18, 31, .9);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font: 800 1.25rem/1 var(--font-display); text-decoration: none;
}
.brand-mark { width: 32px; height: 32px; object-fit: contain; border-radius: 9px; transition: transform .3s cubic-bezier(.3, 1.6, .5, 1); }
.brand:hover .brand-mark { transform: rotate(-10deg) scale(1.1); }

.nav { display: flex; gap: 22px; margin-right: auto; }
.nav a { position: relative; text-decoration: none; color: var(--muted); font-weight: 500; padding: 4px 0; transition: color .2s; }
.nav a::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -2px; height: 2px;
  background: var(--accent-2); transform: scaleX(0); transform-origin: left; transition: transform .25s ease;
}
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); }
.nav a:hover::after, .nav a[aria-current="page"]::after { transform: scaleX(1); }

.donate-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--warm); color: #2a1d00; text-decoration: none; font-weight: 600;
  padding: 8px 16px; border-radius: 999px;
  transition: transform .2s ease, box-shadow .2s ease;
}
.donate-btn svg { width: 18px; height: 18px; fill: #d6336c; }
.donate-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px -6px rgba(255, 200, 87, .6); }
.donate-btn:hover svg { animation: beat .7s ease-in-out infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 30% { transform: scale(1.3); } 60% { transform: scale(1.05); } }

/* ---------- Trang chủ ---------- */
.hero { padding: 64px 0 28px; }
.hero h1 { font-size: clamp(2.4rem, 6vw, 4.4rem); font-weight: 800; letter-spacing: -.02em; white-space: pre-line; }
.hero p { margin-top: 18px; max-width: 52ch; color: var(--muted); font-size: 1.1rem; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 20px 0 28px; }
.search {
  position: relative; flex: 0 1 280px; min-width: 200px;
}
.search svg { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); stroke: var(--muted); fill: none; stroke-width: 2; }
.search input {
  width: 100%; padding: 10px 14px 10px 42px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink); font: inherit;
  transition: border-color .2s, box-shadow .2s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(124, 108, 255, .25); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 14px; border-radius: 999px; background: transparent;
  border: 1px solid var(--line); color: var(--muted);
  transition: transform .2s ease, border-color .2s, color .2s, background .2s;
}
.chip:hover { border-color: var(--accent); color: var(--ink); transform: translateY(-2px); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.result-count { margin-left: auto; color: var(--muted); font-size: .95rem; }

.grid {
  display: grid; gap: 24px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  padding-bottom: 72px;
}
@media (min-width: 720px) { .card.wide { grid-column: span 2; } }

.empty {
  grid-column: 1 / -1; text-align: center; padding: 64px 16px; color: var(--muted);
  border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty strong { display: block; color: var(--ink); font: 700 1.3rem var(--font-display); margin-bottom: 6px; }
.empty button { margin-top: 16px; }

/* ---------- Thẻ game (phần có hiệu ứng hover) ---------- */
.card {
  position: relative; display: flex; flex-direction: column;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
  color: inherit; text-decoration: none; overflow: hidden;
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(var(--lift, 0px));
  transition: transform .3s ease, box-shadow .3s ease, border-color .3s ease;
  will-change: transform;
}
.card.is-tilting { transition: transform .08s linear, box-shadow .3s ease, border-color .3s ease; }
.card:focus-visible { --lift: -6px; border-color: var(--accent-2); }

.card-media { position: relative; aspect-ratio: 315 / 250; overflow: hidden; background: var(--surface-2); }
.card.wide .card-media { aspect-ratio: 630 / 250; }
.card-media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transition: transform .6s cubic-bezier(.2, .7, .2, 1); }

.card-glare {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .3s;
  background: radial-gradient(circle at var(--mx, 50%) var(--my, 50%), rgba(255, 255, 255, .28), transparent 55%);
}

.badges { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; z-index: 2; }
.badge {
  padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: rgba(21, 18, 31, .78); color: var(--ink); border: 1px solid rgba(255, 255, 255, .15);
}

/* lớp phủ hiện khi hover: mô tả + nút Chơi ngay */
.card-over {
  position: absolute; inset: auto 0 0 0; z-index: 2;
  display: flex; flex-direction: column; gap: 10px; padding: 48px 16px 16px;
  background: linear-gradient(to top, rgba(21, 18, 31, .95) 30%, rgba(21, 18, 31, 0));
  transform: translateY(101%); opacity: 0;
  transition: transform .35s cubic-bezier(.2, .8, .2, 1), opacity .25s;
}
.card-over p { font-size: .9rem; color: #e3ddf3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.play-pill {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent-2); color: #0d2a24; font-weight: 700; padding: 8px 16px; border-radius: 999px;
  transition: transform .2s, box-shadow .2s;
}
.play-pill svg { width: 14px; height: 14px; fill: currentColor; }

.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; }
.card-body h3 { font-size: 1.2rem; font-weight: 800; transition: color .2s; }
.card-desc { color: var(--muted); font-size: .92rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags li { color: var(--muted); font-size: .82rem; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); }

/* chỉ áp hiệu ứng hover cho thiết bị có chuột */
@media (hover: hover) and (pointer: fine) {
  .card-desc { display: none; }
  .card:hover { --lift: -6px; border-color: var(--accent); box-shadow: 0 22px 44px -14px rgba(124, 108, 255, .55); }
  .card:hover .card-media img { transform: scale(1.09); }
  .card:hover .card-glare { opacity: 1; }
  .card:hover .card-over, .card:focus-visible .card-over { transform: translateY(0); opacity: 1; }
  .card:hover .card-body h3 { color: var(--accent-2); }
  .card:hover .play-pill { box-shadow: 0 0 0 5px rgba(77, 227, 193, .22); }
  .card:focus-visible .card-media img { transform: scale(1.09); }
}
@media (hover: none), (pointer: coarse) {
  .card-over { display: none; }
  .card:active { --lift: -3px; }
}

/* ---------- Nút chung ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 600;
  padding: 9px 16px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
  transition: transform .2s ease, border-color .2s, background .2s;
}
.btn:hover { transform: translateY(-2px); border-color: var(--accent); background: #332a52; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #8d7fff; border-color: #8d7fff; }

/* ---------- Trang game ---------- */
.game-page { padding: 24px 0 72px; }
.crumb { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; margin-bottom: 14px; transition: color .2s, transform .2s; }
.crumb:hover { color: var(--ink); transform: translateX(-3px); }
.game-title { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 800; margin-bottom: 18px; }

.stage {
  position: relative; margin-inline: auto; overflow: hidden;
  width: min(100%, calc(78vh * var(--arn, 1.6)));
  aspect-ratio: var(--ar, 16 / 10);
  background: #000; border-radius: var(--radius); border: 1px solid var(--line);
}
.stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }
.stage:fullscreen { width: 100%; max-width: none; height: 100%; aspect-ratio: auto; border-radius: 0; border: 0; }
.stage:-webkit-full-screen { width: 100%; max-width: none; height: 100%; aspect-ratio: auto; border-radius: 0; border: 0; }
.stage.pseudo-full {
  position: fixed; inset: 0; z-index: 100; width: 100%; max-width: none; height: 100dvh;
  aspect-ratio: auto; border-radius: 0; border: 0; margin: 0;
}
/* Xoay ngang bằng CSS cho máy không hỗ trợ khoá hướng màn hình thật (chủ yếu iPhone).
   Chỉ áp dụng cho thiết bị cảm ứng đang cầm dọc trong lúc toàn màn hình. */
@media screen and (orientation: portrait) and (pointer: coarse) {
  .stage:fullscreen, .stage:-webkit-full-screen, .stage.pseudo-full {
    position: fixed; top: 50%; left: 50%; margin: 0;
    width: 100vh; height: 100vw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center;
  }
}

.poster { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; padding: 0; background: #000; display: grid; place-items: center; overflow: hidden; }
.poster img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; filter: brightness(.55); transition: transform .6s ease, filter .4s; }
.poster:hover img { transform: scale(1.04); filter: brightness(.7); }
.poster-play {
  position: relative; display: inline-flex; align-items: center; gap: 12px;
  background: var(--accent-2); color: #0d2a24; font: 800 1.2rem var(--font-display);
  padding: 16px 30px; border-radius: 999px; transition: transform .25s cubic-bezier(.3, 1.6, .5, 1);
}
.poster-play svg { width: 20px; height: 20px; fill: currentColor; }
.poster-play::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; border: 2px solid var(--accent-2);
  animation: ring 2s ease-out infinite;
}
.poster:hover .poster-play { transform: scale(1.08); }
@keyframes ring { from { transform: scale(1); opacity: .8; } to { transform: scale(1.5); opacity: 0; } }

.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

.player-bar { width: min(100%, calc(78vh * var(--arn, 1.6))); margin: 14px auto 0; display: flex; flex-wrap: wrap; gap: 10px; }
.player-bar .push { margin-left: auto; }

.notice {
  width: min(100%, calc(78vh * var(--arn, 1.6))); margin: 0 auto 14px; padding: 12px 16px;
  border-radius: 12px; border: 1px solid #6b5a1f; background: #2b2410; color: #ffe9a8;
}

.game-info { display: grid; gap: 32px; grid-template-columns: minmax(0, 1fr) 300px; margin-top: 40px; }
.game-info h2 { font-size: 1.4rem; margin-bottom: 12px; }
.game-info .desc { color: #d7d0e8; max-width: 65ch; }
.side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 16px; align-content: start; }
.side dt { color: var(--muted); font-size: .85rem; }
.side dd { margin: 2px 0 0; font-weight: 500; }
.side .btn { justify-content: center; }
@media (max-width: 800px) { .game-info { grid-template-columns: 1fr; } }

.more { padding-top: 48px; }
.more h2 { font-size: 1.4rem; margin-bottom: 18px; }
.more .grid { padding-bottom: 0; }

/* ---------- Trang Ủng hộ và Giới thiệu ---------- */
.page { padding: 56px 0 80px; }
.page.narrow { width: min(820px, 100% - 40px); }
.page h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; margin-bottom: 16px; }
.page .lead { color: var(--muted); max-width: 60ch; margin-bottom: 32px; }
.page .prose p + p { margin-top: 14px; }
.page .prose { max-width: 62ch; color: #d7d0e8; }

.donate-grid { display: grid; gap: 24px; grid-template-columns: 280px minmax(0, 1fr); align-items: start; }
@media (max-width: 680px) { .donate-grid { grid-template-columns: 1fr; } .qr-card { max-width: 320px; } }
.qr-card { margin: 0; background: #fff; color: #15121f; border-radius: var(--radius); padding: 16px; text-align: center; }
.qr-card img { width: 100%; height: auto; border-radius: 8px; }
.qr-card figcaption { margin-top: 10px; font-size: .9rem; color: #4a4363; }
.qr-missing {
  aspect-ratio: 1; display: grid; place-items: center; text-align: center; padding: 16px;
  border: 2px dashed #b9b2d3; border-radius: 8px; color: #4a4363; font-size: .9rem;
}
.bank-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; display: grid; gap: 16px; }
.bank-card dl { margin: 0; display: grid; gap: 14px; }
.bank-card dt { color: var(--muted); font-size: .85rem; }
.bank-card dd { margin: 2px 0 0; font-weight: 600; font-size: 1.1rem; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.link-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 24px 0 calc(24px + env(safe-area-inset-bottom)); color: var(--muted); font-size: .92rem; }
.footer-row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; }
.footer-row a { text-decoration: none; transition: color .2s; }
.footer-row a:hover { color: var(--ink); }

/* ---------- Điện thoại ---------- */
@media (max-width: 640px) {
  .site-header { gap: 12px; }
  .brand { font-size: 1.05rem; min-width: 0; }
  .brand span { max-width: 26vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav { gap: 12px; font-size: .95rem; }
  .nav a, .donate-btn { white-space: nowrap; }
  .donate-btn { padding: 7px 12px; }
  .hero h1 { font-size: 2.1rem; }
  .hero { padding-top: 40px; }
  .result-count { margin-left: 0; width: 100%; }
}

/* ---------- Tôn trọng người dùng tắt hiệu ứng ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
  .card, .card:hover { transform: none !important; }
}
