/* ══════════════════════════════════════════════
   FORUM — Shared Styles
   Tokens, themes, accessibility, base reset
   ══════════════════════════════════════════════ */

/* ── TOKENS ── */
:root {
  --ease: cubic-bezier(.16,1,.3,1);
  --brand: 'Chevalier', serif;
  --hl: 'DM Serif Display', serif;
  --body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --pad: clamp(16px, 4vw, 60px);
}

/* ── THEMES ── */
[data-theme="midnight"] {
  --bg: #0a0a0a; --bg2: #111; --bg3: #1a1a1a;
  --card: #141414; --card-h: #1c1c1c;
  --text: #f5f5f7; --sub: #a1a1a6; --dim: #6e6e73;
  --accent: #d42020; --accent-b: #ff3b3b;
  --border: rgba(255,255,255,.06); --border-s: rgba(255,255,255,.12);
  --divider: rgba(255,255,255,.04);
  --shadow: 0 8px 40px rgba(0,0,0,.6);
  --focus-ring: rgba(255,59,59,.6);
}
[data-theme="day"] {
  --bg: #ffffff; --bg2: #f5f5f7; --bg3: #ebebed;
  --card: #f9f9fb; --card-h: #f0f0f4;
  --text: #1d1d1f; --sub: #6e6e73; --dim: #a1a1a6;
  --accent: #c41818; --accent-b: #d42020;
  --border: rgba(0,0,0,.06); --border-s: rgba(0,0,0,.12);
  --divider: rgba(0,0,0,.04);
  --shadow: 0 8px 40px rgba(0,0,0,.08);
  --focus-ring: rgba(196,24,24,.5);
}

/* ── RESET ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--body); background: var(--bg); color: var(--text);
  transition: background .5s var(--ease), color .4s var(--ease);
  overflow-x: hidden; line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* ── ACCESSIBILITY: Skip to content ── */
.skip-link {
  position: absolute; top: -100%; left: 16px;
  padding: 8px 16px; background: var(--accent); color: #fff;
  font-size: 14px; font-weight: 600; border-radius: 0 0 6px 6px;
  z-index: 10000; text-decoration: none;
  transition: top .2s var(--ease);
}
.skip-link:focus {
  top: 0;
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ── ACCESSIBILITY: Focus visible ── */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 3px;
}
/* Extra focus for interactive elements */
a:focus-visible, button:focus-visible, [role="button"]:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ── ACCESSIBILITY: Reduced motion ── */
@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;
  }
}

/* ── Screen reader only ── */
.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;
}

/* ── ACCESSIBILITY: System theme auto-detect ── */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) { /* Day as default for light-mode OS */
    --bg: #ffffff; --bg2: #f5f5f7; --bg3: #ebebed;
    --card: #f9f9fb; --card-h: #f0f0f4;
    --text: #1d1d1f; --sub: #6e6e73; --dim: #a1a1a6;
    --accent: #c41818; --accent-b: #d42020;
    --border: rgba(0,0,0,.06); --border-s: rgba(0,0,0,.12);
    --divider: rgba(0,0,0,.04);
    --shadow: 0 8px 40px rgba(0,0,0,.08);
    --focus-ring: rgba(196,24,24,.5);
  }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) { /* Midnight as default for dark-mode OS */
    --bg: #0a0a0a; --bg2: #111; --bg3: #1a1a1a;
    --card: #141414; --card-h: #1c1c1c;
    --text: #f5f5f7; --sub: #a1a1a6; --dim: #6e6e73;
    --accent: #d42020; --accent-b: #ff3b3b;
    --border: rgba(255,255,255,.06); --border-s: rgba(255,255,255,.12);
    --divider: rgba(255,255,255,.04);
    --shadow: 0 8px 40px rgba(0,0,0,.6);
    --focus-ring: rgba(255,59,59,.6);
  }
}

/* ── ACCESSIBILITY: Forced colors (Windows High Contrast) ── */
@media (forced-colors: active) {
  .skip-link { background: Highlight; color: HighlightText; }
  :focus-visible { outline: 3px solid Highlight; }
}

/* ── Shared: Skeleton shimmer ── */
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 800px 100%;
  animation: shimmer 1.5s infinite ease-in-out;
  border-radius: 6px;
}

/* ── Shared: Back to top button ── */
.back-to-top {
  position: fixed; bottom: 28px; right: 28px; z-index: 90;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--border-s);
  color: var(--sub); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(12px);
  transition: opacity .3s var(--ease), transform .3s var(--ease), background .2s, color .2s;
  pointer-events: none; box-shadow: var(--shadow);
}
.back-to-top.visible { opacity: 1; transform: translateY(0); pointer-events: auto; }
.back-to-top:hover { background: var(--card-h); color: var(--text); }
.back-to-top svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ── Shared: Reading progress bar ── */
.reading-progress {
  position: fixed; top: 0; left: 0; height: 3px; z-index: 10001;
  background: var(--accent); width: 0;
  transition: width .1s linear;
  pointer-events: none;
}

/* ── Shared: Toast notification ── */
.forum-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--card); color: var(--text); border: 1px solid var(--border-s);
  padding: 10px 20px; border-radius: 10px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow); z-index: 9999;
  opacity: 0; transition: opacity .25s var(--ease), transform .25s var(--ease);
  pointer-events: none; white-space: nowrap;
}
.forum-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }
.forum-toast.ok { color: #34c759; }
.forum-toast.err { color: #ff453a; }

/* ── Highlight spans ── */
.hl { color: var(--accent-b); font-style: italic; }
