/*
 * Modern CSS Reset and Base Styles
 * Based on modern CSS reset practices and optimized for performance
 * Includes accessibility improvements and modern defaults
 */

/* ===== MODERN CSS RESET ===== */

/* Box sizing rules */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Prevent font size inflation */
html {
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
}

/* Remove default margin in favour of better control in authored CSS */
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
figure,
blockquote,
dl,
dd {
  margin: 0;
}

/* Remove list styles on ul, ol elements with a list role */
ul[role='list'],
ol[role='list'] {
  list-style: none;
}

/* Set core body defaults */
body {
  min-height: 100vh;
  line-height: var(--line-height-normal);
  font-family: var(--font-family-primary);
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  background-color: var(--color-bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeSpeed;
}

/* Set shorter line heights on headings and interactive elements */
h1,
h2,
h3,
h4,
h5,
h6,
button,
input,
label {
  line-height: var(--line-height-tight);
}

/* Balance text wrapping on headings */
h1,
h2,
h3,
h4,
h5,
h6 {
  text-wrap: balance;
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
}

/* Typography Scale */
h1 {
  font-size: var(--font-size-4xl);
  margin-bottom: var(--space-6);
}

h2 {
  font-size: var(--font-size-3xl);
  margin-bottom: var(--space-5);
}

h3 {
  font-size: var(--font-size-2xl);
  margin-bottom: var(--space-4);
}

h4 {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-4);
}

h5 {
  font-size: var(--font-size-lg);
  margin-bottom: var(--space-3);
}

h6 {
  font-size: var(--font-size-base);
  margin-bottom: var(--space-3);
}

/* Paragraph spacing */
p {
  margin-bottom: var(--space-4);
  color: var(--color-text-secondary);
  line-height: var(--line-height-relaxed);
}

/* A elements that don't have a class get default styles */
a:not([class]) {
  text-decoration-skip-ink: auto;
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  transition: color var(--duration-fast) var(--ease-out);
}

a:not([class]):hover,
a:not([class]):focus {
  color: var(--color-primary-dark);
}

/* Modern link styles */
a {
  color: var(--color-primary);
  text-decoration: none;
  transition: all var(--duration-fast) var(--ease-out);
}

a:hover,
a:focus {
  color: var(--color-primary-dark);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

/* Make images easier to work with */
img,
picture,
svg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Modern image loading */
img {
  font-style: italic;
  background-repeat: no-repeat;
  background-size: cover;
  shape-margin: 1rem;
}

/* Inherit fonts for inputs and buttons */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

/* Remove default button styles */
button {
  border: none;
  background: none;
  cursor: pointer;
  padding: 0;
}

/* Modern form elements */
input,
textarea,
select {
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  background-color: var(--color-white);
  transition: all var(--duration-fast) var(--ease-out);
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-color: var(--color-primary);
}

/* Make sure textareas without a rows attribute are not tiny */
textarea:not([rows]) {
  min-height: 10em;
}

/* Anything that has been anchored to should have extra scroll margin */
:target {
  scroll-margin-block: 5ex;
}

/* ===== MODERN BASE STYLES ===== */

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Remove focus outline for mouse users */
:focus:not(:focus-visible) {
  outline: none;
}

/* Modern selection styles */
::selection {
  background-color: var(--color-primary);
  color: var(--color-white);
  text-shadow: none;
}

::-moz-selection {
  background-color: var(--color-primary);
  color: var(--color-white);
  text-shadow: none;
}

/* Modern scrollbar styles */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--color-gray-100);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--color-gray-400);
  border-radius: var(--radius-full);
  transition: background var(--duration-fast) var(--ease-out);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-gray-500);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-gray-400) var(--color-gray-100);
}

/* Modern placeholder styles */
::placeholder {
  color: var(--color-gray-500);
  opacity: 1;
}

::-webkit-input-placeholder {
  color: var(--color-gray-500);
}

::-moz-placeholder {
  color: var(--color-gray-500);
  opacity: 1;
}

:-ms-input-placeholder {
  color: var(--color-gray-500);
}

/* Modern list styles */
ul,
ol {
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
}

li {
  margin-bottom: var(--space-2);
}

/* Modern table styles */
table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: var(--space-6);
}

th,
td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-gray-200);
}

th {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  background-color: var(--color-gray-50);
}

/* Modern code styles */
code,
pre {
  font-family: var(--font-family-mono);
  font-size: 0.9em;
}

code {
  background-color: var(--color-gray-100);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  color: var(--color-gray-800);
}

pre {
  background-color: var(--color-gray-900);
  color: var(--color-gray-100);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  margin-bottom: var(--space-4);
}

pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* Modern blockquote styles */
blockquote {
  border-left: 4px solid var(--color-primary);
  padding-left: var(--space-4);
  margin: var(--space-6) 0;
  font-style: italic;
  color: var(--color-text-secondary);
}

/* Modern hr styles */
hr {
  border: none;
  height: 1px;
  background: linear-gradient(
    to right,
    transparent,
    var(--color-gray-300),
    transparent
  );
  margin: var(--space-8) 0;
}

/* Modern details/summary styles */
details {
  margin-bottom: var(--space-4);
}

summary {
  cursor: pointer;
  font-weight: var(--font-weight-semibold);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-gray-200);
}

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

/* Modern mark styles */
mark {
  background-color: var(--color-accent-light);
  color: var(--color-gray-900);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

/* Modern abbr styles */
abbr[title] {
  text-decoration: underline dotted;
  cursor: help;
}

/* Modern small text */
small {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* Modern strong and em */
strong,
b {
  font-weight: var(--font-weight-bold);
}

em,
i {
  font-style: italic;
}

/* Modern address styles */
address {
  font-style: normal;
  line-height: var(--line-height-relaxed);
  margin-bottom: var(--space-4);
}

/* Modern fieldset and legend */
fieldset {
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-6);
}

legend {
  font-weight: var(--font-weight-semibold);
  padding: 0 var(--space-2);
  color: var(--color-text-primary);
}

/* Modern progress and meter */
progress,
meter {
  width: 100%;
  height: var(--space-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}

/* Modern kbd styles */
kbd {
  background-color: var(--color-gray-100);
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
  color: var(--color-gray-800);
  box-shadow: 0 1px 0 var(--color-gray-400);
}