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

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

/* Highlight target when anchor link clicked */
/* Only for links going down to the footnote, though (not the other way around) */
/* Links going down to the footnote always start with "footnote" */
[id^="footnote"]:not(:target) {
    transition: background-color 0.5s ease-out;
}

[id^="footnote"]:target {
    background-color: rgba(206, 121, 107, 0.3);
}

[data-theme="dark"] [id^="footnote"]:target {
    background-color: rgba(255, 255, 170, 0.3);
    /* yellow */
}

/* Color Variables */
:root {
    --bg-primary: #ECEBE4;
    --bg-secondary: #ECEBE4;
    --text-primary: #494331;
    --text-secondary: #7a6f65;
    --accent: #576490;
    --accent-hover: #6b7aa8;
    --border: #e8ded8;
}

[data-theme="dark"] {
    --bg-primary: #1a1614;
    --bg-secondary: #242220;
    --text-primary: #e8e0d8;
    --text-secondary: #aeaeae;
    --accent: #7b8bb8;
    --accent-hover: #bcc0c8;
    --border: #3a3634;
}

/* Color Variables */
:root {
    --bg-primary: #f4f3ec;
    --bg-secondary: #ECEBE4;
    --text-primary: #494331;
    --text-secondary: #7a6f65;
    --accent: #576490;
    --accent-hover: #6b7aa8;
    --border: #e8ded8;
}

[data-theme="dark"] {
    --bg-primary: #1a1614;
    --bg-secondary: #242220;
    --text-primary: #e8e0d8;
    --text-secondary: #aeaeae;
    --accent: #7b8bb8;
    --accent-hover: #bcc0c8;
    --border: #3a3634;
}

/* Base Styles */
body {
    font-family: "IBM Plex Mono", "Inconsolata", "Courier New", monospace;
    /*font-family: 'Courier New', monospace;*/
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-primary);
    transition: background 0.3s, color 0.3s;
}

/* Disable italics for IBM Plex Mono because I don't like how it looks */
/* The italics are from another font for now... shhhhh... */
em {
    font-family: "Inconsolata", "Courier New", monospace;
    font-style: italic;
    font-size: 1.1em;
    /*font-weight: 600;*/
    /*color: var(--accent);*/
}

a {
    color: var(--accent);
    transition: color 0.3s;
}

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

/* Container */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 40px 20px;
}

.container.narrow {
    max-width: 1000px;
}

/* Header & Navigation */
header {
    margin-bottom: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-left h1 {
    font-size: 2em;
    font-weight: normal;
    margin-bottom: 0;
}

.header-left h1 a {
    color: var(--text-primary);
    text-decoration: none;
}

.header-left .tagline {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-top: 5px;
}

nav {
    display: flex;
    gap: 40px;
    align-items: center;
}

nav a {
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1.1em;
    transition: color 0.3s;
    position: relative;
}

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

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

nav a.active::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
}

/* Theme Toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
}

[data-theme="dark"] .light-icon {
    display: none;
}

[data-theme="dark"] .dark-icon {
    display: block;
}

.light-icon {
    display: block;
}

.dark-icon {
    display: none;
}

/* Page Titles */
.page-title {
    font-size: 2.5em;
    font-weight: normal;
    margin-bottom: 40px;
    color: var(--text-primary);
}

/* Visible Markdown Syntax */
.markdown h2::before {
    content: '## ';
    color: var(--text-secondary);
    font-weight: normal;
    font-family: "Inconsolata", "Courier New", monospace;
    font-size: 1.05em;
}

.markdown h3::before {
    content: '### ';
    color: var(--text-secondary);
    font-weight: normal;
    font-family: "Inconsolata", "Courier New", monospace;
    font-size: 1.05em;
}

.markdown ul li::before {
    content: '* ';
    color: var(--text-secondary);
    position: absolute;
    left: 0;
    font-family: "Inconsolata", "Courier New", monospace;
    font-size: 1.05em;
}

.markdown ul {
    list-style: none;
    margin-left: 0;
    font-family: "Inconsolata", "Courier New", monospace;
    font-size: 1.05em;
}

.markdown ul li {
    padding-left: 20px;
    position: relative;
    margin-bottom: 8px;
    font-family: "Inconsolata", "Courier New", monospace;
    font-size: 1.05em;
}

.markdown em::before {
    content: '_';
    color: var(--text-secondary);
    font-family: "Inconsolata", "Courier New", monospace;
    font-size: 1.05em;
}

.markdown em::after {
    content: '_';
    color: var(--text-secondary);
    font-family: "Inconsolata", "Courier New", monospace;
    font-size: 1.05em;
}

.markdown strong::before {
    content: '**';
    color: var(--text-secondary);
    font-family: "Inconsolata", "Courier New", monospace;
    font-size: 1.05em;
}

.markdown strong::after {
    content: '**';
    color: var(--text-secondary);
    font-family: "Inconsolata", "Courier New", monospace;
    font-size: 1.05em;
}

/* Section Headers */
.section-header {
    font-size: 1.5em;
    font-weight: normal;
    margin: 50px 0 30px 0;
    color: var(--accent);
}

/* Blog Styles */
.blog-list {
    margin-top: 50px;
}

.blog-preview {
    margin-bottom: 60px;
    padding-bottom: 40px;
    border-bottom: 1px solid var(--border);
}

.blog-preview:last-child {
    border-bottom: none;
}

.blog-preview a {
    text-decoration: none;
    color: var(--text-primary);
    display: block;
    transition: color 0.3s;
}

.blog-preview a:hover .blog-title {
    color: var(--accent);
}

.blog-meta {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 12px;
}

.blog-title {
    font-size: 1.8em;
    font-weight: normal;
    margin-bottom: 12px;
    transition: color 0.3s;
}

.blog-excerpt {
    color: var(--text-primary);
    line-height: 1.7;
    margin-bottom: 15px;
}

.read-more {
    color: var(--accent);
    font-size: 0.95em;
}

.read-more:hover {
    color: var(--accent-hover);
}

.rss-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.95em;
    margin-bottom: 40px;
    display: inline-block;
}

.rss-link:hover {
    color: var(--accent-hover);
}

/* Form Styles */
form {
    max-width: 600px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-size: 0.95em;
}

input[type="text"],
input[type="email"],
textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'Courier New', monospace;
    font-size: 0.95em;
    margin-bottom: 20px;
    transition: border-color 0.3s;
}

input[type="text"]:focus,
input[type="email"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

textarea {
    resize: vertical;
    min-height: 150px;
}

input[type="submit"] {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px 30px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-size: 0.95em;
    transition: all 0.3s;
}

input[type="submit"]:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Responsive Design */
@media (max-width: 768px) {
    nav {
        gap: 20px;
    }

    .projects-grid {
        grid-template-columns: 1fr;
    }

    .blog-title {
        font-size: 1.5em;
    }

    .page-title {
        font-size: 2em;
    }
}

/* Ensure no margin or padding on sup and a */
sup {
    line-height: 1;
    margin: 0;
    padding: 0;
    vertical-align: super;
    /* Align sup text properly */
}

.footnote-link a {
    font-size: small;
    /* Adjust text size */
    margin: 0;
    padding: 0;
    vertical-align: baseline;
    /* Aligns footnote link with text */
}

.email [class^='ay3'] {
    display: none;
}

/* Sidenotes */

.sidenote-ref {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.8em;
    vertical-align: super;
    margin-left: 2px;
    cursor: pointer;
}

.sidenote-ref:hover {
    color: var(--accent-hover);
}

.sidenote {
    float: right;
    clear: right;
    margin-right: -220px;
    margin-left: -5px;
    width: 200px;
    font-size: 0.85em;
    line-height: 1.5;
    color: var(--text-secondary);
    padding: 5px;
    padding-left: 10px;
    border-left: 2px solid var(--border);
    transition: background-color 0.3s;
    scroll-margin-top: 200px;
}

.sidenote:target {
    background-color: rgba(206, 121, 107, 0.3);
    border-left-color: var(--text-secondary);
    animation: highlight-fade 2s forwards;
}

[data-theme="dark"] .sidenote:target {
    animation: highlight-fade-dark 2s forwards;
}

@keyframes highlight-fade {
    0% {
        background-color: rgba(206, 121, 107, 0.3);
        border-left-color: var(--text-secondary);
    }

    70% {
        background-color: rgba(206, 121, 107, 0.3);
        border-left-color: var(--text-secondary);
    }

    100% {
        background-color: transparent;
        border-left-color: var(--border);
    }
}

@keyframes highlight-fade-dark {
    0% {
        background-color: rgba(255, 255, 170, 0.3);
        border-left-color: var(--text-secondary);
    }

    70% {
        background-color: rgba(255, 255, 170, 0.3);
        border-left-color: var(--text-secondary);
    }

    100% {
        background-color: transparent;
        border-left-color: var(--border);
    }
}

@media (max-width: 1200px) {
    .sidenote {
        display: block;
        float: none;
        margin: 15px 0;
        margin-right: 0;
        width: 100%;
        padding: 10px 15px;
        border-left: 3px solid var(--accent);
        background: var(--bg-secondary);
    }
}

@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: flex-start;
    }

    nav {
        flex-wrap: wrap;
        gap: 15px;
        width: 100%;
    }

    .theme-controls {
        margin-top: 10px;
    }
}

.post-content {
    position: relative;
}

.theme-controls {
    display: flex;
    gap: 24px;
}


/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.skip-link {
    position: absolute;
    top: -60px;
    left: 0;
    background: var(--accent);
    color: var(--bg-primary);
    padding: 8px;
    z-index: 100;
}

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

a:focus,
button:focus,
.theme-toggle:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* High contrast mode  */
[data-contrast="high"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f0f0f0;
    --text-primary: #000000;
    --text-secondary: #000000;
    --accent: #0000ee;
    /* Classic blue link */
    --accent-hover: #551a8b;
    /* Visited purple */
    --border: #000000;
}

[data-contrast="high"][data-theme="dark"] {
    --bg-primary: #000000;
    --bg-secondary: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --accent: #00ffff;
    /* Bright cyan */
    --accent-hover: #ffff00;
    /* Yellow */
    --border: #ffffff;
}

.contrast-toggle {
    background: none;
    border: 2px solid var(--border);
    color: var(--text-primary);
    padding: 8px;
    cursor: pointer;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 0.9em;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    font-weight: bold;
}

.contrast-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.contrast-icon {
    width: 20px;
    height: 20px;
}

[data-contrast="high"] .contrast-toggle {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

/* Auto-detect system preference */
@media (prefers-contrast: high) {
    :root {
        --bg-primary: #ffffff;
        --bg-secondary: #f0f0f0;
        --text-primary: #000000;
        --text-secondary: #000000;
        --accent: #0000ee;
        --accent-hover: #551a8b;
        --border: #000000;
    }

    [data-theme="dark"] {
        --bg-primary: #000000;
        --bg-secondary: #1a1a1a;
        --text-primary: #ffffff;
        --text-secondary: #ffffff;
        --accent: #00ffff;
        --accent-hover: #ffff00;
        --border: #ffffff;
    }
}