/* ============================================
   RESET
   ============================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  color-scheme: light dark;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: var(--t-base);
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  min-height: 100vh;
  overflow-x: clip;
}

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

img {
  height: auto;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

ul, ol {
  list-style: none;
}

h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
  font-weight: inherit;
  font-size: inherit;
}

p {
  overflow-wrap: break-word;
}

/* ============================================
   TYPOGRAPHY CLASSES
   Mapped 1:1 to Design-Specs.md §6 token table
   ============================================ */

/* Brand logotype: DM Serif Display 400, 16px */
.t-brand {
  font-family: var(--font-brand);
  font-weight: 400;
  font-size: var(--t-base);
  line-height: 1.5;            /* 24px = 3×8 */
  letter-spacing: -0.01em;
}

/* Section headings: DM Serif Display 400, 24px */
.t-section {
  font-family: var(--font-brand);
  font-weight: 400;
  font-size: var(--t-xl);
  line-height: 1.333;           /* 32px = 4×8 */
  letter-spacing: -0.01em;
}

/* Hero book title ONLY: Fraunces 700, 40-48px */
.t-display {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(40px, 5.5vw, 48px);
  line-height: 1.15;            /* ≈ 48px/56px on grid */
  letter-spacing: -0.02em;
}

/* Author names: Source Serif 4 italic 400, 17px */
.t-author {
  font-family: var(--font-reading);
  font-weight: 400;
  font-style: italic;
  font-size: 17px;
  line-height: 1.412;           /* ≈ 24px = 3×8 */
}

/* Body / metadata: Inter 400, 16px */
.t-body {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: var(--t-base);
  line-height: 1.5;             /* 24px = 3×8 */
}

/* UI badges / labels: IBM Plex Sans 500, 13px */
.t-label {
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: var(--t-xs);
  line-height: 1.231;           /* ≈ 16px = 4×4 */
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Buttons / CTAs: Inter 600, 14px */
.t-button {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--t-sm);
  line-height: 1.143;           /* ≈ 16px = 4×4 */
}

/* Stats numbers: Inter 700, 28px */
.t-stat {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 28px;
  line-height: 1.143;           /* 32px = 4×8 */
}

/* Navigation links: Inter 400-500, 14px */
.t-nav {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: var(--t-sm);
  line-height: 1.429;           /* 20px = 5×4 */
}

/* Secondary body / section links: Source Sans 3 400-500, 14px */
.t-secondary {
  font-family: var(--font-secondary);
  font-weight: 400;
  font-size: var(--t-sm);
  line-height: 1.429;           /* 20px = 5×4 */
}

/* Body bold */
.t-body-bold {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--t-base);
  line-height: 1.5;             /* 24px = 3×8 */
}

/* Caption: small descriptive text */
.t-caption {
  font-family: var(--font-body);
  font-weight: 400;
  font-size: var(--t-xs);
  line-height: 1.538;           /* 20px = 5×4 */
}

/* Caption bold */
.t-caption-bold {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: var(--t-xs);
  line-height: 1.538;           /* 20px = 5×4 */
  letter-spacing: 0.02em;
}

/* Text color helpers */
.text-secondary { color: var(--text2); }
.text-tertiary { color: var(--text3); }

/* ============================================
   FOCUS STATES
   ============================================ */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ============================================
   BUTTONS
   ============================================ */
button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

/* Primary: black pill */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--t-sm);
  padding: 12px var(--s-4);
  min-height: 48px;             /* 6×8 — Apple touch target */
  background: var(--cta-bg);
  color: var(--cta-text);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 180ms ease;
}

.btn-primary:hover {
  opacity: 0.85;
  text-decoration: none;
}

/* Secondary: outline */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: var(--t-sm);
  padding: 12px var(--s-4);
  min-height: 48px;             /* 6×8 */
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 180ms ease;
}

.btn-secondary:hover {
  border-color: var(--text);
  text-decoration: none;
}

/* Quiet: text only */
.btn-quiet {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: var(--t-sm);
  padding: var(--s-2) 0;
  min-height: 48px;             /* 6×8 */
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.btn-quiet:hover {
  text-decoration: underline;
}

/* ============================================
   LAYOUT
   ============================================ */
.page-container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ============================================
   GLOBAL NAV
   ============================================ */
.global-nav {
  padding: var(--s-4) 0;
  border-bottom: 1px solid var(--border);
}

.global-nav .page-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
}

.nav-brand {
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}

.nav-brand:hover {
  color: var(--text);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.nav-links a {
  color: var(--text3);
  text-decoration: none;
  padding: var(--s-1) 0;
  transition: color 180ms ease;
}

.nav-links a:hover {
  color: var(--text);
  text-decoration: none;
}

.nav-links a.is-active {
  color: var(--text);
  font-weight: 500;
}

/* Nav avatar (public) */
.nav-links a.nav-avatar,
.nav-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;                  /* 4×8 */
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: -0.01em;
  text-decoration: none;
  flex-shrink: 0;
  transition: opacity 180ms ease;
}

.nav-avatar:hover {
  opacity: 0.85;
  text-decoration: none;
  color: #fff;
}

.nav-links__avatar {
  display: flex;
  align-items: center;
}

/* Hamburger toggle — hidden on desktop */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: border-color 150ms ease;
}

.nav-toggle:hover {
  border-color: var(--text3);
}

/* Mobile nav */
@media (max-width: 640px) {
  .nav-toggle {
    display: flex;
  }

  .global-nav .page-container {
    flex-wrap: wrap;
  }

  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 0;
    padding-top: var(--s-3);
    border-top: 1px solid var(--border);
    margin-top: var(--s-3);
  }

  .global-nav.is-open .nav-links {
    display: flex;
  }

  .nav-links li {
    width: 100%;
  }

  .nav-links a {
    display: block;
    padding: var(--s-3) 0;        /* 16px — ample touch target */
  }

  .nav-links__avatar {
    padding: var(--s-3) 0;
  }
}

/* ============================================
   FOCUS HEADER (nominate/vote/login)
   ============================================ */
.focus-header {
  padding: var(--s-4) 0;
  border-bottom: 1px solid var(--border);
}

/* ============================================
   ADMIN NAV
   ============================================ */
.admin-nav {
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--admin-border);
  background: var(--admin-surface);
}

.admin-nav .page-container {
  display: flex;
  align-items: center;
  gap: var(--s-4);
}

.admin-nav .nav-brand {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.admin-nav .nav-links {
  display: flex;
  gap: 0;
  margin-left: auto;
  align-items: center;
}

.admin-nav .nav-links li {
  position: relative;
}

.admin-nav .nav-links a {
  display: block;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-sm);
  transition: background 150ms ease, color 150ms ease;
}

.admin-nav .nav-links a:hover {
  background: rgba(0, 0, 0, 0.04);
}

.admin-nav .nav-links a.is-active {
  color: var(--text);
  font-weight: 600;
  border-bottom: 2px solid var(--accent);
  border-radius: 0;
}

/* Admin nav: View Site link */
.admin-nav__site-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: var(--s-3);
  padding: var(--s-2) var(--s-3);
  font-family: var(--font-body);
  font-size: var(--t-xs);
  font-weight: 500;
  color: var(--text3);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: color 150ms ease, border-color 150ms ease;
}

.admin-nav__site-link:hover {
  color: var(--text);
  border-color: var(--text3);
  text-decoration: none;
}

/* Admin nav: Hamburger toggle — hidden on desktop */
.admin-nav__toggle {
  display: none;
}

/* Admin nav: Extras row (View Site + theme toggle) — inline on desktop */
.admin-nav__extras {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

/* Admin nav: Mobile layout */
@media (max-width: 640px) {
  .admin-nav__toggle {
    display: flex;
    margin-left: auto;           /* push hamburger to far right */
  }

  .admin-nav .page-container {
    flex-wrap: wrap;
  }

  .admin-nav .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 0;
    padding-top: var(--s-3);
    border-top: 1px solid var(--admin-border);
    margin-top: var(--s-3);
    margin-left: 0;
  }

  .admin-nav.is-open .nav-links {
    display: flex;
  }

  .admin-nav .nav-links li {
    width: 100%;
  }

  .admin-nav .nav-links a {
    display: block;
    padding: var(--s-3) 0;
  }

  .admin-nav .nav-links a.is-active {
    border-bottom: none;
    border-radius: 0;
  }

  /* Extras row: site link + theme toggle side by side */
  .admin-nav__extras {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-3) 0;
    border-top: 1px solid var(--admin-border);
  }

  .admin-nav__extras .admin-nav__site-link {
    margin-left: 0;
  }
}

/* Admin nav: Avatar — reuse .nav-avatar styling */
.admin-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;                  /* 4×8 */
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

/* ---- Unified Avatar (DiceBear + initials) ---- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: -0.01em;
  flex-shrink: 0;
  overflow: hidden;
  object-fit: cover;
}

.avatar--sm {
  width: 28px;
  height: 28px;
  font-size: 11px;
}

.avatar--md {
  width: 36px;
  height: 36px;
  font-size: 13px;
}

.avatar--lg {
  width: 56px;
  height: 56px;
  font-size: 20px;
}

img.avatar {
  background: var(--surface);
}

/* ============================================
   FOOTER
   ============================================ */
.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--s-5) 0;
  margin-top: var(--s-7);
}

.site-footer .page-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer-links {
  display: flex;
  gap: var(--s-3);
}

.footer-link {
  color: var(--text3);
}

.footer-link:hover {
  color: var(--text2);
}

/* ============================================
   UTILITIES
   ============================================ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================
   DARK MODE TRANSITIONS
   ============================================ */
body,
.global-nav,
.admin-nav,
.site-footer,
.banner,
.book-cover,
.form-input,
.form-textarea {
  transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease;
}

/* ---- Theme Toggle ---- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 150ms ease, border-color 150ms ease;
}

.theme-toggle:hover {
  color: var(--text);
  border-color: var(--text3);
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* Hide the inactive icon */
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }

[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* ============================================
   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;
  }
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 480px) {
  .nav-links {
    gap: var(--s-3);
  }
}
