@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg-main: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: rgba(30, 41, 59, 0.7);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent: #38bdf8;
    --accent-hover: #7dd3fc;
    --border: rgba(255, 255, 255, 0.1);
    --glass: rgba(30, 41, 59, 0.4);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar */
aside {
    width: 300px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    height: 100vh;
    position: fixed;
    padding: 2rem;
    overflow-y: auto;
}

aside h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2rem;
    background: linear-gradient(to right, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

aside nav ul {
    list-style: none;
}

aside nav h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
}

aside nav a {
    color: var(--text-secondary);
    text-decoration: none;
    display: block;
    padding: 0.5rem 0;
    font-size: 0.9rem;
    transition: var(--transition);
}

aside nav a:hover {
    color: var(--accent);
    padding-left: 0.5rem;
}

aside nav a.active {
    color: var(--accent);
    font-weight: 600;
}

/* Main Content */
main {
    margin-left: 300px;
    flex: 1;
    padding: 4rem;
    max-width: 1200px;
}

header h1 {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1rem;
    letter-spacing: -0.02em;
}

header p {
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 3rem;
}

section {
    margin-bottom: 4rem;
}

h2 {
    font-size: 1.875rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.5rem;
}

h3 {
    font-size: 1.5rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
}

p {
    margin-bottom: 1.25rem;
    color: var(--text-primary);
    opacity: 0.9;
}

/* Content Links */
main a {
    color: #7dd3fc;
    text-decoration: none;
    border-bottom: 1px solid rgba(125, 211, 252, 0.3);
    transition: var(--transition);
}

main a:visited {
    color: #c4b5fd;
    border-bottom-color: rgba(196, 181, 253, 0.3);
}

main a:hover {
    color: #38bdf8;
    border-bottom-color: var(--accent);
}

/* Cards */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 2rem;
}

.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 2rem;
    text-decoration: none;
    color: inherit;
    transition: var(--transition);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border) !important;
}

.card:visited {
    color: inherit;
}

.card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.card h4 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    color: var(--accent);
}

.card p {
    font-size: 0.9rem;
    margin-bottom: 0;
}

/* Code blocks */
pre {
    background-color: #000;
    padding: 1.5rem;
    border-radius: 0.75rem;
    overflow-x: auto;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.9rem;
    color: #e2e8f0;
}

/* Alerts */
.alert {
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    margin: 1.5rem 0;
    border-left: 4px solid var(--accent);
    background: var(--glass);
}

.alert-tip {
    border-left-color: #10b981;
}

.alert-warning {
    border-left-color: #f59e0b;
}

@media (max-width: 1024px) {
    aside {
        width: 100%;
        height: auto;
        position: relative;
    }

    main {
        margin-left: 0;
        padding: 2rem;
    }
}

/* SVG Primitive Graphics */
.primitive-svg {
    max-width: 400px;
    height: auto;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
    margin: 1.5rem 0;
    --svg-stroke-color: #ffffff;
    --svg-fill-color: none;
    --svg-text-color: #ffffff;
}

/* Override SVG inline styles with CSS custom properties */
.primitive-svg path {
    stroke: var(--svg-stroke-color) !important;
    fill: none !important;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.primitive-svg line {
    stroke: var(--svg-stroke-color) !important;
    fill: none !important;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.primitive-svg rect,
.primitive-svg circle {
    stroke: var(--svg-stroke-color) !important;
    fill: var(--svg-fill-color) !important;
    stroke-width: 2;
}

.primitive-svg ellipse {
    fill: var(--svg-stroke-color) !important;
    stroke: none !important;
}

.primitive-svg text,
.primitive-svg text * {
    fill: var(--svg-text-color) !important;
    stroke: none !important;
    font-size: 14px;
    font-weight: 500;
}

/* Timing Diagram Images - Invert for dark theme */
img[src*=".jpeg"],
img[src*=".jpg"],
img[src*=".png"]:not(.primitive-svg),
img[src*="example.svg"] {
    filter: invert(1) hue-rotate(180deg);
}

/* Images followed by code blocks */
img.diagram-with-code {
    display: block;
    margin-bottom: 0;
    border-radius: 0.75rem 0.75rem 0 0;
    max-width: 100%;
    height: auto;
}

pre.connected-code {
    margin-top: 0;
    border-radius: 0 0 0.75rem 0.75rem;
    width: fit-content;
    max-width: 100%;
}

/* Code block above image (top of three-part block) */
pre.connected-code-top {
    margin-bottom: 0;
    border-radius: 0.75rem 0.75rem 0 0;
    width: fit-content;
    max-width: 100%;
}

/* Image in middle of three-part block */
img.diagram-middle {
    display: block;
    margin-top: 0;
    margin-bottom: 0;
    border-radius: 0;
    max-width: 100%;
    height: auto;
}

/* Specific sizing for Figure 33, 34, 39, 43, and 51 */
img[src*="Figure_33.png"],
img[src*="Figure_34.png"],
img[src*="Figure_39.png"],
img[src*="Figure_43.png"],
img[src*="Figure_51.png"] {
    width: 75%;
    max-width: 600px;
}

/* Connected code blocks below images */
img[src*="Figure_34.png"] + pre.connected-code,
img[src*="Figure_39.png"] + pre.connected-code,
img[src*="Figure_43.png"] + pre.connected-code,
img[src*="Figure_51.png"] + pre.connected-code {
    width: 75%;
    max-width: 600px;
    box-sizing: border-box;
}

/* Code block above Figure 34 (three-part block) */
pre.connected-code-top:has(+ img[src*="Figure_34.png"]) {
    width: 75%;
    max-width: 600px;
    box-sizing: border-box;
}