﻿:root {
    color-scheme: dark;
    font-family: "Leelawadee UI", "Noto Sans Thai", Tahoma, sans-serif;
    color: #fff;
    background: #06042c;
    --pink: #f952dc;
    --surface: #331d85;
    --success: #fef06a;
    --warning: #f8c806;
    --error: #e34d47;
    --menu: url("public/assets/space/menu.webp");
    --game: url("public/assets/space/game.webp");
    --result: url("public/assets/space/result.webp");
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    background: radial-gradient(ellipse at 50% 64%, #331d85, #140a50 47%, #06042c 84%);
}

[hidden] {
    display: none !important;
}

.stage {
    --art: var(--menu);
    width: min(100vw, 56.25vh);
    width: min(100vw, 56.25dvh);
    aspect-ratio: 9 / 16;
    position: relative;
    isolation: isolate;
    container-type: inline-size;
    background: #140a50 var(--art) center / 100% 100% no-repeat;
    box-shadow: 0 0 80px #06042ca0;
}

.stage[data-screen="game"] {
    --art: var(--game);
}

.stage[data-screen="result"] {
    --art: var(--result);
}

.screen {
    position: absolute;
    inset: 0;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

button {
    font: inherit;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.art-button {
    position: absolute;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 999px;
    transition: background-color 150ms, box-shadow 150ms;
}

@media (hover: hover) {
    .art-button:hover {
        background-color: #fff2;
        box-shadow: 0 0 18px #f952dc88;
    }
}

.art-button:active {
    background-color: #fff3;
}

button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

.art-button[aria-disabled="true"] {
    cursor: wait;
}

.start { inset: 50.75% 30.4% 43.3%; }
.home { inset: 20.5% 86.1% 74.1% 4.5%; border-radius: 22%; }
.restart { inset: 20.5% 77.9% 74.1% 13.9%; border-radius: 22%; }
.replay { inset: 75.05% 23.65% 18.35%; }
.result-home { inset: 84.15% 27.7% 9.5% 28.7%; }

.menu-message,
.game-message,
.result-message {
    position: absolute;
    margin: 0;
    left: 5%;
    right: 5%;
    text-align: center;
    font-weight: 600;
    font-size: 3.65cqw;
    line-height: 1.2;
    text-shadow: 0 1px 5px #06042c;
}

.menu-message {
    top: 58%;
}

.score {
    position: absolute;
    top: 20.7%;
    left: 27%;
    width: 31%;
    min-height: 4.9%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.6cqw;
    padding: .45em;
    border: 1px solid #f6b9ff85;
    border-radius: 999px;
    background: #331d85e8;
    font-size: 3.7cqw;
    line-height: 1;
}

.score strong {
    font-size: 1.2em;
    color: var(--success);
}

.remaining {
    position: absolute;
    display: grid;
    place-items: center;
    top: 20.35%;
    left: 77%;
    width: 16.5%;
    height: 3.8%;
    font: 800 5.2cqw / 1 system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
}

.remaining[data-urgent] {
    color: var(--warning);
}

.remaining[data-urgent="expired"] {
    color: var(--error);
}

.board {
    position: absolute;
    top: 28.75%;
    left: 8%;
    right: 8%;
    display: grid;
    grid-template-columns: repeat(var(--card-columns), minmax(0, 1fr));
    gap: 3cqw 4.5cqw;
}

.card {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 1;
    min-width: 0;
    padding: 0;
    border: 0;
    border-radius: 8%;
    background: transparent;
    perspective: 70cqw;
}

.card-inner {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transition: transform 220ms ease;
}

.card[data-state="open"] .card-inner,
.card[data-state="matched"] .card-inner {
    transform: rotateY(180deg);
}

.card img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    backface-visibility: hidden;
    border-radius: inherit;
    pointer-events: none;
}

.card-front {
    transform: rotateY(180deg);
}

.card[data-state="matched"] {
    outline: 2px solid var(--success);
    outline-offset: 1px;
    box-shadow: 0 0 12px #fef06a75;
    cursor: default;
}

.card[data-state="matched"]:focus-visible {
    outline-color: #fff;
    outline-offset: 3px;
}

.card[aria-disabled="true"] {
    cursor: default;
}

.game-message {
    top: 92%;
}

.countdown {
    position: absolute;
    top: 53%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 29cqw;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border: 2px solid #fbbcf8;
    border-radius: 50%;
    background: radial-gradient(circle at 45% 24%, #771bab, #331d85 75%);
    box-shadow: 0 0 0 2cqw #140a508c, 0 0 9cqw var(--pink);
    color: #fff;
    font: 800 17cqw / 1 system-ui, sans-serif;
    pointer-events: none;
}

.result-count {
    position: absolute;
    top: 62%;
    left: 24%;
    width: 52%;
    height: 8.3%;
    display: grid;
    place-items: center;
    color: var(--success);
    font: 800 11cqw / 1 system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
}

.result-message {
    top: 71.8%;
}

@media (prefers-reduced-motion: reduce) {
    .art-button,
    .card-inner {
        transition: none;
    }
}
