/**
 * Typography Polish
 *
 * Font rendering, line heights, letter spacing, heading hierarchy,
 * prose styling, code formatting, and print styles.
 * Uses engine CSS variables (--text, --text-light, --muted, --accent, --link, etc.)
 */

/* ================================================================
   FONT RENDERING OPTIMIZATIONS
   ================================================================ */

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1, "calt" 1;
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ================================================================
   LINE HEIGHT SYSTEM
   ================================================================ */

/* Body text - optimal readability */
body,
p,
li,
.text-body,
.prose,
blockquote {
  line-height: 1.6;
}

/* Headings - tighter for visual hierarchy */
h1, .h1,
h2, .h2,
h3, .h3,
h4, .h4,
h5, .h5,
h6, .h6 {
  line-height: 1.2;
  font-weight: 700;
}

/* Display text - even tighter */
.display-1,
.display-2,
.hero__title,
.page-title {
  line-height: 1.1;
}

/* Small text - slightly increased */
small,
.text-small,
.text-xs,
.caption,
.meta {
  line-height: 1.5;
}

/* Code blocks - monospace optimal */
code,
pre,
kbd,
samp {
  line-height: 1.5;
}

/* ================================================================
   LETTER SPACING
   ================================================================ */

/* Headings - negative tracking for professional look */
h1, .h1 {
  letter-spacing: -0.02em;
  font-size: clamp(2rem, 5vw, 3rem);
}

h2, .h2 {
  letter-spacing: -0.02em;
  font-size: clamp(1.5rem, 4vw, 2.25rem);
}

h3, .h3 {
  letter-spacing: -0.015em;
  font-size: clamp(1.25rem, 3vw, 1.75rem);
}

h4, .h4 {
  letter-spacing: -0.01em;
  font-size: clamp(1.125rem, 2.5vw, 1.5rem);
}

h5, .h5,
h6, .h6 {
  letter-spacing: normal;
}

/* Uppercase elements - increased spacing */
.small-caps,
.all-caps,
.uppercase {
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.875em;
}

/* Button text - slight increase for clarity */
button,
.btn,
input[type="submit"],
input[type="button"] {
  letter-spacing: 0.025em;
  font-weight: 500;
}

/* Meta information */
.meta,
.caption,
time,
.date {
  letter-spacing: 0.01em;
}

/* ================================================================
   FONT SIZE UTILITIES
   ================================================================ */

.text-xs,
.text-extra-small {
  font-size: var(--text-xs, 0.75rem);
}

.text-sm,
.text-small {
  font-size: var(--text-sm, 0.875rem);
}

.text-base,
.text-body {
  font-size: var(--text-base, 1rem);
}

.text-lg,
.text-large {
  font-size: var(--text-lg, 1.125rem);
}

.text-xl {
  font-size: var(--text-xl, 1.25rem);
}

.text-2xl {
  font-size: var(--text-2xl, 1.5rem);
}

.text-3xl {
  font-size: var(--text-3xl, 2rem);
}

.text-4xl {
  font-size: var(--text-4xl, 2.5rem);
}

/* ================================================================
   HEADING HIERARCHY
   ================================================================ */

h1, .h1 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-weight: 700;
}

h2, .h2 {
  margin-top: 2.5rem;
  margin-bottom: 0.875rem;
  font-weight: 700;
}

h3, .h3 {
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
}

h4, .h4 {
  margin-top: 1.75rem;
  margin-bottom: 0.625rem;
  font-weight: 600;
}

h5, .h5 {
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

h6, .h6 {
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: var(--text-light, #555);
  text-transform: uppercase;
  font-size: var(--text-sm, 0.875rem);
  letter-spacing: 0.05em;
}

/* Prevent orphans in headings */
h1, h2, h3 {
  text-wrap: balance;
}

/* ================================================================
   PROSE / READABLE CONTENT
   ================================================================ */

.prose {
  max-width: 70ch;
  line-height: 1.7;
}

.prose > * {
  max-width: 70ch;
}

.prose h2 {
  margin-top: 2em;
  margin-bottom: 0.5em;
}

.prose h3 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.prose p {
  margin-bottom: 1em;
}

.prose ul,
.prose ol {
  margin-bottom: 1em;
  padding-left: 1.5em;
  max-width: 70ch;
}

.prose li {
  margin-bottom: 0.35em;
}

.prose li + li {
  margin-top: 0.25em;
}

.prose a {
  color: var(--link, #0066cc);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose a:hover {
  color: var(--link-hover, #004499);
  border-bottom: 1px solid currentColor;
}

.prose a:focus {
  outline: 2px solid var(--accent, #ff7a59);
  outline-offset: 2px;
}

/* First heading in prose — no top margin */
.prose > h1:first-child,
.prose > h2:first-child,
.prose > h3:first-child {
  margin-top: 0;
}

/* Full width for tables and figures in prose */
.prose table,
.prose figure,
.prose img {
  max-width: 100%;
}

/* ================================================================
   PARAGRAPH & TEXT
   ================================================================ */

p {
  margin-bottom: 1.25em;
  text-wrap: pretty;
}

p:last-child {
  margin-bottom: 0;
}

/* Prevent orphans and widows */
p,
li,
h1, h2, h3, h4, h5, h6 {
  orphans: 3;
  widows: 3;
}

/* Headings should not break */
h1, h2, h3, h4, h5, h6 {
  break-after: avoid;
  page-break-after: avoid;
}

/* ================================================================
   BLOCKQUOTE
   ================================================================ */

blockquote {
  margin: 2rem 0;
  padding-left: 1.5rem;
  border-left: 4px solid var(--accent, #ff7a59);
  font-style: italic;
  color: var(--text-light, #555);
  line-height: 1.6;
}

blockquote p {
  margin-bottom: 0.75em;
}

blockquote cite {
  display: block;
  margin-top: 1rem;
  font-style: normal;
  font-size: var(--text-sm, 0.875rem);
  color: var(--muted, #888);
}

blockquote cite::before {
  content: "\2014\00a0";
}

/* ================================================================
   LISTS
   ================================================================ */

ul,
ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
  line-height: 1.6;
}

li {
  margin-bottom: 0.375em;
}

li:last-child {
  margin-bottom: 0;
}

/* Nested lists */
ul ul,
ul ol,
ol ul,
ol ol {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

/* ================================================================
   CODE & PRE FORMATTING
   ================================================================ */

code {
  font-family: var(--font-mono, 'Consolas', 'Monaco', 'Courier New', monospace);
  font-size: 0.875em;
  background: var(--bg-alt, #f8f9fa);
  padding: 0.125em 0.375em;
  border-radius: var(--radius-sm, 3px);
  color: var(--accent, #ff7a59);
  font-weight: 400;
  -webkit-font-smoothing: auto;
  -moz-osx-font-smoothing: auto;
}

pre {
  font-family: var(--font-mono, 'Consolas', 'Monaco', 'Courier New', monospace);
  font-size: 0.875rem;
  line-height: 1.5;
  background: var(--bg-alt, #f8f9fa);
  padding: 1rem 1.25rem;
  border-radius: var(--radius, 6px);
  overflow-x: auto;
  margin: 1.5rem 0;
  border: 1px solid var(--border, #e1e4e8);
  -webkit-font-smoothing: auto;
  -moz-osx-font-smoothing: auto;
}

pre code {
  background: transparent;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
  color: var(--text, #2e2e2e);
}

/* ================================================================
   TABLE TYPOGRAPHY
   ================================================================ */

table {
  font-size: var(--text-sm, 0.875rem);
  line-height: 1.5;
}

th {
  font-weight: 600;
  text-align: left;
  letter-spacing: 0.025em;
}

td {
  font-weight: 400;
}

caption {
  font-size: var(--text-sm, 0.875rem);
  color: var(--text-light, #555);
  margin-bottom: 0.75rem;
  text-align: left;
  font-weight: 500;
}

/* ================================================================
   DEFINITION LISTS
   ================================================================ */

dl {
  margin-bottom: 1.5rem;
}

dt {
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--text, #2e2e2e);
}

dd {
  margin-left: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-light, #555);
}

dd:last-child {
  margin-bottom: 0;
}

/* ================================================================
   ABBREVIATIONS
   ================================================================ */

abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
  border-bottom: 1px dotted var(--text-light, #555);
}

/* ================================================================
   MARK / HIGHLIGHT
   ================================================================ */

mark,
.highlight {
  background-color: rgba(234, 179, 8, 0.2);
  color: var(--text, #2e2e2e);
  padding: 0.125em 0.25em;
  border-radius: 2px;
}

/* ================================================================
   SUBSCRIPT & SUPERSCRIPT
   ================================================================ */

sub,
sup {
  font-size: 0.75em;
  line-height: 0;
  position: relative;
  vertical-align: baseline;
}

sup {
  top: -0.5em;
}

sub {
  bottom: -0.25em;
}

/* ================================================================
   HORIZONTAL RULES
   ================================================================ */

hr {
  margin: 3rem 0;
  border: none;
  border-top: 1px solid var(--border, #e1e4e8);
}

/* ================================================================
   EMPHASIS & STRONG
   ================================================================ */

strong,
b {
  font-weight: 700;
  color: var(--text, #2e2e2e);
}

em,
i {
  font-style: italic;
}

/* ================================================================
   RESPONSIVE TYPOGRAPHY
   ================================================================ */

@media (max-width: 768px) {
  h1, .h1 {
    font-size: clamp(1.75rem, 6vw, 2.5rem);
  }

  h2, .h2 {
    font-size: clamp(1.5rem, 5vw, 2rem);
    margin-top: 2rem;
  }

  h3, .h3 {
    font-size: clamp(1.25rem, 4vw, 1.5rem);
    margin-top: 1.5rem;
  }

  /* Full width on mobile */
  .prose {
    max-width: 100%;
  }
}

/* ================================================================
   TEXT SELECTION
   ================================================================ */

::selection {
  background: var(--accent, #ff7a59);
  color: #fff;
}

::-moz-selection {
  background: var(--accent, #ff7a59);
  color: #fff;
}

/* ================================================================
   SCROLLBAR STYLING
   ================================================================ */

/* Webkit (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-alt, #f8f9fa);
}

::-webkit-scrollbar-thumb {
  background: var(--border, #e1e4e8);
  border-radius: 5px;
  border: 2px solid var(--bg-alt, #f8f9fa);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted, #888);
}

/* Firefox */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--border, #e1e4e8) var(--bg-alt, #f8f9fa);
}

/* ================================================================
   ACCESSIBILITY ALIAS
   ================================================================ */

/* Common alias for .visually-hidden (provided by engine base theme) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Becomes visible on focus (for skip links / show-on-focus elements) */
.sr-only-focusable:focus,
.sr-only-focusable:focus-visible {
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* ================================================================
   PRINT STYLES
   ================================================================ */

@media print {
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
  }

  h1 {
    font-size: 24pt;
    page-break-after: avoid;
  }

  h2 {
    font-size: 18pt;
    page-break-after: avoid;
  }

  h3 {
    font-size: 14pt;
    page-break-after: avoid;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  /* Hide UI elements in print */
  .share-buttons,
  .image-lightbox-modal,
  .error-toast,
  .cookie-consent,
  .btn--secondary {
    display: none !important;
  }

  /* Show link URLs in print */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.875em;
    color: #666;
  }
}
