/* Base: fonts, colour tokens (light and dark), type, page layout, header and menu. Loaded first. */

/* Fonts are served from this site (SIL Open Font License, see fonts/OFL-*.txt), so no visitor
   data goes to a third-party font service. */
@font-face {
    font-family: "Cormorant Garamond";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/cormorant-garamond-latin-400-normal.woff2") format("woff2");
}

@font-face {
    font-family: "Cormorant Garamond";
    font-style: italic;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/cormorant-garamond-latin-400-italic.woff2") format("woff2");
}

@font-face {
    font-family: "Cormorant Garamond";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/cormorant-garamond-latin-600-normal.woff2") format("woff2");
}

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/inter-latin-400-normal.woff2") format("woff2");
}

@font-face {
    font-family: "Inter";
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url("../fonts/inter-latin-500-normal.woff2") format("woff2");
}

:root {
    /* Colour scheme: "Charcoal and red". The --gold-* names are kept from the first (gold) scheme so the rest of the
       stylesheets needn't change; they now hold the red accent. */
    --ink: #18181b;
    --ink-soft: #5b5b63;
    --paper: #fafafa;
    --paper-deep: #f1f1f2;
    --gold: #e5484d;
    --gold-soft: #f3a5a7;
    /* The accent for text, links and button fills: deep enough to read (WCAG AA, 4.5:1) on both paper colours. */
    --gold-ink: #c2272d;
    --on-gold: #fff;
    --field: #fff;
    --danger: #8a1f15;
    --danger-bg: #fbe9e7;
    --win: #1f6b3a;
    /* A warning that isn't a blunder (the coach's "caution" comments): amber, apart from the red accent. */
    --caution: #c8902a;
    --rule: #e5e5e7;
    /* The logo's two quieter squares (the accent ones use --gold). */
    --mark-muted: #d4d4d8;
    /* The board: its squares, the last move's squares, and the frame around it. */
    --board-light: #ededed;
    --board-dark: #9a9a9a;
    --board-last-light: #f6c4c2;
    --board-last-dark: #d98a87;
    --board-frame: #18181b;
    /* Rounded corners and soft shadows, shared by cards, panels, buttons and fields. */
    --radius: 14px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.05), 0 2px 6px rgba(24, 24, 27, 0.06);
    --shadow: 0 6px 16px rgba(24, 24, 27, 0.08), 0 18px 40px rgba(24, 24, 27, 0.08);
    /* A faint accent wash, for hover backgrounds and the active menu item. */
    --gold-tint: rgba(194, 39, 45, 0.08);
    --serif: "Cormorant Garamond", Georgia, serif;
    --sans: "Inter", system-ui, sans-serif;
    color-scheme: light dark;  /* checkboxes, dropdowns and scrollbars follow the page's light or dark colours */
}

@media (prefers-color-scheme: dark) {
    :root {
        --ink: #f2f2f3;
        --ink-soft: #a8a8b0;
        --paper: #121214;
        --paper-deep: #1c1c1f;
        --rule: #2c2c31;
        --gold: #e5484d;
        --gold-ink: #f0686c;  /* a lighter red, to read on the dark paper */
        --on-gold: #121214;
        --field: #1c1c1f;
        --danger: #f0a093;
        --danger-bg: #3a1f26;
        --win: #7fd49c;
        --caution: #e2b356;
        --mark-muted: #3a3a40;
        --board-frame: #000;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px rgba(0, 0, 0, 0.25);
        --shadow: 0 6px 16px rgba(0, 0, 0, 0.35), 0 18px 40px rgba(0, 0, 0, 0.3);
        --gold-tint: rgba(240, 104, 108, 0.12);
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
}

/* The hidden attribute always hides, even on elements whose own rules give them a display (flex, grid, ...);
   the scripts show and hide parts of the page with it. */
[hidden] {
    display: none !important;
}

/* Form controls use the page's font. Safari (and iPhones' other browsers) otherwise draw buttons and fields in
   the system font; their own styles below still set size and weight where they need to. */
button, input, select, textarea {
    font: inherit;
}

body {
    /* A soft gold glow behind the top of every page, over the plain paper. */
    background:
        radial-gradient(1200px 420px at 50% -120px, var(--gold-tint), transparent 70%) no-repeat,
        var(--paper);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: var(--ink);
    font-family: var(--sans);
    font-size: 1rem;
    line-height: 1.65;
    overflow-wrap: break-word;  /* a long web address or word wraps rather than widening the page on a phone */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1, h2, h3 {
    font-family: var(--serif);
    font-weight: 600;
    line-height: 1.15;
    margin: 0 0 0.5em;
}

h1 { font-size: clamp(2.4rem, 6vw, 3.8rem); letter-spacing: -0.01em; }
h2 { font-size: clamp(1.7rem, 3vw, 2.1rem); margin-top: 1.6em; letter-spacing: -0.005em; }

h1:focus {
    outline: none;
}

a {
    color: var(--gold-ink);
    text-underline-offset: 0.18em;
    text-decoration-thickness: 1px;
}

/* One clear focus ring for keyboard users, everywhere. */
:where(a, button, summary, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid var(--gold-soft);
    outline-offset: 2px;
}

.lede {
    font-size: clamp(1.1rem, 2vw, 1.25rem);
    line-height: 1.6;
    color: var(--ink-soft);
}

/* Layout */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 1rem clamp(1rem, 4vw, 3rem);
    border-bottom: 1px solid var(--rule);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--sans);
    font-size: 1.5rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    color: var(--ink);
    text-decoration: none;
}

.brand-mark {
    display: block;
    width: 2rem;
    height: 2rem;
}

.brand-square {
    fill: var(--gold);
}

.brand-square.muted {
    fill: var(--mark-muted);
}

.brand-hub {
    color: var(--gold-ink);
}

.site-header nav {
    display: flex;
    gap: 1.5rem;
}

.site-header nav a {
    color: var(--ink-soft);
    text-decoration: none;
    font-weight: 500;
    padding-bottom: 2px;
    border-bottom: 2px solid transparent;
}

.site-header nav a:hover,
.site-header nav a.active {
    color: var(--ink);
    border-bottom-color: var(--gold);
}

/* "Learn" dropdown: a native <details>, so it works without JavaScript. */
.nav-menu {
    position: relative;
}

.nav-menu summary {
    list-style: none;
    cursor: pointer;
    color: var(--ink-soft);
    font-weight: 500;
}

.nav-menu summary::-webkit-details-marker {
    display: none;
}

.nav-menu summary::after {
    content: " ▾";
    font-size: 0.8em;
}

.nav-menu[open] summary,
.nav-menu summary:hover {
    color: var(--ink);
}

.nav-menu-items {
    border-radius: var(--radius);
    position: absolute;
    top: calc(100% + 0.5rem);
    left: -1rem;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-width: 10rem;
    padding: 0.8rem 1rem;
    background: var(--paper);
    border: 1px solid var(--rule);
    box-shadow: var(--shadow);
}

.nav-menu-items a {
    width: fit-content;
}

/* "Endgames": the label is a link to its page; the submenu opens on hover or keyboard focus. */
.nav-hover-menu > a::after {
    content: " ▾";
    font-size: 0.8em;
}

.nav-hover-menu .nav-menu-items {
    display: none;
    min-width: 15rem;
}

.nav-hover-menu:hover .nav-menu-items,
.nav-hover-menu:focus-within .nav-menu-items {
    display: flex;
}

/* Bridges the gap between the label and the submenu, so moving the mouse down doesn't close it. */
.nav-hover-menu .nav-menu-items::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: -0.6rem;
    height: 0.6rem;
}

/* "Learn": three columns (openings, endgames, the rest), each under a heading; the first two link to their overview pages. */
.nav-columns .nav-menu-items {
    flex-direction: row;
    gap: 2rem;
    /* Wide, and near the right end of the menu bar: it opens leftwards so it stays on screen. */
    left: auto;
    right: -1rem;
}

.nav-menu-column {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.site-header nav .nav-menu-heading {
    font-weight: 600;
    color: var(--ink);
}

.nav-menu summary,
.site-header nav a,
.site-footer a {
    white-space: nowrap;
}

.site-footer a {
    display: inline-block;
    padding: 0.35rem 0.15rem;
}

/* Desktop: the header stays at the top, frosted over the page, and the menu items are soft pills. (Not on phones:
   the open menu there can be taller than the screen.) */
@media (min-width: 1101px) {
    .site-header {
        position: sticky;
        top: 0;
        z-index: 50;
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
        background: color-mix(in srgb, var(--paper) 82%, transparent);
        -webkit-backdrop-filter: saturate(1.4) blur(14px);
        backdrop-filter: saturate(1.4) blur(14px);
    }

    .site-header nav {
        gap: 0.15rem;
        align-items: center;
    }

    .site-header nav a,
    .nav-menu summary,
    .nav-signout button {
        display: block;
        padding: 0.4rem 0.8rem;
        border: none;
        border-radius: 999px;
        transition: background-color 0.15s, color 0.15s;
    }

    .site-header nav a:hover,
    .nav-menu summary:hover,
    .nav-menu[open] summary,
    .nav-signout button:hover {
        background: var(--gold-tint);
        color: var(--ink);
    }

    .site-header nav a.active {
        background: var(--ink);
        color: var(--paper);
    }

    .nav-menu-items {
        gap: 0.1rem;
        padding: 0.6rem;
    }

    .site-header .nav-menu-items a {
        padding: 0.35rem 0.7rem;
        border-radius: var(--radius-sm);
    }

    .site-header nav .nav-menu-items a.active {
        background: var(--gold-tint);
        color: var(--ink);
    }

    .site-header nav span.nav-menu-heading {
        padding: 0.35rem 0.7rem;
    }

    .nav-columns .nav-menu-items { gap: 1rem; }
    .nav-menu-column { gap: 0.1rem; }
}

/* Phones and tablets: the menu collapses behind a "Menu" button (site.js toggles it). */
.menu-button {
    display: none;
}

@media (max-width: 1100px) {
    .site-header {
        flex-wrap: wrap;
        row-gap: 0;
    }

    .menu-button {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.6rem 0.9rem;
        min-height: 44px;
        border: 1px solid var(--rule);
        border-radius: 999px;
        background: transparent;
        color: var(--ink);
        font: 500 1rem var(--sans);
        cursor: pointer;
    }

    .menu-icon,
    .menu-icon::before,
    .menu-icon::after {
        display: block;
        width: 18px;
        height: 2px;
        background: currentColor;
        position: relative;
        transition: transform 0.15s ease;
    }

    .menu-icon::before,
    .menu-icon::after {
        content: "";
        position: absolute;
    }

    .menu-icon::before { top: -6px; }
    .menu-icon::after { top: 6px; }

    .site-header.menu-open .menu-icon { background: transparent; }
    .site-header.menu-open .menu-icon::before { transform: translateY(6px) rotate(45deg); }
    .site-header.menu-open .menu-icon::after { transform: translateY(-6px) rotate(-45deg); }

    .site-header nav {
        display: none;
        flex-basis: 100%;
        flex-direction: column;
        gap: 0;
        margin-top: 0.75rem;
        border-top: 1px solid var(--rule);
    }

    .site-header.menu-open nav {
        display: flex;
    }

    /* Big, full-width tap targets. */
    .site-header nav a,
    .site-header nav span.nav-menu-heading,
    .nav-menu summary {
        display: flex;
        align-items: center;
        min-height: 48px;
        padding: 0 0.25rem;
        border-bottom: 1px solid var(--rule);
        font-size: 1.05rem;
    }

    .site-header nav a:hover,
    .site-header nav a.active {
        border-bottom-color: var(--rule);
        color: var(--gold-ink);
    }

    /* "Learn" opens inline inside the list rather than as a floating box. */
    .nav-menu-items {
        position: static;
        gap: 0;
        min-width: 0;
        padding: 0 0 0 1rem;
        border: none;
        box-shadow: none;
        background: transparent;
    }

    .nav-menu-items a {
        width: auto;
    }

    .nav-hover-menu .nav-menu-items {
        display: flex;
        min-width: 0;
    }

    .nav-columns .nav-menu-items {
        flex-direction: column;
        gap: 0;
    }

    .nav-menu-column {
        gap: 0;
    }

    .nav-hover-menu > a::after {
        content: none;
    }
}

.site-main {
    flex: 1;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: clamp(2rem, 6vw, 4rem) clamp(1rem, 4vw, 3rem);
}

.site-footer {
    border-top: 1px solid var(--rule);
    text-align: center;
    color: var(--ink-soft);
    font-size: 0.85rem;
    padding: 1.5rem 1rem;
}

.site-footer p {
    margin: 0;
}

/* Sign-out button in the header (a form, so it can't be a plain link) */
.nav-signout {
    display: contents;
}

.nav-signout button {
    background: none;
    border: none;
    padding: 0;
    font: 500 1rem var(--sans);
    color: var(--ink-soft);
    cursor: pointer;
    white-space: nowrap;
}

.nav-signout button:hover {
    color: var(--ink);
}

@media (max-width: 1100px) {
    .nav-signout button {
        min-height: 48px;
        text-align: left;
        padding: 0 0.25rem;
        font-size: 1.05rem;
    }
}

/* Blazor's own error bar (Layout/MainLayout.razor): hidden unless blazor.web.js shows it */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}
