/**
 * App-specific extensions for The Monospace Web by Oskar Wickström.
 * Upstream: https://github.com/owickstrom/the-monospace-web
 * License: MIT
 */

:root {
    --app-accent: var(--text-color);
    color-scheme: light;
}

:root[data-theme="light"] {
    --text-color: #000;
    --text-color-alt: #666;
    --background-color: #fff;
    --background-color-alt: #eee;
    color-scheme: light;
}

:root[data-theme="dark"] {
    --text-color: #fff;
    --text-color-alt: #aaa;
    --background-color: #000;
    --background-color-alt: #111;
    color-scheme: dark;
}

body {
    max-width: none;
}

a {
    text-underline-offset: .12em;
    transition:
        background-color 160ms ease,
        text-underline-offset 160ms ease;
}

a:not(.spell-card) {
    margin: -.2em -.25ch;
    padding: .2em .25ch;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

a:hover {
    background-color: var(--background-color-alt);
    text-underline-offset: .3em;
}

.shell {
    width: 100%;
    margin-inline: 0;
}

.site-header,
.site-header table,
.site-header tbody,
.site-header tr,
.site-header td,
.site-header th,
.brand,
.brand h1 {
    margin-top: 0;
}

.site-header .header {
    width: 100%;
    margin-bottom: calc(var(--line-height) * 2);
}

.brand {
    display: inline-block;
    text-decoration: none;
}

.brand .title {
    margin: 0;
}

.section-switch {
    display: block;
    margin-top: calc(var(--line-height) / 2);
    color: var(--text-color-alt);
    font-size: .75rem;
    text-transform: uppercase;
}

.section-switch > * {
    margin-top: 0;
}

.section-switch a {
    color: var(--text-color-alt);
    text-decoration: none;
}

.section-switch a.active {
    color: var(--text-color);
    text-decoration: underline;
}

.theme-toggle,
.theme-toggle > * {
    margin: 0;
}

.site-header td.theme-cell {
    text-align: center;
    vertical-align: middle;
}

.site-header th.theme-label {
    vertical-align: middle;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    height: auto;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    line-height: inherit;
    white-space: nowrap;
    text-decoration: none;
    text-transform: none;
}

.theme-toggle [data-theme-icon] {
    display: inline-grid;
    width: 24px;
    height: 24px;
    flex: 0 0 24px;
    font-size: 24px;
    line-height: 1;
    place-items: center;
}

.subtitle,
.english-name,
.school-name,
.multi-select-hint,
.source-line {
    color: var(--text-color-alt);
}

.hero {
    margin-top: 0;
}

.hero h1 {
    margin-bottom: var(--line-height);
}

.hero > p:last-child {
    max-width: 70ch;
}

.eyebrow {
    margin-bottom: var(--line-height);
    color: var(--text-color-alt);
    font-size: .875rem;
    text-transform: uppercase;
}

.filters-toggle,
.search-submit-icon {
    display: none;
}

.filters-toggle > *,
.search-submit > * {
    margin-top: 0;
}

.search-panel {
    display: grid;
    grid-template-columns:
        minmax(24ch, 2fr)
        repeat(3, minmax(13ch, 1fr))
        minmax(12ch, 1fr);
    gap: var(--line-height) 1ch;
    align-items: end;
    width: 100%;
    margin-bottom: calc(var(--line-height) * 2);
    padding: calc(var(--line-height) - var(--border-thickness)) 1ch;
    border: var(--border-thickness) solid var(--text-color);
}

.search-panel > *,
.search-panel label,
.search-panel input,
.search-panel button {
    margin-top: 0;
}

.query-field {
    position: relative;
    min-width: 0;
}

.spell-suggestions {
    position: absolute;
    z-index: 20;
    top: 100%;
    right: 0;
    left: 0;
    overflow-y: auto;
    max-height: calc(var(--line-height) * 12);
    margin: calc(var(--border-thickness) * -1) 0 0;
    padding: 0;
    border: var(--border-thickness) solid var(--text-color);
    background: var(--background-color);
    list-style: none;
}

.spell-suggestions[hidden] {
    display: none;
}

.spell-suggestion {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1ch;
    min-height: calc(var(--line-height) * 2);
    margin: 0;
    padding: calc(var(--line-height) / 2) 1ch;
    cursor: pointer;
}

.spell-suggestion + .spell-suggestion {
    border-top: var(--border-thickness) dotted var(--text-color-alt);
}

.spell-suggestion[aria-selected="true"],
.spell-suggestion:hover {
    background: var(--background-color-alt);
}

.spell-suggestion > * {
    overflow: hidden;
    margin: 0;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.spell-suggestion-english {
    color: var(--text-color-alt);
    font-size: .875rem;
}

.search-panel label,
.fact-label {
    display: block;
    margin-bottom: calc(var(--line-height) / 2);
    color: var(--text-color);
    font-size: .875rem;
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
}

.search-panel input,
.search-panel button {
    width: 100%;
    border: var(--border-thickness) solid var(--text-color);
    border-radius: 0;
    color: var(--text-color);
    background: var(--background-color);
    font: inherit;
}

.search-panel input::placeholder,
[data-multi-select-value][data-empty="true"] {
    color: var(--text-color-alt);
    opacity: 1;
}

.multi-select {
    position: relative;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
}

.multi-select summary {
    position: relative;
    overflow: hidden;
    min-height: calc(var(--line-height) * 2);
    margin-top: 0;
    padding: calc(var(--line-height) / 2 - var(--border-thickness)) 4ch
        calc(var(--line-height) / 2 - var(--border-thickness)) 1ch;
    border: var(--border-thickness) solid var(--text-color);
    color: var(--text-color);
    background: var(--background-color);
    cursor: pointer;
    list-style: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.multi-select summary::-webkit-details-marker {
    display: none;
}

.multi-select summary::marker {
    content: "";
}

.multi-select summary::after {
    position: absolute;
    top: 50%;
    right: 1ch;
    width: .55rem;
    height: .55rem;
    border-right: var(--border-thickness) solid currentColor;
    border-bottom: var(--border-thickness) solid currentColor;
    content: "";
    transform: translateY(-70%) rotate(45deg);
}

.multi-select[open] summary::after {
    transform: translateY(-30%) rotate(-135deg);
}

.multi-select[open] summary {
    margin-bottom: 0;
}

.multi-select summary:focus-visible {
    outline: none;
    background: var(--background-color-alt);
}

.multi-select-menu {
    position: absolute;
    z-index: 10;
    top: 100%;
    right: 0;
    left: 0;
    overflow-y: auto;
    max-height: calc(var(--line-height) * 10);
    margin-top: calc(var(--border-thickness) * -1);
    border: var(--border-thickness) solid var(--text-color);
    background: var(--background-color);
}

.multi-select-option {
    display: flex !important;
    align-items: center;
    gap: 1ch;
    min-height: calc(var(--line-height) * 2);
    margin: 0 !important;
    padding: calc(var(--line-height) / 2) 1ch;
    font-size: inherit !important;
    font-weight: inherit !important;
    text-transform: none !important;
    cursor: pointer;
}

.multi-select-option > * {
    margin-top: 0;
}

.multi-select-option + .multi-select-option {
    border-top: var(--border-thickness) dotted var(--text-color-alt);
}

.multi-select-option:hover,
.multi-select-option:focus-within {
    background: var(--background-color-alt);
}

.search-panel .multi-select-option input {
    width: 1.25rem;
    height: 1.25rem;
    min-height: 1.25rem;
    flex: 0 0 auto;
    accent-color: var(--text-color);
}

.search-panel button {
    min-height: calc(var(--line-height) * 2);
}

.search-panel .search-submit:hover,
.theme-toggle:active {
    color: var(--background-color);
    background: var(--text-color);
}

@media (hover: hover) and (pointer: fine) {
    .theme-toggle:hover {
        color: var(--background-color);
        background: var(--text-color);
    }
}

/* Keep touch targets stationary while they are pressed. */
button:active {
    transform: none;
}

.multi-select-hint {
    grid-column: 1 / -1;
    margin: 0;
    font-size: .75rem;
}

.results-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 2ch;
    margin: calc(var(--line-height) * 2) 0 var(--line-height);
    border-bottom: var(--border-thickness) solid var(--text-color);
}

.results-heading > * {
    margin-top: 0;
}

.results-heading h2 {
    margin-bottom: calc(var(--line-height) / 2);
}

.clear-link,
.back-link {
    font-size: .875rem;
    font-weight: var(--font-weight-medium);
    text-transform: uppercase;
}

.spell-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--line-height) 1ch;
    margin-top: 0;
}

.spell-link-index {
    columns: 3 24ch;
    column-gap: 4ch;
    margin-top: 0;
}

.spell-link-group {
    display: inline-block;
    width: 100%;
    margin: 0 0 var(--line-height);
    break-inside: avoid;
}

.spell-link-group h2 {
    margin: 0 0 calc(var(--line-height) / 2);
    border-bottom: var(--border-thickness) solid var(--text-color);
}

.spell-link-group ul,
.spell-link-group li {
    margin: 0;
    padding: 0;
    list-style: none;
}

.spell-link-group li + li {
    margin-top: calc(var(--line-height) / 2);
}

.spell-link-group li:not(:last-child) {
    padding-bottom: calc(var(--line-height) / 2);
    border-bottom: var(--border-thickness) dotted var(--text-color-alt);
}

.spell-link-group a {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    gap: 1ch;
    text-decoration: none;
    transition: transform 160ms ease;
}

.spell-link-group a:hover {
    transform: translateX(.25ch);
}

.spell-link-group a > *,
.spell-link-main > * {
    margin-top: 0;
}

.spell-link-main {
    display: grid;
    grid-template-columns: 2ch minmax(0, 1fr);
    gap: 1ch;
    min-width: 0;
}

.monster-link-index .spell-link-main {
    grid-template-columns: 4ch minmax(0, 1fr);
}

.spell-link-level {
    color: var(--text-color-alt);
    text-align: right;
    text-decoration: none;
}

.spell-link-school {
    overflow: hidden;
    color: var(--text-color-alt);
    font-size: .875rem;
    text-align: right;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.spell-card {
    display: flex;
    min-width: 0;
    min-height: calc(var(--line-height) * 12);
    flex-direction: column;
    margin-top: 0;
    padding: 0 1ch calc(var(--line-height) - var(--border-thickness));
    border: var(--border-thickness) solid var(--text-color);
    color: var(--text-color);
    background: var(--background-color);
    text-decoration: none;
}

.monster-card--compact {
    min-height: 0;
}

.spell-card:hover,
.spell-card:focus-visible {
    color: var(--text-color);
    background: var(--background-color-alt);
    outline: none;
}

.spell-card:active {
    transform: translate(2px, 2px);
}

.spell-card > *,
.card-topline > *,
.card-meta > * {
    margin-top: 0;
}

.card-topline,
.card-meta,
.detail-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1ch;
}

.level-badge {
    display: inline-block;
    padding-inline: 1ch;
    color: var(--background-color);
    background: var(--text-color);
    font-size: .75rem;
    font-weight: var(--font-weight-bold);
    white-space: nowrap;
}

.school-name {
    overflow: hidden;
    font-size: .75rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.spell-card h2 {
    margin: var(--line-height) 0 0;
    font-size: 1rem;
}

.card-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1ch;
}

.spell-card .card-heading h2 {
    margin-top: 0;
}

.card-heading .level-badge {
    flex: none;
}

.english-name {
    margin: 0;
    font-size: .875rem;
}

.card-description {
    margin: var(--line-height) 0;
    font-size: .875rem;
}

.monster-card-summary {
    margin-bottom: 0;
}

.card-meta {
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-top: auto;
    padding-top: var(--line-height);
    border-top: var(--border-thickness) dotted var(--text-color-alt);
    color: var(--text-color-alt);
    font-size: .7rem;
}

.card-meta span + span::before {
    content: "/";
    margin-right: 1ch;
}

.pagination {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1ch;
    margin: calc(var(--line-height) * 2) 0;
    text-align: center;
}

.pagination > * {
    margin-top: 0;
}

.pagination > span {
    grid-column: 2;
    grid-row: 1;
}

.pagination a:first-child {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
}

.pagination a:last-child {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
}

.empty-state {
    margin: 0 0 calc(var(--line-height) * 2);
    padding: calc(var(--line-height) * 2) 2ch;
    border: var(--border-thickness) dashed var(--text-color);
    text-align: center;
}

.empty-state > * {
    margin-top: 0;
}

.detail-shell {
    margin-top: 0;
    padding-bottom: calc(var(--line-height) * 2);
}

.spell-detail {
    margin-top: var(--line-height);
}

.detail-heading {
    align-items: flex-start;
    padding: var(--line-height) 0;
    border-top: calc(var(--border-thickness) * 3) double var(--text-color);
    border-bottom: calc(var(--border-thickness) * 3) double var(--text-color);
}

.detail-heading > *,
.detail-heading h1,
.detail-heading p {
    margin-top: 0;
}

.detail-heading h1 {
    margin-bottom: 0;
}

.detail-heading .level-badge {
    margin-top: .25rem;
    padding: .1em 1.25ch;
    font-size: .875rem;
}

.facts-table {
    margin-top: var(--line-height);
}

.monster-stats-layout {
    display: grid;
    grid-template-columns: minmax(24rem, 1fr) minmax(32rem, 2fr);
    gap: 1ch;
    width: calc(round(down, 100%, 1ch));
    margin-top: var(--line-height);
}

.monster-stat-table-scroll {
    overflow-x: auto;
    margin-top: 0;
}

.monster-stat-table {
    width: 100%;
    margin-top: 0;
}

.monster-stat-table th,
.monster-stat-table td {
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

.monster-combat-stats .monster-stat-table {
    min-width: 24rem;
}

.monster-ability-stats .monster-stat-table {
    min-width: 32rem;
}

.facts-table th {
    white-space: nowrap;
}

.rules-text {
    max-width: 76ch;
}

.rules-text p {
    line-height: var(--line-height);
    white-space: pre-line;
}

.source-line {
    margin-top: calc(var(--line-height) * 2);
    padding-top: var(--line-height);
    border-top: var(--border-thickness) solid var(--text-color);
    font-size: .75rem;
    text-transform: uppercase;
}

@media (prefers-reduced-motion: reduce) {
    a,
    .spell-link-group a {
        transition: none;
    }
}

@media screen and (min-width: 761px) {
    .site-header td.theme-cell {
        position: relative;
        padding: 0;
    }

    .site-header td.theme-cell .theme-toggle {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
    }

    .theme-toggle [data-theme-icon] {
        width: 1rem;
        height: 1rem;
        flex-basis: 1rem;
        font-size: 1rem;
    }

    .rules-text {
        max-width: none;
    }

    .search-panel {
        grid-template-columns:
            minmax(24ch, 2fr)
            repeat(3, minmax(16ch, 1.25fr))
            max-content;
        padding: 0;
        border: 0;
    }

    .search-panel .search-submit {
        width: max-content;
        padding-inline: 1ch;
        white-space: nowrap;
    }
}

@media screen and (max-width: 960px) {
    .monster-stats-layout {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media screen and (max-width: 760px) {
    .search-panel {
        padding: 0;
        border: 0;
    }

    .monster-ability-stats .monster-stat-table {
        min-width: 0;
        table-layout: fixed;
    }

    .monster-ability-stats .monster-stat-table th,
    .monster-ability-stats .monster-stat-table td {
        padding-right: .35ch;
        padding-left: .35ch;
    }

    .search-panel,
    .spell-grid {
        grid-template-columns: 1fr;
    }

    .query-field {
        grid-column: auto;
    }

    .site-header .header th,
    .site-header .header tr:first-child td:last-child {
        display: none;
    }

    .site-header .header td:last-child {
        width: 0;
    }

    .detail-heading {
        display: block;
    }

    .detail-heading .level-badge {
        margin-top: var(--line-height);
    }
}

@media screen and (min-width: 481px) and (max-width: 760px) {
    .site-header td.theme-cell {
        position: relative;
        min-width: 2.5rem;
        padding: 0;
    }

    .site-header td.theme-cell .theme-toggle {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
    }
}

@media screen and (max-width: 480px) {
    .search-panel .filters-toggle {
        display: grid;
        grid-row: 1;
        grid-column: 2;
        width: 3.5rem;
        min-height: 3.5rem;
        margin: 0;
        padding: 0;
        border: var(--border-thickness) solid var(--text-color);
        border-left: 0;
        color: inherit;
        background: transparent;
        place-items: center;
        cursor: pointer;
    }

    .search-panel .filters-toggle[aria-expanded="true"] {
        color: var(--background-color);
        background: var(--text-color);
    }

    .filters-toggle:focus-visible {
        outline: calc(var(--border-thickness) * 2) solid var(--text-color);
        outline-offset: calc(var(--border-thickness) * 2);
    }

    .filters-toggle-label {
        display: none;
    }

    .filters-toggle-icon {
        font-size: 24px;
    }

    .site-header .header td.theme-cell {
        position: relative;
        min-width: 5rem;
        text-align: center;
        vertical-align: middle;
    }

    .theme-toggle {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 3.5rem;
        height: 3.5rem;
        gap: 0;
        margin: 0;
        font-size: 0;
        line-height: 1;
        text-decoration: none;
        transform: translate(-50%, -50%);
    }

    .theme-toggle:active {
        transform: translate(-50%, -50%);
    }

    .theme-toggle [data-theme-icon] {
        display: grid;
    }

    .search-panel {
        grid-template-columns: minmax(0, 1fr) repeat(2, 3.5rem);
        gap: 0;
        padding: 0;
        border: 0;
        align-items: stretch;
    }

    .search-panel .query-field {
        grid-column: 1;
    }

    .search-panel .query-field label,
    .search-panel .multi-select-field {
        display: none;
    }

    .search-panel .search-submit {
        display: grid;
        grid-row: 1;
        grid-column: 3;
        width: 3.5rem;
        padding: 0;
        border-left: 0;
        place-items: center;
    }

    .search-submit-label {
        display: none;
    }

    .search-submit-icon {
        display: inline-block;
        font-size: 24px;
    }

    .search-panel input,
    .search-panel button,
    .multi-select summary {
        min-height: 3.5rem;
    }

    .query-field input {
        font-size: 16px;
    }

    .search-panel.filters-expanded .multi-select-field {
        display: block;
        grid-column: 1 / -1;
        margin-top: var(--line-height);
    }

    .multi-select summary {
        display: flex;
        align-items: center;
        padding-right: 3.5rem;
    }

    .multi-select summary::after {
        right: 1.475rem;
    }

    .results-heading {
        display: flex;
        align-items: center;
        gap: 1ch;
    }

    .results-heading .clear-link {
        flex: 0 0 auto;
        margin-left: auto;
        margin-bottom: calc(var(--line-height) / 2);
        text-align: right;
        white-space: nowrap;
    }

    .spell-link-group a {
        font-size: 1.0625rem;
    }

}

/* Error responses */
.error-page,
.error-message {
    max-width: 72ch;
    margin-inline: auto;
}

.error-page {
    padding-block: calc(var(--line-height) * 2);
}

.error-status {
    margin-bottom: 0;
    font-size: 2rem;
    font-weight: 700;
}
