/* ==========================================================================
   overplus.ca - site.css
   Palette plus the lockup, hero, definition box and Flip puzzle.
   Shared styles are in core/core.css (loads first).
   ========================================================================== */

/* TOKENS -------------------------------------------------------------------*/
:root {
    /* brand colours, also in logo/overplus_logo.py, core/core.css and joeyvilleneuve.ca/site.css */
    --ink: #1C1A17;
    --paper: #E9E6DF;
    --red: #FC0345;
    --accent: var(--red);
    --accent-strong: var(--accent);   /* red is already 3:1 on paper */

    /* light (default) */
    --ground: var(--paper);
    --figure: var(--ink);
    --muted: #57524A;          /* secondary text, 6.2:1 on paper */
    --rule: #C0B9AB;           /* decorative hairlines */
    --line: #7E776B;           /* control outlines and link underlines, 3.6:1 on paper */
    --raised: #F5F3EE;         /* panels, cards, footer */
    --media: #DDD8CE;          /* behind posters and video */
    --slot: #DDD8CE;           /* empty Flip tile */
    --grain-blend: multiply;
    --grain-opacity: 0.22;

    --serif: "Newsreader", "Iowan Old Style", Georgia, serif;

    color-scheme: light;
}

:root[data-theme="dark"] {
    --ground: var(--ink);
    --figure: var(--paper);
    --muted: #A39C90;          /* 6.4:1 on ink */
    --rule: #3A3631;
    --line: #716B61;           /* 3.3:1 on ink */
    --raised: #24211D;
    --media: #141210;
    --slot: #35312B;
    --grain-blend: screen;
    --grain-opacity: 0.05;
    color-scheme: dark;
}

/* centre the hero vertically when there's extra space (no projects yet, tall screen) */
main:has(> .hero) {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* hardcoded, ::backdrop doesn't reliably inherit custom properties */
.modal::backdrop {
    background: rgba(28, 26, 23, 0.6);
}

/* footer link to joeyvilleneuve.ca, styled like a nav link */
.footer__sibling {
    display: inline-block;
}

/* LOCKUP -------------------------------------------------------------------*/
.lockup {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    color: inherit;
    text-decoration: none;
}
.lockup span {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.015em;
}

/* HERO ---------------------------------------------------------------------*/
.hero {
    padding-block: clamp(2.5rem, 8vh, 5.5rem) clamp(1rem, 3vh, 2.5rem);
}
.hero .wrap {
    container-type: inline-size;
}

/* the wordmark below finishes this sentence */
.lede {
    max-width: 28ch;
    margin: 0 0 clamp(0.5rem, 1.5vh, 1rem);
    font-size: clamp(1.35rem, 1rem + 1.35vw, 2.1rem);
    font-weight: 500;
    line-height: 1.28;
    letter-spacing: -0.02em;
    animation: rise 0.9s var(--ease) backwards;
}

/* one font-size scales the mark and the word together, cqi sizes it to the column */
.hero__lockup {
    display: flex;
    align-items: center;
    gap: 0.19em;
    font-size: clamp(3rem, 15vw, 14rem);
    font-size: clamp(3rem, 18.6cqi, 14rem);  /* ~full column width */
    animation: rise 0.9s 0.12s var(--ease) backwards;
}
.hero__lockup h1 {
    margin: 0;
    font-size: 1em;
    font-weight: 800;
    letter-spacing: -0.045em;
    line-height: 0.9;
}

/* the big mark is a button that opens Flip */
.hero__mark {
    flex: none;
    display: block;
    width: 0.96em;
    height: 0.96em;
    margin: 0;
    padding: 0;
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
    transition: transform 0.35s var(--ease);
}
.hero__mark .mark {
    width: 100%;
    height: 100%;
}
.hero__mark:active {
    transform: scale(0.97);
}
.hero__mark:focus-visible {
    outline-offset: 0.05em;
}

.hero__row {
    --panel-pad: clamp(1.4rem, 2.6vw, 2.1rem);
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.85fr);
    gap: clamp(2rem, 6vw, 6rem);
    align-items: start;
    margin-top: clamp(1.75rem, 4.5vh, 3rem);
    padding-top: clamp(1.5rem, 3.5vh, 2.25rem);
    border-top: 1px solid var(--rule);
}
/* top padding lines it up with the text inside the definition box */
.hero__about {
    max-width: 44ch;
    margin: 0;
    padding-top: calc(var(--panel-pad) + 1px);
    font-size: clamp(1.05rem, 0.95rem + 0.4vw, 1.25rem);
    color: var(--muted);
    animation: rise 0.9s 0.18s var(--ease) backwards;
}
.hero__about .text-link {
    color: var(--figure);
}

/* DEFINITION ---------------------------------------------------------------*/
.definition {
    padding: var(--panel-pad);
    animation: rise 0.9s 0.24s var(--ease) backwards;
}
.definition p {
    margin: 0;
}
.definition .kicker {
    margin-bottom: 1.1rem;
}
.definition__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.2rem 0.65rem;
}
.definition dfn {
    font-family: var(--serif);
    font-style: normal;
    font-size: 1.65rem;
    font-weight: 600;
    line-height: 1.1;
}
.definition .pos {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.1rem;
    color: var(--muted);
}
.definition .pron {
    margin-top: 0.35rem;
    font-family: var(--mono);
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    color: var(--muted);
}
.definition .definition__body {
    margin-top: 1rem;
    font-family: var(--serif);
    font-size: clamp(1.3rem, 1.1rem + 0.55vw, 1.6rem);
    font-weight: 500;
    line-height: 1.4;
}

/* FLIP PUZZLE --------------------------------------------------------------*/
.flip {
    width: min(100% - 2 * var(--gutter), 56rem);
    max-width: none;
    max-height: calc(100% - 2rem);
    margin: auto;
    padding: 0;
    color: var(--figure);
    overflow: auto;
    overscroll-behavior: contain;
}
/* hardcoded, same reason as .modal::backdrop */
.flip::backdrop {
    background: rgba(28, 26, 23, 0.45);
}
.flip[open] {
    animation: sheet-in 0.4s var(--ease);
}
.flip[open]::backdrop {
    animation: fade-in 0.4s ease;
}

.flip__inner {
    padding: clamp(1.25rem, 3.5vw, 2.75rem);
}
.flip__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.flip__layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "intro board" "play board";
    align-items: start;
    gap: 1.5rem clamp(1.75rem, 4vw, 3.5rem);
    margin-top: clamp(1rem, 2.5vw, 1.75rem);
}
.flip__intro {
    grid-area: intro;
}
.flip__play {
    grid-area: play;
}
.flip h2 {
    margin: 0 0 0.9rem;
    font-size: clamp(2.5rem, 1.8rem + 2.6vw, 4rem);
    font-weight: 800;
    letter-spacing: -0.05em;
    line-height: 0.9;
}
.flip__intro p {
    margin: 0;
    max-width: 40ch;
}

.flip__stats {
    display: flex;
    gap: clamp(1.5rem, 4vw, 3rem);
    margin: 0;
}
.flip__stats div {
    min-width: 4.5rem;
}
.flip__stats dd {
    margin: 0.35rem 0 0;
    font-size: clamp(2.25rem, 1.8rem + 1.5vw, 3rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}
.flip__status {
    min-height: 1.6em;
    margin: 1.25rem 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}
.flip__status.is-win {
    color: var(--figure);
    font-weight: 600;
}
.flip__controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1.25rem;
}

/* 5x5 board using the logo's 26:4 tile to gap ratio (5 tiles + 4 gaps = 146 units) */
.flip__stage {
    position: relative;
    grid-area: board;
    align-self: center;
    width: min(100%, 24rem);
    margin-inline: auto;
    container-type: inline-size;
}
.flip__board {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    gap: calc(100cqi * 4 / 146);
    perspective: 800px;
    touch-action: manipulation;
}
.tile {
    position: relative;
    aspect-ratio: 1;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: var(--slot);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    /* swap colour halfway through the flip, when the tile is edge-on */
    transition: background-color 0s linear calc(var(--d, 0ms) + 90ms), box-shadow 0.15s;
}
.tile.is-on {
    background: var(--figure);
}
.tile.is-flipping {
    animation: tile-flip 0.18s var(--d, 0ms) ease-in-out;
}
@keyframes tile-flip {
    50% { transform: rotateY(90deg); }
}

/* outline the tiles a press would flip */
.tile.is-near {
    box-shadow: inset 0 0 0 1px var(--red);
}
.tile.is-aim {
    box-shadow: inset 0 0 0 2px var(--red);
}
.tile.is-hint {
    animation: tile-hint 0.6s ease-in-out 3;
}
@keyframes tile-hint {
    50% { box-shadow: inset 0 0 0 5px var(--red); }
}
.tile:focus-visible {
    outline: 2px solid var(--figure);
    outline-offset: 2px;
    z-index: 1;
}

/* dashed goal outline drawn through the gaps. dashoffset makes the dashes wrap the corners evenly */
.flip__target {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
    transition: opacity 0.4s ease;
}
.flip__target path {
    fill: none;
    stroke: var(--figure);
    stroke-width: 0.6;
    stroke-dasharray: 3 2;
    stroke-dashoffset: 1.5;
    opacity: 0.55;
}

/* solved: tiles outside the mark fade out (site.js staggers --f from the centre), then the accent tile fills red */
.is-solved .tile {
    cursor: default;
    transition:
        background-color 0s linear calc(var(--d, 0ms) + 90ms),
        opacity 0.5s ease calc(var(--f, 0ms) + 250ms),
        transform 0.6s var(--ease) calc(var(--f, 0ms) + 250ms);
}
.is-solved .tile:not(.is-on) {
    opacity: 0;
    transform: scale(0.6);
}
.is-solved .flip__target {
    opacity: 0;
    transition-delay: 0.2s;
}

/* red fill grows out from the centre */
.tile::before {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--red);
    clip-path: inset(50%);
}
.tile.is-accent::before {
    clip-path: inset(0);
    transition: clip-path 0.75s cubic-bezier(0.4, 0, 0.2, 1) 0.65s;
}

/* RESPONSIVE ---------------------------------------------------------------*/
@media (max-width: 860px) {
    /* stacked, with equal space above and below the rule */
    .hero__row {
        grid-template-columns: minmax(0, 1fr);
        row-gap: 1.5rem;
        margin-top: clamp(1.5rem, 3.5vh, 3rem);
    }
    .hero__about {
        padding-top: 0;
    }
    .definition {
        max-width: 34rem;
    }
}

@media (max-width: 760px) {
    .flip__layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: "intro" "board" "play";
    }
}
