/* =============================
   Variables
   ============================= */
:root {
  /* Color palette — dark, ominous, grunge, occult */
  --color-bg: #0b0d10;            /* abyssal backdrop */
  --color-bg-elevated: #12151a;   /* for cards/raised surfaces */
  --color-surface: #151920;       /* subtle surface tone */
  --color-text: #d7d6cf;          /* bone parchment */
  --color-text-muted: #a1a09a;    /* weathered parchment */
  --color-heading: #e6e0cf;       /* aged vellum for headings */
  --color-primary: #79c596;       /* eldritch green glow */
  --color-primary-strong: #ffffff;
  --color-success: #3fbf6d;       /* ritual succeeded */
  --color-warning: #d4a63f;       /* tarnished gold */
  --color-danger: #cc4a4a;        /* sacrificial crimson */

  /* Neutral grays (cold slate) */
  --gray-950: #0a0b0d;
  --gray-900: #101317;
  --gray-800: #171a1f;
  --gray-700: #1f2329;
  --gray-600: #2a2f37;
  --gray-500: #3a404b;
  --gray-400: #555c69;
  --gray-300: #788191;
  --gray-200: #a1a7b1;
  --gray-100: #c8ccd2;
  --gray-50:  #e6e8eb;

  /* Typography */
  --font-sans: "Inter", "Source Sans 3", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Cormorant Garamond", "EB Garamond", "Garamond", Georgia, serif;
  --font-display: "IM Fell English", "Cinzel", "Cormorant Unicase", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Font sizes (fluid scale) */
  --fs-100: 0.75rem;
  --fs-200: 0.875rem;
  --fs-300: 1rem;
  --fs-400: clamp(1rem, 0.4vw + 0.95rem, 1.125rem);
  --fs-500: clamp(1.125rem, 0.8vw + 1rem, 1.5rem);
  --fs-600: clamp(1.25rem, 1.2vw + 1rem, 1.875rem);
  --fs-700: clamp(1.5rem, 2vw + 1rem, 2.25rem);
  --fs-800: clamp(1.875rem, 2.8vw + 1rem, 3rem);
  --fs-900: clamp(2.25rem, 3.8vw + 1rem, 4rem);

  /* Line heights */
  --lh-tight: 1.2;
  --lh-normal: 1.6;
  --lh-loose: 1.8;

  /* Spacing scale (0–96px in 4px steps) */
  --space-0: 0;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-9: 36px;
  --space-10: 40px;
  --space-11: 44px;
  --space-12: 48px;
  --space-13: 52px;
  --space-14: 56px;
  --space-15: 60px;
  --space-16: 64px;
  --space-17: 68px;
  --space-18: 72px;
  --space-19: 76px;
  --space-20: 80px;
  --space-21: 84px;
  --space-22: 88px;
  --space-23: 92px;
  --space-24: 96px;

  /* Radius */
  --radius-xs: 2px;
  --radius-s: 4px;
  --radius-m: 8px;
  --radius-l: 12px;
  --radius-xl: 18px;
  --radius-round: 9999px;

  /* Shadows (subtle, for dark UI) */
  --shadow-1: 0 1px 0 rgba(255,255,255,0.03), 0 1px 2px rgba(0,0,0,0.5);
  --shadow-2: 0 2px 6px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
  --shadow-3: 0 10px 30px rgba(0,0,0,0.65), 0 0 24px rgba(121,197,150,0.08);

  /* Transitions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --duration-fast: 120ms;
  --duration-base: 200ms;
  --duration-slow: 400ms;

  /* Layout */
  --container-max: 1200px;
}

/* =============================
   Reset / Normalize
   ============================= */
*, *::before, *::after { box-sizing: border-box; }

html:focus-within { scroll-behavior: smooth; }
html { color-scheme: dark; -webkit-text-size-adjust: 100%; }

body, h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd { margin: 0; }

img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }

ul[role="list"], ol[role="list"] { list-style: none; }

button, input, select, textarea { font: inherit; color: inherit; }

/* Improve text rendering on dark backgrounds */
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  html:focus-within { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* =============================
   Base
   ============================= */
body {
  min-height: 100dvh;
  font-family: var(--font-serif);
  font-size: var(--fs-400);
  line-height: var(--lh-normal);
  color: var(--color-text);
  background-color: var(--color-bg);
  background-image:
    radial-gradient(1200px 800px at 50% -10%, rgba(121,197,150,0.06), rgba(121,197,150,0) 40%),
    radial-gradient(1000px 600px at 100% 110%, rgba(0,0,0,0.55), rgba(0,0,0,0) 40%),
    radial-gradient(1000px 600px at 0% 110%, rgba(0,0,0,0.6), rgba(0,0,0,0) 40%);
  background-attachment: fixed, fixed, fixed;
}

::selection { background: color-mix(in oklab, var(--color-primary) 30%, transparent); color: var(--color-heading); }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  color: var(--color-heading);
  line-height: var(--lh-tight);
  letter-spacing: 0.01em;
}

h1 { font-size: var(--fs-900); }
h2 { font-size: var(--fs-800); }
h3 { font-size: var(--fs-700); }
h4 { font-size: var(--fs-600); }
h5 { font-size: var(--fs-500); }
h6 { font-size: var(--fs-400); }

/* Heading spacing */
h1, h2, h3, h4, h5, h6 { margin-block: var(--space-6) var(--space-3); }

p { max-width: 75ch; margin-block: 0 var(--space-4); }

a { color: var(--color-primary); text-decoration: none; text-underline-offset: 3px; }
a:hover { color: var(--color-primary); text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

hr {
  border: 0; height: 1px; margin-block: var(--space-8);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
}

code, pre, kbd, samp { font-family: var(--font-mono); font-size: 0.95em; }

/* Make media elements fluid with rounded corners for grunge cards */
img, video { border-radius: var(--radius-s); }

/* =============================
   Utilities
   ============================= */
.container { width: 100%; max-width: var(--container-max); margin-inline: auto; padding-inline: var(--space-4); }
@media (min-width: 768px) { .container { padding-inline: var(--space-6); } }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; gap: var(--space-3); }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }

.grid { display: grid; gap: var(--space-4); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }

.flow > * + * { margin-top: var(--space-4); }

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

/* Optional atmospheric flicker utility (respects reduced motion) */
@media (prefers-reduced-motion: no-preference) {
  @keyframes ui-flicker { 0%, 100% { opacity: 1 } 92% { opacity: 0.96 } 94% { opacity: 1 } 96% { opacity: 0.92 } 98% { opacity: 1 } }
  .fx-flicker { animation: ui-flicker 6s infinite; }
}

/* =============================
   Components
   ============================= */
/* Buttons */
.btn {
  --_bg: var(--color-primary);
  --_bg-hover: var(--color-primary-strong);
  --_fg: #0b1112;
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--space-2);
  padding: calc(var(--space-2) + 2px) var(--space-5);
  border: 1px solid color-mix(in oklab, var(--_bg) 55%, black);
  border-radius: var(--radius-m);
  background: linear-gradient(180deg, color-mix(in oklab, var(--_bg) 85%, white 0%), var(--_bg));
  color: var(--_fg);
  font-weight: 600; letter-spacing: 0.02em;
  text-decoration: none;
  box-shadow: var(--shadow-1), 0 0 0 0 rgba(121,197,150,0);
  cursor: pointer;
  transition: background var(--duration-base) var(--ease-out),
              color var(--duration-base) var(--ease-out),
              transform var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out),
              border-color var(--duration-base) var(--ease-out);
}
.btn:hover { background: var(--_bg-hover); transform: translateY(-1px); box-shadow: var(--shadow-2), 0 0 24px rgba(121,197,150,0.08); }
.btn:active { transform: translateY(0); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Ghost / secondary button */
.btn--ghost {
  --_bg: transparent; --_bg-hover: rgba(121,197,150,0.1); --_fg: var(--color-text);
  background: var(--_bg); color: var(--_fg);
  border-color: var(--gray-600);
}
.btn--ghost:hover { border-color: color-mix(in oklab, var(--color-primary) 40%, var(--gray-600)); }

/* Inputs */
.input, input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], textarea, select {
  width: 100%;
  padding: calc(var(--space-2) + 2px) var(--space-4);
  color: var(--color-text);
  background-color: var(--gray-800);
  border: 1px solid var(--gray-600);
  border-radius: var(--radius-s);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.02);
  transition: border-color var(--duration-base) var(--ease-out), box-shadow var(--duration-base) var(--ease-out), background-color var(--duration-base) var(--ease-out);
}
.input::placeholder, textarea::placeholder { color: var(--gray-300); }
.input:focus, input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: color-mix(in oklab, var(--color-primary) 50%, var(--gray-600));
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-primary) 20%, transparent);
}

/* Cards */
.card {
  position: relative;
  background: linear-gradient(180deg, color-mix(in oklab, var(--color-bg-elevated) 92%, black), var(--color-surface));
  color: var(--color-text);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: var(--radius-l);
  padding: var(--space-6);
  box-shadow: var(--shadow-2);
}
/* Subtle grunge vignette */
.card::before {
  content: "";
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 120% at 50% -10%, rgba(255,255,255,0.02), transparent 40%),
              radial-gradient(100% 100% at 50% 120%, rgba(0,0,0,0.35), transparent 60%);
  border-radius: inherit;
}

/* Links styled as buttons */
.a-btn { display: inline-block; }
.a-btn.btn { text-decoration: none; }

/* Alerts (basic) */
.alert { padding: var(--space-4); border-radius: var(--radius-m); border: 1px solid transparent; }
.alert--success { background: color-mix(in oklab, var(--color-success) 12%, var(--color-bg)); border-color: color-mix(in oklab, var(--color-success) 40%, transparent); }
.alert--warning { background: color-mix(in oklab, var(--color-warning) 12%, var(--color-bg)); border-color: color-mix(in oklab, var(--color-warning) 40%, transparent); }
.alert--danger  { background: color-mix(in oklab, var(--color-danger) 12%, var(--color-bg)); border-color: color-mix(in oklab, var(--color-danger) 40%, transparent); }

/* =============================
   Accessibility
   ============================= */
:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Ensure interactive elements have visible focus */
button:focus-visible, [role="button"]:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Reduced motion already handled in reset; also ensure smooth scroll is disabled in that mode */
@media (prefers-reduced-motion: reduce) { :focus-visible { scroll-behavior: auto; } }
