/* ============================================================
   BASE.CSS — Reset, Custom Properties, Type Scale
   LearnShrooms Design System
   ============================================================ */

/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400&display=swap');

/* ============================================================
   CSS CUSTOM PROPERTIES — LIGHT MODE (DEFAULT)
   ============================================================ */
:root {
  /* Brand Colors */
  --cap-red: #C41E2A;
  --mycelium-crimson: #8B1520;
  --spore-coral: #E8544E;

  /* Surfaces */
  --substrate-dark: #F8F6F2;
  --midnight-loam: #FFFFFF;
  --dark-grain: #F0EDE8;

  /* Text */
  --cream: #1A1A1D;
  --spore-dust: #6B6560;
  --clean-white: #1A1A1D;

  /* Status */
  --flush-green: #3A9D5C;
  --caution-gold: #D4A843;
  --alert-vermillion: #E63946;

  /* Typography */
  --font-heading: 'DM Serif Display', Georgia, serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-data: 'JetBrains Mono', 'Courier New', monospace;

  /* Type Scale (1.25 ratio, base 16px) */
  --text-xs: 0.8rem;       /* 12.8px */
  --text-sm: 0.875rem;     /* 14px  — data */
  --text-base: 1rem;       /* 16px  — body */
  --text-h4: 1.25rem;      /* 20px */
  --text-h3: 1.563rem;     /* 25px */
  --text-h2: 1.953rem;     /* 31px */
  --text-h1: 2.441rem;     /* 39px */

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-24: 6rem;

  /* Layout */
  --max-width: 1200px;
  --sidebar-width: 300px;
  --header-height: 64px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;

  /* Border radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* ── Token aliases for inline page styles ──────────────────────────────── */
  /* These map the inline-style token system used by home/forum/directory/
     people/societies/channels pages onto the main design system.           */
  --surface-1:      var(--substrate-dark);   /* page background     */
  --surface-2:      var(--dark-grain);       /* card / panel surface */
  --border:         rgba(0,0,0,0.1);         /* subtle border on light */
  --accent-green:   var(--flush-green);      /* green accent (CTA, stat) */
  --text-primary:   var(--cream);            /* #1A1A1D — near-black */
  --text-secondary: var(--spore-dust);       /* #6B6560 — medium grey */
  --text-muted:     #9A948F;                 /* lighter label text   */
  --text-lg:        var(--text-h4);          /* 1.25rem              */
  --text-2xl:       var(--text-h2);          /* 1.953rem             */
  --text-3xl:       2.25rem;                 /* large stat number    */
  --space-5:        1.25rem;                 /* between space-4/space-6 */
}

/* ============================================================
   DARK MODE OVERRIDES
   ============================================================ */
html.dark-mode {
  --substrate-dark: #1A1A1D;
  --midnight-loam: #242428;
  --dark-grain: #2E2E33;
  --cream: #F5F0E8;
  --spore-dust: #A8A29E;
  --clean-white: #FFFFFF;

  /* token aliases — dark overrides */
  --border:         rgba(255,255,255,0.08);
  --text-muted:     var(--spore-dust);
}

/* ============================================================
   RESET & BASE STYLES
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
  width: 100%;
}

body {
  background-color: var(--substrate-dark);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.65;
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='224' height='224' viewBox='0 0 224 224'%3E%3Cg fill='none' stroke='%238B1520' stroke-width='1.25' stroke-linecap='round' stroke-linejoin='round' opacity='0.052'%3E%3Cpath d='M28 66c5-17 19-27 39-26 18 1 31 11 34 27 2 9-4 15-16 13-9-2-12-7-18-7s-10 6-18 7c-13 2-23-4-21-14Z'/%3E%3Cpath d='M57 79h19l3 34c1 8-5 14-13 14-8 0-13-6-12-14l3-34Z'/%3E%3Cpath d='M50 88c11 4 24 4 35 0'/%3E%3Cpath d='M145 54c9-12 27-16 42-8 13 7 18 20 12 30-5 9-18 8-31 3-13-5-25-8-32-1 0-8 3-17 9-24Z'/%3E%3Cpath d='M160 81c4 10 3 23-6 34'/%3E%3Cpath d='M174 84c2 12 0 23-6 33'/%3E%3Cpath d='M35 163c2-13 10-22 23-23 13-1 23 6 27 18 3 9-3 15-14 14-8-1-11-5-16-4-5 1-8 6-15 7-9 1-7-8-5-12Z'/%3E%3Cpath d='M51 173h12l1 24c0 5-3 9-7 9s-7-4-7-9l1-24Z'/%3E%3Cpath d='M139 164c2-16 11-27 25-28 14-1 25 8 27 23 2 10-4 16-15 14-7-1-10-5-14-5s-7 4-13 5c-9 1-12-2-10-9Z'/%3E%3Cpath d='M157 173h13l2 28c0 6-4 10-9 10s-9-4-8-10l2-28Z'/%3E%3Cpath d='M154 145c3-9 8-17 15-24'/%3E%3C/g%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 224px 224px;
}

html.dark-mode body {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='224' height='224' viewBox='0 0 224 224'%3E%3Cg fill='none' stroke='%23F5F0E8' stroke-width='1.25' stroke-linecap='round' stroke-linejoin='round' opacity='0.045'%3E%3Cpath d='M28 66c5-17 19-27 39-26 18 1 31 11 34 27 2 9-4 15-16 13-9-2-12-7-18-7s-10 6-18 7c-13 2-23-4-21-14Z'/%3E%3Cpath d='M57 79h19l3 34c1 8-5 14-13 14-8 0-13-6-12-14l3-34Z'/%3E%3Cpath d='M50 88c11 4 24 4 35 0'/%3E%3Cpath d='M145 54c9-12 27-16 42-8 13 7 18 20 12 30-5 9-18 8-31 3-13-5-25-8-32-1 0-8 3-17 9-24Z'/%3E%3Cpath d='M160 81c4 10 3 23-6 34'/%3E%3Cpath d='M174 84c2 12 0 23-6 33'/%3E%3Cpath d='M35 163c2-13 10-22 23-23 13-1 23 6 27 18 3 9-3 15-14 14-8-1-11-5-16-4-5 1-8 6-15 7-9 1-7-8-5-12Z'/%3E%3Cpath d='M51 173h12l1 24c0 5-3 9-7 9s-7-4-7-9l1-24Z'/%3E%3Cpath d='M139 164c2-16 11-27 25-28 14-1 25 8 27 23 2 10-4 16-15 14-7-1-10-5-14-5s-7 4-13 5c-9 1-12-2-10-9Z'/%3E%3Cpath d='M157 173h13l2 28c0 6-4 10-9 10s-9-4-8-10l2-28Z'/%3E%3Cpath d='M154 145c3-9 8-17 15-24'/%3E%3C/g%3E%3C/svg%3E");
}

/* ============================================================
   TYPOGRAPHY
   ============================================================ */
h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 400;
  color: var(--clean-white);
  letter-spacing: 0;
}

h1 { font-size: var(--text-h1); line-height: 1.15; }
h2 { font-size: var(--text-h2); line-height: 1.2; }
h3 { font-size: var(--text-h3); line-height: 1.25; }
h4 { font-size: var(--text-h4); line-height: 1.3; font-family: var(--font-body); font-weight: 600; color: var(--clean-white); }
h5, h6 { font-family: var(--font-body); font-weight: 600; color: var(--clean-white); }

@media (max-width: 520px) {
  :root {
    --text-h1: 2.05rem;
    --text-h2: 1.68rem;
    --text-h3: 1.38rem;
    --text-h4: 1.16rem;
    --space-12: 2.25rem;
    --space-16: 3rem;
    --space-24: 4rem;
  }

  h1 { line-height: 1.08; }
  h2 { line-height: 1.16; }
}

p { margin-bottom: var(--space-4); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--spore-coral);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover { color: var(--cap-red); }
a:focus-visible {
  outline: 2px solid var(--cap-red);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

strong { font-weight: 600; }
em { font-style: italic; }

small, .text-small {
  font-size: var(--text-xs);
  line-height: 1.5;
}

code, kbd, samp, pre {
  font-family: var(--font-data);
  font-size: var(--text-sm);
}

code {
  background: var(--dark-grain);
  padding: 0.125em 0.375em;
  border-radius: var(--radius-sm);
  color: var(--spore-coral);
}

pre {
  background: var(--dark-grain);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--space-4);
}

pre code {
  background: transparent;
  padding: 0;
  color: var(--cream);
}

blockquote {
  border-left: 3px solid var(--cap-red);
  padding-left: var(--space-6);
  margin-left: 0;
  margin-bottom: var(--space-4);
  color: var(--spore-dust);
  font-style: italic;
}

ul, ol { padding-left: var(--space-6); margin-bottom: var(--space-4); }
li { margin-bottom: var(--space-2); }

hr {
  border: none;
  margin: var(--space-8) 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-3);
}

hr::before {
  content: '';
  display: block;
  width: 60px;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--spore-dust));
}

hr::after {
  content: '';
  display: block;
  width: 60px;
  height: 1px;
  background: linear-gradient(to left, transparent, var(--spore-dust));
}

/* Dot divider — use <div class="dot-divider"> instead of <hr> */
.dot-divider {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-8) 0;
}

.dot-divider::before,
.dot-divider::after {
  content: '• • •';
  color: var(--spore-dust);
  letter-spacing: 0.5em;
  font-size: var(--text-xs);
  opacity: 0.5;
}

/* ============================================================
   IMAGES & MEDIA
   ============================================================ */
img, video, svg {
  display: block;
  max-width: 100%;
  height: auto;
}

@media (max-width: 767px) {
  :root {
    --space-8: 1.5rem;
    --space-12: 2.25rem;
    --space-16: 3rem;
  }

  body {
    background-size: 168px 168px;
  }

  p,
  li,
  dd,
  figcaption {
    font-size: max(1rem, var(--text-base));
  }

  h1 {
    font-size: clamp(2rem, 11vw, 2.7rem);
  }
}

figure { margin: 0 0 var(--space-4); }
figcaption {
  font-size: var(--text-xs);
  color: var(--spore-dust);
  margin-top: var(--space-2);
  text-align: center;
}

/* ============================================================
   TABLES
   ============================================================ */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-6);
  font-family: var(--font-data);
  font-size: var(--text-sm);
}

th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  background: var(--dark-grain);
  color: var(--clean-white);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid rgba(0,0,0,0.1);
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid rgba(0,0,0,0.08);
  color: var(--cream);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(0,0,0,0.03); }

html.dark-mode th { border-bottom: 1px solid rgba(255,255,255,0.1); }
html.dark-mode td { border-bottom: 1px solid rgba(255,255,255,0.05); }
html.dark-mode tr:hover td { background: rgba(255,255,255,0.02); }

/* ============================================================
   FORMS (base)
   ============================================================ */
input, textarea, select {
  font-family: var(--font-body);
  font-size: var(--text-base);
  background: var(--dark-grain);
  color: var(--cream);
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  width: 100%;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
}

input::placeholder, textarea::placeholder { color: var(--spore-dust); }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--cap-red);
  box-shadow: 0 0 0 3px rgba(196, 30, 42, 0.2);
}

label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--spore-dust);
  margin-bottom: var(--space-2);
}

html.dark-mode input,
html.dark-mode textarea,
html.dark-mode select {
  border-color: rgba(255,255,255,0.1);
}

/* ============================================================
   ACCESSIBILITY
   ============================================================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--cap-red);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
