:root {
    /* Color Palette */
    --color-primary: #60a5fa;
    --color-primary-dark: #3b82f6;
    --color-primary-darker: #2563eb;
    --color-primary-light: #93c5fd;
    --color-primary-lighter: #bfdbfe;
    --color-primary-lightest: #e0f2fe;

    --color-accent: #1e3a8a;
    --color-accent-dark: #1e40af;
    --color-accent-darker: #1d4ed8;

    --color-bg-darkest: #0f0f0f;
    --color-bg-darker: #0b1120;
    --color-bg-dark: #0c4a6e;
    --color-bg-card: #111827;
    --color-bg-card-alt: #1a1a2e;
    --color-bg-input: #0f172a;

    --color-border: #1e293b;
    --color-border-light: #1f2937;
    --color-border-lighter: #1f2a44;

    --color-text-primary: #e5e7eb;
    --color-text-secondary: #cbd5e1;
    --color-text-tertiary: #94a3b8;
    --color-text-muted: #64748b;
    --color-text-link: #e0e7ff;
    --color-text-light: #d1d5db;
    --color-text-faint: #9ca3af;

    /* Typography */
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-size-base: 1rem;
    --font-size-small: 0.85rem;
    --font-size-xsmall: 0.75rem;
    --font-size-large: 1.1rem;
    --font-size-xlarge: 1.3rem;

    --font-weight-normal: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    --font-weight-extrabold: 800;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-2xl: 2.5rem;
    --spacing-3xl: 3rem;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-xl: 12px;
    --radius-2xl: 14px;
    --radius-full: 999px;

    /* Shadows */
    --shadow-sm: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 20px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 25px rgba(96,165,250,0.18);
    --shadow-xl: 0 12px 30px rgba(96, 165, 250, 0.2);
    --shadow-2xl: 0 15px 35px rgba(0,0,0,0.35);
    --shadow-3xl: 0 18px 40px rgba(15,23,42,0.35);
    --shadow-card: 0 10px 30px rgba(15,23,42,0.45);

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;

    /* Container */
    --container-max-width: 1200px;
}

/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    line-height: 1.6;
    color: var(--color-text-primary);
    background: var(--color-bg-darkest);
}

/* Accessibility - Screen Reader Only */
.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;
}

/* Skip to Content Link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-primary);
    color: white;
    padding: 0.5rem 1rem;
    text-decoration: none;
    border-radius: 0 0 var(--radius-md) 0;
    font-weight: var(--font-weight-semibold);
    z-index: 1000;
}

.skip-link:focus {
    top: 0;
}

/* Focus Styles */
:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

/* Header */
header {
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-bg-card) 100%);
    color: white;
    padding: 1.5rem 0;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

/* Navigation */
nav {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 var(--spacing-xl);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    font-size: 1.4rem;
    font-weight: var(--font-weight-bold);
    letter-spacing: 0.5px;
    text-decoration: none;
    color: inherit;
}

.logo-icon {
    width: 80px;
    height: 80px;
    display: block;
    background: #ffffff;
    mask: url("../images/Star.png") center/contain no-repeat;
    -webkit-mask: url("../images/Star.png") center/contain no-repeat;
}

nav ul {
    list-style: none;
    display: flex;
    gap: 2.5rem;
}

nav a {
    text-decoration: none;
    color: var(--color-text-link);
    font-weight: var(--font-weight-normal);
    transition: color var(--transition-normal);
    font-size: 0.95rem;
}

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

nav a.active {
    color: var(--color-primary);
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    background: transparent;
    border: 0;
    color: var(--color-text-link);
    padding: var(--spacing-sm);
    border-radius: var(--radius-md);
    cursor: pointer;
}

.menu-toggle .hamburger {
    display: inline-block;
    width: 28px;
    height: 18px;
    position: relative;
}

.menu-toggle .hamburger span {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--color-text-link);
    border-radius: 1px;
    transition: transform var(--transition-fast), top var(--transition-fast), opacity var(--transition-fast);
}

.menu-toggle .hamburger span:nth-child(1) { top: 0; }
.menu-toggle .hamburger span:nth-child(2) { top: 8px; }
.menu-toggle .hamburger span:nth-child(3) { top: 16px; }

nav.open .hamburger span:nth-child(1) { top: 8px; transform: rotate(45deg); }
nav.open .hamburger span:nth-child(2) { opacity: 0; }
nav.open .hamburger span:nth-child(3) { top: 8px; transform: rotate(-45deg); }

/* Container */
.container {
    max-width: var(--container-max-width);
    margin: 0 auto;
    padding: 0 var(--spacing-xl);
}

/* Section */
section {
    padding: 5rem 0;
}

.section {
    padding: 2rem 0;
}

section h2 {
    font-size: 2.8rem;
    margin-bottom: 3rem;
    text-align: center;
    color: var(--color-text-link);
    font-weight: var(--font-weight-extrabold);
}

/* Breadcrumbs */
.breadcrumbs {
    max-width: var(--container-max-width);
    margin: 0 auto;
    color: var(--color-primary-light);
    padding: var(--spacing-sm) var(--spacing-md);
}

.breadcrumbs a {
    color: var(--color-primary-light);
    text-decoration: none;
}

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

/* Page Header */
.page-header {
    background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-bg-dark) 100%);
    color: white;
    padding: 5rem var(--spacing-xl) 4rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.page-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at 20% 50%, rgba(96, 165, 250, 0.1) 0%, transparent 50%);
    pointer-events: none;
}

.page-header-content {
    position: relative;
    z-index: 1;
    max-width: 800px;
    margin: 0 auto;
}

.page-header h1 {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    font-weight: var(--font-weight-extrabold);
    letter-spacing: -1px;
}

.page-header p {
    font-size: var(--font-size-large);
    color: var(--color-text-secondary);
    opacity: 0.95;
}

/* Footer */
footer {
    background: var(--color-bg-darkest);
    color: var(--color-primary-light);
    text-align: center;
    padding: var(--spacing-xl);
    border-top: 1px solid var(--color-border);
}

footer a {
    color: var(--color-primary);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Media Queries */
@media (max-width: 768px) {
    nav ul {
        gap: 0;
        position: absolute;
        left: 0;
        right: 0;
        top: 100%;
        background: var(--color-bg-card);
        border-top: 1px solid var(--color-border);
        flex-direction: column;
        padding: var(--spacing-sm) var(--spacing-md);
        display: none;
    }

    nav.open ul {
        display: flex;
    }

    .menu-toggle {
        display: inline-block;
    }

    .logo-icon {
        width: 56px;
        height: 56px;
    }

    .container {
        padding: 0 var(--spacing-md);
    }

    header {
        padding: var(--spacing-md) 0;
    }

    .page-header {
        padding: 3.5rem var(--spacing-md) 3rem;
    }

    .page-header h1 {
        font-size: 2rem;
    }

    section h2 {
        font-size: 2rem;
    }
}

@media (max-width: 480px) {
    .logo-icon {
        width: 48px;
        height: 48px;
    }

    .logo span {
        font-size: 1.1rem;
    }

    .container {
        padding: 0 0.75rem;
    }

    .page-header {
        padding: 3rem 0.75rem 2.5rem;
    }
}

/* Defensive rules to improve behavior for charts/graphs, figures and flex children on small screens
   - many layout issues come from containers with explicit min-widths or interactive canvases intercepting touch
   - these rules don't change layout on larger screens but make elements shrink/scroll correctly on mobile
*/

.chart-container,
.figure,
.image-card,
.responsive-wrap,
.table-responsive,
.embed-responsive,
.snapshot-item,
.reference-table {
    max-width: 100%;
    min-width: 0; /* allow flex children to shrink */
    box-sizing: border-box;
}

/* Make canvases and chart SVGs scale where possible - do NOT target UI icons (lucide) */
/* Only target SVG/canvas inside chart containers so small inline icons are preserved */
canvas,
.chart svg,
.chart canvas,
.chart,
.chart-wrapper svg,
.chart-wrapper canvas {
    max-width: 100% !important;
    height: auto !important;
    width: 100% !important;
    display: block;
}

/* Restore and protect small UI icons from global SVG rules (lucide and similar) */
svg.lucide,
svg[data-lucide],
i[data-lucide],
i[data-lucide] svg {
    max-width: none !important;
    width: 1em !important;
    height: 1em !important;
    display: inline-block !important;
}

/* Ensure touch and scroll still work for embedded or interactive charts */
.responsive-wrap, .table-responsive, .embed-responsive, .chart-wrapper {
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
    touch-action: auto; /* don't block default touch scroll gestures */
}

/* When chart libraries intercept gestures, let the container allow panning for overflow */
@media (max-width: 768px) {
    .chart-wrapper { overflow-x: auto; }
}

/* Lucide Icon Styling */
i[data-lucide] {
    display: inline-block;
    vertical-align: middle;
    width: 1em;
    height: 1em;
    stroke-width: 2;
}

/* Icon size variations */
.category-icon i[data-lucide] {
    width: 2rem;
    height: 2rem;
}

.med-category-title i[data-lucide] {
    width: 1.2rem;
    height: 1.2rem;
    margin-right: 0.5rem;
}

.clinical-pearl-icon i[data-lucide] {
    width: 1.2rem;
    height: 1.2rem;
}

.icon i[data-lucide] {
    width: 1.25rem;
    height: 1.25rem;
}

/* Ensure resource card title links do not show default visited/purple colors */
.resource-card h3 a {
    color: inherit;
    text-decoration: none;
    font-weight: inherit;
}

/* ------------------------------------------------------------------
   Responsive utilities
   - Provide small, well-tested wrappers and helper classes to ensure
     large images, tables, SVGs and embeds/iframes don't break layouts
     on narrow screens.
   - Use these wrappers in HTML (see README updates) where content
     would otherwise overflow or break the CSS layout at small widths.
   Examples:
     <div class="responsive-wrap"> <img src="..."> </div>
     <div class="table-responsive"> <table>...</table> </div>
     <div class="embed-responsive"> <iframe src="..."></iframe> </div>
   ------------------------------------------------------------------ */

.responsive-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
}

.responsive-wrap img,
.responsive-wrap svg,
.responsive-wrap video,
.responsive-wrap picture {
    max-width: 100%;
    height: auto;
    display: block;
}

.responsive-image,
img.responsive-image {
    max-width: 100%;
    height: auto;
    display: block;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

.table-responsive table {
    width: 100%;
    border-collapse: collapse;
    /* allow the table to define a wider minimum width but still be scrollable */
}

/* Responsive embed for video, iframes or interactive charts */
.embed-responsive {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* default 16:9 — override by adding class embed-4-3 etc. */
    overflow: hidden;
}

.embed-responsive > iframe,
.embed-responsive > object,
.embed-responsive > embed,
.embed-responsive > video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* utilities for alternate aspect ratios */
.embed-4-3 { padding-bottom: 75%; }
.embed-1-1 { padding-bottom: 100%; }

/* SVGs: ensure inline or embedded SVGs scale */
svg {
    max-width: 100%;
    height: auto;
}

@media (max-width: 480px) {
    /* Reduce default padding around responsive wrappers for very small screens */
    .responsive-wrap, .table-responsive, .embed-responsive { margin-left: 0; margin-right: 0; }
}

.resource-card h3 a:hover,
.resource-card h3 a:focus {
    color: var(--color-primary);
    text-decoration: underline;
}
