/* ===========================================================================
   Election Math shared theme, v1.

   Every page on the site links this file by its full URL:
     <link rel="stylesheet" href="https://electionmath.org/theme/v1/theme.css">
     <script type="module" src="https://electionmath.org/theme/v1/site-chrome.js"></script>

   This file is a contract other repos depend on. Within v1, only ADD things:
   never rename or remove a variable or an .em- class. A breaking change goes
   in theme/v2/.

   What it provides:
     1. Colour tokens (CSS variables). Unprefixed, and identical in name and
        value to the ones CVSIM already uses, so pages can adopt the theme
        without renaming anything.
     2. Base element styles: page colours, body font, heading font.
     3. Components, all prefixed .em- so they cannot collide with a page's own
        class names: layout, section labels, buttons, cards, tags.
     4. Styles for <site-header> and <site-footer> (defined in site-chrome.js).

   Colours and type come from the Guinier Project primer, "Getting From Votes
   to Seats" (J. Sherman Studio). The primer's typefaces, Cera Pro and Mark
   Pro, are commercial; Jost and Public Sans are the free substitutes.

   LIGHT BY DEFAULT. Dark mode is opt-in per page, because some pages (CVSIM's
   charts, for one) are destined for printed figures and must not flip:
     <html data-theme="auto">   follow the reader's OS setting
     <html data-theme="dark">   always dark
     (no attribute)             always light
   =========================================================================== */

@import url("https://fonts.googleapis.com/css2?family=Jost:wght@400;500;600;700&family=Public+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap");

/* ---------- 1. tokens ---------- */
:root {
  /* primer stock */
  --paper:     #F6F3E2;   /* page background */
  --surface:   #FFFFFF;   /* cards, panels */
  --surface-2: #EFEBD8;   /* recessed areas */
  --ink:       #231F20;   /* text */
  --muted:     #4D4A4B;   /* secondary text */
  --rule:      #DED7C3;   /* hairlines, borders */
  --shadow:    rgba(35, 31, 32, .10);

  /* primer accents */
  --gold:      #FAB812;   /* the primer's highlight block; fills, not text */
  --gold-deep: #B07D00;   /* gold that is legible as text on paper */
  --teal:      #056878;
  --violet:    #7E5A95;
  --green:     #5A8A2C;

  /* fonts */
  --font-display: Jost, Futura, "Century Gothic", -apple-system, Helvetica, Arial, sans-serif;
  --font-body: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  /* layout */
  --page-width:   1080px;
  --text-width:   760px;
  --page-gutter:  24px;

  color-scheme: light;
}

/* Dark values. Applied only to pages that opt in (see header comment). */
:root[data-theme="dark"] {
  --paper: #232021; --surface: #2C2829; --surface-2: #332F30;
  --ink: #F6F3E2; --muted: #BDB6B7; --rule: #403B3C;
  --shadow: rgba(0, 0, 0, .45);
  --gold: #F5C043; --gold-deep: #F5C043;
  --teal: #7FC3CB; --violet: #C7A7D5; --green: #9BC46A;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --paper: #232021; --surface: #2C2829; --surface-2: #332F30;
    --ink: #F6F3E2; --muted: #BDB6B7; --rule: #403B3C;
    --shadow: rgba(0, 0, 0, .45);
    --gold: #F5C043; --gold-deep: #F5C043;
    --teal: #7FC3CB; --violet: #C7A7D5; --green: #9BC46A;
    color-scheme: dark;
  }
}

/* ---------- 2. base ---------- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); text-wrap: balance; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- 3. components ---------- */

/* Accent colour. Put one of these on a card or section label (or set
   --accent yourself) to pick its colour. */
.em-gold   { --accent: var(--gold);   --accent-text: var(--gold-deep); }
.em-teal   { --accent: var(--teal);   --accent-text: var(--teal); }
.em-violet { --accent: var(--violet); --accent-text: var(--violet); }
.em-green  { --accent: var(--green);  --accent-text: var(--green); }

/* Centred page column, and a narrower one for running text. */
.em-wrap   { max-width: var(--page-width); margin: 0 auto; padding-inline: var(--page-gutter); }
.em-narrow { max-width: var(--text-width); }

/* Section with a hairline below it and generous vertical padding. */
.em-section { border-bottom: 1px solid var(--rule); }
.em-section > .em-wrap { padding-block: clamp(44px, 6vw, 72px); }
.em-section h2 {
  margin: 0 0 18px; font-size: clamp(1.7rem, 3.6vw, 2.4rem);
  font-weight: 500; letter-spacing: -.015em; line-height: 1.1;
}

/* Small capitals label above a heading, with a trailing rule. */
.em-label {
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: .18em;
  font-size: .76rem; font-weight: 600; margin: 0 0 10px;
  display: flex; align-items: center; gap: 10px;
  color: var(--accent-text, var(--ink));
}
.em-label::after {
  content: ""; height: 2px; flex: 1; max-width: 120px;
  background: currentColor; opacity: .35;
}

/* Running text. */
.em-prose p { margin: 0 0 16px; max-width: 64ch; }
.em-prose p:last-child { margin-bottom: 0; }

/* Buttons: outlined by default, gold with .em-btn-solid. */
.em-btn {
  display: inline-flex; align-items: center; gap: 10px; text-decoration: none;
  font-family: var(--font-display); font-weight: 600; font-size: .98rem; letter-spacing: .01em;
  padding: 13px 22px; border: 1.5px solid var(--ink); color: var(--ink); background: transparent;
  cursor: pointer;
}
.em-btn:hover, .em-btn:focus-visible { background: var(--ink); color: var(--paper); }
.em-btn-solid { background: var(--gold); border-color: var(--gold); color: #231F20; }
.em-btn-solid:hover, .em-btn-solid:focus-visible {
  background: var(--ink); border-color: var(--ink); color: var(--paper);
}

/* Cards: a grid of them, each with a coloured stripe on top.
   <div class="em-cards">
     <article class="em-card em-teal">
       <span class="em-card-kind">Interactive simulation</span>
       <h3>Title</h3>
       <p>Summary.</p>
       <a class="em-card-link" href="...">Open it</a>
     </article>
   </div> */
.em-cards {
  display: grid; gap: 22px; margin-top: 28px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr));
}
.em-card {
  background: var(--surface); border: 1px solid var(--rule);
  border-top: 6px solid var(--accent, var(--gold));
  box-shadow: 0 1px 2px var(--shadow);
  padding: 24px 22px; min-width: 0;
  display: flex; flex-direction: column; gap: 10px;
}
.em-card h3 { margin: 0; font-size: 1.22rem; font-weight: 600; line-height: 1.25; }
.em-card p  { margin: 0; font-size: .94rem; color: var(--muted); line-height: 1.55; }
.em-card-kind {
  font-family: var(--font-display); text-transform: uppercase; letter-spacing: .14em;
  font-size: .7rem; font-weight: 600; color: var(--muted);
}
.em-card-link {
  margin-top: auto; padding-top: 14px;
  font-family: var(--font-display); font-weight: 600; font-size: .92rem;
  color: var(--accent-text, var(--gold-deep)); text-decoration: none;
}
.em-card-link::after { content: " →"; }
.em-card-link:hover, .em-card-link:focus-visible { text-decoration: underline; }

/* Small outlined tag, e.g. "In development". Takes the current text colour. */
.em-tag {
  display: inline-block; align-self: flex-start;
  font-family: var(--font-display); font-weight: 600; font-size: .68rem;
  letter-spacing: .12em; text-transform: uppercase;
  padding: 3px 8px; border: 1px solid currentColor; color: var(--muted);
}

/* ---------- 4. site chrome (<site-header>, <site-footer>) ---------- */
site-header, site-footer { display: block; }
site-header { min-height: 64px; } /* reserve space before the script runs */

.em-header { border-bottom: 1px solid var(--rule); background: var(--paper); }
.em-header .em-wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding-block: 18px; flex-wrap: wrap;
}
.em-mark {
  display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink);
  font-family: var(--font-display); font-weight: 600; letter-spacing: .01em; font-size: 1.05rem;
}
.em-mark::before { content: ""; width: 26px; height: 26px; background: var(--gold); flex: none; }
.em-nav {
  display: flex; gap: 22px; flex-wrap: wrap;
  font-size: .86rem; font-weight: 500; letter-spacing: .06em; text-transform: uppercase;
}
.em-nav a {
  text-decoration: none; color: var(--muted);
  padding-block: 4px; border-bottom: 2px solid transparent;
}
.em-nav a:hover, .em-nav a:focus-visible { color: var(--ink); border-bottom-color: var(--gold); }

/* The footer is charcoal in both light and dark mode. */
.em-footer { background: #4D4A4B; color: #F6F3E2; font-size: 16px; line-height: 1.6; }
.em-footer .em-wrap {
  padding-block: 40px; display: flex; gap: 30px; flex-wrap: wrap;
  justify-content: space-between; align-items: flex-start;
}
.em-lockup { display: flex; align-items: stretch; flex-wrap: wrap; font-family: var(--font-display); }
.em-lockup-gold { background: #FAB812; color: #231F20; padding: 14px 16px; line-height: 1.2; }
.em-lockup-gold span { display: block; font-size: .72rem; letter-spacing: .04em; }
.em-lockup-gold strong { display: block; font-size: 1.02rem; font-weight: 700; letter-spacing: -.01em; }
.em-lockup-dark {
  background: #231F20; color: #F6F3E2; padding: 14px 16px;
  font-size: .78rem; line-height: 1.3; display: flex; align-items: center; max-width: 210px;
}
.em-footer-nav { display: flex; flex-direction: column; gap: 7px; font-size: .9rem; }
.em-footer-nav a { color: rgba(246, 243, 226, .72); text-decoration: none; }
.em-footer-nav a:hover, .em-footer-nav a:focus-visible { color: #F6F3E2; text-decoration: underline; }
.em-footer-fine { margin: 0; font-size: .82rem; color: rgba(246, 243, 226, .72); max-width: 38ch; line-height: 1.55; }
