:root {
    --bg: #fffff8;
    --fg: #111111;
    --accent: #b13e3e;
    --grid-major: #ccc;
    --grid-minor: #eee;
    --vector-i: #b13e3e;
    --vector-j: #3e3eb1;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'et-book', 'Palatino', 'Palatino Linotype', 'Palatino LT STD', 'Book Antiqua', 'Georgia', serif;
    background-color: var(--bg);
    color: var(--fg);
    line-height: 1.6;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* Aligns content to the left */
    padding-left: 15%;
    /* Book-like left margin */
    padding-right: 5%;
}

main,
header {
    width: 100%;
    max-width: 650px;
    /* Readable measure */
    padding: 2rem;
}

h1,
h2,
h3 {
    font-weight: normal;
    margin-top: 2rem;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-style: italic;
}

.subtitle {
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, sans-serif;
    font-size: 1.2rem;
    color: #555;
    margin-bottom: 3rem;
    display: block;
}

ul {
    list-style: none;
    padding: 0;
}

li {
    margin-bottom: 1rem;
}

a {
    color: var(--fg);
    text-decoration: none;
    border-bottom: 1px solid var(--accent);
    transition: opacity 0.2s;
}

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

/* Visualization Components */
.visualization-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 2rem 0;
}

canvas {
    background-color: #fff;
    border: 1px solid #ddd;
    width: 100%;
    max-width: 600px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.controls {
    margin-top: 2rem;
    display: flex;
    gap: 2rem;
    align-items: center;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, sans-serif;
}

/* Buttons */
button {
    padding: 8px 16px;
    background: transparent;
    color: var(--fg);
    border: 1px solid var(--fg);
    font-family: inherit;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
}

button:hover {
    background: rgba(0, 0, 0, 0.05);
}

button.active,
button:active {
    background: var(--fg);
    color: var(--bg);
}

/* Specific Inputs */
.matrix-input {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    position: relative;
    padding: 10px;
}

.matrix-input::before,
.matrix-input::after {
    content: '';
    position: absolute;
    width: 10px;
    top: 0;
    bottom: 0;
    border: 2px solid #333;
}

.matrix-input::before {
    left: 0;
    border-right: none;
}

.matrix-input::after {
    right: 0;
    border-left: none;
}

input[type="number"] {
    width: 50px;
    padding: 5px;
    text-align: center;
    border: 1px solid #ccc;
    background: transparent;
    font-family: inherit;
    font-size: 1.1rem;
}

/* Text & Layout Elements */
.explanation {
    margin-top: 3rem;
    max-width: 65ch;
    /* Optimal reading width */
}

.sidenote {
    float: right;
    clear: right;
    margin-right: -45%;
    width: 40%;
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    line-height: 1.3;
    vertical-align: baseline;
    position: relative;
    color: #555;
}


header a.back-link {
    text-decoration: none;
    color: #888;
    font-size: 0.9rem;
    font-family: 'Gill Sans', sans-serif;
    border-bottom: none;
}


@media (max-width: 1000px) {
    body {
        padding-left: 5%;
        padding-right: 5%;
        align-items: center;
    }

    .sidenote {
        float: none;
        display: block;
        margin: 1rem 0;
        width: 100%;
        padding-left: 1rem;
        border-left: 2px solid #eee;
    }
}

/* Navigation */
.chapter-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid #eee;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, sans-serif;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #555;
    text-decoration: none;
    border-bottom: none;
    transition: color 0.2s;
}

.nav-link:hover {
    color: var(--accent);
}

.nav-link span {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #888;
}

.nav-link div {
    display: flex;
    flex-direction: column;
}

.nav-link strong {
    font-size: 1rem;
    font-weight: normal;
    color: var(--fg);
}