/* ============================================================================
   Puzzmint Blog — Design System CSS
   Source of truth: brand/design-tokens.json  (PUZZMINT_DESIGN_BIBLE_v1.1)
   Dark-first, 60/30/10. No inline one-off values — tokens only.
   Lens: Color (60/30/10, AA), Type (Fraunces+Inter, tnum), Cognition (Gestalt
   proximity/common-region), Accessibility (focus, contrast, reduced-motion).
   ============================================================================ */

:root {
  /* --- Color tokens (dark theme = default) --- */
  --surface-dominant: #0F1419;   /* 60% base ink */
  --surface-secondary: #1A222B;  /* 30% raised cards/boards */
  --surface-line: #2A3540;       /* grid lines, dividers, hairlines */
  --text-primary: #ECF1F2;       /* AA+ 16.25:1 on dominant */
  --text-muted: #8A97A0;         /* AA 6.18:1 on dominant */
  --accent-primary: #4C6FFF;     /* 10% — focus/selection/action (UI/large only) */
  --accent-mint: #3FD6B0;        /* brand bridge — gradients/highlights, sparing */
  --semantic-success: #37C871;
  --semantic-caution: #F2B33D;
  --semantic-error: #E5544B;
  --brand-gradient: linear-gradient(135deg, #4C6FFF 0%, #3FD6B0 100%);

  /* --- Type --- */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* --- Spacing scale (4px base) --- */
  --space-1: 0.25rem;  --space-2: 0.5rem;   --space-3: 0.75rem;
  --space-4: 1rem;     --space-5: 1.5rem;    --space-6: 2rem;
  --space-7: 3rem;     --space-8: 4rem;      --space-9: 6rem;

  /* --- Radii / elevation --- */
  --radius-sm: 8px;  --radius-md: 12px;  --radius-lg: 18px;  --radius-pill: 999px;
  --elev-card: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.25);
  --elev-card-hover: 0 2px 4px rgba(0,0,0,0.5), 0 16px 40px rgba(0,0,0,0.35);

  /* --- Measure / motion --- */
  --measure: 68ch;          /* article reading measure */
  --max-content: 1040px;    /* listing grid width */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 180ms;             /* < Doherty 400ms */
}

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

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

body {
  background: var(--surface-dominant);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.7;
  font-feature-settings: 'tnum' 1, 'ss01' 1;  /* tabular numerals, slashed zero */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(76,111,255,0.35); color: #fff; }

/* --- Accessibility: visible focus ring (accent, UI/large per a11y constraint) --- */
a:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
  border-radius: 3px;
}
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent-primary); color: #fff;
  padding: var(--space-2) var(--space-4); border-radius: 0 0 var(--radius-sm) 0;
  z-index: 100; text-decoration: none; font-weight: 600;
}
.skip-link:focus { left: 0; }

/* ============================================================================
   Header / Footer (shared chrome — Common Region via hairline)
   ============================================================================ */
.site-header {
  border-bottom: 1px solid var(--surface-line);
  background: rgba(15,20,25,0.72);
  backdrop-filter: saturate(140%) blur(12px);
  position: sticky; top: 0; z-index: 50;
}
.site-header__inner {
  max-width: var(--max-content);
  margin: 0 auto;
  padding: var(--space-3) var(--space-5);
  display: flex; align-items: center; gap: var(--space-5);
}
.site-header__lockup { display: flex; align-items: center; gap: var(--space-3); text-decoration: none; }
.site-header__lockup .icon { height: 28px; width: 28px; display: block; border-radius: 7px; }
.wordmark-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1;
}
.wordmark-text .pip {
  background: var(--brand-gradient);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.site-header__nav { margin-left: auto; display: flex; gap: var(--space-5); align-items: center; }
.site-header__nav a {
  color: var(--text-muted); text-decoration: none;
  font-size: 0.9rem; font-weight: 500;
  transition: color var(--dur) var(--ease);
}
.site-header__nav a:hover { color: var(--text-primary); }
.site-header__cta {
  background: var(--brand-gradient); color: #0A0E12 !important;
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-pill);
  font-weight: 600; font-size: 0.85rem;
}
.site-header__cta:hover { filter: brightness(1.06); }

.site-footer {
  border-top: 1px solid var(--surface-line);
  margin-top: var(--space-9);
  padding: var(--space-7) var(--space-5);
}
.site-footer__inner {
  max-width: var(--max-content); margin: 0 auto;
  display: flex; flex-wrap: wrap; gap: var(--space-4);
  align-items: center; justify-content: space-between;
}
.site-footer__inner img { height: 22px; width: auto; opacity: 0.9; }
.site-footer__meta { color: var(--text-muted); font-size: 0.85rem; }
.site-footer__nav { display: flex; gap: var(--space-5); }
.site-footer__nav a { color: var(--text-muted); text-decoration: none; font-size: 0.85rem; }
.site-footer__nav a:hover { color: var(--text-primary); }

/* ============================================================================
   Listing page — hero, sections, cards
   ============================================================================ */
.listing { max-width: var(--max-content); margin: 0 auto; padding: 0 var(--space-5); }

.hero {
  padding: var(--space-9) 0 var(--space-7);
  border-bottom: 1px solid var(--surface-line);
  margin-bottom: var(--space-7);
  display: flex; align-items: center; gap: var(--space-7);
}
.hero__copy { flex: 1 1 auto; }

/* Hero mini puzzle-board — 3x3, one tile "placed" top-right (logo story) */
.hero__board {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px;
  width: 156px; height: 156px; padding: 10px;
  background: var(--surface-secondary);
  border: 1px solid var(--surface-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-card);
}
.hero__cell { border-radius: 7px; background: rgba(138,151,160,0.12); }
.hero__cell.is-filled { background: rgba(138,151,160,0.28); }
.hero__cell.is-placed {
  background: var(--brand-gradient);
  box-shadow: 0 0 0 1px rgba(63,214,176,0.4), 0 6px 16px rgba(76,111,255,0.35);
  animation: tile-place 600ms var(--ease) both;
}
@keyframes tile-place {
  0% { transform: scale(0) rotate(-18deg); opacity: 0; }
  60% { transform: scale(1.12) rotate(6deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Section mark — small placed-tile bullet before the heading */
.section__mark {
  width: 14px; height: 14px; border-radius: 4px;
  background: var(--brand-gradient); transform: rotate(12deg);
  flex: 0 0 auto; align-self: center;
}
.hero__eyebrow {
  display: inline-block; font-size: 0.78rem; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--accent-mint); margin-bottom: var(--space-3);
}
.hero h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.2rem, 5.5vw, 3.4rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  max-width: 18ch;
  margin-bottom: var(--space-4);
}
.hero h1 .accent {
  background: var(--brand-gradient);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero p {
  color: var(--text-muted); font-size: 1.15rem; max-width: 56ch; line-height: 1.6;
}

.section { margin-bottom: var(--space-8); }
.section__head {
  display: flex; align-items: baseline; gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.section__head h2 {
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.6rem; letter-spacing: -0.01em;
}
.section__head .count {
  color: var(--text-muted); font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

/* Pillar cards — large, featured (Gestalt: common region + proximity) */
.card-grid { display: grid; gap: var(--space-4); }
.card-grid--pillars { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.card {
  display: flex; flex-direction: column;
  background: var(--surface-secondary);
  border: 1px solid var(--surface-line);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  text-decoration: none; color: inherit;
  box-shadow: var(--elev-card);
  transition: transform var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
  position: relative; overflow: hidden;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--elev-card-hover);
  border-color: rgba(76,111,255,0.4);
}
/* Level number — like a puzzle level index (playful, monospace) */
.card__level {
  position: absolute; top: var(--space-4); right: var(--space-5);
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 0.78rem; font-weight: 600; letter-spacing: 0.05em;
  color: var(--text-muted); opacity: 0.5;
  font-variant-numeric: tabular-nums;
  transition: color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.card:hover .card__level { color: var(--accent-mint); opacity: 1; }
/* Placed-tile — a tile "snaps" into the corner on hover (the brand verb) */
.card__tile {
  position: absolute; right: -10px; bottom: -10px;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand-gradient);
  transform: rotate(12deg) scale(0.4); opacity: 0;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.card:hover .card__tile { transform: rotate(12deg) scale(1); opacity: 0.9; }
.card__cat {
  align-self: flex-start;
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  margin-bottom: var(--space-3);
  border: 1px solid currentColor;
}
.cat-glyph { display: block; flex: 0 0 auto; }
/* Per-puzzle accent families (tint-only, same calm system) + glyph for color-independence */
.cat--sudoku    { color: #6E8BFF; }
.cat--nonogram  { color: #3FD6B0; }
.cat--logic-grid{ color: #C49BFF; }
.cat--general   { color: #8A97A0; }

.card__title {
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.3rem; line-height: 1.25; margin-bottom: var(--space-3);
  letter-spacing: -0.01em;
}
.card__desc { color: var(--text-muted); font-size: 0.95rem; line-height: 1.55; }
.card__foot {
  margin-top: auto; padding-top: var(--space-4);
  display: flex; align-items: center; gap: var(--space-3);
  color: var(--text-muted); font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.card__arrow { margin-left: auto; color: var(--accent-primary); transition: transform var(--dur) var(--ease); }
.card:hover .card__arrow { transform: translateX(3px); }

/* Cluster list — compact rows (Similarity) */
.card-grid--clusters { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row {
  display: flex; align-items: center; gap: var(--space-3);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-line);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  text-decoration: none; color: inherit;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.row:hover { border-color: rgba(76,111,255,0.4); background: #1F2832; }
.row__glyph { display: flex; flex: 0 0 auto; transition: transform var(--dur) var(--ease); }
.row:hover .row__glyph { transform: rotate(8deg) scale(1.08); }
.row__title { font-weight: 500; font-size: 0.98rem; color: var(--text-primary); line-height: 1.3; }
.row__arrow { margin-left: auto; color: var(--text-muted); }

/* ============================================================================
   Article reading experience
   ============================================================================ */
.article-shell { max-width: var(--max-content); margin: 0 auto; padding: var(--space-6) var(--space-5) 0; }

.breadcrumb {
  display: flex; gap: var(--space-2); align-items: center;
  font-size: 0.85rem; color: var(--text-muted); margin-bottom: var(--space-5);
}
.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--text-primary); }
.breadcrumb .sep { opacity: 0.5; }

.article-container { max-width: var(--measure); margin: 0 auto; padding-bottom: var(--space-8); }

.article-meta {
  display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center;
  margin-bottom: var(--space-6); color: var(--text-muted); font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.article-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--text-muted); }

.draft-banner {
  background: rgba(242,179,61,0.12);
  border: 1px solid rgba(242,179,61,0.35);
  color: var(--semantic-caution);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 0.85rem; margin-bottom: var(--space-6);
  display: flex; gap: var(--space-2); align-items: center;
}

article > :first-child { margin-top: 0; }

article h1 {
  font-family: var(--font-display); font-weight: 600;
  font-size: clamp(1.9rem, 4.5vw, 2.7rem);
  line-height: 1.12; letter-spacing: -0.02em;
  margin-bottom: var(--space-4); color: var(--text-primary);
}
article h2 {
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.55rem; letter-spacing: -0.01em;
  margin: var(--space-8) 0 var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--surface-line);
  scroll-margin-top: 80px;
}
article h3 {
  font-size: 1.2rem; font-weight: 600;
  margin: var(--space-6) 0 var(--space-2); color: var(--text-primary);
  scroll-margin-top: 80px;
}
article p { margin-bottom: var(--space-5); color: #C8D2D8; }
article strong { color: var(--text-primary); font-weight: 600; }
article a {
  color: var(--accent-mint); text-decoration: none;
  border-bottom: 1px solid rgba(63,214,176,0.35);
  transition: border-color var(--dur) var(--ease);
}
article a:hover { border-bottom-color: var(--accent-mint); }

article ul, article ol { margin: 0 0 var(--space-5) var(--space-5); color: #C8D2D8; }
article li { margin-bottom: var(--space-2); padding-left: var(--space-1); }
article li::marker { color: var(--accent-primary); }

article blockquote {
  border-left: 3px solid var(--accent-primary);
  background: rgba(76,111,255,0.06);
  padding: var(--space-4) var(--space-5);
  margin: var(--space-6) 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-muted); font-style: italic;
}
article blockquote p:last-child { margin-bottom: 0; }

/* Callout / example blocks */
article .callout, article :global(.callout) {
  background: rgba(76,111,255,0.07);
  border: 1px solid rgba(76,111,255,0.22);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  margin: var(--space-6) 0;
}

/* Code — monospace example grids (tabular, github-dark shiki) */
article code {
  font-family: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, monospace;
  font-size: 0.9em;
  background: rgba(255,255,255,0.06);
  padding: 0.15em 0.4em; border-radius: 5px;
}
article pre {
  background: #0B0F14 !important;
  border: 1px solid var(--surface-line);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  overflow-x: auto; margin: var(--space-6) 0;
  font-size: 0.9rem; line-height: 1.6;
}
article pre code { background: none; padding: 0; }

article table {
  width: 100%; border-collapse: collapse; margin: var(--space-6) 0;
  font-size: 0.92rem; font-variant-numeric: tabular-nums;
}
article th, article td {
  text-align: left; padding: var(--space-3) var(--space-4);
  border: 1px solid var(--surface-line);
}
article th { background: var(--surface-secondary); color: var(--text-primary); font-weight: 600; }

article hr { border: none; border-top: 1px solid var(--surface-line); margin: var(--space-7) 0; }

/* FAQ section (paired with FAQPage schema) */
article .faq h2, article :global(.faq) h2 { border-bottom: none; }
article details {
  border: 1px solid var(--surface-line);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  margin-bottom: var(--space-3);
  background: var(--surface-secondary);
}
article details summary {
  cursor: pointer; font-weight: 600; color: var(--text-primary);
  list-style: none; display: flex; align-items: center; justify-content: space-between;
}
article details summary::-webkit-details-marker { display: none; }
article details summary::after { content: '+'; color: var(--accent-primary); font-size: 1.2rem; }
article details[open] summary::after { content: '−'; }
article details[open] summary { margin-bottom: var(--space-3); }

/* End-of-article CTA back to the app */
.article-cta {
  margin: var(--space-8) 0 var(--space-7);
  background: var(--surface-secondary);
  border: 1px solid var(--surface-line);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
}
.article-cta h3 { font-family: var(--font-display); font-size: 1.4rem; margin-bottom: var(--space-2); }
.article-cta p { color: var(--text-muted); margin-bottom: var(--space-4); }
.article-cta a {
  display: inline-block; background: var(--brand-gradient); color: #0A0E12;
  padding: var(--space-3) var(--space-5); border-radius: var(--radius-pill);
  font-weight: 600; text-decoration: none; border: none;
  transition: filter var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.article-cta a:hover { filter: brightness(1.06); transform: translateY(-1px); }

/* ============================================================================
   Responsive
   ============================================================================ */
@media (max-width: 640px) {
  body { font-size: 1rem; }
  .site-header__inner { padding: var(--space-3) var(--space-4); gap: var(--space-3); }
  .site-header__nav { gap: var(--space-3); }
  .site-header__lockup img { height: 22px; }
  .listing, .article-shell { padding-left: var(--space-4); padding-right: var(--space-4); }
  .hero {
    padding: var(--space-7) 0 var(--space-6);
    flex-direction: column; align-items: flex-start;
  }
  /* Standalone board reads awkward stacked on narrow screens — drop it here;
     the puzzle motif still carries via glyph badges, level numbers, tile bullets. */
  .hero__board { display: none; }
  .card-grid--pillars { grid-template-columns: 1fr; }
  .site-footer__inner { flex-direction: column; align-items: flex-start; gap: var(--space-4); }
}

/* ============================================================================
   Reduced motion — honor user preference (Motion lens)
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .card:hover { transform: none; }
}

/* ============================================================================
   Light theme — follow OS (dark-first, but respect system light)
   Tokens swap to design-bible light values; mint/accent unchanged.
   ============================================================================ */
@media (prefers-color-scheme: light) {
  :root {
    --surface-dominant: #F7FAF9;
    --surface-secondary: #FFFFFF;
    --surface-line: #DBE3E2;
    --text-primary: #101820;
    --text-muted: #5C6B72;
  }
  body { -webkit-font-smoothing: auto; }
  .site-header { background: rgba(247,250,249,0.8); }
  .site-header__cta, .article-cta a { color: #06231C; }
  article p, article ul, article ol { color: #2C3A40; }
  article pre { background: #0B0F14 !important; }  /* keep code dark (shiki github-dark) */
  .row:hover { background: #EEF3F2; }
  /* Dark lockup SVG is light-on-dark; swap to wordmark visibility handled in template via picture */
}
