/* CSS Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-tab-size: 4;
  tab-size: 4;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

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

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* CSS Variables */
:root {
  --color-primary: #B21F2D;
  --color-secondary: #1F3A5F;
  --color-accent: #D97A1B;
  --color-background: #FBF7F2;
  --color-surface: #FFFFFF;
  --color-text: #1B1B1D;
  --color-text-muted: #5A5E66;
  --color-border: #D9D2C7;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(27, 27, 29, 0.10);
  --maxw: 1100px;
}

/* Typography Scale with clamp() */
body {
  background-color: var(--color-background);
  color: var(--color-text);
  font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
}

h1 {
  font-size: clamp(2rem, 1.5rem + 2vw, 3rem);
  line-height: 1.1;
  font-weight: 700;
  color: var(--color-secondary);
  margin-bottom: 1rem;
}

h2 {
  font-size: clamp(1.5rem, 1.25rem + 1vw, 2rem);
  line-height: 1.2;
  font-weight: 700;
  color: var(--color-secondary);
  margin-top: 2.5rem;
  margin-bottom: 0.875rem;
}

h3 {
  font-size: clamp(1.25rem, 1.1rem + 0.5vw, 1.5rem);
  line-height: 1.3;
  font-weight: 600;
  color: var(--color-text);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

h4 {
  font-size: clamp(1.125rem, 1rem + 0.25vw, 1.25rem);
  line-height: 1.4;
  font-weight: 600;
  color: var(--color-text);
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

p {
  margin-bottom: 1.25rem;
  max-width: 70ch;
}

/* Header */
header {
  background-color: var(--color-surface);
  border-bottom: 2px solid var(--color-border);
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(27, 27, 29, 0.05);
}

.header-container {
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.site-name {
  font-size: clamp(1.5rem, 1.25rem + 0.75vw, 1.875rem);
  font-weight: 700;
  color: var(--color-primary);
  text-decoration: none;
  letter-spacing: -0.02em;
}

.site-name:hover {
  color: var(--color-accent);
  transition: color 0.2s ease;
}

/* Navigation with Flexbox clusters */
nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}

nav a {
  color: var(--color-text);
  text-decoration: none;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: calc(var(--radius) / 2);
  transition: background-color 0.2s ease, color 0.2s ease;
}

nav a:hover {
  background-color: var(--color-background);
  color: var(--color-primary);
}

nav a:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* Breadcrumbs */
.breadcrumbs {
  max-width: var(--maxw);
  margin: 1rem auto;
  padding: 0 1rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.breadcrumbs ol {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.breadcrumbs li:not(:last-child)::after {
  content: "›";
  margin-left: 0.5rem;
  color: var(--color-border);
}

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

.breadcrumbs a:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.breadcrumbs a:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Main Layout - CSS Grid */
.page-container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 2rem 1rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

main {
  background-color: var(--color-surface);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

aside {
  background-color: var(--color-surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  align-self: start;
}

/* Links */
a {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

a:hover {
  color: var(--color-accent);
  text-decoration-thickness: 2px;
}

a:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Blockquotes */
blockquote {
  margin: 2rem 0;
  padding: 1.5rem 1.5rem 1.5rem 2rem;
  background-color: var(--color-background);
  border-left: 4px solid var(--color-primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-style: italic;
  color: var(--color-text);
  box-shadow: 0 2px 8px rgba(27, 27, 29, 0.05);
}

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

blockquote cite {
  display: block;
  margin-top: 0.75rem;
  font-style: normal;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  font-weight: 600;
}

blockquote cite::before {
  content: "— ";
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  background-color: var(--color-surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(27, 27, 29, 0.08);
}

.table-wrapper {
  overflow-x: auto;
  margin: 2rem 0;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

caption {
  caption-side: top;
  text-align: left;
  font-weight: 600;
  font-size: 1.125rem;
  color: var(--color-secondary);
  padding: 1rem;
  background-color: var(--color-background);
}

thead {
  background-color: var(--color-secondary);
  color: var(--color-surface);
}

th {
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--color-primary);
}

td {
  padding: 1rem;
  border-bottom: 1px solid var(--color-border);
}

tbody tr:nth-child(odd) {
  background-color: var(--color-background);
}

tbody tr:nth-child(even) {
  background-color: var(--color-surface);
}

tbody tr:hover {
  background-color: rgba(178, 31, 45, 0.05);
  transition: background-color 0.2s ease;
}

/* Details/Summary Accordion */
details {
  margin: 1.5rem 0;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

summary {
  padding: 1.25rem 1.5rem;
  font-weight: 600;
  color: var(--color-secondary);
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background-color 0.2s ease;
  user-select: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "+";
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-primary);
  transition: transform 0.3s ease;
}

details[open] summary::after {
  content: "−";
  transform: rotate(180deg);
}

summary:hover {
  background-color: var(--color-background);
}

summary:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: -3px;
}

details > *:not(summary) {
  padding: 0 1.5rem 1.25rem 1.5rem;
}

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

/* Lists */
ul, ol {
  margin: 1rem 0 1.5rem 1.5rem;
}

li {
  margin-bottom: 0.5rem;
}

/* Footer */
footer {
  background-color: var(--color-secondary);
  color: var(--color-surface);
  padding: 2rem 1rem;
  margin-top: 4rem;
  text-align: center;
  font-size: 0.875rem;
}

footer a {
  color: var(--color-surface);
  text-decoration: underline;
}

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

.footer-container {
  max-width: var(--maxw);
  margin: 0 auto;
}

/* Buttons */
button, .button {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  background-color: var(--color-primary);
  color: var(--color-surface);
  border: none;
  border-radius: calc(var(--radius) / 2);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

button:hover, .button:hover {
  background-color: var(--color-accent);
  transform: translateY(-1px);
}

button:focus-visible, .button:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
}

button:active, .button:active {
  transform: translateY(0);
}

/* Utility Classes */
.lead {
  font-size: clamp(1.125rem, 1rem + 0.5vw, 1.25rem);
  line-height: 1.7;
  color: var(--color-text);
  margin-bottom: 1.5rem;
  font-weight: 400;
}

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

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

/* Responsive Breakpoints */
@media (min-width: 768px) {
  .header-container {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  nav ul {
    gap: 0.75rem 2rem;
  }

  .page-container {
    padding: 3rem 2rem;
  }

  main {
    padding: 3rem;
  }
}

@media (min-width: 1024px) {
  .page-container.with-sidebar {
    grid-template-columns: 1fr 300px;
  }

  thead {
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .table-wrapper {
    overflow-x: visible;
  }
}

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

/* Print Styles */
@media print {
  body {
    background-color: white;
    color: black;
  }

  header, footer, nav, aside, .breadcrumbs {
    display: none;
  }

  main {
    box-shadow: none;
    padding: 0;
  }

  a {
    text-decoration: underline;
    color: black;
  }

  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.875rem;
  }

  table {
    page-break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  tr {
    page-break-inside: avoid;
  }

  h1, h2, h3 {
    page-break-after: avoid;
  }

  blockquote {
    border-left: 2px solid black;
    background-color: transparent;
  }
}