:root {
    --main-grey: #c1c7c8;
    --dark-grey: #87888e;
    --title-dark-blue: #000080;
    --title-light-blue: #1084d0;

    --max-page-width: 1500px;
}

@font-face {
    font-family: "Microsoft Sans Serif";
    src: url("MicrosoftSansSerif.woff2") format("woff2"),
         url("MicrosoftSansSerif.woff") format("woff");
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

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

body, html {
    margin: 0;
    padding: 0;
    font-family: Tahoma, Geneva, Verdana, Arial, sans-serif;
    background-color: var(--main-grey);
}

body {
    display: grid;
    grid-template: 
        "header header header" auto
        "left main right" 1fr
        "footer footer footer" auto / auto 1fr auto;
    max-height: 100dvh;
    overscroll-behavior: none;
}

/*header, footer {
    position: sticky;
    z-index: 1;
    background-color: var(--main-grey);
    width: 100%;
}*/

header {
/*    top: 0;*/
    grid-area: header;
    position: sticky;
    z-index: 1;
}

main {
    grid-area: main;
    overflow: scroll;
    overscroll-behavior: none;
}

footer {
/*    bottom: 0;*/
    grid-area: footer;
    position: sticky;
    z-index: 1;
}

hgroup {
    text-align: center;
}

figure {
    margin: 2rem auto;
}

figure img {
    display: block;
    margin: 0.5rem auto;
    max-width: 100%;
    object-fit: contain;
    height: auto;
}

figure figcaption {
    text-align: center;
    font-style: italic;
    font-size: 0.9rem;
}

code, pre {
    background-color: #eeeeee;
}

code {
    font-family: Courier, monospace;
    border-radius: 0.2rem;
    padding: 0 0.2rem;
    white-space: nowrap;
}

pre {
    border-radius: 0.4rem;
    padding: 0.4rem;
    white-space: pre-wrap;
    margin: 2rem 0;
}

u {
    text-decoration: underline;
}

aside {
    background-color: #FFFFCC;
    padding: 0.5rem 1rem 0.5rem calc(1rem + 32px);
    border-radius: 0.4rem;
    border: 1px solid black;
    background-repeat: no-repeat;
    background-position: 0.5rem 0.5rem;
    min-height: calc(1rem + 32px);
    display: flex;
    align-items: center;
    margin: 2rem;
}

@media (max-width: 632px) {
    aside {
        margin: 2rem 0;
    }
}

aside.info {
    background-image: image-set(
        url(/img/info.png) 1x,
        url(/img/info-2x.png) 2x
    );
}

aside.prompt {
    background-image: image-set(
        url(/img/prompt.png) 1x,
        url(/img/prompt-2x.png) 2x
    );
}

aside.warning {
    background-image: image-set(
        url(/img/warning.png) 1x,
        url(/img/warning-2x.png) 2x
    );
}

aside.error {
    background-image: image-set(
        url(/img/error.png) 1x,
        url(/img/error-2x.png) 2x
    );
}

aside p {
    margin: 0;
}



#title-bar {
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0.25rem;
    font-family: "Microsoft Sans Serif";
    font-size: 0.75rem;
    gap: 0.25rem;
    width: 100%;
    background-color: #0000a1;
    /* background: linear-gradient(to right, var(--title-dark-blue), var(--title-light-blue)); */
    border-bottom: 1px solid var(--main-grey);
}

#title-bar img {
    display: block;
}

#title-bar .title {
    text-shadow: 0.5px 0px white,
                 1.5px 0px white;
    color: transparent;
    letter-spacing: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}



.window-controls {
    margin-left: auto;
    display: flex;
}

.window-controls .close {
    margin-left: 0.25em;
}



.grip {
    display: flex;
    align-items: center;
    align-self: stretch;
}

.grip span {
    height: calc(100% - 2px);
    width: 3px;
    border-top: 1px solid white;
    border-bottom: 1px solid var(--dark-grey);
    border-left: 1px solid white;
    border-right: 1px solid var(--dark-grey);
}

.separator {
    height: calc(100% - 2px);
    width: 2px;
    border-left: 1px solid var(--dark-grey);
    border-right: 1px solid white;
}

.disabled {
    filter: drop-shadow(1px 1px 0 white);
}

.selected {
    padding: calc((1.75rem - 16px - 6px) / 2);
    margin: 0 calc(((1.75rem - 16px - 6px) / 2) * -1);
    border-top: 1px solid var(--dark-grey);
    border-bottom: 1px solid white;
    border-left: 1px solid var(--dark-grey);
    border-right: 1px solid white;
    background: image-set(
        url(/img/checkerboard.png) 1x,
        url(/img/checkerboard-2x.png) 2x
    );
}

.divider {
    height: 1px;
}

.divider.dark {
    border-top: 1px solid var(--dark-grey);
}

.divider.light {
    border-top: 1px solid var(--main-grey);
}



.select {
    height: 1rem;
    background: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.75rem;
    gap: 0.75rem;
    padding: 1px;
    user-select: none;
}

.select .dropdown {
    display: flex;
    align-items: center;
    padding: 0.2rem;
    background-color: var(--main-grey);
    height: 100%;
}

.select:first-child {
    min-width: 5.5rem;
}



#menu-bar {
    min-height: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 0.25rem;
    font-size: 0.75rem;
    width: 100%;
    background-color: var(--main-grey);
    border-top: 1px solid white;
    border-bottom: 1px solid var(--dark-grey);
    border-left: 1px solid white;
    border-right: 1px solid var(--dark-grey);
    user-select: none;
}

#menu-bar .icon {
    margin-left: 0.25rem;
}

#menu-links {
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

#menu-bar #menu-links .link {
    padding-left: 0.735rem;
}

#menu-bar #menu-links img + .link {
    padding-left: 0.5rem;
}

#menu-bar #menu-links .link a {
    color: inherit;
    text-decoration: underline;
    cursor: default;
}



#tool-bars {
    width: fit-content;
    max-width: 100%;
    border-right: 1px solid var(--dark-grey);
}

@media (max-width: 716px) {
    .undock {
        width: 1rem;
        height: 100%;
        background: image-set(
            url(/img/undock.png) 1x,
            url(/img/undock-2x.png) 2x
        ) 0.15rem 0.15rem no-repeat;
        position: absolute;
        right: 0;
        background-color: var(--main-grey);
    }
}

.tool-bar {
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 0.25rem;
    width: 100%;
    max-width: 100vw;
    background-color: var(--main-grey);
    border-top: 1px solid white;
    border-bottom: 1px solid var(--dark-grey);
    border-left: 1px solid white;
    overflow: hidden;
    position: relative;
}

.tool-group {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 0.45rem;
    gap: 0.6rem;
    flex-shrink: 0;
}

.with-dropdown {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.25rem;
}





/* Ruler */

#ruler-frame {
    border-top: 1px solid var(--dark-grey);
    border-left: 1px solid var(--dark-grey);
    border-right: 1px solid var(--dark-grey);
}

#ruler-top {
    width: 100%;
    height: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--main-grey);
    border-top: 1px solid black;
    border-left: 1px solid black;
    border-right: 1px solid black;
}

#ruler-top #ruler-container {
    width: min(calc(max(60vw, 600px) + 0.2rem), 100%);
    max-width: var(--max-page-width);
    height: 0.8rem;
    display: flex;
    align-items: center;
    position: relative;
    gap: 0.2rem;
}

#ruler-top #ruler-container > div:not(.markers) {
    height: 100%;
    display: flex;
    align-items: center;
    overflow: hidden;
}

#ruler-top #ruler-container .left-margin {
    width: calc(15% - 0.1rem);
    justify-content: flex-end;
    background-color: var(--dark-grey);
}

#ruler-top #ruler-container .center {
    width: calc(70% - 0.2rem);
    justify-content: flex-start;
    background-color: white;
}

#ruler-top #ruler-container .right-margin {
    width: calc(15% - 0.1rem);
    justify-content: flex-start;
    background-color: var(--dark-grey);
}

@media (max-width: 632px) {
    #ruler-top #ruler-container {
        padding: 0 0.8rem;
        width: min(calc(max(60vw, 100%) + 0.2rem), 100%);
    }
    #ruler-top #ruler-container .center {
        width: calc(100% - (max(60vw, 600px) * 0.05 * 2));
    }
    #ruler-top #ruler-container .left-margin,
    #ruler-top #ruler-container .right-margin {
        width: calc(max(60vw, 600px) * 0.05);
    }
}

#ruler-top #ruler-container * .inch {
    height: 100%;
    display: flex;
    align-items: center;
    /* Keep ruler sized appropriately */
    width: calc(max(max(60vw, 600px), 100%) / 8.5);
    font-size: 0.65rem;
    flex-shrink: 0;
}

#ruler-top #ruler-container * .inch div {
    height: 0.2rem;
    width: 12.5%;
    display: inline-block;
}

#ruler-top #ruler-container * .inch div:first-child {
    height: 100%;
    width: calc(12.5% * 2 - 1px);
    text-align: center;
}

@media (max-width: 632px) {
    #ruler-top #ruler-container .left-margin .inch div:first-child,
    #ruler-top #ruler-container .right-margin .inch div:first-child {
        width: 12.5%;
    }
}

#ruler-top #ruler-container * .inch div:first-child::before {
    content: attr(data-val);
}

@media (max-width: 632px) {
    #ruler-top #ruler-container .left-margin .inch div:first-child::before,
    #ruler-top #ruler-container .right-margin .inch div:first-child::before {
        content: "";
    }
}

#ruler-top #ruler-container * .inch div:not(:first-child) {
    border-left: 1px solid black;
}

#ruler-top #ruler-container * .inch div:nth-child(5) {
    height: 0.4rem;
}

#ruler-top #ruler-container * .inch div:last-child {
    width: 1px;
}

/* First inch is handled a little differently */
#ruler-top #ruler-container * .inch:first-child {
    margin-left: calc((12.5% / 16) * -1);
}
#ruler-top #ruler-container * .inch:first-child div:first-child {
    width: 12.5%;
}

/* Space out left margin */
#ruler-top #ruler-container .left-margin .inch:last-child {
    margin-right: calc(12.5% / 2);
}

@media (max-width: 632px) {
    #ruler-top #ruler-container .left-margin .inch:last-child {
        margin-right: 0;
    }
    #ruler-top #ruler-container .left-margin .inch div,
    #ruler-top #ruler-container .right-margin .inch div {
        border-left: none;
    }
}

/* Mark sure each adjusted margin is fit to its own contents */
#ruler-top #ruler-container .left-margin .inch:nth-child(2),
#ruler-top #ruler-container .right-margin .inch:nth-child(2) {
    margin-left: calc(((12.5% / 2) * -1) - 1px);
}
#ruler-top #ruler-container .center .inch:nth-child(2) {
    margin-left: calc(((12.5% / 8) * -1) - 1px);
}

@media (max-width: 632px) {
    #ruler-top #ruler-container .left-margin .inch:nth-child(2),
    #ruler-top #ruler-container .right-margin .inch:nth-child(2) {
        margin-left: 0;
    }
}

.markers {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    position: absolute;
}

#left-markers {
    left: calc(15% - 0.275rem);
    top: 0.1rem;
}

#right-markers {
    right: calc(15% - 0.275rem);
    top: 0.1rem;
}

@media (max-width: 632px) {
    #left-markers {
        left: calc(max(60vw, 600px) * 0.05 - 0.45rem + 1rem);
    }
    #right-markers {
        right: calc(max(60vw, 600px) * 0.05 - 0.45rem + 1rem);
    }
}

#right-markers img:first-child,
#right-markers img:last-child {
    visibility: hidden;
}





/* Page Layout */

main {
    border-left: 1px solid var(--dark-grey);
    border-right: 1px solid var(--dark-grey);
}

#page-layout {
    background-color: var(--dark-grey);
    border-left: 1px solid black;
    border-right: 1px solid black;
    padding: 1rem;
}

#page-layout .page {
    width: max(60vw, 600px);
    /* max-width: calc(100vw - 2rem); */
    max-width: min(calc(100vw - 2rem), var(--max-page-width));
    min-height: max(min(77vw, var(--max-page-width)), 777px);
    background-color: white;
    margin: 0 auto;
    /* padding: calc(max(60vw, 600px) * 0.15); */
    padding-top: 0;
    border: 1px solid black;
    filter: drop-shadow(2px 2px 0 black);
    /* font-family: "Times New Roman"; */
    overflow-wrap: break-word;
}

#page-layout .page .content {
    padding: calc(min(max(60vw, 600px), var(--max-page-width)) * 0.15);
    padding-top: calc(min(max(60vw, 600px), var(--max-page-width)) * 0.15 - 3rem);
}

@media (max-width: 632px) {
    #page-layout .page .content {
        padding: calc(max(60vw, 600px) * 0.05);
        padding-top: calc(max(60vw, 600px) * 0.05 - 3rem);
    }
}

#page-layout .page:not(:first-child) {
    margin-top: 1rem;
}

#page-layout .page > .pagenum {
    text-align: right;
    padding: 1rem;
    width: 100%;
    height: 3rem;
    font-size: 0.8rem;
}

#page-layout .page .title,
#page-layout .page .subtitle {
    font-weight: normal;
    text-align: center;
}

#page-layout .page .title {
    margin: 0.5rem 0;
    border-bottom: 1px solid black;
    padding-bottom: 0.5rem;
}

#page-layout .page .subtitle {
    margin-top: 0;
    font-size: 1.15rem;
}

#page-layout .page hgroup + p {
    margin-top: 2.5rem;
}

#page-layout .page h2 {
    margin-top: 3rem;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid black;
}

#page-layout .page h3 {
    margin-top: 2rem;
}

#page-layout .page img {
    max-width: 100%;
    object-fit: contain;
}

/* Tables */
table {
    border-spacing: 0;
    border-collapse: collapse;
    border: 3px solid #DEDEDE;
    margin-bottom: 2rem;
    margin: 2rem auto;
}

table td,
table th {
    border: 1px solid #DEDEDE;
    padding: 0.25rem 0.5rem;
}

table tr td:first-child {
    text-align: center;
}

.hex-table {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    align-items: center;
    border: 3px solid #DEDEDE;
    max-width: 100%;
    margin: 2rem auto;
}

.hex-table div {
    padding: 0.25rem 0.5rem;
    border: 1px solid #DEDEDE;
    height: 100%;
    max-width: 100%;
}

.hex-table div:nth-child(-n + 3) {
    font-weight: bold;
    text-align: center;
}

@media (max-width: 632px) {
    .hex-table {
        grid-template-columns: min-content auto;
        grid-template-rows: repeat(2, 1fr);
        grid-auto-flow: dense;
    }
    .hex-table div:nth-child(2) {
        display: none;
    }
    .hex-table div:nth-child(3n + 4) {
        grid-row: span 1;
        border-bottom: none;
    }
    .hex-table div:nth-child(3n + 5) {
        grid-row: span 1;
        grid-column: 1;
        border-top: none;
        text-align: center;
    }
    .hex-table div:nth-child(3n + 6) {
        grid-row: auto / span 2;
        display: flex;
        align-items: center;
    }
}

/* Table of Contents */
#page-layout .page .toc a {
    display: flex;
    justify-content: space-between;
    text-decoration: none;
    color: initial;
}

#page-layout .page .toc a.main {
    margin-top: 1.5rem;
}

#page-layout .page .toc a.sub {
    margin-top: 0.25rem;
    margin-left: 1rem;
}

#page-layout .page .toc a.sub2 {
    margin-top: 0.25rem;
    margin-left: 2rem;
}

#page-layout .page .toc a .name {
    position: relative;
    overflow-wrap: normal;
    width: 100%;
    resize: none;
}

#page-layout .page .toc a.main .name {
    font-weight: bold;
}

#page-layout .page .toc a.sub2 .name {
    font-style: italic;
}

#page-layout .page .toc a .name::after {
    position: absolute;
    padding-right: 0.25rem;
    overflow-y: hidden;
    height: 1rem;
    content:
            ". . . . . . . . . . . . . . . . "
            ". . . . . . . . . . . . . . . . "
            ". . . . . . . . . . . . . . . . "
            ". . . . . . . . . . . . . . . . "
            ". . . . . . . . . . . . . . . . "
            ". . . . . . . . . . . . . . . . "
            ". . . . . . . . . . . . . . . . "
            ". . . . . . . . . . . . . . . . "
            ". . . . . . . . . . . . . . . . "
            ". . . . . . . . . . . . . . . . ";
    text-align: right;
    font-weight: normal;
}

#page-layout .page .toc a .pagenum {
    align-self: flex-end;
    padding-left: 1ch;
}





/* Clippy */

dialog {
    height: auto;
    position: fixed;
    bottom: 0;
    right: 0;
    margin: 0 2rem 2rem auto;
    padding: 0;
    border-top: 1px solid var(--main-grey);
    border-bottom: 1px solid black;
    border-left: 1px solid var(--main-grey);
    border-right: 1px solid black;
}

dialog .mini-window {
    width: 100%;
    height: 100%;
    padding: 0.2rem;
    background-color: var(--main-grey);
    border-top: 1px solid white;
    border-bottom: 1px solid var(--dark-grey);
    border-left: 1px solid white;
    border-right: 1px solid var(--dark-grey);
}

dialog .mini-window .mini-title-bar {
    height: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0.1rem;
    gap: 0.25rem;
    width: 100%;
    background-color: #0000a1;
    /* background: linear-gradient(to right, var(--title-dark-blue), var(--title-light-blue)); */
    border-bottom: 1px solid var(--main-grey);
}

dialog .mini-window .mini-title-bar .close {
    margin-left: auto;
    height: min-content;
}

dialog .mini-window .mini-content {
    background-color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

dialog .mini-window .mini-content .assistant {
    position: absolute;
}





/* Footer */

footer {
    margin-top: auto;
    height: 1.6rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 0.25rem;
    font-size: 0.75rem;
    width: 100%;
    background-color: var(--main-grey);
    border-top: 1px solid white;
    border-bottom: 1px solid white;
    user-select: none;
    gap: 0.35rem;
    overflow: hidden;
}

footer > div {
    border-top: 1px solid var(--dark-grey);
    border-bottom: 1px solid white;
    border-left: 1px solid var(--dark-grey);
    border-right: 1px solid white;
}

footer .goto {
    display: grid;
    grid-template-columns: 4.25rem 4.25rem 4.25rem;
    padding-left: 0.3rem;
}

footer .goto.cur-doc *:nth-child(3) {
    text-align: center;
}

footer .goto.cur-page {
    grid-template-columns: 4rem 2.5rem 4rem;
}

footer .status {
    padding: 0 0.2rem;
    /* color: var(--dark-grey); */
}

footer .spellcheck {
    padding: 0 0.65rem;
}

footer .autosave {
    padding-right: 1.2rem;
}