/* ==========================================================================
   Design System — SaaS Minecraft Map Renderer
   Clean, modern, Apple-inspired aesthetic with Minecraft personality.
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
  /* Brand colors */
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #dbeafe;
  /* Dark variant for text on --color-primary-light backgrounds (WCAG AA, ~9.5:1) */
  --color-primary-dark: #1e40af;

  /* Semantic colors */
  --color-success: #16a34a;
  --color-success-light: #dcfce7;
  /* Dark variant for text on --color-success-light backgrounds (WCAG AA, ~6.5:1) */
  --color-success-dark: #15803d;
  --color-warning: #f59e0b;
  --color-warning-light: #fef3c7;
  /* Dark variant for text on --color-warning-light backgrounds (WCAG AA, ~7.5:1) */
  --color-warning-dark: #92400e;
  --color-danger: #dc2626;
  --color-danger-light: #fee2e2;
  /* Dark variant for text on --color-danger-light backgrounds (WCAG AA, ~5.5:1) */
  --color-danger-dark: #b91c1c;

  /* Neutrals */
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-text: #1f2937;
  --color-text-secondary: #4b5563;
  /* Darkened from #6b7280 (4.7:1 on #fafafa) to #5b6470 (~5.5:1) so small
     text at 12px meets WCAG AA contrast per the 2026-04 UI review. */
  --color-text-muted: #5b6470;
  --color-border: #e5e7eb;
  --color-border-light: #f3f4f6;

  /* Minecraft-themed accent */
  --color-grass: #5b8731;
  --color-dirt: #8b6914;
  --color-stone: #7f7f7f;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Typography.
     Apple devices get native SF first (Inter is a close substitute but
     SF is free and ships with the OS). Everyone else falls back to
     Inter, then the generic system stack. (UI-review #27) */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', system-ui, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;
  --text-4xl: 2.5rem;
  --text-5xl: 3.5rem;

  /* Borders & Radius — 3 sizes plus full (UI-review #25).
     `--radius-md` is kept as an alias of `--radius-lg` so existing rules
     keep working without needing an all-at-once sweep. */
  --radius-sm: 6px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-md: var(--radius-lg);
  --radius-full: 9999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.06);
  --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.12), 0 8px 10px rgba(0, 0, 0, 0.06);

  /* Transitions — split by purpose (UI-review #50).
     Micro: button state, hover — snappy, feels instant.
     Base: element show/hide.
     Slow: layout changes, modal, nav. */
  --transition-micro: 120ms ease;
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms cubic-bezier(0.32, 0.72, 0, 1);

  /* Layout */
  --max-width: 1200px;
  --nav-height: 64px;

  /* Focus indicator — single treatment reused everywhere (UI-review #33).
     A 2px outline is the WCAG-compliant baseline; the pale halo is
     decorative and reinforced the focus visually without stacking. */
  --focus-ring-color: var(--color-primary);
  --focus-ring-halo: color-mix(in srgb, var(--color-primary) 30%, transparent);
}

/* ==========================================================================
   Dark mode (UI-review #28)
   Activated via OS preference. Tokens override at :root so every rule
   that uses them gets dark values without per-component work.
   ========================================================================== */
@media (prefers-color-scheme: dark) {
  :root {
    --color-primary: #3b82f6;
    --color-primary-hover: #60a5fa;
    --color-primary-light: #1e3a8a;
    --color-primary-dark: #93c5fd;

    --color-success: #22c55e;
    --color-success-light: #14532d;
    --color-success-dark: #86efac;

    --color-warning: #fbbf24;
    --color-warning-light: #78350f;
    --color-warning-dark: #fcd34d;

    --color-danger: #ef4444;
    --color-danger-light: #7f1d1d;
    --color-danger-dark: #fca5a5;

    --color-bg: #0b0d10;
    --color-surface: #15181c;
    --color-text: #e5e7eb;
    --color-text-secondary: #c5cad1;
    --color-text-muted: #9098a3;
    --color-border: #2a2f36;
    --color-border-light: #1f2328;

    /* Shadows need higher alpha to show on dark surfaces. */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5), 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px rgba(0, 0, 0, 0.5), 0 8px 10px rgba(0, 0, 0, 0.3);
  }
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
}

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

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-hover);
}

/* Global focus-visible ring for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

ul, ol {
  list-style: none;
}

/* --------------------------------------------------------------------------
   Typography
   -------------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text);
}

h1 { font-size: var(--text-5xl); letter-spacing: -0.025em; }
h2 { font-size: var(--text-3xl); letter-spacing: -0.02em; }
h3 { font-size: var(--text-2xl); letter-spacing: -0.015em; }
h4 { font-size: var(--text-xl); letter-spacing: -0.01em; }

p {
  color: var(--color-text-secondary);
  line-height: 1.7;
}

.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: var(--text-sm); }

/* --------------------------------------------------------------------------
   Layout Utilities
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.section {
  padding: var(--space-3xl) 0;
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

/* --------------------------------------------------------------------------
   Navigation
   -------------------------------------------------------------------------- */
.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--color-border-light);
  z-index: 100;
  display: flex;
  align-items: center;
}

.nav .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--color-text);
}

.nav-logo:hover {
  color: var(--color-text);
}

.nav-logo-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--color-grass), var(--color-primary));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: var(--text-sm);
  font-weight: 800;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-xl);
}

.nav-links a {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  transition: color var(--transition-fast);
}

.nav-links a:hover {
  color: var(--color-text);
}

.nav-mobile-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-sm);
  color: var(--color-text);
}

/* --------------------------------------------------------------------------
   Page Content Offset (for fixed nav)
   -------------------------------------------------------------------------- */
.page-content {
  padding-top: var(--nav-height);
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }

  .section { padding: var(--space-2xl) 0; }

  .nav-mobile-toggle { display: block; }

  /* Mobile nav uses CSS grid's `grid-template-rows: 0fr → 1fr` pattern
     to animate from collapsed to expanded without needing to know the
     content height (UI-review #31). `gap`-animation jitter is gone
     because the menu gets `gap` only while open. `visibility` is
     toggled so links leave the tab order when hidden. */
  .nav-links {
    position: absolute;
    top: var(--nav-height);
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: grid;
    grid-template-rows: 0fr;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    padding: 0 var(--space-lg);
    transition:
      grid-template-rows var(--transition-slow),
      opacity var(--transition-fast),
      padding var(--transition-base),
      visibility 0s linear var(--transition-slow);
  }

  .nav-links > * {
    min-height: 0;
  }

  .nav-links.open {
    grid-template-rows: 1fr;
    opacity: 1;
    visibility: visible;
    padding: var(--space-md) var(--space-lg);
    transition:
      grid-template-rows var(--transition-slow),
      opacity var(--transition-fast),
      padding var(--transition-base),
      visibility 0s linear 0s;
  }

  /* Inner wrapper lets us stack nav links vertically while the outer
     grid animates the collapse. */
  .nav-links.open > * {
    margin-bottom: var(--space-md);
  }
  .nav-links.open > *:last-child { margin-bottom: 0; }
}

/* ==========================================================================
   Print styles (UI-review #46)
   Strip chrome so maps/invoices print cleanly.
   ========================================================================== */
@media print {
  .nav, .footer, .toast-region, .user-menu, .dashboard-loading,
  .map-topbar, .upload-section, .billing-actions {
    display: none !important;
  }

  body {
    background: #fff !important;
    color: #000 !important;
  }

  .card, .world-card, .billing-section, .account-section {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    break-inside: avoid;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }
}
