/*  adapated from https://exp.krj.st/typst.test/main.css   */
/*  For optimal mobile viewing, ensure HTML includes: <meta name="viewport" content="width=device-width, initial-scale=1">  */

/* GENERAL */
* {
    padding: 0;
    margin: 0;
    border: 0;
}

h1,
h2,
h3,
h4,
h5,
h6,
blockquote,
form,
label,
ul,
ol,
dl,
address {
    margin-bottom: 0.9rem;
}

*,
::before,
::after {
    box-sizing: border-box;
}

html {
    line-height: 1.45;
    -ms-text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
    word-break: break-word;
}

main {
    display: block;
}

a {
    -ms-touch-action: manipulation;
    touch-action: manipulation;
    transition: color .3s;
    color: var(--link-colour);
}

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

html {
    font-size: 18px;
    height: 100%;
    font-family: "Libertinus Serif", alegreya, palatino, serif;
}

@media screen and (min-width: 800px) {
    html {
        font-size: 19px;
    }
}

::selection {
    background-color: var(--selection-color);
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 1rem;
    margin: auto;
    padding: 2.5rem 0 5rem 0;
    -webkit-hyphens: auto;
    -ms-hyphens: auto;
    hyphens: auto;
}

/* Mobile responsive adjustments */
@media all and (max-width: 666px) {
    body {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
    
    /* Constrain content width on mobile */
    body > * {
        max-width: 100%;
        padding: 0 0.5rem;
    }
    
    /* Ensure figures don't overflow */
    figure {
        margin: 1rem -0.5rem;
        padding: 0 0.5rem;
    }
    
    /* Adjust headings for mobile */

    h1 {
        font-size: 2.2rem;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }

    h2 {
        font-size: 2.0rem;
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }
    
    h3 {
        font-size: 1.6rem;
    }
    
    /* Ensure all images and media scale properly */
    img, 
    video,
    iframe {
        max-width: 100%;
        height: auto;
    }
}

body > * {
    max-width: 44rem;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

/* Ensure all content respects container width */
.container {
    width: 100%;
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* Responsive adjustments for different screen sizes */
@media screen and (max-width: 768px) {
    body > * {
        max-width: 100%;
        padding: 0 1rem;
    }
}

@media screen and (max-width: 480px) {
    body > * {
        padding: 0 0.5rem;
    }
}

[type=checkbox] {
    vertical-align: middle;
}

/* /\* Custom styling for dark mode toggle checkbox *\/ */
/* #dark { */
/*     opacity: 0; */
/*     position: absolute; */
/*     width: 0; */
/*     height: 0; */
/* } */

/* #dark + label { */
/*     position: relative; */
/*     display: inline-block; */
/*     cursor: pointer; */
/*     padding-left: 2.5rem; */
/*     line-height: 1.4; */
/* } */

/* #dark + label::before { */
/*     content: '☀'; /\* Sun emoji for light mode *\/ */
/*     position: absolute; */
/*     left: 0; */
/*     top: 50%; */
/*     transform: translateY(-50%); */
/*     font-size: 1.2rem; */
/*     line-height: 1; */
/*     transition: content 0.3s ease; */
/* } */

/* #dark:checked + label::before { */
/*     content: '🌙'; /\* Moon emoji for dark mode *\/ */
/* } */
h1 {
    text-align: center;
    font-size: 3rem;
    line-height: 1.2;
    color: var(--heading-color);
    margin-top: 2rem;
}

h2 {
    text-align: center;
    font-size: 2.8rem;
    line-height: 1.2;
    color: var(--heading-color);
    margin-top: 2rem;
}

h3 {
    font-size: 2rem;
    font-weight: 300;
    color: var(--heading-color);
}

p {
    line-height: 1.5;
    margin-bottom: 0.75rem;
}

p em {
    font-style: italic;
}

hr {
    border: 1px solid var(--hr-color);
    text-align: center;
}

/* CUSTOM FORMATTING */
span.right {
    float: right;
}

div.center {
    text-align: center;
    margin: 1rem auto;
}

/* MATH */
sup {
    font-size: 75%;
    line-height: 0;
    vertical-align: baseline;
    position: relative;
    top: -0.45em;
    left: 0.05em;
}

span.math {
    display: inline-block;
    zoom: 1.2;
}

figure {
    margin-top: 1rem;
    margin-bottom: 1rem;
    zoom: 1.2;
    max-width: 100%;
    overflow-x: auto;
}

/* Additional constraints for responsive figures */
figure.typst {
    max-width: 100vw;
    overflow-x: auto;
    overflow-y: visible;
}

/* Ensure math figures are responsive */
figure.math {
    max-width: 100%;
    overflow-x: auto;
}

span > svg,
figure > svg {
    width: auto !important;
    height: auto !important;
    display: block;
    margin-left: auto;
    margin-right: auto;
    max-width: 100%;
    height: auto;
}

/* override color and ensure responsiveness */
svg use {
  fill: var(--text-color);
}

svg path {
    stroke: var(--text-color);
}

/* Ensure all SVG elements scale properly */
svg {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

/* Specific responsive handling for math SVGs */
span.math svg,
figure.math svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

/* Prevent overflow for any SVG containers */
svg, 
svg * {
    max-width: 100%;
    box-sizing: border-box;
}

/* FONTS */
@import url('https://fonts.googleapis.com/css2?family=Libertinus+Serif:ital,wght@0,400;0,700;1,400;1,700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Lexend:wght@100;200;300;400;500;600;700;800;900&display=swap');
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Rasa:wght@300&display=swap');

:root {
    --font-serif: "Libertinus Serif", alegreya, palatino, serif;
    --font-sans: "Lexend", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: "JetBrains Mono", "k.iosevka", "fira mono", monospace;
    --font-extra: "Rasa";
    
    /* Light mode colors (default) */
    --bg-color: #fcfcfc;
    --text-color: #5c6166;
    --heading-color: #222;
    --link-colour: #4cbf99;
    --link-hover-color: #F07171;
    --selection-color: rgba(255, 119, 51, 0.6);
    --hr-color: #84878b;
}

/* Dark mode colors */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0f0f17;
        --text-color: #cbccc6;
        --heading-color: #DDD;
        --link-colour: #95E6CB;
        --link-hover-color: #F07178;
        --selection-color: rgba(255, 119, 51, 0.6);
        --hr-color: #565a6e;
    }
}

/* #html.elem("input", attrs:(id: "dark", type: "checkbox") */)
body:has(#dark:checked) {
    --bg-color: #0f0f17;
    --text-color: #cbccc6;
    --heading-color: #DDD;
    --link-colour: #95E6CB;
    --link-hover-color: #F07178;
    --selection-color: rgba(255, 119, 51, 0.6);
    --hr-color: #565a6e;
}

/* Helper classes for specific font usage */
.serif { font-family: var(--font-serif); }
.sans-serif { font-family: var(--font-sans); }
.mono { font-family: var(--font-mono); }
.extra { font-family: var(--font-extra); }
