/*
 * pSEO Blocks - Base Stylesheet
 * Layout primitives, typography, buttons, cards, grids, and surface token system
 * NO block-specific styles - those live in blocks.css
 */

/* ========================================
   RESET & BASE
   ======================================== */

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

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg);
}

img, video, iframe {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

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

/* ========================================
   LAYOUT PRIMITIVES
   ======================================== */

.site {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: var(--container-max, 1200px);
  margin: 0 auto;
  padding: 0 1.5rem;
}

.container--narrow {
  max-width: 800px;
}

.container--wide {
  max-width: 1400px;
}

/* ========================================
   BLOCK & SURFACE TOKEN SYSTEM
   ======================================== */

.block {
  position: relative;
  padding: var(--space-section-y, 5rem) 0;
  background: var(--surface-bg);
  color: var(--surface-text);
}

.block--compact {
  padding: calc(var(--space-section-y, 5rem) * 0.6) 0;
}

.block--flush {
  padding: 0;
}

/* Surface-aware elements */
.block .text-muted {
  color: var(--surface-muted);
}

.block .card {
  background: var(--surface-card, var(--surface-bg));
  border-color: var(--surface-border);
}

.block a:not(.btn) {
  color: var(--surface-link, var(--color-accent));
}

/* ========================================
   TONE DEFINITIONS
   Set local --surface-* vars per tone
   ======================================== */

.block[data-tone="base"],
.block:not([data-tone]) {
  --surface-bg: var(--color-bg);
  --surface-text: var(--color-text);
  --surface-muted: var(--color-muted);
  --surface-border: var(--color-border);
  --surface-card: var(--color-surface);
  --surface-link: var(--color-primary);
}

.block[data-tone="alt"] {
  --surface-bg: var(--color-alt-bg);
  --surface-text: var(--color-alt-text);
  --surface-muted: var(--color-alt-muted);
  --surface-border: var(--color-alt-border);
  --surface-card: var(--color-alt-card);
  --surface-link: var(--color-primary);
}

.block[data-tone="dark"] {
  --surface-bg: var(--color-dark-bg);
  --surface-text: var(--color-dark-text);
  --surface-muted: var(--color-dark-muted);
  --surface-border: var(--color-dark-border);
  --surface-card: var(--color-dark-card);
  --surface-link: var(--color-dark-link);
}

.block[data-tone="accent"] {
  --surface-bg: var(--color-accent-surface);
  --surface-text: var(--color-accent-text);
  --surface-muted: var(--color-accent-muted);
  --surface-border: var(--color-accent-border);
  --surface-card: var(--color-accent-card);
  --surface-link: var(--color-accent-text);
}

/* Mint tone (minted_terminal theme only, falls back to accent) */
.block[data-tone="mint"] {
  --surface-bg: var(--color-mint-bg, var(--color-accent-surface));
  --surface-text: var(--color-mint-text, var(--color-accent-text));
  --surface-muted: var(--color-mint-muted, var(--color-accent-muted));
  --surface-border: var(--color-mint-border, var(--color-accent-border));
  --surface-card: var(--color-mint-card, var(--color-accent-card));
  --surface-link: var(--color-mint-text, var(--color-accent-text));
}

/* Light tone (for contrast sections in dark themes) */
.block[data-tone="light"] {
  --surface-bg: var(--color-light-bg, var(--color-bg));
  --surface-text: var(--color-light-text, var(--color-text));
  --surface-muted: var(--color-light-muted, var(--color-muted));
  --surface-border: var(--color-light-border, var(--color-border));
  --surface-card: var(--color-light-card, var(--color-surface));
  --surface-link: var(--color-primary);
}

/* ========================================
   BACKGROUND OVERLAYS (data-bg attribute)
   ======================================== */

/* Gradient background */
.block[data-bg="gradient"]::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: var(--bg-gradient, linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-end)));
}

/* Image background with overlay */
.block[data-bg="image"] {
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
}

.block[data-bg="image"]::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: var(--color-overlay);
}

/* Pattern background */
.block[data-bg="pattern"]::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: var(--bg-pattern);
  opacity: var(--bg-pattern-opacity, 0.05);
}

/* ========================================
   TYPOGRAPHY
   ======================================== */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--heading-weight, 700);
  line-height: 1.2;
  color: inherit;
  letter-spacing: var(--heading-letter-spacing, -0.02em);
}

/* Heading gradient support (used by dark themes) */
h1, h2, .h1, .h2 {
  background: var(--heading-gradient, none);
  -webkit-background-clip: text;
  -webkit-text-fill-color: var(--heading-text-fill, currentColor);
  background-clip: text;
}

h1, .h1 {
  font-size: clamp(2.25rem, 5vw, 3.5rem);
  letter-spacing: -0.02em;
}

h2, .h2 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  letter-spacing: -0.015em;
}

h3, .h3 {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
}

h4, .h4 {
  font-size: 1.25rem;
}

h5, .h5 {
  font-size: 1rem;
  font-weight: 600;
}

h6, .h6 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

p {
  margin-bottom: 1rem;
}

p:last-child {
  margin-bottom: 0;
}

.text-muted {
  color: var(--color-muted);
}

.text-small {
  font-size: 0.875rem;
}

.text-large {
  font-size: 1.125rem;
}

.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

/* Block typography helpers */
.block__eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-accent);
  margin-bottom: 0.75rem;
}

.block__title {
  margin-bottom: 1rem;
}

.block__subtitle {
  font-size: 1.125rem;
  color: var(--surface-muted);
  max-width: 600px;
}

.block__subtitle--centered {
  margin-left: auto;
  margin-right: auto;
}

.block__header {
  margin-bottom: 3rem;
}

.block__header--centered {
  text-align: center;
}

.block__footer {
  text-align: center;
  margin-top: 2.5rem;
}

/* ========================================
   BUTTONS
   ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.875rem 1.75rem;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  border: 2px solid transparent;
  border-radius: var(--radius-btn, var(--radius));
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Primary button - uses theme variables */
.btn--primary {
  background: var(--btn-primary-bg, linear-gradient(135deg, var(--color-accent-light), var(--color-accent-dark)));
  color: var(--btn-primary-text, var(--color-accent-contrast));
  border-color: var(--btn-primary-border, transparent);
}

.btn--primary:hover {
  background: var(--btn-primary-hover-bg, var(--btn-primary-bg));
  transform: translateY(-2px);
  box-shadow: var(--btn-primary-shadow, 0 4px 12px var(--color-shadow));
  color: var(--btn-primary-text, var(--color-accent-contrast));
}

/* Secondary button - uses theme variables */
.btn--secondary {
  background: var(--btn-secondary-bg, transparent);
  color: var(--btn-secondary-text, var(--surface-text));
  border-color: var(--btn-secondary-border, var(--surface-border));
}

.btn--secondary:hover {
  border-color: var(--btn-secondary-hover-border, var(--color-accent));
  background: var(--btn-secondary-hover-bg, transparent);
  color: var(--btn-secondary-hover-text, var(--color-accent));
}

/* Ghost button - minimal */
.btn--ghost {
  background: transparent;
  color: var(--surface-text);
  border-color: transparent;
  padding: 0.5rem 1rem;
}

.btn--ghost:hover {
  color: var(--color-accent);
}

/* Button sizes */
.btn--sm {
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
}

.btn--lg {
  padding: 1rem 2.25rem;
  font-size: 1.125rem;
}

.btn--full {
  width: 100%;
}

/* Button icon */
.btn__icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
}

/* ========================================
   CARDS
   ======================================== */

.card {
  background: var(--surface-card, var(--color-surface));
  border: 1px solid var(--surface-border, var(--color-border));
  border-radius: var(--radius);
  padding: var(--space-card, 1.5rem);
  transition: all 0.2s ease;
}

.card--hover:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow);
}

.card--clickable {
  cursor: pointer;
}

.card--flush {
  padding: 0;
}

.card__image {
  border-radius: calc(var(--radius) - 2px);
  overflow: hidden;
  margin-bottom: 1rem;
}

.card__image img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
}

.card__image--square img {
  aspect-ratio: 1;
}

.card__badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
  background: var(--color-accent);
  color: var(--color-accent-contrast);
}

.card__title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.card__snippet {
  font-size: 0.9375rem;
  color: var(--surface-muted);
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__meta {
  font-size: 0.8125rem;
  color: var(--surface-muted);
}

.card__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
}

/* ========================================
   TAGS
   ======================================== */

.tag {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  font-family: var(--tag-font, var(--font-body));
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: var(--tag-transform, none);
  letter-spacing: var(--tag-letter-spacing, 0);
  border-radius: var(--radius-tag, 4px);
  background: var(--tag-bg, var(--surface-card));
  color: var(--surface-muted);
  border: var(--tag-border, 1px solid var(--surface-border));
}

.tag--accent {
  background: var(--color-accent);
  color: var(--color-accent-contrast);
  border-color: transparent;
}

/* ========================================
   GRIDS
   ======================================== */

.grid {
  display: grid;
  gap: 1.5rem;
}

.grid--2 {
  grid-template-columns: repeat(2, 1fr);
}

.grid--3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid--4 {
  grid-template-columns: repeat(4, 1fr);
}

.grid--auto {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* Grid alignment */
.grid--center {
  align-items: center;
}

.grid--start {
  align-items: start;
}

.grid--stretch {
  align-items: stretch;
}

/* Grid gaps */
.grid--gap-sm {
  gap: 1rem;
}

.grid--gap-lg {
  gap: 2.5rem;
}

.grid--gap-xl {
  gap: 4rem;
}

/* ========================================
   FLEXBOX UTILITIES
   ======================================== */

.flex {
  display: flex;
}

.flex--col {
  flex-direction: column;
}

.flex--wrap {
  flex-wrap: wrap;
}

.flex--center {
  align-items: center;
  justify-content: center;
}

.flex--between {
  justify-content: space-between;
}

.flex--gap-sm {
  gap: 0.5rem;
}

.flex--gap {
  gap: 1rem;
}

.flex--gap-lg {
  gap: 2rem;
}

/* ========================================
   FORMS
   ======================================== */

.input {
  width: 100%;
  padding: 0.875rem 1.25rem;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--surface-text);
  background: var(--surface-card);
  border: 2px solid var(--surface-border);
  border-radius: var(--radius-input, var(--radius));
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input:focus {
  outline: none;
  border-color: var(--search-input-focus-border, var(--color-accent));
  box-shadow: var(--search-input-focus-shadow, none);
}

.input::placeholder {
  color: var(--surface-muted);
}

.input--lg {
  padding: 1rem 1.5rem;
  font-size: 1.125rem;
}

/* Input with icon */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group__icon {
  position: absolute;
  left: 1.25rem;
  color: var(--surface-muted);
  pointer-events: none;
}

.input-group .input {
  padding-left: 3rem;
}

/* Input with button */
.input-group--button {
  display: flex;
  gap: 0;
}

.input-group--button .input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.input-group--button .btn {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  flex-shrink: 0;
}

/* ========================================
   PROSE (Article Content)
   ======================================== */

.prose {
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--surface-text);
}

.prose > * + * {
  margin-top: 1.5em;
}

.prose h2 {
  font-size: 1.75rem;
  margin-top: 2.5em;
  margin-bottom: 1rem;
}

.prose h3 {
  font-size: 1.375rem;
  margin-top: 2em;
  margin-bottom: 0.75rem;
}

.prose h4 {
  font-size: 1.125rem;
  margin-top: 1.5em;
  margin-bottom: 0.5rem;
}

.prose p {
  margin-bottom: 1.25em;
}

.prose strong {
  font-weight: 600;
}

.prose em {
  font-style: italic;
}

.prose a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose a:hover {
  text-decoration: none;
}

.prose ul,
.prose ol {
  padding-left: 1.5em;
  margin: 1.25em 0;
}

.prose li {
  margin-bottom: 0.5em;
}

.prose li::marker {
  color: var(--color-accent);
}

.prose blockquote {
  border-left: 4px solid var(--color-accent);
  padding: 1rem 1.5rem;
  margin: 1.5em 0;
  background: var(--surface-card);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-card);
  padding: 0.2em 0.4em;
  border-radius: 4px;
}

.prose pre {
  background: var(--color-code-bg, var(--surface-card));
  color: var(--color-code-text, var(--surface-text));
  padding: 1.5rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1.5em 0;
}

.prose pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.6;
}

.prose img {
  border-radius: var(--radius);
  margin: 2em 0;
}

.prose hr {
  border: none;
  border-top: 1px solid var(--surface-border);
  margin: 3em 0;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.9375rem;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.prose th,
.prose td {
  padding: 0.875rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--surface-border);
}

.prose th {
  background: var(--surface-card);
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--surface-muted);
}

.prose tbody tr:nth-child(even) {
  background: var(--surface-card);
}

.prose tbody tr:hover {
  background: var(--color-alt-bg, var(--surface-card));
}

.prose tbody tr:last-child td {
  border-bottom: none;
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

.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;
}

.hidden {
  display: none !important;
}

.visible {
  visibility: visible;
}

.invisible {
  visibility: hidden;
}

/* Spacing utilities */
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mt-5 { margin-top: 3rem; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.mb-5 { margin-bottom: 3rem; }

/* ========================================
   SCROLL ANIMATIONS
   ======================================== */

.reveal {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.reveal.revealed {
  opacity: 1;
  transform: translateY(0);
}

/* Staggered delays for children */
.reveal-children > *:nth-child(1) { transition-delay: 0s; }
.reveal-children > *:nth-child(2) { transition-delay: 0.1s; }
.reveal-children > *:nth-child(3) { transition-delay: 0.2s; }
.reveal-children > *:nth-child(4) { transition-delay: 0.3s; }
.reveal-children > *:nth-child(5) { transition-delay: 0.4s; }
.reveal-children > *:nth-child(6) { transition-delay: 0.5s; }

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
  .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
  
  html {
    scroll-behavior: auto;
  }
}

/* ========================================
   THEME EXTRAS (scrollbar, selection)
   ======================================== */

/* Scrollbar - uses theme variables */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track, var(--color-surface));
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb, var(--color-border));
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover, var(--color-muted));
}

/* Selection */
::selection {
  background: var(--selection-bg, rgba(139, 92, 246, 0.2));
  color: var(--selection-text, var(--color-text));
}

/* ========================================
   RESPONSIVE BREAKPOINTS
   ======================================== */

/* Tablet and below (900px) */
@media (max-width: 900px) {
  .grid--2,
  .grid--3,
  .grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .block {
    padding: calc(var(--space-section-y, 5rem) * 0.75) 0;
  }
  
  .hide-tablet {
    display: none;
  }
}

/* Mobile (600px) */
@media (max-width: 600px) {
  .grid--2,
  .grid--3,
  .grid--4 {
    grid-template-columns: 1fr;
  }
  
  .container {
    padding: 0 1rem;
  }
  
  .block {
    padding: calc(var(--space-section-y, 5rem) * 0.6) 0;
  }
  
  .btn {
    padding: 0.75rem 1.5rem;
  }
  
  .hide-mobile {
    display: none;
  }
  
  .block__subtitle {
    font-size: 1rem;
  }
}

/* Large screens (1400px+) */
@media (min-width: 1400px) {
  .container {
    padding: 0 2rem;
  }
}
