/* ═══════════════════════════════════════════════════════════════════════════
   AstroTown · Base Styles — Reset + Global
   ═══════════════════════════════════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--bg-deep);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Starfield canvas always behind everything */
#starfield-canvas {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  width: 100%;
  height: 100%;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-void); }
::-webkit-scrollbar-thumb { background: var(--bg-overlay); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }

/* ── Typography base ─────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  line-height: var(--leading-tight);
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--t-fast) ease;
}
a:hover { color: var(--accent-pulse); }

img, video, canvas { display: block; max-width: 100%; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ── Focus ring ──────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ── Selection ───────────────────────────────────────────────────────────── */
::selection {
  background: rgba(99,102,241,0.35);
  color: var(--text-primary);
}

/* ── Layout helpers ──────────────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

.page-wrapper {
  min-height: 100vh;
  padding-top: var(--nav-h);
}

@media (max-width: 959px) {
  .page-wrapper { padding-bottom: var(--tabbar-h); }
}

.container {
  width: 100%;
  max-width: var(--max-w);
  margin-inline: auto;
  padding-inline: var(--s4);
}

@media (min-width: 600px)  { .container { padding-inline: var(--s6); } }
@media (min-width: 960px)  { .container { padding-inline: var(--s8); } }
@media (min-width: 1280px) { .container { padding-inline: var(--s10); } }

/* ── Utility classes ─────────────────────────────────────────────────────── */
.text-clamp-1 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.text-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.text-clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--s2); }
.gap-3 { gap: var(--s3); }
.gap-4 { gap: var(--s4); }

.sr-only { @extend .visually-hidden; }

/* ── Glass panel ─────────────────────────────────────────────────────────── */
.glass {
  background: var(--bg-glass);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border-subtle);
}

/* ── Glow text ───────────────────────────────────────────────────────────── */
.glow-text {
  text-shadow: 0 0 20px rgba(167,139,250,0.6), 0 0 40px rgba(99,102,241,0.3);
}

/* ── Loading shimmer ─────────────────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

.shimmer {
  background: linear-gradient(90deg,
    var(--bg-surface) 25%,
    var(--bg-raised) 50%,
    var(--bg-surface) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s linear infinite;
}

/* ── Scroll row (horizontal swipe) ──────────────────────────────────────── */
.scroll-row {
  display: flex;
  gap: var(--s3);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--s2);
  scrollbar-width: none;
}
.scroll-row::-webkit-scrollbar { display: none; }
.scroll-row > * { scroll-snap-align: start; flex-shrink: 0; }

/* ── Section header ──────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--s5);
}

.section-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  display: flex;
  align-items: center;
  gap: var(--s2);
}

.section-title .star { color: var(--accent-glow); }

.section-link {
  font-size: var(--text-sm);
  color: var(--accent-glow);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: gap var(--t-fast) ease;
}
.section-link:hover { gap: 8px; color: var(--accent-pulse); }

/* ── Toast system ────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--tabbar-h) + var(--s4));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  pointer-events: none;
}

@media (min-width: 960px) {
  #toast-container { bottom: var(--s6); right: var(--s6); left: auto; transform: none; }
}

.toast {
  background: var(--bg-overlay);
  border: 1px solid var(--border-normal);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s5);
  font-size: var(--text-sm);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in var(--t-enter) both;
}

.toast.success { border-color: rgba(52,211,153,0.4); }
.toast.error   { border-color: rgba(248,113,113,0.4); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Format badge colors ─────────────────────────────────────────────────── */
.badge-xmp-cc     { background: rgba(99,102,241,0.85);  color: #fff; }
.badge-xmp-native { background: rgba(139,92,246,0.85);  color: #fff; }
.badge-h5-pure    { background: rgba(6,182,212,0.85);   color: #fff; }
.badge-advanced   { background: rgba(217,119,6,0.85);   color: #fff; }
.badge-unknown    { background: rgba(71,85,105,0.7);    color: var(--text-secondary); }

/* ══ Global Motion System  ══════════════════════════════════════════════════
   1. page-fade-in    — main content enters on load
   2. card-rise       — game cards stagger up when row renders
   3. modal-scale-in  — dialogs/panels pop from slightly below
   4. filter-pop      — filter tab activates with a micro-bounce
   5. sidebar-item-in — nav items slide in on expand
   Honour prefers-reduced-motion: reduce by removing all motion.
   ══════════════════════════════════════════════════════════════════════════ */

@keyframes page-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0);   }
}

@keyframes card-rise {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

@keyframes modal-scale-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

@keyframes filter-pop {
  0%   { transform: scale(1);    }
  40%  { transform: scale(1.07); }
  70%  { transform: scale(0.97); }
  100% { transform: scale(1);    }
}

@keyframes sidebar-item-in {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0);    }
}

/* Apply page-fade-in to main content area */
.at-main {
  animation: page-fade-in 0.32s var(--ease-out, cubic-bezier(.22,1,.36,1)) both;
}

/* Card stagger: first 8 children in a row get sequential delays */
.cat-row-list > .gc:nth-child(1)  { animation: card-rise 0.36s var(--ease-out, cubic-bezier(.22,1,.36,1)) 0.04s  both; }
.cat-row-list > .gc:nth-child(2)  { animation: card-rise 0.36s var(--ease-out, cubic-bezier(.22,1,.36,1)) 0.08s  both; }
.cat-row-list > .gc:nth-child(3)  { animation: card-rise 0.36s var(--ease-out, cubic-bezier(.22,1,.36,1)) 0.12s  both; }
.cat-row-list > .gc:nth-child(4)  { animation: card-rise 0.36s var(--ease-out, cubic-bezier(.22,1,.36,1)) 0.16s  both; }
.cat-row-list > .gc:nth-child(5)  { animation: card-rise 0.36s var(--ease-out, cubic-bezier(.22,1,.36,1)) 0.20s  both; }
.cat-row-list > .gc:nth-child(6)  { animation: card-rise 0.36s var(--ease-out, cubic-bezier(.22,1,.36,1)) 0.22s  both; }
.cat-row-list > .gc:nth-child(n+7){ animation: card-rise 0.36s var(--ease-out, cubic-bezier(.22,1,.36,1)) 0.24s  both; }

/* Filter tab activation micro-bounce */
.filter-tab.active { animation: filter-pop 0.28s ease; }

/* Modal/panel entrance */
.modal-backdrop.open .modal,
.at-auth-backdrop.open .at-auth-card,
.at-game-over-panel.visible .at-go-inner {
  animation: modal-scale-in 0.26s var(--ease-out, cubic-bezier(.22,1,.36,1)) both;
}

/* Sidebar nav items animate in when sidebar expands */
body:not(.sidebar-collapsed) .at-nav-item {
  animation: sidebar-item-in 0.2s ease both;
}

/* Suppress all motion if user prefers it */
@media (prefers-reduced-motion: reduce) {
  .at-main,
  .cat-row-list > .gc,
  .filter-tab.active,
  .modal-backdrop.open .modal,
  .at-auth-backdrop.open .at-auth-card,
  .at-game-over-panel.visible .at-go-inner,
  .at-nav-item {
    animation: none !important;
    transition: none !important;
  }
}
