/* ===============================================
   TYPOGRAPHY ENHANCEMENTS
   Fluid typography, proper spacing, and hierarchy
   =============================================== */

/* ================ CSS Custom Properties ================ */
:root {
  /* Fluid Typography using clamp() */
  --font-size-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --font-size-sm: clamp(0.875rem, 0.8rem + 0.375vw, 1rem);
  --font-size-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
  --font-size-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
  --font-size-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
  --font-size-2xl: clamp(1.5rem, 1.3rem + 1vw, 1.875rem);
  --font-size-3xl: clamp(1.875rem, 1.6rem + 1.375vw, 2.25rem);
  --font-size-4xl: clamp(2.25rem, 1.9rem + 1.75vw, 3rem);
  --font-size-5xl: clamp(3rem, 2.5rem + 2.5vw, 4rem);

  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-snug: 1.375;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;
  --line-height-loose: 2;

  /* Letter Spacing */
  --letter-spacing-tight: -0.025em;
  --letter-spacing-normal: 0;
  --letter-spacing-wide: 0.025em;
  --letter-spacing-wider: 0.05em;

  /* Font Weights */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Spacing Scale */
  --space-xs: clamp(0.5rem, 0.45rem + 0.25vw, 0.625rem);
  --space-sm: clamp(0.75rem, 0.65rem + 0.5vw, 1rem);
  --space-md: clamp(1rem, 0.85rem + 0.75vw, 1.5rem);
  --space-lg: clamp(1.5rem, 1.25rem + 1.25vw, 2rem);
  --space-xl: clamp(2rem, 1.5rem + 2.5vw, 3rem);
  --space-2xl: clamp(3rem, 2rem + 5vw, 4rem);

  /* Max Content Width for Readability */
  --content-width: 65ch;
  --content-width-narrow: 45ch;
  --content-width-wide: 80ch;
}

/* ================ Base Typography ================ */
html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: #1f2937;
  font-weight: var(--font-weight-normal);
}

/* ================ Heading Hierarchy ================ */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  letter-spacing: var(--letter-spacing-tight);
  margin-top: 0;
  margin-bottom: var(--space-md);
  color: #111827;
}

h1 {
  font-size: var(--font-size-4xl);
  margin-bottom: var(--space-lg);
}

h2 {
  font-size: var(--font-size-3xl);
  margin-bottom: var(--space-lg);
}

h3 {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-md);
}

h4 {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-md);
}

h5 {
  font-size: var(--font-size-lg);
  margin-bottom: var(--space-sm);
}

h6 {
  font-size: var(--font-size-base);
  margin-bottom: var(--space-sm);
  font-weight: var(--font-weight-semibold);
}

/* ================ Paragraph Styling ================ */
p {
  margin-top: 0;
  margin-bottom: var(--space-md);
  line-height: var(--line-height-relaxed);
}

p:last-child {
  margin-bottom: 0;
}

/* Lead paragraph */
.lead,
.hero-sub {
  font-size: var(--font-size-lg);
  line-height: var(--line-height-relaxed);
  color: #4b5563;
  margin-bottom: var(--space-lg);
}

/* Small text */
.text-sm,
small {
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

/* Extra small text */
.text-xs {
  font-size: var(--font-size-xs);
  line-height: var(--line-height-normal);
}

/* ================ Lists ================ */
ul, ol {
  margin-top: 0;
  margin-bottom: var(--space-md);
  padding-right: var(--space-lg);
  line-height: var(--line-height-relaxed);
}

li {
  margin-bottom: var(--space-xs);
}

li:last-child {
  margin-bottom: 0;
}

/* Nested lists */
ul ul,
ol ol,
ul ol,
ol ul {
  margin-top: var(--space-xs);
  margin-bottom: var(--space-xs);
}

/* ================ Links ================ */
a {
  color: #2563eb;
  text-decoration: none;
  transition: color 0.2s ease;
}


a:focus {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 2px;
}

/* ================ Text Utilities ================ */
.text-center {
  text-align: center;
}

.text-left {
  text-align: left;
}

.text-right {
  text-align: right;
}

.text-justify {
  text-align: justify;
}

/* Font Weights */
.font-normal {
  font-weight: var(--font-weight-normal);
}

.font-medium {
  font-weight: var(--font-weight-medium);
}

.font-semibold {
  font-weight: var(--font-weight-semibold);
}

.font-bold {
  font-weight: var(--font-weight-bold);
}

/* Text Colors */
.text-primary {
  color: #2563eb;
}

.text-secondary {
  color: #6b7280;
}

.text-success {
  color: #10b981;
}

.text-danger {
  color: #ef4444;
}

.text-warning {
  color: #f59e0b;
}

.text-muted {
  color: #9ca3af;
}

/* ================ Content Sections ================ */
.content-section {
  margin-bottom: var(--space-2xl);
}

.content-section:last-child {
  margin-bottom: 0;
}

/* Readable content width */
.content-readable {
  max-width: var(--content-width);
  margin-left: auto;
  margin-right: auto;
}

.content-narrow {
  max-width: var(--content-width-narrow);
  margin-left: auto;
  margin-right: auto;
}

.content-wide {
  max-width: var(--content-width-wide);
  margin-left: auto;
  margin-right: auto;
}

/* ================ Blockquotes ================ */
blockquote {
  margin: var(--space-lg) 0;
  padding: var(--space-md) var(--space-lg);
  border-right: 4px solid #2563eb;
  background: #f8fafc;
  border-radius: 8px;
  font-style: italic;
  color: #4b5563;
}

blockquote p:last-child {
  margin-bottom: 0;
}

blockquote cite {
  display: block;
  margin-top: var(--space-sm);
  font-size: var(--font-size-sm);
  color: #6b7280;
  font-style: normal;
}

/* ================ Code and Pre ================ */
code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.9em;
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  color: #dc2626;
}

pre {
  font-family: 'Courier New', Courier, monospace;
  font-size: var(--font-size-sm);
  background: #1f2937;
  color: #f3f4f6;
  padding: var(--space-md);
  border-radius: 8px;
  overflow-x: auto;
  line-height: var(--line-height-relaxed);
  margin: var(--space-lg) 0;
}

pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* ================ Tables ================ */
table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-lg) 0;
  font-size: var(--font-size-sm);
}

th, td {
  padding: var(--space-sm) var(--space-md);
  text-align: right;
  border-bottom: 1px solid #e5e7eb;
}

th {
  font-weight: var(--font-weight-semibold);
  background: #f8fafc;
  color: #374151;
}

tr:hover {
  background: #f9fafb;
}

/* ================ Hero Typography ================ */
.hero-title {
  font-size: var(--font-size-5xl);
  line-height: var(--line-height-tight);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-md);
  letter-spacing: var(--letter-spacing-tight);
}

.hero-sub {
  font-size: var(--font-size-xl);
  line-height: var(--line-height-relaxed);
  color: #6b7280;
  margin-bottom: var(--space-xl);
  max-width: var(--content-width-wide);
  margin-left: auto;
  margin-right: auto;
}

/* ================ Section Titles ================ */
.section-title {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  text-align: center;
  margin-bottom: var(--space-xl);
  color: #111827;
}

.section-subtitle {
  font-size: var(--font-size-lg);
  color: #6b7280;
  text-align: center;
  margin-bottom: var(--space-lg);
  max-width: var(--content-width);
  margin-left: auto;
  margin-right: auto;
}

/* ================ Card Typography ================ */
.card-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-sm);
  color: #111827;
}

.card-text {
  font-size: var(--font-size-base);
  line-height: var(--line-height-relaxed);
  color: #4b5563;
}

/* ================ Tool Card Typography ================ */
.tool-card h3 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-xs);
  line-height: var(--line-height-snug);
}

.tool-card p {
  font-size: var(--font-size-sm);
  line-height: var(--line-height-relaxed);
  color: #6b7280;
  margin: 0;
}

/* ================ Form Typography ================ */
label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: #374151;
  margin-bottom: var(--space-xs);
}

input,
textarea,
select {
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  font-family: inherit;
}

/* ================ Responsive Typography Adjustments ================ */
@media (max-width: 767px) {
  :root {
    --content-width: 100%;
  }

  /* Adjust spacing for mobile */
  h1, h2, h3 {
    margin-bottom: var(--space-md);
  }

  p {
    margin-bottom: var(--space-sm);
  }

  .content-section {
    margin-bottom: var(--space-xl);
  }
}

/* ================ Print Typography ================ */
@media print {
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
  }

  h1 {
    font-size: 24pt;
  }

  h2 {
    font-size: 20pt;
  }

  h3 {
    font-size: 16pt;
  }

  h4, h5, h6 {
    font-size: 14pt;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  blockquote {
    border-right: 2px solid #000;
    background: none;
  }
}

/* ================ Accessibility ================ */
/* Ensure sufficient contrast */
::selection {
  background: #2563eb;
  color: white;
}

/* Focus visible for keyboard navigation */
:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
