/* ===== FONT & RESET ===== */
@font-face {
    font-family: "Inter Local";
    src: url("/assets/fonts/Inter-Regular.woff2") format("woff2");
    font-weight: 400;
    font-style: normal;
    font-display: swap;
    unicode-range: U+0000-00FF, U+00A9, U+2011, U+2022, U+2192, U+2197;
}

@font-face {
    font-family: "Inter Local";
    src: url("/assets/fonts/Inter-Bold.woff2") format("woff2");
    font-weight: 700;
    font-style: normal;
    font-display: swap;
    unicode-range: U+0000-00FF, U+00A9, U+2011, U+2022, U+2192, U+2197;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    transition:
        background-color 0.2s ease,
        color 0.2s ease,
        border-color 0.2s ease,
        text-decoration-color 0.2s ease;
}

/* ===== CSS VARIABLES ===== */
:root {
    /* Typography */
    --h1: clamp(2.25rem, 4vw, 3rem);
    --h2: clamp(0.9375rem, 1.75vw, 1rem);
    --h3: clamp(1.1875rem, 2.5vw, 1.25rem);
    --h4: clamp(0.9375rem, 2vw, 1rem);
    --h5: calc(var(--body) * 1.1);
    --body: clamp(0.9375rem, 2vw, 1rem);

    /* Spacing */
    --space-xs: clamp(0.25rem, 1vw, 0.5rem);
    --space-s: clamp(0.7rem, 1.67vw, 1rem);
    --space: clamp(1rem, 4vw, 2rem);
    --space-l: clamp(1.5rem, 6vw, 3rem);
    --space-xl: clamp(3rem, 8vw, 6rem);
}

/* Theme Variables */
[data-theme="dark"] {
    --bubble: #739bd0;
    --bg: #111828;
    --header: #e2e8f0;
    --text: #a2afc1;
    --article: #a2afc110;
    --article-box: #0000001a;
}

[data-theme="light"] {
    --bubble: #485470;
    --bg: #e2e8f0;
    --header: #111828;
    --text: #2d323d;
    --article: #2d323d10;
    --article-box: #0000001a;
}

/* ===== BASE STYLES ===== */
::selection {
    background-color: var(--text);
    color: var(--bg);
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    font-family:
        "Inter Local",
        system-ui,
        -apple-system,
        "Segoe UI",
        sans-serif;
    font-size: var(--body);
    line-height: 1.6;
    color: var(--text);
    margin: var(--space-xl) auto;
    display: flex;
    flex-direction: column;
    gap: var(--space);
    max-width: clamp(320px, 90vw, 1280px);
    padding: 0 var(--space-l);
    position: relative;
}

/* ===== TYPOGRAPHY ===== */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 700;
    line-height: 1.2;
    color: var(--header);
    margin-bottom: var(--space-s);
}

h1 {
    font-size: var(--h1);
    font-weight: 700;
}

h2 {
    font-size: var(--h2);
    font-weight: 400;
}

h3 {
    font-size: var(--h3);
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    scroll-margin-top: var(--space);
    position: sticky;
    top: 0;
    padding: var(--space-s) 0;
    background-color: var(--bg);
    z-index: 10;
    margin-top: calc(var(--space-xl) * 1.5);
    margin-bottom: var(--space-xs);
}

h4 {
    font-size: var(--h4);
    font-weight: 700;
    margin-bottom: var(--space-xs);
}

h5 {
    font-size: var(--h5);
    font-weight: 700;
    margin-bottom: var(--space-xs);
}

b {
    color: var(--header);
}

p,
ul,
ol,
li {
    margin-bottom: 0;
}

ul,
ol {
    margin-left: 1em;
}

li > ul,
li > ol {
    margin-top: var(--space-s);
}

/* ===== LINKS ===== */
a {
    color: var(--header);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-color: var(--text);
}

/* ===== LAYOUT ===== */
aside {
    flex: 2;
    display: flex;
    flex-direction: column;
    margin-bottom: var(--space);
}

aside footer {
    margin-top: var(--space-s);
}

main {
    flex: 3;
    min-width: 0;
}

/* ===== HEADER ===== */
header nav {
    display: none;
}

header p {
    margin-bottom: var(--space-s);
    height: 3.4em;
    display: flex;
    align-items: flex-start;
}

/* ===== CURSOR ANIMATION ===== */
header p span[data-cursor="true"] {
    display: none;
    color: var(--header);
    animation: cursor-blink 0.8s infinite;
}

@keyframes cursor-blink {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
}

/* ===== ARTICLES ===== */
main section p {
    font-size: calc(var(--body) * 0.9);
}

main section p {
    margin-top: var(--space-s);
    margin-bottom: 0;
}

main section p:last-child {
    margin-top: var(--space);
}

main article {
    display: flex;
    flex-direction: column;
    margin-bottom: var(--space-s);
    align-items: flex-start;
    padding: calc(var(--space) / 2);
    margin-left: calc(-1 * var(--space) / 2);
    margin-right: calc(-1 * var(--space) / 2);
    border: 1px solid transparent;
    border-radius: 8px;
    transition:
        border-color 0.2s ease,
        background-color 0.2s ease,
        box-shadow 0.2s ease;
}

main article:not(:last-child) {
    position: relative;
    margin-bottom: var(--space);
}

main article:not(:last-child)::after {
    content: "";
    position: absolute;
    bottom: calc(-1 * var(--space) / 2);
    left: calc(var(--space) / 2);
    right: calc(var(--space) / 2);
    height: 2px;
    border-radius: 1px;
    background-color: var(--text);
    opacity: 0.2;
    display: block;
}

main article div {
    flex-shrink: 0;
}

main article div:first-child {
    text-align: left;
    padding-right: 0;
    padding-bottom: var(--space-xs);
}

main article div:first-child h4 {
    font-size: calc(var(--body) * 0.9);
    font-weight: 400;
    color: var(--text);
    opacity: 0.8;
    margin-bottom: var(--space-s);
}

main article div:last-child {
    padding-left: 0;
}

main article div:last-child h4 {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    color: var(--text);
    font-size: calc(var(--body) * 0.9);
    font-weight: 700;
    margin-bottom: var(--space-s);
    line-height: 1.3;
    text-align: left;
}

main article div:last-child h4:has(img) {
    font-size: var(--body);
    color: var(--header);
    margin-bottom: var(--space-xs);
}

main article div:last-child h4:has(img) img {
    width: 1.3em;
    height: 1.3em;
}

main article div:last-child p {
    margin-top: var(--space-s);
    margin-bottom: 0;
    font-size: calc(var(--body) * 0.9);
}

main article div:last-child li {
    margin-bottom: var(--space-s);
    font-size: calc(var(--body) * 0.9);
}

main article div:last-child li:last-child {
    margin-bottom: 0;
}

/* ===== ICONS ===== */
aside footer img,
h3 img {
    width: 100%;
    max-width: calc(var(--body) * 2);
    height: auto;
}

aside footer a {
    display: inline-block;
    transition:
        opacity 0.2s ease,
        transform 0.1s ease;
    position: relative;
}

aside footer a:not(:last-child) {
    margin-right: var(--space-s);
}

/* ===== FOOTER ===== */
main footer {
    font-size: 0.8em;
    margin-top: var(--space-xl);
    opacity: 0.7;
    text-align: center;
}

main footer p {
    margin-bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.2em;
    flex-wrap: wrap;
}

main footer span {
    display: block;
    visibility: hidden;
    margin-bottom: var(--space-xs);
}

body[data-js] main footer span {
    visibility: visible;
}

main footer img {
    width: 1em;
    height: 1em;
    vertical-align: middle;
    opacity: 1;
}

/* ===== THEME TOGGLE ===== */
[data-toggle="theme"] {
    padding: 0.6em;
    display: inline-block;
    font-weight: 400;
    color: inherit;
    background: transparent;
    border: none;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

[data-toggle="theme"]:hover,
[data-toggle="theme"]:focus {
    font-weight: 400;
    text-decoration: none;
    text-decoration-color: transparent;
    color: inherit;
    background-color: transparent;
    outline: none;
}

[data-toggle="theme"]:focus-visible {
    outline: 2px solid var(--header);
    outline-offset: 2px;
}

[data-toggle="theme"] img {
    transition: transform 0.3s ease;
    width: 1.3em;
    height: 1.3em;
}

[data-theme="dark"] [data-toggle="theme"] img {
    filter: invert(1) brightness(1.2) hue-rotate(200deg);
}

[data-theme="light"] [data-toggle="theme"] img {
    filter: brightness(0.7);
}

/* ===== BACKGROUND ANIMATIONS ===== */
body::before,
body::after {
    content: "";
    position: absolute;
    filter: blur(75px);
    z-index: -1;
    pointer-events: none;
    opacity: 0.08;
    background-color: var(--bubble);
    border-radius: 50% 40% 60% 30%;
    animation: float ease-in-out infinite;
}

body::before {
    width: clamp(200px, 25vw, 400px);
    height: clamp(200px, 25vw, 400px);
    top: clamp(1rem, 5vh, 3rem);
    left: clamp(1rem, 5vw, 3rem);
    animation-duration: 20s;
}

body::after {
    width: clamp(150px, 20vw, 300px);
    height: clamp(150px, 20vw, 300px);
    bottom: clamp(1rem, 5vh, 3rem);
    right: clamp(1rem, 5vw, 3rem);
    animation-duration: 15s;
    animation-delay: -7s;
}

@keyframes float {
    0%,
    100% {
        transform: translate(0, 0) rotate(0deg);
    }
    25% {
        transform: translate(clamp(20px, 4vw, 60px), clamp(-30px, -6vw, -80px))
            rotate(3deg);
    }
    50% {
        transform: translate(clamp(-15px, -3vw, -40px), clamp(25px, 5vw, 70px))
            rotate(-2deg);
    }
    75% {
        transform: translate(
                clamp(-25px, -5vw, -50px),
                clamp(-15px, -3vw, -30px)
            )
            rotate(1.5deg);
    }
}

/* ===== DESKTOP STYLES ===== */
@media (min-width: 1024px) {
    body {
        flex-direction: row;
    }

    h3 {
        margin-top: var(--space-xl);
    }

    /* Links */
    a:hover {
        text-decoration-color: var(--header);
    }

    /* Sidebar */
    aside {
        position: sticky;
        top: var(--space-xl);
        max-height: calc(100vh - 2 * var(--space-xl));
        min-height: calc(100vh - 2 * var(--space-xl));
        margin-bottom: 0;
        overflow-y: auto;
        justify-content: space-between;
    }

    aside footer {
        margin-top: auto;
    }

    /* Navigation */
    aside header nav {
        position: static;
        background-color: transparent;
        padding: 0;
        margin-bottom: var(--space);
        display: flex;
        flex-direction: column;
        margin-top: var(--space-l);
        width: fit-content;
        opacity: 1;
        transition: opacity 0.3s ease;
    }

    aside header nav a {
        color: var(--text);
        text-decoration: none;
        font-size: calc(var(--body) * 0.8);
        letter-spacing: 1.5px;
        font-weight: 700;
        padding: var(--space-xs) 0;
        position: relative;
        transition: all 0.2s ease;
        padding-left: calc(2 * (var(--space-s) + var(--space-xs)));
        opacity: 0.7;
    }

    aside header nav a::before {
        content: "";
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: calc(2 * var(--space-s));
        height: 2px;
        background-color: var(--text);
        transition: all 0.2s ease;
        border-radius: 1px;
    }

    aside header nav a:hover {
        padding-left: calc(2 * var(--space));
        color: var(--header);
    }

    aside header nav a:hover::before {
        background-color: var(--header);
        width: calc(2 * var(--space-s) * 1.5);
    }

    aside header nav a[data-active="true"] {
        padding-left: calc(2 * (var(--space) + var(--space-xs)));
        opacity: 1;
    }

    aside header nav a[data-active="true"]::before {
        background-color: var(--header);
        width: calc(2 * var(--space-s) * 2);
    }

    /* Footer interactions */
    body:has(aside footer a:hover) aside footer a:not(:hover) {
        opacity: 0.4;
    }

    aside footer a:hover {
        transform: translateY(-8px);
    }

    aside footer a::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        transition: height 0.1s ease;
    }

    aside footer a:hover::before {
        height: calc(100% + 8px);
    }

    aside footer a::after {
        content: attr(data-tooltip);
        position: absolute;
        bottom: calc(100% + 5px);
        left: 50%;
        transform: translateX(-50%);
        color: var(--text);
        font-size: 0.8rem;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        z-index: 20;
    }

    aside footer a:hover::after {
        opacity: 1;
    }

    /* Main content */
    main h3 {
        background-color: transparent;
        position: static;
        padding: 0;
        z-index: auto;
    }

    main footer {
        margin-top: 25vw;
    }

    /* Articles */
    main article {
        flex-direction: row;
        margin-bottom: var(--space);
        transition:
            border-color 0.2s ease,
            background-color 0.2s ease,
            box-shadow 0.2s ease,
            opacity 0.3s ease;
    }

    main article:hover {
        background-color: var(--article);
        box-shadow: 0 4px 12px var(--article-box);
    }

    main article:not(:last-child) {
        margin-bottom: var(--space-s);
    }

    main article:not(:last-child)::after {
        display: none;
    }

    main article div:first-child {
        flex: 1;
        text-align: right;
        padding-right: var(--space-s);
        padding-bottom: 0;
    }

    main article div:last-child {
        flex: 3;
        padding-left: var(--space-s);
    }

    section:has(article:hover) article:not(:hover) {
        opacity: 0.5;
    }

    /* Theme toggle */
    [data-toggle="theme"]:hover img {
        transform: rotate(180deg);
    }

    /* Background animations */
    body::before,
    body::after {
        position: fixed;
    }

    /* Short screen optimization */
    @media (max-height: 700px) {
        aside header nav {
            opacity: 0;
            max-height: 0;
            margin-top: 0;
            margin-bottom: 0;
            overflow: hidden;
            transition:
                opacity 0.3s ease,
                max-height 0.3s ease,
                margin 0.3s ease;
        }
    }
}
