/* ══════════════════════════════════════
   ARTHUMAN WORKS — Stylesheet
   Single page, no scrolling, monochrome.
   Dark by default; body.light-mode inverts
   the palette and the background media.
   ══════════════════════════════════════ */

/* ── VARIABLES (RGB channels, so alpha can be applied) ── */

:root {
    --fg: 255 255 255;
    --bg: 0 0 0;
    --logo-top: 2rem;
}

.light-mode {
    --fg: 0 0 0;
    --bg: 255 255 255;
}

/* ── RESET ── */

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

html {
    font-size: 18px;
}

html,
body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    background: rgb(var(--bg));
    color: rgb(var(--fg));
    font-family: "EB Garamond", "Georgia", serif;
    line-height: 1.7;
    cursor: crosshair;
    transition:
        background-color 0.6s ease,
        color 0.6s ease;
}

::selection {
    background: rgb(var(--fg));
    color: rgb(var(--bg));
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}

:focus-visible {
    outline: 1px solid rgb(var(--fg));
    outline-offset: 4px;
}

/* ══════════════════════════════════════
   BACKGROUND LAYERS
   ══════════════════════════════════════ */

.bg-video,
.bg-image,
.bg-overlay,
.hex-grid,
.particle-canvas {
    position: fixed;
    inset: 0;
    pointer-events: none;
}

.bg-video {
    z-index: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: filter 0.6s ease;
}

/* Static portrait image, shown instead of the video on mobile */
.bg-image {
    z-index: 0;
    display: none;
    background: url("bgi.jpg") center / cover no-repeat;
    transition: filter 0.6s ease;
}

.light-mode .bg-video,
.light-mode .bg-image {
    filter: invert(1);
}

.bg-overlay {
    z-index: 1;
    background: rgb(var(--bg) / 0.6);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    transition: background-color 0.6s ease;
}

/* Hex grid, visible only in a soft circle around the cursor (js/hexgrid.js
   sets --mx/--my). The outer mask is the spotlight; ::before is the grid,
   drawn by masking a flat fill with a tiling hex outline. */
.hex-grid {
    z-index: 2;
    opacity: 0;
    transition: opacity 0.4s ease;
    --spot: radial-gradient(
        circle 150px at var(--mx, -999px) var(--my, -999px),
        black,
        rgb(0 0 0 / 0.5) 45%,
        transparent
    );
    -webkit-mask-image: var(--spot);
    mask-image: var(--spot);
}

.hex-grid.visible {
    opacity: 1;
}

.hex-grid::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgb(var(--fg) / 0.28);
    --hex: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 123 71.014'%3E%3Cpath d='M0 35.507 20.5 0h41L82 35.507 61.5 71.014h-41zM82 35.507h41' fill='none' stroke='black'/%3E%3C/svg%3E");
    -webkit-mask: var(--hex) 0 0 / 123px 71.014px;
    mask: var(--hex) 0 0 / 123px 71.014px;
}

.particle-canvas {
    z-index: 3;
}

/* ══════════════════════════════════════
   LOGO — top center, opens the maze
   ══════════════════════════════════════ */

.logo {
    position: fixed;
    top: var(--logo-top);
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.logo button {
    pointer-events: auto;
    animation: bleed-in 2.5s ease 0.3s both;
}

.logo img {
    display: block;
    width: 470px;
    max-width: calc(100vw - 3rem);
    height: auto;
    opacity: 0.5;
    transition:
        opacity 0.3s ease,
        filter 0.6s ease;
}

.logo button:hover img {
    opacity: 0.8;
}

.light-mode .logo img {
    filter: invert(1);
}

/* ══════════════════════════════════════
   PANEL — floating tabs, center-right
   ══════════════════════════════════════ */

.panel {
    position: fixed;
    top: 50%;
    left: 75%;
    z-index: 10;
    width: min(30rem, 40vw);
    transform: translate(-50%, -50%);
    text-shadow: 0 0 1em rgb(var(--bg) / 0.6);
}

.tabs {
    position: relative;
    display: flex;
    gap: 2.2rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.95rem; /* room for the tab line's heartbeat */
    animation: bleed-in 2.5s ease 1s both;
}

.tab {
    padding: 0.3rem 0;
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    opacity: 0.45;
    transition: opacity 0.4s ease;
}

.tab:hover,
.tab[aria-selected="true"] {
    opacity: 1;
}

/* Underline, drawn as a path so it can show a beat while it extends;
   js/tabs.js springs its edges from tab to tab. The baseline sits 6px
   down the 12px box, i.e. 1px above the bottom of the tabs. */
.tab-line {
    position: absolute;
    bottom: -5px;
    left: 0;
    height: 12px;
    overflow: visible;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Panels share one grid cell, so the box keeps its size between tabs */
.tab-panels {
    display: grid;
    animation: bleed-in 2.5s ease 1.6s both;
}

.tab-panel {
    grid-area: 1 / 1;
    font-size: clamp(0.85rem, 0.6rem + 1.2vh, 1.05rem);
    opacity: 0;
    visibility: hidden;
    filter: blur(4px);
    transform: translateY(0.4rem);
    transition:
        opacity 0.4s ease,
        filter 0.4s ease,
        transform 0.4s ease,
        visibility 0s 0.4s;
}

.tab-panel.active {
    opacity: 1;
    visibility: visible;
    filter: blur(0);
    transform: none;
    transition:
        opacity 0.8s ease 0.3s,
        filter 0.8s ease 0.3s,
        transform 0.8s ease 0.3s;
}

.tab-panel p + p {
    margin-top: 0.8em;
}

.def-word {
    line-height: 1.3;
}

.def-word strong {
    margin-right: 0.2em;
    font-size: 1.45em;
    font-weight: 500;
}

.def-pron,
.tab-panel .def-pos {
    color: rgb(var(--fg) / 0.65);
}

.tab-panel .def-pos {
    margin-top: 0.2em;
    font-style: italic;
}

/* ══════════════════════════════════════
   BAR — socials + copyright, toggles
   ══════════════════════════════════════ */

.bar {
    position: fixed;
    left: 2rem;
    right: 2rem;
    bottom: 1.8rem;
    z-index: 10;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "socials controls"
        "copyright controls";
    align-items: end;
    gap: 0.6rem 1rem;
}

.socials,
.copyright,
.controls {
    animation: bleed-in 2s ease 2.2s both;
}

.socials {
    grid-area: socials;
    display: flex;
    gap: 0.9rem;
}

.socials a {
    display: flex;
    color: inherit;
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.socials a:hover {
    opacity: 1;
}

.socials svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
}

.copyright {
    grid-area: copyright;
    font-size: 0.55rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: rgb(var(--fg) / 0.5);
    transition: color 0.6s ease;
}

.controls {
    grid-area: controls;
    display: flex;
    gap: 0.6rem;
}

/* ── Toggle buttons: music, language, theme ── */

.toggle-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid currentColor;
    border-radius: 50%;
    opacity: 0.5;
    transition: opacity 0.3s ease;
}

.toggle-btn:hover,
.music-btn[aria-pressed="true"] {
    opacity: 1;
}

.toggle-btn svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.lang-label {
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.1em;
    line-height: 1;
}

.icon-sun,
.light-mode .icon-moon {
    display: none;
}

.light-mode .icon-sun {
    display: block;
}

/* ══════════════════════════════════════
   MAZE GAME POP-UP (js/maze.js)
   No backdrop: only the maze is drawn,
   and the page UI steps aside meanwhile
   ══════════════════════════════════════ */

/* Visibility flips at once when showing (so focus can land) and only after
   the fade when hiding */
.logo,
.panel,
.bar {
    transition: opacity 0.6s ease;
}

.game-open .logo,
.game-open .panel,
.game-open .bar {
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.6s ease,
        visibility 0s 0.6s;
}

.game {
    position: fixed;
    inset: 0;
    z-index: 20;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.5s ease,
        visibility 0s 0.5s;
}

.game.open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.5s ease;
}

.game:focus {
    outline: none;
}

.game-stage {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    transition: filter 0.6s ease;
}

.light-mode #game-canvas {
    filter: invert(1);
}

.game-close {
    position: absolute;
    top: 2rem;
    right: 2rem;
    pointer-events: auto;
}

.game-legend {
    position: absolute;
    bottom: 1.8rem;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: rgb(var(--fg) / 0.6);
}

.game-legend kbd {
    min-width: 1.9em;
    padding: 0.1em 0.4em;
    border: 1px solid rgb(var(--fg) / 0.3);
    border-radius: 3px;
    font-family: inherit;
    text-align: center;
}

.cat-dot {
    width: 7px;
    height: 7px;
    margin: 0 0.25rem 0 1.2rem;
    border: 1px solid currentColor;
    border-radius: 50%;
}

.cat-dot:first-child {
    margin-left: 0;
}

.cat-dot.white {
    background: currentColor;
}

/* Touch D-pads, hidden on desktop */
.touch-dpad {
    display: none;
}

@media (pointer: coarse) and (hover: none) {
    .game-legend {
        display: none;
    }

    .touch-dpad {
        position: absolute;
        top: 50%;
        z-index: 1;
        display: grid;
        grid-template-areas:
            ". up ."
            "left . right"
            ". down .";
        grid-template-columns: 52px 52px 52px;
        grid-template-rows: 52px 52px 52px;
        gap: 5px;
        transform: translateY(-50%);
        pointer-events: auto;
    }

    #touch-p1 {
        left: calc(18px + 10%);
    }

    #touch-p2 {
        right: calc(18px + 10%);
    }

    .dpad-up {
        grid-area: up;
    }

    .dpad-left {
        grid-area: left;
    }

    .dpad-right {
        grid-area: right;
    }

    .dpad-down {
        grid-area: down;
    }

    .dpad-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.3rem;
        color: rgb(var(--fg) / 0.65);
        background: rgb(var(--fg) / 0.07);
        border: 1px solid rgb(var(--fg) / 0.18);
        border-radius: 6px;
        user-select: none;
        -webkit-user-select: none;
        touch-action: manipulation;
        transition: background 0.08s ease;
    }

    .dpad-btn:active {
        background: rgb(var(--fg) / 0.22);
        border-color: rgb(var(--fg) / 0.4);
    }
}

/* Portrait touch screens: rotate the stage to fake landscape */
@media (pointer: coarse) and (hover: none) and (orientation: portrait) {
    .game-stage {
        width: 100vh;
        height: 100vw;
        top: calc(50% - 50vw);
        left: calc(50% - 50vh);
        transform: rotate(90deg);
    }
}

/* ══════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════ */

@keyframes bleed-in {
    from {
        opacity: 0;
        filter: blur(3px);
    }
    to {
        opacity: 1;
        filter: blur(0);
    }
}

/* ══════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════ */

/* Mobile — keep in sync with MOBILE_QUERY in js/app.js */
@media (max-width: 768px), (hover: none) and (pointer: coarse) {
    .bg-video {
        display: none;
    }

    .bg-image {
        display: block;
    }

    .bg-overlay {
        background: rgb(var(--bg) / 0.4);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }

    .hex-grid {
        display: none;
    }

    .panel {
        left: 50%;
        width: min(26rem, calc(100vw - 3rem));
    }

    .tabs {
        justify-content: center;
    }

    /* Footer stacks, centered: socials, copyright, toggles */
    .bar {
        grid-template-columns: auto;
        grid-template-areas:
            "socials"
            "copyright"
            "controls";
        justify-items: center;
    }

    .copyright {
        text-align: center;
    }
}

@media (max-width: 600px) {
    :root {
        --logo-top: 1.4rem;
    }

    html {
        font-size: 16px;
    }

    .bar {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
    }

    .toggle-btn {
        width: 31px;
        height: 31px;
    }

    .game-close {
        top: 1rem;
        right: 1rem;
    }
}

/* Short screens (e.g. phones in landscape) */
@media (max-height: 500px) {
    :root {
        --logo-top: 1rem;
    }

    .bar {
        bottom: 1rem;
    }

    .tabs {
        margin-bottom: 0.45rem;
    }

    .tab-panel {
        line-height: 1.5;
    }
}

/* Short mobile screens (phones in landscape): make room for the stacked
   footer with phone-sized type and a wider panel, centered between the
   logo and the footer */
@media (max-height: 500px) and (max-width: 768px),
    (max-height: 500px) and (hover: none) and (pointer: coarse) {
    html {
        font-size: 16px;
    }

    .panel {
        top: 47%;
        width: min(34rem, calc(100vw - 3rem));
    }

    .bar {
        row-gap: 0.3rem;
    }
}
