body {
    background-color: white;
    color: black;
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    font-size: calc(1vw + 1vh);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    height: 100%;
    overflow: hidden;
}
body.dark-mode {
    background-color: black;
    color: white;
}

nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 300;
    padding: calc(0.5em + env(safe-area-inset-top)) 0.5em 0.5em 0.5em;
}
body.dark-mode nav {
    background-color: black;
}

nav .left {
    display: flex;
    align-items: center;
}

nav .left .logo {
    display: block;
    width: clamp(20px, 1em, 40px);
    height: clamp(20px, 1em, 40px);
}
body.dark-mode nav .left .logo {
    filter: brightness(0) invert(1);
}

nav .left ul {
    list-style: none;
    margin: 0;
    margin-left: 2em;
    padding: 0;
    display: flex;
    gap: 2em;
    font-size: clamp(10px, 0.5em, 40px);
}
nav .left ul li:hover {
    cursor: pointer;
    text-shadow: 0 0 8px silver, 0 0 12px silver;
}

nav .left ul li a {
    color: black;
    text-decoration: none;
}
nav .left ul li a:visited {
    color: black;
}
body.dark-mode nav .left ul li a,
body.dark-mode nav .left ul li a:visited {
    color: white;
}

nav .right {
    display: flex;
    align-items: center;
    gap: 0.5em;
    color: red;
    font-size: clamp(15px, 0.65em, 40px);
    margin-left: auto;
    margin-right: 1em;
}
body.dark-mode nav .right {
    color: red;
}

nav .right .heart,
nav .right .heart:visited,
nav .right .heart:hover,
nav .right .heart:active {
    position: relative;
    text-decoration: none;
    color: red;
}
nav .right .heart::after {
    content: "Buy me a coffee!";
    position: absolute;
    top: 120%;
    right: 50%;
    transform: translateX(50%);
    background: white;
    color: black;
    font-size: 0.65em;
    padding: 0.3em 0.6em;
    border-radius: 6px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
body.dark-mode nav .right .heart::after {
    background: black;
    color: white;
    text-shadow: 0 0 8px rgb(255, 149, 149), 0 0 12px rgb(255, 149, 149);
}
@media (hover: hover) {
    nav .right .heart:hover,
    nav .right .heart:hover > * {
        cursor: pointer;
        text-shadow: 0 0 8px red, 0 0 12px red;
    }
    nav .right .heart:hover::after {
        opacity: 1;
    }
}
nav .right .heart.show-hint {
    text-shadow: 0 0 8px red, 0 0 12px red;
}
/* Allow JS to force-show the tooltip */
nav .right .heart.show-hint::after {
    opacity: 1;
}

nav .right button {
    border: none;
    background: transparent;
    cursor: pointer;
}
nav .right svg {
    width: clamp(20px, 1.4vw, 40px);
    height: clamp(20px, 1.4vw, 40px);
    color: black;
}
body.dark-mode nav .right svg {
    color: white;
}

#icon-sun {
    display: none;
}
body.dark-mode #icon-sun {
    display: inline;
}

#icon-moon {
    display: inline;
}
body.dark-mode #icon-moon {
    display: none;
}

.tip-container {
    display: flex;
    flex: 1;
    padding: 2rem;
    box-sizing: border-box;
    min-height: 0;
}

.toc-toggle {
    display: none;
    top: calc(5rem + env(safe-area-inset-top));
}

.toc {
    width: 33.33%;
    padding: calc(0.5rem + env(safe-area-inset-top)) 2rem 0.5rem 0;
    box-sizing: border-box;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
}
body.dark-mode .toc {
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.toc-intro {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    font-size: clamp(10px, 0.55em, 40px);
    font-weight: 200;
    line-height: 1.5;
    opacity: 1.0;
    margin-bottom: 1rem;
    margin-top: 0;
}

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

.toc-list li {
    padding: 0.4em 0;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.2s ease;
    font-size: clamp(10px, 0.55em, 40px);
    font-weight: 200;
}

.toc-list li:hover {
    opacity: 1;
}

.toc-list li.active {
    opacity: 1;
}

.article-area {
    position: relative;
    width: 66.66%;
    padding-left: 0rem;
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.article {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    padding: 0.1rem 2rem 0.1rem 2rem;
    margin-top: 0;
    transition: opacity 0.25s ease-out;
    pointer-events: none;
    font-size: clamp(10px, 0.8em, 45px);
    font-weight: 200;
    inset: 0;
    overflow-y: auto;
}

.article.active {
    opacity: 1;
    transition: opacity 0.25s ease-in;
    pointer-events: auto;
}

.article h1 {
    margin-top: 0;
    font-size: clamp(20px, 2em, 50px);
    font-weight: 300;
}

.code-area {
    background-color: whitesmoke;
    font-family: 'Courier New', Courier, monospace;
    font-size: clamp(10px, 0.8em, 40px);
    text-align: left;
    margin-left: 2%;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.4;
}
body.dark-mode .code-area {
    background-color: rgb(60, 60, 60);
    color: white;
}

.code-area-inline {
    background-color: whitesmoke;
    font-family: 'Courier New', Courier, monospace;
    font-size: clamp(10px, 0.8em, 40px);
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.4;
}
body.dark-mode .code-area-inline {
    background-color: rgb(60, 60, 60);
    color: white;
}

/* Hamburger menu for narrow screens */
.nav-toggle {
    display: none;
    position: relative;
    left: 10%;
    width: 16px;
    height: 12px;
    background: none;
    border: none;
    cursor: pointer;
    margin-left: 0.3em;
    color: black;
}
body.dark-mode .nav-toggle {
    color: white;
}

.nav-toggle span {
    position: absolute;
    width: 100%;
    height: 2px;
    background: currentColor;
    transition: transform 0.3s ease, top 0.3s ease; opacity: 0.3s ease;
}

.nav-toggle span:nth-child(1) {
    top: 0;
}

.nav-toggle span:nth-child(2) {
    top: 6px;
}

.nav-toggle span:nth-child(3) {
    top: 12px;
}

nav.open .nav-toggle span:nth-child(1) {
    top: 9px;
    transform: rotate(45deg);
}

nav.open .nav-toggle span:nth-child(2) {
    opacity: 0;
}

nav.open .nav-toggle span:nth-child(3) {
    top: 9px;
    transform: rotate(-45deg)
}

/* Narrow screen */
@media (max-width: 700px) {
    nav {
        flex-wrap: wrap;
        position: relative;
        z-index: 1;
    }

    nav .left .logo {
        width: 3.5em;
        height: 3.5em;
        margin-left: 1em;
    }

    .nav-toggle {
        display: block;
    }

    nav .left ul {
        flex-direction: column;
        gap: 1rem;
        width: 20%;
        max-height: 0;
        overflow: hidden;
        background: transparent;
        background-color: rgba(0, 0, 0, 0);
        border-radius: 0 0 0 0;
        backdrop-filter: blur(6px);
        padding: 1em 0;
        padding-left: 1.2rem;
        box-sizing: border-box;
        font-size: 1em;
        position: fixed;
        top: 3.8rem; /* sit right below nav */
        left: 0;
        margin-left: 7.5%;
        opacity: 0;
        transition: max-height 0.5s ease, opacity 0.5s ease;
    }

    /* Show menu when nav is toggled */
    nav.open .left ul {
        max-height: 300px;
        padding: 1rem 0 1rem 1.1rem;
        opacity: 1;
    }

    nav .right {
        font-size: 1.9em;
        margin: 0.3em;
    }

    nav .right svg {
        width: 7vw;
        height: 7vw;
    }

    .tip-container {
        padding: 0;
    }

    .toc-toggle {
        display: block;
        position: fixed;
        top: 5rem;
        left: 0;
        z-index: 1;
        background: transparent;
        border: none;
        font-size: 1.6rem;
        padding: 0.4em 0.6em;
        cursor: pointer;
        color: inherit;
    }

    .toc {
        position: fixed;
        top: 0;
        left: 0;
        width: 75%;
        max-width: 300px;
        height: 100vh;
        background: transparent;
        backdrop-filter: blur(6px);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 2;
        padding: 5rem 1.5rem 1.5rem;
        border-right: 1px solid rgba(0, 0, 0, 0.1);
    }

    body.dark-mode .toc {
        background: transparent;
        backdrop-filter: blur(6px);
        border-right: 1px solid rgba(255, 255, 255, 0.2);
    }

    .toc.open {
        transform: translateX(0);
    }

    .article-area {
        width: 100%;
        padding: 1.5rem 1.5rem 1.5rem 2.5rem;
    }

    .article-area.dim {
        opacity: 0.3;
        pointer-events: none;
    }
}

@media (hover: none) and (pointer: coarse) {
    .toc-toggle {
        top: 3rem;
    }

    nav .right .heart::after {
        content: "Double tap to Buy me a coffee!";
        right: 30%;
        transform: translateX(30%);
        font-size: 0.55em;
    }

    .article {
        font-size: clamp(7px, 0.6em, 40px);
    }

    .article h1 {
        font-size: clamp(20px, 2em, 50px);
    }

    .code-area {
        font-size: clamp(7px, 0.6em, 40px);
    }

    .code-area-inline {
        font-size: clamp(7px, 0.6em, 40px);
    }
}

@media (hover: none) and (pointer: coarse) and (max-width: 700px) {
    .article {
        font-size: clamp(10px, 1em, 40px);
    }

    .article h1 {
        font-size: clamp(18px, 1.8em, 50px);
    }

    .code-area {
        font-size: clamp(10px, 1em, 40px);
    }

    .code-area-inline {
        font-size: clamp(10px, 1em, 40px);
    }
}