/* ============================================================
   English Mafia Unified — shared styles
   Noir palette: light = black on white + red accent,
                 dark  = white on black + red accent.
   Theme resolves in this order:
     1. html[data-theme="light" | "dark"]  (manual toggle, persisted)
     2. @media (prefers-color-scheme)      (follows the OS)
   ============================================================ */

:root {
  --radius: 12px;
  --maxw-text: 60rem;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: "Oswald", "Arial Narrow", "Segoe UI", system-ui, sans-serif;
  --transition: 160ms ease;

  /* light (default) */
  --bg: #ffffff;
  --surface: #faf9f8;
  --surface-2: #f0eeec;
  --ink: #171615;
  --ink-muted: #6b6862;
  --border: #e2dfda;
  --accent: #a3323f;
  --accent-ink: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 6px 20px rgba(0, 0, 0, .05);
}

/* follow the OS when the visitor has not chosen manually */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0d0c;
    --surface: #1a1918;
    --surface-2: #232220;
    --ink: #e9e7e3;
    --ink-muted: #9a968e;
    --border: #302e2b;
    --accent: #c95c5c;
    --accent-ink: #0e0d0c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
  }
}

/* manual override — wins in both directions */
:root[data-theme="dark"] {
  --bg: #0e0d0c;
  --surface: #1a1918;
  --surface-2: #232220;
  --ink: #e9e7e3;
  --ink-muted: #9a968e;
  --border: #302e2b;
  --accent: #c95c5c;
  --accent-ink: #0e0d0c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .45);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--accent); }

::selection { background: var(--accent); color: var(--accent-ink); }

/* ---- visually hidden but still present in the DOM/text
   (screen readers, and agents/crawlers that read text without a renderer) ---- */
.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;
}

/* ---- theme toggle button (shared) ---- */
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 10px;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============================================================
   Landing page (index.html)
   ============================================================ */
.landing {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.25rem;
  gap: 0.5rem;
}

.landing-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: clamp(2rem, 1.1rem + 5vw, 4rem);
  line-height: 1.05;
}
.landing-title span { color: var(--accent); }

.landing-tagline {
  margin: 0;
  color: var(--ink-muted);
  font-size: clamp(0.85rem, 0.78rem + 0.35vw, 1rem);
}

.landing-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 1.25rem;
  font-size: clamp(0.7rem, 0.62rem + 0.25vw, 0.8rem);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.landing-links a {
  color: var(--ink-muted);
  text-decoration: none;
  padding-bottom: 1px;
  border-bottom: 1px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.landing-links a:hover { color: var(--accent); border-color: var(--accent); }

.landing .theme-toggle { position: fixed; top: 1rem; right: 1rem; }

.landing-footer {
  position: fixed;
  bottom: 1rem;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--ink-muted);
}
.landing-footer a { color: var(--ink-muted); }

/* ============================================================
   Testimonials (index.html)
   ============================================================ */
.testimonials { width: 100%; margin-top: 1.5rem; }
.testimonials--top { margin-top: 0; margin-bottom: 1.5rem; }

.testimonials-grid {
  position: relative;
  width: 100%;
  max-width: 60rem;
  height: 23rem;
  margin: 0 auto;
  overflow: hidden;
}

.testimonial-card {
  position: absolute;
  margin: 0;
  width: clamp(9.5rem, 42vw, 12.5rem);
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  opacity: 0.4;
  transform: rotate(var(--rot));
  transition: opacity var(--transition), transform var(--transition),
    top var(--transition), left var(--transition), width var(--transition);
}
.testimonial-card:hover,
.testimonial-card:focus-within {
  opacity: 1;
  transform: rotate(0deg) scale(1.04);
  z-index: 10 !important;
}

/* ---- expanded (clicked) card: full text, above everything ----
   position/top/left/width/transform are driven from JS as plain inline
   styles (see toggleExpand in js/testimonials.js) so the card animates
   out from its actual on-screen spot instead of jumping to a fixed
   percentage — this block only carries the cosmetic bits. */
.testimonials-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.testimonials-backdrop.is-active {
  opacity: 1;
  pointer-events: auto;
}

.testimonial-card.is-expanded {
  max-height: 80vh;
  overflow-y: auto;
  cursor: default;
  opacity: 1;
  z-index: 100 !important;
}
.testimonial-card.is-expanded .testimonial-quote {
  display: block;
  -webkit-line-clamp: unset;
  overflow: visible;
}

.testimonial-theme {
  margin: 0 0 0.35em;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.testimonial-quote {
  margin: 0 0 0.6em;
  font-size: 0.8rem;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
}
.testimonial-author {
  font-size: 0.72rem;
  color: var(--ink-muted);
}

/* ---- small / portrait screens: 2 cards per cluster instead of 4 ---- */
@media (max-width: 640px) {
  .testimonials-grid { height: 9.5rem; }

  /* keep the first 2 (of 4) rendered cards, hide the rest */
  .testimonials-grid .testimonial-card:nth-child(n + 3) { display: none; }

  .testimonial-card {
    width: clamp(7.5rem, 38vw, 9.5rem);
    padding: 0.6rem 0.7rem;
  }
  .testimonial-theme { font-size: 0.6rem; }
  .testimonial-quote {
    margin-bottom: 0.4em;
    font-size: 0.72rem;
    line-height: 1.35;
    -webkit-line-clamp: 3;
  }
  .testimonial-author { font-size: 0.64rem; }
}

/* ============================================================
   Ruleset page (rules/index.html)
   ============================================================ */
.page {
  max-width: var(--maxw-text);
  margin: 0 auto;
  padding: 1.25rem 1.25rem 4rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.5rem 0 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2rem;
}
.page-header .home {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.82rem;
  color: var(--ink-muted);
  text-decoration: none;
}
.page-header .home:hover { color: var(--accent); }
.page-header nav {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.page-header nav a { color: var(--ink-muted); text-decoration: none; }
.page-header nav a:hover { color: var(--accent); }

/* ---- ruleset footer ---- */
.page-footer {
  margin-top: 3rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--accent);
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-muted);
}
.page-footer a { color: var(--ink-muted); }
.page-footer a:hover { color: var(--accent); }

/* ---- rendered markdown ---- */
.content {
  animation: fade var(--transition);
  font-size: 1rem;
  line-height: 1.55;
}
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.content .loading, .content .error { color: var(--ink-muted); }
.content .error { color: var(--accent); }

.content h1, .content h2, .content h3, .content h4 {
  font-family: var(--font-body);
  font-weight: 700;
  line-height: 1.3;
  scroll-margin-top: 1rem;
}
.content h1 { font-size: 1.5rem; margin: 0 0 0.8em; }
.content h2 {
  font-size: 1.2rem;
  margin: 1.8em 0 0.5em;
  padding-top: 0.6em;
  border-top: 1px solid var(--accent);
}
.content h3 { font-size: 1.02rem; margin: 1.3em 0 0.3em; }
.content h4 { font-size: 0.95rem; margin: 1.1em 0 0.3em; color: var(--ink-muted); }
.content p { margin: 0 0 0.9em; }
.content pre.license-text {
  font-family: var(--font-body);
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.content ul, .content ol { margin: 0 0 0.9em; padding-left: 1.4em; }
.content li { margin: 0.2em 0; }
.content li > ul, .content li > ol { margin-top: 0.2em; }
.content a { text-decoration: underline; text-underline-offset: 2px; }
.content strong { font-weight: 700; }
.content hr { border: none; border-top: 1px solid var(--border); margin: 2.5em 0; }

.content blockquote {
  margin: 0 0 1em;
  padding: 0.5em 1em;
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  color: var(--ink-muted);
  border-radius: 0 8px 8px 0;
}

.content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
}
.content pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9em 1em;
  overflow-x: auto;
}
.content pre code { border: none; padding: 0; background: none; font-size: 0.85em; }

.content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 1em;
  display: block;
  overflow-x: auto;
}
.content th, .content td {
  border: 1px solid var(--border);
  padding: 0.5em 0.65em;
  text-align: left;
}
.content th { background: var(--surface-2); }

.content img { max-width: 100%; height: auto; border-radius: 8px; }

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
