/* =====================================================================
   CSEG8003 - Modelling and Simulation
   Shared stylesheet for the unit lecture notes (reading documents,
   not slide decks).  Design follows the LaTeX student-notes house
   style: navy headings, soft-blue definition boxes, green exam tips,
   amber cautions, plain example boxes, ruled tables.
   ===================================================================== */

:root {
    --primary: #1f3864;
    --primary-soft: #2f4f8f;
    --accent: #c00000;
    --ink: #16202f;
    --ink-soft: #40506a;
    --ink-faint: #6d7c93;
    --page: #ffffff;
    --bg: #eef1f6;
    --line: #d6dde9;
    --line-soft: #e7ecf3;
    --soft-bg: #eef2f8;
    --exam-green: #1b5e20;
    --exam-bg: #eaf3ea;
    --warn-line: #b35c00;
    --warn-bg: #fdf1e7;
    --code-bg: #f4f6fa;
    --shadow: 0 1px 2px rgba(20, 35, 60, .06), 0 14px 40px rgba(20, 35, 60, .09);
    --radius: 10px;
    --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
    --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

html[data-theme="dark"] {
    --primary: #8ab4ff;
    --primary-soft: #a9c8ff;
    --accent: #ff8f8f;
    --ink: #e8eefb;
    --ink-soft: #b9c6dc;
    --ink-faint: #8b9cb8;
    --page: #131c2b;
    --bg: #0a111c;
    --line: #2b3a53;
    --line-soft: #223047;
    --soft-bg: #1a2942;
    --exam-green: #6ee7a4;
    --exam-bg: #112a1c;
    --warn-line: #f0b45f;
    --warn-bg: #33240f;
    --code-bg: #17233a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 44px rgba(0, 0, 0, .5);
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: 84px;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 17px;
    line-height: 1.62;
    -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------- top bar ----- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 20px;
    background: var(--page);
    border-bottom: 1px solid var(--line);
    font-family: var(--sans);
    font-size: .82rem;
}

.topbar a {
    color: var(--ink-soft);
    text-decoration: none;
    font-weight: 600;
}

.topbar a:hover {
    color: var(--primary);
}

.topbar .code {
    font-weight: 800;
    color: var(--primary);
    letter-spacing: .04em;
}

.topbar .spacer {
    flex: 1;
}

.topbar button {
    font-family: var(--sans);
    font-size: .78rem;
    font-weight: 600;
    color: var(--ink-soft);
    background: var(--soft-bg);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 5px 13px;
    cursor: pointer;
}

.topbar button:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.readbar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: var(--accent);
    z-index: 60;
    transition: width .1s linear;
}

/* ------------------------------------------------------ layout ---- */
.wrap {
    max-width: 1240px;
    margin: 26px auto 60px;
    padding: 0 20px;
    display: grid;
    grid-template-columns: 268px minmax(0, 1fr);
    gap: 28px;
    align-items: start;
}

/* -------------------------------------------------------- toc ----- */
.toc {
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
    background: var(--page);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 14px;
    font-family: var(--sans);
    font-size: .82rem;
}

.toc h2 {
    margin: 0 0 10px;
    font-size: .72rem;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

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

.toc li {
    margin: 0;
}

.toc a {
    display: block;
    padding: 5px 9px;
    border-left: 2px solid transparent;
    color: var(--ink-soft);
    text-decoration: none;
    border-radius: 0 6px 6px 0;
}

.toc a:hover {
    background: var(--soft-bg);
    color: var(--primary);
}

.toc a.active {
    border-left-color: var(--accent);
    background: var(--soft-bg);
    color: var(--primary);
    font-weight: 700;
}

.toc a.sub {
    padding-left: 22px;
    font-size: .78rem;
}

/* ------------------------------------------------------- page ----- */
.page {
    background: var(--page);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 46px clamp(22px, 4vw, 62px) 60px;
}

/* -------------------------------------------------- title block --- */
.titleblock {
    text-align: center;
    padding-bottom: 26px;
    border-bottom: 2px solid var(--primary);
    margin-bottom: 32px;
}

.titleblock .school {
    font-family: var(--sans);
    font-size: .78rem;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.titleblock .course {
    font-family: var(--sans);
    font-weight: 800;
    color: var(--primary);
    margin-top: 8px;
    font-size: 1.02rem;
    letter-spacing: .02em;
}

.titleblock .unit {
    font-family: var(--sans);
    font-size: 2.15rem;
    font-weight: 800;
    color: var(--primary);
    margin: 16px 0 2px;
    line-height: 1.15;
}

.titleblock .unitno {
    font-family: var(--sans);
    font-size: .82rem;
    font-weight: 800;
    letter-spacing: .24em;
    text-transform: uppercase;
    color: var(--accent);
}

.titleblock .sub {
    color: var(--ink-soft);
    font-size: .96rem;
    margin-top: 10px;
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 16px;
    font-family: var(--sans);
}

.badges span {
    font-size: .74rem;
    font-weight: 700;
    color: var(--primary);
    background: var(--soft-bg);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 12px;
}

/* --------------------------------------------------- headings ----- */
h2.sec,
h3.sub,
h4.subsub {
    font-family: var(--sans);
    color: var(--primary);
    line-height: 1.25;
}

h2.sec {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 44px 0 12px;
    padding-top: 10px;
    border-top: 1px solid var(--line-soft);
}

h2.sec .n {
    color: var(--accent);
    margin-right: .45em;
}

h3.sub {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 26px 0 8px;
}

h4.subsub {
    font-size: 1rem;
    font-weight: 700;
    color: var(--ink);
    margin: 18px 0 6px;
}

p {
    margin: 0 0 12px;
}

ul,
ol {
    margin: 0 0 14px;
    padding-left: 1.5em;
}

li {
    margin: 4px 0;
}

li>ul,
li>ol {
    margin: 4px 0;
}

.kw {
    font-weight: 700;
    color: var(--primary);
}

em {
    color: inherit;
}

a {
    color: var(--primary-soft);
}

code {
    font-family: var(--mono);
    font-size: .86em;
    background: var(--code-bg);
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    padding: 1px 5px;
}

pre {
    font-family: var(--mono);
    font-size: .84rem;
    line-height: 1.5;
    background: var(--code-bg);
    border: 1px solid var(--line);
    border-left: 3px solid var(--primary);
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
    margin: 0 0 14px;
}

pre code {
    background: none;
    border: none;
    padding: 0;
    font-size: 1em;
}

/* ------------------------------------------------------ boxes ----- */
.box {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 16px 0 18px;
    overflow: hidden;
}

.box>.bt {
    font-family: var(--sans);
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 7px 14px;
    color: #fff;
}

.box>.bb {
    padding: 12px 14px 4px;
}

.box>.bb> :last-child {
    margin-bottom: 10px;
}

.def {
    border-color: var(--primary);
    background: var(--soft-bg);
}

.def>.bt {
    background: var(--primary);
}

.exam {
    border-color: var(--exam-green);
    background: var(--exam-bg);
}

.exam>.bt {
    background: var(--exam-green);
    color: #fff;
}

html[data-theme="dark"] .exam>.bt {
    color: #0a111c;
}

.caution {
    border-color: var(--warn-line);
    background: var(--warn-bg);
}

.caution>.bt {
    background: var(--warn-line);
}

html[data-theme="dark"] .caution>.bt {
    color: #0a111c;
}

.eg {
    border-color: rgba(31, 56, 100, .45);
    background: var(--page);
}

.eg>.bt {
    background: transparent;
    color: var(--primary);
    border-bottom: 1px solid var(--line);
}

/* --------------------------------------------------- equations ---- */
.eq {
    font-family: var(--serif);
    text-align: center;
    background: var(--code-bg);
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 11px 14px;
    margin: 14px 0;
    font-size: 1.04rem;
    overflow-x: auto;
}

.eq .tag {
    float: right;
    font-family: var(--sans);
    font-size: .74rem;
    color: var(--ink-faint);
}

var,
.mv {
    font-style: italic;
    font-family: var(--serif);
}

sub,
sup {
    font-size: .72em;
}

/* ------------------------------------------------------ tables ---- */
.tw {
    overflow-x: auto;
    margin: 0 0 18px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
    font-family: var(--sans);
    min-width: 520px;
}

caption {
    caption-side: top;
    text-align: left;
    font-family: var(--sans);
    font-size: .82rem;
    font-weight: 700;
    color: var(--ink-faint);
    padding: 0 0 7px;
}

thead th {
    text-align: left;
    color: var(--primary);
    border-top: 1.5px solid var(--ink-soft);
    border-bottom: 1px solid var(--ink-soft);
    padding: 8px 10px;
}

tbody td {
    border-bottom: 1px solid var(--line-soft);
    padding: 8px 10px;
    vertical-align: top;
}

tbody tr:last-child td {
    border-bottom: 1.5px solid var(--ink-soft);
}

tbody td:first-child {
    font-weight: 600;
    color: var(--ink);
}

/* ------------------------------------------------ figures/misc ---- */
figure {
    margin: 18px 0;
    text-align: center;
}

figure svg {
    max-width: 100%;
    height: auto;
}

figcaption {
    font-family: var(--sans);
    font-size: .8rem;
    color: var(--ink-faint);
    margin-top: 7px;
}

.callout {
    border-left: 3px solid var(--accent);
    background: var(--soft-bg);
    padding: 10px 14px;
    border-radius: 0 8px 8px 0;
    margin: 14px 0;
}

.qlist {
    counter-reset: q;
    list-style: none;
    padding-left: 0;
}

.qlist li {
    counter-increment: q;
    padding: 6px 0 6px 34px;
    position: relative;
    border-bottom: 1px dashed var(--line);
}

.qlist li::before {
    content: "Q" counter(q);
    position: absolute;
    left: 0;
    top: 6px;
    font-family: var(--sans);
    font-size: .74rem;
    font-weight: 800;
    color: var(--accent);
}

.marks {
    font-family: var(--sans);
    font-size: .72rem;
    font-weight: 700;
    color: var(--ink-faint);
}

.pager {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 42px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    font-family: var(--sans);
    font-size: .86rem;
}

.pager a {
    text-decoration: none;
    font-weight: 700;
    color: var(--primary);
    background: var(--soft-bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 14px;
}

.pager a:hover {
    border-color: var(--primary);
}

.docfoot {
    margin-top: 26px;
    font-family: var(--sans);
    font-size: .78rem;
    color: var(--ink-faint);
    text-align: center;
}

/* --------------------------------------------------- responsive --- */
@media (max-width: 1000px) {
    .wrap {
        grid-template-columns: minmax(0, 1fr);
    }

    .toc {
        position: static;
        max-height: none;
        order: -1;
    }
}

@media (max-width: 620px) {
    body {
        font-size: 16px;
    }

    .titleblock .unit {
        font-size: 1.6rem;
    }
}

/* ------------------------------------------------------- print ---- */
@media print {

    .topbar,
    .toc,
    .pager,
    .readbar {
        display: none !important;
    }

    body {
        background: #fff;
        font-size: 10.6pt;
    }

    .wrap {
        display: block;
        margin: 0;
        padding: 0;
        max-width: none;
    }

    .page {
        border: none;
        box-shadow: none;
        padding: 0;
    }

    h2.sec {
        break-after: avoid;
        page-break-after: avoid;
    }

    .box,
    table,
    figure,
    .eq {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
