/* =========================
   Root Variables (Light)
   ========================= */

:root {
    --button-height: 2.4em;
    --code-bg: #f3f3f3;
    --color-bg: hsla(165, 0%, 100%, 1);
    --color-link: rgb(10, 0, 0);
    --color-link-hover: #fff;
    --color-link-hover-bg: #000;
    --color-text: #010635;
    --grad-1: hsla(256, 82%, 77%, 0.35);
    --grad-2: hsla(197, 77%, 74%, 0.35);
    --grad-3: hsla(147, 77%, 74%, 0.35);
    --grad-4: hsla(88, 77%, 74%, 0.35);
    --grad-5: hsla(23, 77%, 74%, 0.35);
    --grad-6: hsla(234, 100%, 50%, 0.35);
    --link-color: #aaaaaa;
    --p-font: monospace;
    --p-font-size: 12pt;
    --text-color: #000000;
}

/* =========================
   Dark Mode
   ========================= */

/* CSS fallback for first-time visitors before JS has a chance to run.
   Once the user has a stored preference, the JS class takes over. */
@media (prefers-color-scheme: dark) {
    :root:not(.dark-mode):not(.light-mode) {
        --code-bg: #1e1e1e;
        --color-bg: rgb(10, 0, 0);
        --color-link: #ffdbac;
        --color-link-hover: #000000;
        --color-link-hover-bg: #ffffff;
        --color-text: #e6e6e6;
        --grad-1: hsla(256, 60%, 40%, 0.25);
        --grad-2: hsla(197, 60%, 38%, 0.25);
        --grad-3: hsla(147, 55%, 35%, 0.25);
        --grad-4: hsla(88, 55%, 32%, 0.25);
        --grad-5: hsla(23, 60%, 38%, 0.25);
        --grad-6: hsla(234, 80%, 45%, 0.25);
        --link-color: #8ab4f8;
        --text-color: #e6e6e6;
    }
}

html.dark-mode,
body.dark-mode {
    --code-bg: #1e1e1e;
    --color-bg: rgb(10, 0, 0);
    --color-link: #ffdbac;
    --color-link-hover: #000000;
    --color-link-hover-bg: #ffffff;
    --color-text: #e6e6e6;
    /* Dark-mode gradient colors
       Lower lightness + slightly lower opacity
       to avoid glowing neon effect */
    --grad-1: hsla(256, 60%, 40%, 0.25);
    --grad-2: hsla(197, 60%, 38%, 0.25);
    --grad-3: hsla(147, 55%, 35%, 0.25);
    --grad-4: hsla(88, 55%, 32%, 0.25);
    --grad-5: hsla(23, 60%, 38%, 0.25);
    --grad-6: hsla(234, 80%, 45%, 0.25);
    --link-color: #8ab4f8;
    --text-color: #e6e6e6;
}

/* =========================
   Animations
   ========================= */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

* {
    font-family: var(--p-font);
    font-size: var(--p-font-size);
    transition:
        background-color 0.3s ease,
        color 0.3s ease,
        border-color 0.3s ease,
        fill 0.3s ease;
}

html,
body {
    background-attachment: fixed;
    background-blend-mode: overlay, normal, normal, normal, normal, normal, normal;
    background-color: var(--color-bg);
    background-image:
        url("data:image/svg+xml,%3Csvg viewBox='0 0 962 962' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E"),
        radial-gradient(circle at 0% 0%, var(--grad-1) 3%, transparent 40%),
        radial-gradient(circle at 20% 0%, var(--grad-2) 3%, transparent 40%),
        radial-gradient(circle at 40% 0%, var(--grad-3) 3%, transparent 40%),
        radial-gradient(circle at 60% 0%, var(--grad-4) 3%, transparent 40%),
        radial-gradient(circle at 80% 0%, var(--grad-5) 3%, transparent 40%),
        radial-gradient(circle at 100% 0%, var(--grad-6) 3%, transparent 40%);
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    margin: 0;
    min-height: 100vh;
}

body {
    color: var(--color-text);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 100vh;
}

/* =========================
   Layout
   ========================= */

.main-layout {
    box-sizing: border-box;
    display: flex;
    flex: 1 0 auto;
    flex-direction: row;
    justify-content: center;
    margin: 0 auto;
    width: 100%;
}

.main-content {
    animation: fadeIn 0.6s ease-in;
    box-sizing: border-box;
    flex: 1 1 0%;
    margin-left: auto;
    margin-right: auto;
    max-width: 800px;
    min-width: 0;
    padding: 1em;
    width: 100%;
}

.sidebar-left,
.sidebar-right {
    animation: fadeIn 0.6s ease-in;
    background: none;
    box-sizing: border-box;
    flex: 0 0 280px;
    max-width: 280px;
    min-width: 120px;
    padding: 1em;
}

/* =========================
   TOC Sidebar
   ========================= */

.toc {
    padding: 0.5em 0;
    position: sticky;
    top: 1em;
}

.toc-title {
    font-weight: 700;
    margin-bottom: 0.5em;
}

.toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc-item {
    margin: 0.35em 0;
}

.toc-item a {
    color: var(--color-link);
    text-decoration: none;
}

.toc-item a:hover {
    background-color: var(--color-link);
    color: var(--color-bg);
}

.toc-level-2 { margin-left: 0.5em; }
.toc-level-3 { margin-left: 1em; }
.toc-level-4 { margin-left: 1.5em; }
.toc-level-5 { margin-left: 2em; }
.toc-level-6 { margin-left: 2.5em; }

main {
    box-sizing: border-box;
    max-width: 800px;
    width: 100%;
}

header {
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    padding: 20px 0;
    width: 100%;
}

.header-inner {
    align-items: center;
    box-sizing: border-box;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    max-width: 800px;
    padding: 0 1em;
    width: 100%;
}

.header-actions {
    align-items: center;
    display: flex;
    gap: 0.25em;
}

footer {
    margin-left: auto;
    margin-right: auto;
    max-width: 800px;
    padding: 20px;
    text-align: center;
}

/* =========================
   Navigation
   ========================= */

.nav-links {
    display: flex;
    gap: 0.75em;
}

.nav-links a {
    background: transparent;
    border: 2px solid var(--color-link);
    border-radius: 0;
    box-sizing: border-box;
    color: var(--color-link);
    display: inline-block;
    height: var(--button-height);
    line-height: var(--button-height);
    opacity: 1;
    padding: 0 1.2em;
    text-decoration: none;
    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        transform 0.05s ease;
}

.nav-links a:hover {
    background-color: var(--color-link);
    color: var(--color-bg);
}

.nav-links a:active {
    transform: scale(0.96);
}

.github-link {
    align-items: center;
    border: 2px solid var(--color-link);
    box-sizing: border-box;
    color: var(--color-link);
    opacity: 1;
    display: inline-flex;
    height: var(--button-height);
    justify-content: center;
    width: var(--button-height);
}

.github-link:hover {
    background-color: var(--color-link);
    color: var(--color-bg);
}

.github-link svg {
    display: block;
    fill: currentColor;
    height: 1.5em;
    width: 1.5em;
}

/* =========================
   Buttons
   ========================= */

button,
.button {
    appearance: none;
    background: transparent;
    border: 2px solid var(--color-link);
    border-radius: 0;
    box-sizing: border-box;
    color: var(--color-link);
    cursor: pointer;
    display: inline-block;
    font-family: var(--p-font);
    font-size: var(--p-font-size);
    height: var(--button-height);
    line-height: var(--button-height);
    padding: 0 1.2em;
    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        transform 0.05s ease,
        opacity 0.15s ease;
}

button:hover,
.button:hover {
    background-color: var(--color-link);
    color: var(--color-bg);
}

button:active,
.button:active {
    transform: scale(0.96);
}

button:focus-visible,
.button:focus-visible {
    outline: 2px solid var(--color-text);
    outline-offset: 2px;
}

button:disabled,
.button:disabled {
    cursor: not-allowed;
    opacity: 0.4;
    transform: none;
}

.button-ghost {
    background: transparent;
    border: 1px solid var(--color-text);
    color: var(--color-text);
}

.button-ghost:hover {
    background-color: var(--color-text);
    color: var(--color-bg);
}

/* =========================
   Typography & Elements
   ========================= */

h1 {
    border-bottom: 2px solid var(--color-link);
    font-size: 1.8em;
    letter-spacing: 0.02em;
    margin-bottom: 0.6em;
    margin-top: 1.2em;
    padding-bottom: 0.3em;
}

h2 {
    border-bottom: 1px solid var(--color-link);
    font-size: 1.5em;
    margin-bottom: 0.55em;
    margin-top: 1.1em;
    padding-bottom: 0.25em;
}

h3 {
    font-size: 1.3em;
    margin-bottom: 0.5em;
    margin-top: 1em;
}

a {
    color: var(--color-link);
    opacity: 0.7;
    outline: none;
    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        transform 0.05s ease;
}

a:hover {
    background-color: var(--color-link);
    color: var(--color-bg);
    opacity: 1;
}

code {
    background: var(--code-bg);
    padding: 0.1rem 0.25rem;
}

/* =========================
   Misc / Utilities
   ========================= */

.about_pic {
    border: 2px solid var(--color-link);
    border-radius: 8px;
    filter: url(#profile_filter);
    padding: 2px;
    width: 200px;
}

svg {
    height: 0;
    position: absolute;
    width: 0;
}

/* =========================
   Markdown
   =========================*/

.md-doc img {
    border: 2px solid var(--color-link);
    box-sizing: border-box;
    display: block;
    margin: 1.5em auto;
    max-height: 256px;
    max-width: 600px;
    padding: 0.35em;
    width: auto;
}

.md-doc .md-figure {
    margin: 1.5em auto;
    text-align: center;
}

.md-doc .md-figure img {
    margin: 0 auto;
}

.md-doc .md-figure figcaption {
    font-size: 0.95em;
    margin-top: 0.5em;
    opacity: 0.8;
}

.md-doc h1 {
    border-bottom: 2px solid var(--color-link);
    font-size: 1.8em;
    letter-spacing: 0.02em;
    margin-bottom: 0.6em;
    margin-top: 1.2em;
    padding-bottom: 0.3em;
}

.md-doc h2 {
    border-bottom: 1px solid var(--color-link);
    font-size: 1.5em;
    margin-bottom: 0.55em;
    margin-top: 1.1em;
    padding-bottom: 0.25em;
}

.md-doc h3 {
    font-size: 1.3em;
    margin-bottom: 0.5em;
    margin-top: 1em;
}

.md-doc h4 {
    font-size: 1.15em;
    margin-bottom: 0.45em;
    margin-top: 0.9em;
}

.md-doc h5 {
    font-size: 1.05em;
    margin-bottom: 0.4em;
    margin-top: 0.8em;
}

.md-doc h6 {
    font-size: 1em;
    margin-bottom: 0.35em;
    margin-top: 0.7em;
    opacity: 0.8;
}

/* Block quotes */
.md-doc blockquote {
    background: var(--code-bg);
    border-left: 3px solid var(--color-link);
    margin: 1em 0;
    opacity: 0.9;
    padding: 0.75em 1em;
}

/* Lists */
.md-doc ul,
.md-doc ol {
    margin: 0.75em 0 0.75em 1.5em;
    padding: 0;
}

.md-doc li {
    margin: 0.3em 0;
}

/* Task list */
.md-doc input[type="checkbox"] {
    margin-right: 0.4em;
}

/* Definition Lists */
.md-doc dt {
    margin-top: 0.8em;
}

.md-doc dd {
    margin-left: 1.5em;
    opacity: 0.85;
}

/* Horisontal rule */
.md-doc hr {
    border: none;
    border-top: 2px solid var(--color-link);
    margin: 2em 0;
    opacity: 0.4;
}

/* Fenced Blocks */
.md-doc pre {
    background: var(--code-bg);
    overflow-x: auto;
    padding: 1em;
}

.md-doc pre code {
    background: none;
    padding: 0;
}

/* Tables */
.md-doc table {
    border-collapse: collapse;
    margin: 1em 0;
    width: 100%;
}

.md-doc th,
.md-doc td {
    border: 1px solid var(--color-link);
    padding: 0.5em;
    text-align: left;
}

.md-doc th {
    background: var(--code-bg);
}



/* =========================
   Media Queries
   ========================= */

@media (max-width: 1000px) {
    .sidebar-right {
        display: none;
    }

    .sidebar-left {
        display: none;
    }

    .main-layout {
        max-width: 100vw;
    }
}