/* ==========================================================================
   Base Styles - Reset and Global Styles
   
   This file provides CSS reset and global element styles using design tokens.
   All styles reference tokens from variables.css exclusively.
   
   Requirements: 8.2, 11.3
   ========================================================================== */

/* ==========================================================================
   CSS Reset - Consistent Cross-Browser Rendering
   ========================================================================== */

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

/* Remove default margin and padding */
* {
  margin: 0;
  padding: 0;
}

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

/* Set core root defaults */
html {
  scroll-behavior: smooth;
  font-size: 100%; /* 16px base for rem calculations */
}

/* ==========================================================================
   Body - Global Defaults
   ========================================================================== */

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

/* ==========================================================================
   Typography Base Styles
   ========================================================================== */

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
  margin-bottom: var(--space-md);
}

h1 {
  font-size: var(--font-size-4xl);
  font-weight: var(--font-weight-bold);
}

h2 {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
}

h3 {
  font-size: var(--font-size-2xl);
}

h4 {
  font-size: var(--font-size-xl);
}

h5 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
}

h6 {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
}

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

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

/* ==========================================================================
   Links
   ========================================================================== */

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

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

a:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Links without class get default underline on hover */
a:not([class]) {
  text-decoration-skip-ink: auto;
}

/* ==========================================================================
   Lists
   ========================================================================== */

ul, ol {
  margin-bottom: var(--space-md);
  padding-left: var(--space-lg);
}

li {
  margin-bottom: var(--space-xs);
  color: var(--color-text-secondary);
}

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

/* Nested lists */
ul ul, ul ol, ol ul, ol ol {
  margin-top: var(--space-xs);
  margin-bottom: 0;
}

/* ==========================================================================
   Code and Monospace
   ========================================================================== */

code,
pre,
kbd,
samp {
  font-family: var(--font-family-mono);
  font-size: var(--font-size-sm);
}

code {
  background-color: var(--color-bg-elevated);
  color: var(--color-text-primary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
}

pre {
  background-color: var(--color-bg-elevated);
  color: var(--color-text-primary);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin-bottom: var(--space-md);
}

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

/* ==========================================================================
   Blockquotes
   ========================================================================== */

blockquote {
  border-left: 4px solid var(--color-accent);
  padding-left: var(--space-md);
  margin: var(--space-lg) 0;
  font-style: italic;
  color: var(--color-text-secondary);
}

/* ==========================================================================
   Text Elements
   ========================================================================== */

small {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

strong, b {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}

em, i {
  font-style: italic;
}

mark {
  background-color: var(--color-warning);
  color: var(--color-bg-primary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Media Elements
   ========================================================================== */

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

/* ==========================================================================
   Form Element Inheritance
   ========================================================================== */

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

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

/* ==========================================================================
   Tables
   ========================================================================== */

table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
}

/* ==========================================================================
   Horizontal Rule
   ========================================================================== */

hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-lg) 0;
}

/* ==========================================================================
   Focus Styles - Accessibility
   ========================================================================== */

:focus {
  outline: none;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ==========================================================================
   Selection
   ========================================================================== */

::selection {
  background-color: var(--color-accent);
  color: var(--color-text-primary);
}

/* ==========================================================================
   Reduced Motion - Accessibility
   ========================================================================== */

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

/* ==========================================================================
   High Contrast Mode - Accessibility
   ========================================================================== */

@media (prefers-contrast: high) {
  :root {
    --color-text-primary: #ffffff;
    --color-text-secondary: #ffffff;
    --color-bg-primary: #000000;
    --color-surface: #000000;
    --color-border: #ffffff;
  }
}

/* ==========================================================================
   Screen Reader Utilities - Accessibility (Requirement 8.2)
   ========================================================================== */

/* Visually hidden but accessible to screen readers */
.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;
}

/* Allow element to be focusable when navigated to via keyboard */
.sr-only-focusable:focus,
.sr-only-focusable:active {
  position: static;
  width: auto;
  height: auto;
  padding: inherit;
  margin: inherit;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

/* Skip link for keyboard navigation */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-md);
  z-index: var(--z-tooltip);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-accent);
  color: var(--color-text-primary);
  border-radius: var(--radius-md);
  text-decoration: none;
  font-weight: var(--font-weight-medium);
}

.skip-link:focus {
  top: var(--space-md);
}
