/* =====================================================
   global.css — Shared layout, typography, base styles
   Miniatures Collection & Army Builder
   Mobile-first. No framework.
   ===================================================== */

/* ── Reset ───────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Ensure [hidden] always wins over display:flex/grid rules on components */
[hidden] { display: none !important; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100dvh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

img, svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

ul, ol {
  list-style: none;
}

/* ── Typography ───────────────────────────────────────── */
h1 { font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 700; line-height: 1.2; }
h2 { font-size: clamp(1.25rem, 3vw, 1.5rem); font-weight: 600; line-height: 1.3; }
h3 { font-size: 1.125rem; font-weight: 600; line-height: 1.3; }
h4 { font-size: 1rem; font-weight: 600; }

p { line-height: 1.6; }

.text-muted { color: var(--color-text-muted); }
.text-accent { color: var(--color-accent); }
.text-primary { color: var(--color-primary); }
.text-small { font-size: 0.875rem; }
.text-xs    { font-size: 0.75rem; }
.text-lg    { font-size: 1.125rem; }

/* ── Layout ───────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

main.container {
  padding-top: calc(var(--nav-height) + var(--space-4));
  padding-bottom: var(--space-8);
  min-height: 100dvh;
}

.container--narrow {
  max-width: 720px;
}

.page-content {
  padding-top: calc(var(--nav-height) + 1rem);
  padding-bottom: 2rem;
  min-height: 100dvh;
}

/* ── Design tokens ────────────────────────────────────── */
:root {
  /* Spacing scale (4px base) */
  --space-1: 0.25rem;   /*  4px */
  --space-2: 0.5rem;    /*  8px */
  --space-3: 0.75rem;   /* 12px */
  --space-4: 1rem;      /* 16px */
  --space-5: 1.25rem;   /* 20px */
  --space-6: 1.5rem;    /* 24px */
  --space-8: 2rem;      /* 32px */
  --space-10: 2.5rem;   /* 40px */
  --space-12: 3rem;     /* 48px */
}

/* ── Navigation ───────────────────────────────────────── */
:root {
  --nav-height: 56px;
}

@media (min-width: 768px) {
  :root { --nav-height: 64px; }
}

.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: var(--nav-height);
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.nav-home {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.nav-home:hover {
  color: var(--color-text);
  text-decoration: none;
}

.nav-divider {
  color: var(--color-text-muted);
  opacity: 0.4;
  flex-shrink: 0;
}

.nav-game,
.nav-brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-primary);
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
}

.nav-game:hover,
.nav-brand:hover {
  color: var(--color-accent);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding-left: 0.5rem;
}

.nav-links::-webkit-scrollbar { display: none; }

.nav-link {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  white-space: nowrap;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.nav-link:hover {
  color: var(--color-text);
  background-color: var(--color-surface-2);
  text-decoration: none;
}

.nav-link.active {
  color: var(--color-accent);
  background-color: rgba(var(--color-accent-rgb), 0.12);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  margin-left: auto;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.nav-user-name {
  color: var(--color-text-muted);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: none;
}

@media (min-width: 480px) {
  .nav-user-name { display: block; }
}

/* ── Section headings ────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.section-title {
  font-size: 1.125rem;
  font-weight: 600;
}

/* ── Grid utilities ──────────────────────────────────── */
.grid {
  display: grid;
  gap: 1rem;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 479px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

@media (min-width: 480px) and (max-width: 767px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Flex utilities ──────────────────────────────────── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-xs { gap: 0.25rem; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.gap-lg { gap: 1.5rem; }

/* ── Spacing utilities ────────────────────────────────── */
.mt-xs { margin-top: 0.25rem; }
.mt-sm { margin-top: 0.5rem; }
.mt-md { margin-top: 1rem; }
.mt-lg { margin-top: 1.5rem; }
.mt-xl { margin-top: 2rem; }
.mb-sm { margin-bottom: 0.5rem; }
.mb-md { margin-bottom: 1rem; }
.mb-lg { margin-bottom: 1.5rem; }

/* ── Auth gate ────────────────────────────────────────── */
.auth-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  min-height: 70dvh;
  text-align: center;
  padding: 2rem;
}

.auth-gate h2 { color: var(--color-text); }
.auth-gate p  { color: var(--color-text-muted); max-width: 360px; }

/* ── Restricted banner ────────────────────────────────── */
.access-restricted {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 70dvh;
  text-align: center;
  color: var(--color-text-muted);
}

/* ── Divider ──────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 1.5rem 0;
}

/* ── Offline banner ───────────────────────────────────── */
.offline-banner {
  background-color: rgba(var(--color-accent-rgb), 0.15);
  border: 1px solid rgba(var(--color-accent-rgb), 0.3);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--color-accent);
  text-align: center;
  margin-bottom: 1rem;
  display: none;
}

.offline-banner.visible { display: block; }

/* ── Toast notifications ─────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background-color: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.2s ease;
  pointer-events: auto;
  white-space: nowrap;
}

.toast.success { border-color: #4caf50; color: #4caf50; }
.toast.error   { border-color: #f44336; color: #f44336; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar styling ────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: 3px;
}

/* ── Focus visible ────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
