/* =====================================================
   Variables
   ===================================================== */
:root {
  /* Color scheme */
  color-scheme: dark;
  /* Core palette (gothic / occult) */
  --color-bg: #0a0b0d;               /* abyssal black */
  --color-surface: #101218;          /* deep surface */
  --color-elevated: #161922;         /* elevated panels */
  --color-text: #e6e0d6;             /* warm parchment */
  --color-muted: #b8aea3;            /* muted text */
  --color-primary: #e0b15c;          /* candlelight amber */
  --color-success: #2f6a51;          /* hemlock green */
  --color-warning: #dfaf4a;          /* warning ochre */
  --color-danger: #8e2230;           /* ritual crimson */

  /* Neutral warm grays */
  --gray-50: #f4f1ec;
  --gray-100: #e6e0d8;
  --gray-200: #cfc7be;
  --gray-300: #b8aea3;
  --gray-400: #9f968b;
  --gray-500: #827a70;
  --gray-600: #666058;
  --gray-700: #4c4741;
  --gray-800: #34312c;
  --gray-900: #1d1b18;

  /* Typography */
  --font-display: "Cinzel", "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-body: "Spectral", "Merriweather", Georgia, "Times New Roman", serif;

  --fs-xs: 12px;
  --fs-sm: 14px;
  --fs-base: 16px;
  --fs-md: 18px;
  --fs-lg: 20px;
  --fs-xl: 24px;
  --fs-2xl: 30px;
  --fs-3xl: 36px;
  --fs-4xl: 48px;
  --fs-5xl: 60px;

  --lh-body: 1.65;
  --lh-heading: 1.2;
  --measure: 70ch; /* comfortable line length */

  /* Spacing scale (0–96px) */
  --space-0: 0;
  --space-1: 2px;
  --space-2: 4px;
  --space-3: 8px;
  --space-4: 12px;
  --space-5: 16px;
  --space-6: 20px;
  --space-7: 24px;
  --space-8: 32px;
  --space-9: 40px;
  --space-10: 48px;
  --space-11: 56px;
  --space-12: 64px;
  --space-13: 72px;
  --space-14: 80px;
  --space-15: 96px;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-round: 9999px;

  /* Shadows (subtle warm glow for dark UI) */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.35);
  --shadow-md: 0 6px 16px rgba(0,0,0,0.45), 0 0 0 1px rgba(255, 198, 120, 0.04);
  --shadow-lg: 0 16px 40px rgba(0,0,0,0.55), 0 0 0 1px rgba(255, 198, 120, 0.06);

  /* Motion */
  --ease-emphasized: cubic-bezier(0.2, 0, 0, 1);
  --motion-fast: 120ms var(--ease-emphasized);
  --motion-base: 200ms var(--ease-emphasized);
  --motion-slow: 320ms var(--ease-emphasized);

  /* Focus ring */
  --ring-color: color-mix(in srgb, var(--color-primary) 70%, #fff 0%);
  --ring-offset: 2px;

  /* Form accent */
  accent-color: var(--color-primary);
}

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

/* Remove default margins */
* { margin: 0; }

html { 
  scroll-behavior: smooth; 
  hanging-punctuation: first last;
  overflow-x: hidden;
  width: 100%;
}

body {
  min-height: 100dvh;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  width: 100%;
  position: relative;
}

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

/* Remove animations and smooth scrolling for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

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

/* Buttons reset */
button { background: none; border: 0; padding: 0; }

/* Lists */
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }

/* Anchor defaults */
a { color: inherit; text-decoration: none; }

/* =====================================================
   Base Styles
   ===================================================== */
body {
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--color-text);
  background-color: var(--color-bg);
  /* Atmospheric vignette and subtle occult texture */
  background-image:
    radial-gradient(1200px 800px at 20% -10%, rgba(224,177,92,0.06), transparent 60%),
    radial-gradient(1000px 600px at 120% 10%, rgba(142,34,48,0.05), transparent 70%),
    radial-gradient(1200px 700px at 50% 120%, rgba(47,106,81,0.05), transparent 65%),
    radial-gradient(80% 80% at 50% 50%, rgba(0,0,0,0.5), transparent 70%);
}

::selection { background-color: rgba(224,177,92,0.35); color: var(--color-text); }

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  line-height: var(--lh-heading);
  font-weight: 600;
  color: var(--gray-50);
  letter-spacing: 0.02em;
}

h1 { font-size: clamp(2rem, 3vw + 1rem, 3.75rem); margin-block: var(--space-10) var(--space-5); }
h2 { font-size: clamp(1.75rem, 2.2vw + 0.5rem, 3rem); margin-block: var(--space-9) var(--space-5); }
h3 { font-size: clamp(1.5rem, 1.6vw + 0.5rem, 2.25rem); margin-block: var(--space-8) var(--space-4); }
h4 { font-size: var(--fs-xl); margin-block: var(--space-7) var(--space-4); }
h5 { font-size: var(--fs-lg); margin-block: var(--space-6) var(--space-3); }
h6 { font-size: var(--fs-md); margin-block: var(--space-5) var(--space-2); }

/* Paragraphs */
p { max-width: var(--measure); margin-block: 0 var(--space-5); color: var(--color-text); }

/* Links */
a, a:visited { color: var(--color-primary); text-decoration: none; transition: color var(--motion-base); }
a:hover { color: color-mix(in srgb, var(--color-primary) 80%, #fff 20%); }
a:active { color: color-mix(in srgb, var(--color-primary) 65%, #000 35%); }

/* Focus visible outline for accessibility */
:focus-visible { outline: 2px solid var(--ring-color); outline-offset: var(--ring-offset); border-radius: 2px; }

/* Media elements */
figure { margin: 0; max-width: 100%; }

/* Prevent layout overflow */
* { max-width: 100%; }
img, video, canvas, svg { max-width: 100%; height: auto; }
pre, code { max-width: 100%; overflow-x: auto; }

/* Provide comfortable default spacing between siblings in flow containers */
.flow > * + * { margin-block-start: var(--space-6); }

/* =====================================================
   Utilities
   ===================================================== */
/* Container */
.container {
  width: min(100% - 2 * var(--space-7), 1200px);
  margin-inline: auto;
  max-width: 100%;
  box-sizing: border-box;
}

@media (max-width: 900px) {
  .container {
    width: calc(100% - 2 * var(--space-5));
    padding-inline: 0;
  }
}

/* Flex & Grid Helpers */
.flex { display: flex; max-width: 100%; }
.inline-flex { display: inline-flex; max-width: 100%; }
.grid { display: grid; max-width: 100%; }

.flex-center { display: flex; align-items: center; justify-content: center; max-width: 100%; }
.flex-between { display: flex; align-items: center; justify-content: space-between; max-width: 100%; }

@media (max-width: 900px) {
  .flex, .flex-center, .flex-between {
    flex-wrap: wrap;
  }
}

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

@media (max-width: 900px) {
  .grid-auto {
    grid-template-columns: 1fr;
    gap: var(--space-5);
  }
}

/* Fix for form grids to ensure proper full-width elements */
form.grid-auto > div {
  width: 100%;
  max-width: 100%;
}

form.grid-auto > div > * {
  width: 100%;
  max-width: 100%;
}

.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

.pad-6 { padding: var(--space-6); }
.pad-8 { padding: var(--space-8); }

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

/* Optional atmospheric flicker (apply manually to elements like icons) */
@keyframes lantern-flicker {
  0%, 100% { opacity: 0.9; text-shadow: 0 0 6px rgba(224,177,92,0.25); }
  10% { opacity: 0.8; text-shadow: 0 0 10px rgba(224,177,92,0.35); }
  20% { opacity: 0.95; }
  30% { opacity: 0.75; }
  40% { opacity: 0.92; }
  50% { opacity: 0.7; }
  60% { opacity: 0.96; }
  70% { opacity: 0.78; }
  80% { opacity: 0.9; }
  90% { opacity: 0.85; }
}
.motion-flicker { animation: lantern-flicker 3.2s infinite var(--ease-emphasized); }
@media (prefers-reduced-motion: reduce) { .motion-flicker { animation: none; } }

/* =====================================================
   Components
   ===================================================== */
/* Buttons */
.btn {
  --btn-bg: var(--gray-800);
  --btn-fg: var(--gray-50);
  --btn-border: var(--gray-700);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: calc(var(--space-4) + 2px) var(--space-7);
  border-radius: var(--radius-md);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-sm);
  transition: background-color var(--motion-base), color var(--motion-base), border-color var(--motion-base), box-shadow var(--motion-base), transform var(--motion-fast);
  max-width: 100%;
  box-sizing: border-box;
}

@media (max-width: 900px) {
  .btn {
    padding: var(--space-3) var(--space-5);
    font-size: var(--fs-sm);
  }
}

.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; filter: none; }

/* Button variants */
.btn--primary { --btn-bg: color-mix(in srgb, var(--color-primary) 92%, #000 8%); --btn-border: color-mix(in srgb, var(--color-primary) 60%, #000 40%); color: #000000; }
a.btn--primary { color: #000000; }
.btn--success { --btn-bg: color-mix(in srgb, var(--color-success) 92%, #000 8%); --btn-border: color-mix(in srgb, var(--color-success) 60%, #000 40%); color: #07130e; }
.btn--warning { --btn-bg: color-mix(in srgb, var(--color-warning) 92%, #000 8%); --btn-border: color-mix(in srgb, var(--color-warning) 60%, #000 40%); color: #1a1406; }
.btn--danger { --btn-bg: color-mix(in srgb, var(--color-danger) 92%, #000 8%); --btn-border: color-mix(in srgb, var(--color-danger) 60%, #000 40%); color: #160406; }
.btn--ghost { --btn-bg: transparent; --btn-border: var(--gray-700); color: var(--color-text); }

/* Inputs */
.input, input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], textarea, select {
  width: 100%;
  max-width: 100%;
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-700);
  background-color: var(--color-elevated);
  color: var(--color-text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
  transition: border-color var(--motion-base), box-shadow var(--motion-base), background-color var(--motion-base);
  box-sizing: border-box;
}

@media (max-width: 900px) {
  .input, input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], textarea, select {
    padding: var(--space-3) var(--space-4);
  }
}

.input::placeholder, input::placeholder, textarea::placeholder { color: var(--gray-400); }

.input:focus, input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--ring-color);
  outline-offset: var(--ring-offset);
  border-color: color-mix(in srgb, var(--color-primary) 60%, var(--gray-700));
  box-shadow: 0 0 0 3px rgba(224,177,92,0.15);
}

input:disabled, textarea:disabled, select:disabled { opacity: 0.6; cursor: not-allowed; }

input:invalid, textarea:invalid { border-color: color-mix(in srgb, var(--color-danger) 70%, var(--gray-700)); }

/* Cards */
.card {
  background:
    linear-gradient(180deg, rgba(224,177,92,0.04), transparent 22%),
    var(--color-surface);
  border: 1px solid rgba(255,255,255,0.04);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-8);
  color: var(--color-text);
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

@media (max-width: 900px) {
  .card {
    padding: var(--space-6);
  }
}

.card--elevated { background-color: var(--color-elevated); box-shadow: var(--shadow-lg); }

/* Card header/footer helpers */
.card__header { margin-bottom: var(--space-6); }
.card__footer { margin-top: var(--space-6); }

/* Link-like button inside dark card */
.card a { color: color-mix(in srgb, var(--color-primary) 85%, #fff 15%); }
.card a:hover { color: #fff1d6; }

/* =====================================================
   Enhancements & Theming Hooks
   ===================================================== */
/* Vignette utility for sections */
.vignette {
  position: relative;
  isolation: isolate;
}
.vignette::after {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background: radial-gradient(80% 60% at 50% 50%, transparent 55%, rgba(0,0,0,0.48) 100%);
  z-index: -1;
}

/* Subtle divider */
.hr, hr {
  border: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
  margin-block: var(--space-10);
}

/* Navbar/backdrop blur helper (if desired) */
.backdrop-blur { backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
