/**********************
    RESETS
**********************/

/* Use a sane box sizing model */
*,
::after,
::before {
    box-sizing: border-box;
}

/* Undo all the margins and make sure text doesn't overflow */
* {
    margin: 0;
    hyphens: auto;
    overflow-wrap: break-word;
}

/* Set up smooth scrolling */
html:focus-within {
    scroll-behavior: smooth;
}

/* Adding this for now just in case I want to use percentage-based heights */
html,
body {
    height: 100%;
}

/* Set up the default body styles */
body {
    line-height: 1.5;
    /* min-height: 100vh; restore this if I remove the percentage height, above */
}

/* Make images and other media easier to work with */
canvas,
img,
picture,
svg,
video {
    display: block;
    max-width: 100%;
}

/* Allow form controls to inherit font properties */
button,
input,
select,
textarea {
    font: inherit;
}

/* Respect users that prefer reduced motion !important */
@media (prefers-reduced-motion: reduce) {
    
    /* Turn off smooth scrolling */
    html:focus-within {
        scroll-behavior: auto;
    }
    
    /* Turn off all animations and transitions */
    *,
    ::after,
    ::before {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/************************
    CUSTOM PROPERTIES
************************/

:root {
    --color-open: hsl(90deg 50% 25%);
    --color-closed: hsl(210deg 50% 25%);
    --color-accent: hsl(330deg 50% 25%);
    --color-darker: hsl(0deg 0% 20%);
    --color-dark: hsl(210deg 19% 43%);
    --color-light: hsl(0deg 0% 90%);
    --color-lighter: hsl(0deg 0% 100%);
    --color-text-darker: hsl(0deg 0% 20%);
    --color-text-lighter: hsl(0deg 0% 100%);
    --font-family-monospace: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;
    --font-family-system-ui: system-ui, sans-serif;
    --font-family-sans: Avenir, 'Avenir Next LT Pro', Montserrat, Corbel, 'URW Gothic', source-sans-pro, sans-serif;
    --font-family-serif: 'Iowan Old Style', 'Palatino Linotype', 'URW Palladio L', P052, serif;
    --text-color: hsl(0, 0%, 30%);
    --font-size-sm: clamp(0.85rem, 0.17vw + 0.76rem, 0.9rem);
    --font-size-base: clamp(1rem, 0.34vw + 0.91rem, 1.19rem);
    --font-size-md: clamp(1.25rem, 0.61vw + 1.1rem, 1.58rem);
    --font-size-lg: clamp(1.56rem, 1vw + 1.31rem, 2.11rem);
    --font-size-xl: clamp(1.95rem, 1.56vw + 1.56rem, 2.81rem);
    --font-size-xxl: clamp(2.44rem, 2.38vw + 1.85rem, 3.75rem);
    --font-size-xxxl: clamp(3.05rem, 3.54vw + 2.17rem, 5rem);
    --font-size-xxxxl: clamp(3.55rem, 4.25vw + 2.4rem, 8rem);
    --padding-base: 1rem;
    --padding-lg: 2rem;
}
@media (prefers-color-scheme: dark) {
   :root {
        /*--color-darker: hsl(0deg 0% 90%);*/
        --color-dark: hsl(0deg 0% 50%);
        --color-text-lighter: hsl(0deg 0% 80%);
        --color-text-darker: hsl(0deg 0% 80%);
        --color-light: hsl(0deg 0% 20%);
        --color-lighter: hsl(0deg 0% 0%);
        --color-accent-lighter: hsl(330deg 80% 90%);
        --color-accent: hsl(330deg 50% 75%);
        --color-accent-darker: hsl(330deg 80% 20%);
   }
   a,
   a:visited {
       color: var(--color-text-darker);
   }
   a:hover,
   a:focus {
       color: var(--color-accent-darker);
   }
   img {
       filter: brightness(0.5);
   }
   .nav-search-text::placeholder {
       color: var(--color-text-darker);
   }
}

/**************
    LAYOUT
***************/

main {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
    justify-content: start;
}

/***********************
    SEMANTIC ELEMENTS
************************/
body {
    color: var(--color-text-darker);
    font-family: var(--font-family-serif);
    font-size: var(--font-size-md);
    position: relative;
    height: 100%;
}
main {
    margin: var(--padding-base);
}
nav {
    align-items: center;
    background: var(--color-closed);
    border-block-start: 1px ridge hsl(0deg 0% 67%);
    display: flex;
    justify-content: space-between;
    padding: 0.5rem var(--padding-base);
}
:is(h1, h2, h3, h4) {
    font-family: var(--font-family-sans); 
}
:is(h1, h2, h3, h4, p) {
    margin-block-start: 1rem; 
}
h1 {
    font-size: var(--font-size-xl);
}
h2 {
    font-size: var(--font-size-xxl);
    line-height: 1.2;
    margin-block-start: 0;
    margin-block-end: 1rem;
}
h3 {
    font-size: var(--font-size-md);
}
h4 {
    font-size: var(--font-size-base);
}
footer {
    border-block-start: 1px solid hsl(0deg 0% 60%);
    padding: var(--padding-base);
}

/****************
    COMPONENTS
*****************/

.books-background {
    background: var(--color-darker);
    color: hsl(0deg 0% 100% / 50%);
    font-family: var(--font-family-monospace);
    overflow: hidden;
    padding: 0 0.5rem;
}
.page-wing {
    background: transparent;
}
.site-title {
    font-size: var(--font-size-lg);
    grid-area: title;
    letter-spacing: 0;
    margin-block-start: -0.25rem;
    margin-inline-start: 2rem;
}
.site-title > a {
    color: var(--color-text-lighter);
    text-decoration: none;
}
.site-title > a:hover {
    text-decoration: underline;
}
.site-subtitle {
    grid-area: subtitle;
    line-height: 1.4;
    margin-block-start: 0.5rem;
    margin-inline-start: 2rem;
}
.content-wrapper {
    background: var(--color-lighter);
    height: 100%;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
}
.content-wrapper > header {
    background: var(--color-closed);
    color: var(--color-text-lighter);
    display: grid;
    grid-template-columns: 100px 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
        "icon title"
        "icon subtitle";
    line-height: 1;
    padding: var(--padding-base);
}
.header-image {
    border-radius: 50%;
    max-height: 100px;
    max-width: 100px;
    grid-area: icon;
}
.nav-browse-menu {
    background: var(--color-light);
    border-radius: 4px;
    color: var(--color-text-darker);
    font-family: var(--font-family-serif);
    font-size: 1.25rem;
}
.nav-links {
    display: inline-block;
    font-family: var(--font-family-sans);
    list-style-type: none;
}
.nav-links > label {
    color: var(--color-text-lighter);
    display: none;
    font-size: 1.5rem;
}
.nav-links a {
    color: hsl(0deg 0% 100%);
    font-weight: bold;
    padding-inline-end: var(--padding-base);
    text-decoration: none;    
}
.nav-links a:hover {
    color: hsl(0deg 0% 100%);
    text-decoration: underline;    
}
.nav-search-dropdown-contents.show {
    display: block;
    right: 0;
    z-index: 1;   
}
.nav-search-dropdown-contents > a {
    display: block;
    border-radius: 5px;
    color: var(--color-text-darker);
    padding: 4px 8px;
    text-decoration: none;
}
.nav-search-dropdown-contents > a:hover {
    background: var(--color-accent);
    color: var(--color-lighter);
}
.nav-search-form {
    align-items: center;
    margin-block-start: 0.25rem;
    padding-top: 2px;
}
.nav-search-text {
    background: var(--color-light);
    border: 1px solid var(--color-light);
    border-radius: 4px;
    box-shadow: inset 0 1px 3px #ddd;
    color: var(--color-text-darker);
    display: inline-block;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    vertical-align: middle;
    width: 10rem;
}
.nav-search-dropdown-contents {
    background: var(--color-light);
    border-radius: 8px;
    display: none;
    margin-left: 0.25rem;
    max-height: 200px;
    overflow: auto;
    padding: 0.5rem;
    position: absolute;
    width: fit-content;  
}
.page-background {
    display: none;
}
.book-image {
    max-height: 400px;
}
ul {
    margin-inline-start: -1rem;
}
summary {
    background: var(--color-closed);
    border-radius: 10px 10px 0 0;
    color: var(--color-text-lighter);
    cursor: pointer;
    font-family: var(--font-family-sans);
    font-weight: bold;
    margin-block-start: 1rem;
    padding: var(--padding-base);
    position: relative;
    transition: 0.5s;
}
summary ~ * {
    padding-inline-start: 1rem;
    background: var(--color-light);
}
details[open] summary {
    background: var(--color-open);
}
.contact-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.contact-form button {
    cursor: pointer;
    max-width: 200px;
    padding: 0.5rem 1rem;
}
.contact-form button:hover {
    background: var(--color-accent-lighter);
}
.contact-form button:focus {
    outline: 2px solid var(--color-accent-darker);
    outline-offset: 2px;
}
.form-note {
    color: var(--color-text-darker);
    font-size: 1rem;
    margin-inline-start: 0.7rem;
    text-indent: -0.7rem;
}
.form-output {
    color: var(--color-text-darker);
    font-size: 1rem;
    margin-inline-start: 0.5rem;
}
/*************
    CLASSES
**************/
.surtitle {
    background: var(--color-open);
    border-radius: 10px 10px 0 0;
    color: var(--color-text-lighter);
    font-family: var(--font-family-sans);
    font-weight: bold;
    margin-block: 1rem;
    padding: var(--padding-base);
}
.latest-book-image {
    width: 100%;
    margin-block-end: var(--padding-base);
}
.toc-wrapper {
    border-radius: 0 0 10px 10px;
    max-height: 50vh;
    overflow-y: auto;
    padding-inline-start: var(--padding-base);
}
.toc-title {
    margin-block-start: 0;
    padding: 0.75rem 0 0.25rem 0;
}
.toc-cag-part,
.toc-part {
    margin-block-start: 0;
    padding: 0.75rem 0 0.5rem 0;
}
.toc-cag-chapter,
.toc-chapter {
    font-weight: 400;
    margin-block-start: 0;
    padding: 0.75rem 0 0 0;    
}
.toc-heading-1 {
    margin-block-start: 0;
    text-indent: 1rem;
}
.toc-heading-2 {
    margin-block-start: 0;
    text-indent: 2rem;
}
.tag-books-wrapper,
.related-books-wrapper,
.buy-it-wrapper,
.recent-books-wrapper,
.all-books-wrapper {
    border-radius: 0 0 10px 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: var(--padding-base);
}
.tag-books-wrapper > figure,
.related-books-wrapper > figure,
.buy-it-wrapper > figure,
.recent-books-wrapper > figure {
    flex: 1 0 250px;
}
.tag-books-wrapper > figure img,
.related-books-wrapper > figure img,
.recent-books-wrapper > figure img {
    height: 360px;
    margin: auto;
}
.buy-it-wrapper > figure img {
    height: 148px;
    margin-inline-start: 1.25rem;
}
.all-books-wrapper > figure {
    flex: 1 0 125px;
}
.all-books-wrapper > figure img {
    height: 180px;
}
.tags-menu {
    background: var(--color-light);
    border-radius: 4px;
    color: var(--color-text-darker);
    font-family: var(--font-family-serif);
    font-size: 1.25rem;
    font-weight: 400;
    max-width: 200px;
}
.tag-books-wrapper figcaption,
.recent-books-wrapper figcaption,
.all-books-wrapper figcaption {
    font-size: 1.25rem;
    margin-block-start: 0.5rem;
    text-align: center;
}
.tag-books-wrapper {
    background: var(--color-light);
    grid-area: books;
}
.tag-books-container > .surtitle {
    display: flex;
    justify-content: space-between;
    padding-inline: 1.5rem;
}
.tag-books-container label {
    display: none;
}


/*******************
    MEDIA QUERIES
********************/
@media (max-width: 600px) {
    .site-subtitle {
        font-size: var(--font-size-sm);
    }
    .recent-books-wrapper > figure {
        margin-inline-start: 0.75rem;
    }
}
@media (min-width: 600px) {
    .site-subtitle {
        text-indent: -0.75rem;
    }
    .nav-links > label,
    .tag-books-container label {
        color: var(--color-text-lighter);
        display: inline;
        font-size: 1.25rem;
        font-weight: normal;
    }
    .tags-menu {
        max-width: fit-content;
    }
    .nav-search-text {
        width: 15rem;
    }

    /*
     * Home Page: Latest Book
     */
    .latest-book-container {
        display: grid;
        gap: 1rem;
        grid-template-columns: 1fr 2fr;
        grid-template-rows: auto auto;
        grid-template-areas: 
            "surtitle surtitle"
            "image text";
    }
    .surtitle {
        grid-area: surtitle;
        margin-block: 0;
    }
    .latest-book-image {
        grid-area: image;
        padding-inline-start: var(--padding-lg);
        margin-block-end: 0;
    }
    .latest-book-text {
        grid-area: text;
        padding-inline-end: var(--padding-lg);
    }
    .latest-book-title {
        font-size: var(--font-size-xl);
        line-height: 1.1;
    }
    .latest-book-subtitle {
        font-style: italic;
    }
    .nav-search-dropdown-contents.show {
        right: auto;
    }
    /*
     * Tags Page
     */
    .tag-books-container {
        display: grid;
        grid-auto-columns: auto 1fr;
        grid-template-rows: auto 1fr;
        grid-template-areas: 
            "surtitle surtitle"
            "books books";
    }
}    
@media (min-width: 50rem) {
    main {
        margin: var(--padding-lg);
    }
    
    .page-background {
        background: var(--color-darker);
        color: hsl(0deg 0% 100% / 50%);
        display: block;
        font-family: var(--font-family-monospace);
        min-height: 100vh;
        left: 0;
        opacity: 1;
        position: fixed;
        top: 0;
        width: 100vw;
        z-index: -1;
    }
    .page-background-text {
        rotate: -22.5deg;
        font-size: 4rem;
        width: 400vh;
        translate: -25vw -50vh;
    }
    .page-wrapper {
        display: grid;
        grid-template-columns: auto 64rem auto;
        grid-template-areas: 
            ". content .";
        height: 100%;
    }
    .content-wrapper {
        grid-area: content;
    }
    .content-wrapper > header {
        align-items: center;
        display: flex;
        flex-wrap: wrap;
    }
    .site-title{
        font-size: var(--font-size-xl);
        letter-spacing: 0.5rem;
    }
    .site-subtitle {
        flex: 1 1 250px;
    }
    .nav-search-text {
        width: 20rem;
    }
    /*
     * Book Page Header
    */
    main > header {
        display: flex;
        column-gap: 1rem;   
    }
    .book-title-wrapper {
        
        order: 2;
    }
    .book-title {
        font-size: var(--font-size-xxxl);
        line-height: 1;
    }
    .book-subtitle {
        font-style: italic;
    }
    .book-image {
        order: 1;
    }
    .related-books-wrapper {
        display: flex;
        flex-wrap: wrap;
        gap: 2rem;
        padding: 1rem;
    }
    .related-books-wrapper > figure {
        flex: 1 0 200px;
    }
    .buy-it-wrapper {
        display: flex;
        flex-wrap: wrap;
        gap: 2rem;
        padding: var(--padding-lg);
    }
    .buy-it-wrapper > figure {
        flex: 1 0 300px;
    }
    .buy-it-wrapper > figure img {
        margin-inline-start: auto;
    }
    .nav-links a {
        padding-inline-end: var(--padding-lg);
    }    
    .toc-wrapper {
        padding-inline-start: var(--padding-lg);
    }
    .content-wrapper > header,
    .recent-books-wrapper,
    footer {
        padding: var(--padding-lg);
    }
    nav {
        padding: 0.5rem var(--padding-lg);
    }
}
@media (prefers-reduced-motion: no-preference) {
    .page-background {
        opacity: 0;
        transition: opacity 750ms ease;
    }
}