:root {
    color-scheme: dark;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    --bg-a: #170d12;
    --bg-b: #2a1415;
    --bg-c: #553a2c;
    --ink: #f7f1e7;
    --muted: #ceb89a;
    --line: rgba(216, 162, 81, 0.3);
    --panel: rgba(26, 14, 18, 0.72);
    --panel-strong: rgba(35, 19, 19, 0.84);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(circle at 20% 14%, rgba(128, 49, 34, 0.26), transparent 32%),
        radial-gradient(circle at 80% 18%, rgba(111, 27, 47, 0.28), transparent 28%),
        linear-gradient(135deg, var(--bg-a), var(--bg-b) 48%, var(--bg-c));
}

body.is-won {
    overflow: hidden;
}

.home-back {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 20;
    display: inline-block;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid rgba(216, 162, 81, 0.52);
    background: rgba(35, 19, 19, 0.8);
    color: #f4d7a7;
    text-decoration: none;
    font-size: 14px;
    font-weight: 700;
}

.memo-shell {
    width: min(1720px, calc(100% - 24px));
    margin: 0 auto;
    padding: 72px 0 28px;
}

.memo-header {
    margin-bottom: 18px;
    padding: 18px 20px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--panel);
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.28);
    text-align: center;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    font-size: 12px;
}

.memo-header h1 {
    margin: 0;
    font-size: clamp(30px, 4vw, 52px);
    line-height: 1.05;
    color: #fff4df;
}

.memo-lead {
    margin: 10px 0 0;
    max-width: 64ch;
    margin-left: auto;
    margin-right: auto;
    color: #e1cfb1;
    font-size: 16px;
}

.memo-stats {
    margin-top: 14px;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
    color: #f0dcc0;
    font-weight: 650;
}

.memo-board {
    display: grid;
    grid-template-columns: repeat(6, clamp(96px, 11vw, 150px));
    gap: 12px;
    align-items: start;
    justify-content: center;
    width: max-content;
    min-width: 100%;
    margin: 0 auto;
}

.memo-card {
    position: relative;
    border: 0;
    padding: 0;
    background: transparent;
    aspect-ratio: 1 / 1;
    perspective: 1200px;
    cursor: pointer;
    animation: pop-in 420ms ease both;
    animation-delay: var(--delay, 0ms);
}

.memo-card__inner {
    position: relative;
    width: 100%;
    height: 100%;
    display: block;
    transform-style: preserve-3d;
    transition: transform 420ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

.memo-card.is-flipped .memo-card__inner,
.memo-card.is-matched .memo-card__inner {
    transform: rotateY(180deg);
}

.memo-card__face {
    position: absolute;
    inset: 0;
    border-radius: 16px;
    overflow: hidden;
    backface-visibility: hidden;
    border: 1px solid rgba(216, 162, 81, 0.42);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.28);
}

.memo-card__face--front {
    background: rgba(23, 13, 18, 0.95);
    transform: rotateY(180deg);
}

.memo-card__face--front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center top;
    display: block;
}

.memo-card__name {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 8px;
    padding: 6px 8px;
    border-radius: 999px;
    background: rgba(18, 10, 14, 0.72);
    color: #fff5e2;
    text-align: center;
    font-size: 11px;
    line-height: 1.2;
    font-weight: 750;
}

.memo-card__face--back {
    display: grid;
    place-items: center;
    overflow: hidden;
    background:
        radial-gradient(circle at 34% 28%, rgba(255, 239, 202, 0.12), transparent 40%),
        linear-gradient(180deg, rgba(52, 29, 26, 0.96), rgba(21, 11, 15, 0.98));
    transition: transform 360ms ease, box-shadow 240ms ease, border-color 240ms ease;
}

.memo-card__back-frame {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 16px;
    background: rgba(35, 19, 19, 0.55);
    box-shadow:
        0 28px 56px rgba(0, 0, 0, 0.58),
        0 0 0 1px rgba(111, 27, 47, 0.32);
    transition: transform 240ms ease, box-shadow 240ms ease, border-color 240ms ease;
}

.memo-card__back-frame::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: inset 0 0 0 1px rgba(255, 229, 177, 0.22);
    pointer-events: none;
}

.memo-card__back-frame img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    display: block;
    transition: transform 360ms ease, filter 260ms ease;
    filter: saturate(1.02) contrast(1.02);
}

.memo-card.is-flipped .memo-card__face--front img,
.memo-card.is-matched .memo-card__face--front img {
    object-fit: cover;
    object-position: center top;
}

.memo-card.is-matched {
    cursor: default;
}

.memo-card.is-matched .memo-card__face {
    border-color: rgba(240, 196, 113, 0.72);
}

.memo-card:hover .memo-card__face--back img,
.memo-card:focus-visible .memo-card__face--back img,
.memo-card.is-flipped .memo-card__face--back img {
    transform: scale(1.04);
    filter: saturate(1.06) contrast(1.04);
}

.memo-card:hover .memo-card__back-frame,
.memo-card:focus-visible .memo-card__back-frame,
.memo-card.is-flipped .memo-card__back-frame {
    transform: scale(1.04);
    box-shadow:
        0 34px 68px rgba(0, 0, 0, 0.62),
        0 0 0 1px rgba(216, 162, 81, 0.28);
}

.memo-card:focus-visible {
    outline: 2px solid rgba(240, 196, 113, 0.9);
    outline-offset: 2px;
    border-radius: 18px;
}

.win-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    background: rgba(18, 10, 14, 0.68);
    backdrop-filter: blur(8px);
}

.win-overlay[hidden] {
    display: none;
}

.win-overlay__card {
    position: relative;
    z-index: 1;
    width: min(92vw, 520px);
    padding: 28px 24px 24px;
    border-radius: 24px;
    border: 1px solid rgba(240, 196, 113, 0.5);
    background:
        radial-gradient(circle at top, rgba(255, 239, 202, 0.1), transparent 42%),
        rgba(28, 15, 18, 0.92);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
    text-align: center;
    animation: win-pop 420ms ease both;
}

.win-overlay__eyebrow {
    margin: 0;
    color: #f6dca7;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    font-size: 12px;
    font-weight: 800;
}

.win-overlay__title {
    margin: 10px 0 0;
    font-size: clamp(34px, 5vw, 56px);
    line-height: 1;
    color: #fff4df;
}

.win-overlay__text {
    margin: 12px 0 0;
    color: #e7d2af;
    font-size: 16px;
}

.win-overlay__button {
    margin-top: 18px;
    padding: 12px 18px;
    border: 1px solid rgba(240, 196, 113, 0.72);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(80, 38, 32, 0.96), rgba(40, 19, 22, 0.96));
    color: #fff3d8;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.win-overlay__particles {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

@keyframes win-pop {
    from {
        opacity: 0;
        transform: scale(0.94);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pop-in {
    from {
        transform: translateY(10px) scale(0.96);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@media (max-width: 760px) {
    .memo-shell {
        width: min(100% - 14px, 1720px);
        padding-top: 58px;
    }

    .memo-header {
        padding: 14px;
        border-radius: 16px;
    }

    .memo-board {
        grid-template-columns: repeat(6, 92px);
        gap: 8px;
        width: max-content;
        min-width: unset;
        overflow-x: auto;
        overflow-y: hidden;
        padding-bottom: 8px;
        justify-content: start;
        justify-items: stretch;
    }

    .memo-card {
        aspect-ratio: 1 / 1;
    }

    .memo-card__name {
        font-size: 10px;
        padding: 5px 6px;
    }
}

@media (min-width: 761px) and (max-width: 1200px) {
    .memo-board {
        grid-template-columns: repeat(6, clamp(84px, 9vw, 120px));
    }
}

@media (min-width: 1201px) and (max-width: 1500px) {
    .memo-board {
        grid-template-columns: repeat(6, clamp(92px, 10vw, 136px));
    }
}

@media (min-width: 1501px) and (max-width: 1780px) {
    .memo-board {
        grid-template-columns: repeat(6, clamp(96px, 10vw, 144px));
    }
}

@media (min-width: 1781px) {
    .memo-board {
        grid-template-columns: repeat(6, clamp(100px, 9.6vw, 150px));
    }
}
