/* Base styles - Reset, typography, and core layout foundations */

/* Global reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    background-color: var(--background);
    font-size: 16px;
    scroll-behavior: smooth;
}

/* T009: Enhanced body text with better readability */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    font-size: var(--text-base);
    background: var(--app-backdrop, var(--background));
    color: var(--color-text-primary);
    line-height: var(--leading-relaxed);
    transition: background 0.4s ease, color 0.2s ease;
    overflow-x: hidden;
    overflow-y: auto;
    position: relative;
    min-height: 100vh;
    padding-bottom: 2rem;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at 25% 20%, rgba(var(--primary-rgb), 0.08), transparent 45%), radial-gradient(circle at 80% 0%, rgba(var(--primary-rgb), 0.05), transparent 55%);
    opacity: 0.7;
    pointer-events: none;
    z-index: -2;
}

/* Typography - Enhanced hierarchy with design tokens (T008-T014) */
h1, h2, h3, h4, h5, h6 {
    color: var(--color-text-primary);
    margin-top: 0;
}

/* T008, T010: H1 with gradient text effect */
h1 {
    font-size: var(--text-4xl);
    font-weight: var(--font-bold);
    line-height: var(--leading-tight);
    letter-spacing: -0.025em;
    margin-bottom: 1.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* T008: H2-H6 hierarchy */
h2 {
    font-size: var(--text-3xl);
    font-weight: var(--font-bold);
    line-height: var(--leading-tight);
    margin-top: 2.5rem;
    margin-bottom: 1rem;
}

h3 {
    font-size: var(--text-2xl);
    font-weight: var(--font-semibold);
    line-height: var(--leading-snug);
    margin-top: 2rem;
    margin-bottom: 0.75rem;
}

h4 {
    font-size: var(--text-xl);
    font-weight: var(--font-semibold);
    line-height: var(--leading-normal);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

h5, h6 {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    line-height: var(--leading-normal);
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}

/* T009: Enhanced body text readability */
p {
    margin-bottom: 1.25rem;
    max-width: 65ch;
    color: var(--color-text-secondary);
    line-height: var(--leading-relaxed);
}

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

em, i {
    font-style: italic;
}

/* T011: Improved link styling with hover states */
a {
    color: var(--color-primary-600);
    text-decoration: none;
    transition: color var(--duration-fast) var(--ease-in-out-smooth);
}

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

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

/* Lists */
ul, ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

li {
    margin-bottom: 0.25rem;
}

/* T012: Polished code blocks and inline code */
code {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace;
    background: var(--color-bg-base);
    color: var(--color-text-primary);
    padding: 0.2rem 0.4rem;
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    border: 1px solid var(--color-border-subtle);
    font-weight: var(--font-medium);
}

pre {
    background: var(--color-bg-base);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    overflow-x: auto;
    margin-bottom: 1.5rem;
    border: 1px solid var(--color-border-subtle);
    box-shadow: var(--shadow-sm);
}

pre code {
    background: none;
    padding: 0;
    border: none;
    font-weight: var(--font-normal);
}

/* Form elements */
input, textarea, select, button {
    font-family: inherit;
    font-size: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s ease, background 0.2s ease;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.1);
}

button {
    cursor: pointer;
    background: var(--primary);
    color: white;
    border: none;
    font-weight: 500;
    transition: all 0.2s ease;
}

button:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
}

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

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Images */
img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-darker);
}

/* Selection styling */
::selection {
    background: rgba(var(--primary-rgb), 0.2);
    color: var(--text);
}

::-moz-selection {
    background: rgba(var(--primary-rgb), 0.2);
    color: var(--text);
}

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

/* Reduced motion support */
@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;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    a {
        text-decoration: underline;
    }

    button {
        border: 2px solid var(--text);
    }

    input, textarea, select {
        border-width: 2px;
    }
}
