:root {
    color-scheme: dark;
    --background: #141719;
    --surface: #1c2124;
    --line: #30383b;
    --text: #f4f7f6;
    --muted: #adb9ba;
    --accent: #a3e0ce;
    --accent-deep: #14352d;
    --board-max: 560px;
    font-family: "Avenir Next", Avenir, system-ui, sans-serif;
    background: var(--background);
    color: var(--text);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
}

[hidden] {
    display: none !important;
}

button {
    color: inherit;
    font: inherit;
    touch-action: manipulation;
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

.page-width {
    width: min(100% - 3rem, 1100px);
    margin-inline: auto;
}

.site-header {
    border-bottom: 1px solid var(--line);
}

.site-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    min-height: 4.25rem;
    font-weight: 650;
    letter-spacing: -0.025em;
}

.brand-icon {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2px;
    width: 1.5rem;
    aspect-ratio: 1;
}

.brand-icon span {
    border-radius: 2px;
    background: var(--accent);
}

.brand-icon span:last-child {
    border: 1px dashed var(--accent);
    background: transparent;
}

.hero {
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    align-items: center;
    gap: 2.5rem;
    margin-block: 2.5rem 2.75rem;
    min-height: 21.25rem;
}

.hero h1 {
    margin: 0;
    font-size: clamp(3rem, 7vw, 5.6rem);
    font-weight: 700;
    letter-spacing: -0.055em;
    line-height: 0.99;
    text-wrap: balance;
}

.hero h1 span {
    display: block;
    color: var(--accent);
}

.hero p {
    max-width: 25rem;
    margin: 1.45rem 0 0;
    color: var(--muted);
    font-size: clamp(1rem, 2vw, 1.2rem);
    line-height: 1.55;
}

.hero-art {
    display: grid;
    place-items: center;
    padding: 1.6rem;
    border: 1px solid var(--line);
    border-radius: 1.5rem;
    background:
        radial-gradient(ellipse at 50% 45%, #233a36, transparent 72%),
        #191e20;
}

.illustration {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
    width: min(100%, 16.75rem);
    aspect-ratio: 1;
}

.illustration span {
    overflow: hidden;
    border: 1px solid #a3e0ce28;
    border-radius: 0.65rem;
    background: #2c4c44;
}

.illustration span:nth-child(1) {
    background: radial-gradient(circle at 100% 100%, #b2e8d4 0 53%, #38564f 54%);
}

.illustration span:nth-child(2) {
    background: radial-gradient(circle at 0 100%, #83bea9 0 53%, #2f5148 54%);
}

.illustration span:nth-child(3) {
    background: linear-gradient(135deg, #649789 0 50%, #213b36 51%);
}

.illustration span:nth-child(4) {
    background: radial-gradient(circle at 100% 0, #78ac9d 0 53%, #344f49 54%);
}

.illustration span:nth-child(5) {
    background: radial-gradient(circle at 0 0, #c4ecdc 0 53%, #51796e 54%);
}

.illustration span:nth-child(6) {
    background: radial-gradient(circle at 100% 100%, #a3e0ce 0 67%, #3f675c 68%);
}

.illustration span:nth-child(7) {
    background: linear-gradient(135deg, #35574e 0 50%, #83bea9 51%);
}

.illustration span:nth-child(8) {
    background: radial-gradient(circle at 100% 0, #547e72 0 57%, #2b473f 58%);
}

.illustration span:last-child {
    border: 1px dashed #6a9a8c;
    background: #161f20;
}

.difficulty {
    padding-bottom: 2.5rem;
}

.difficulty h2 {
    margin: 0 0 1rem;
    font-size: 1.35rem;
    letter-spacing: -0.025em;
}

.difficulty-options {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
}

.difficulty-option {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 0.3rem;
    min-inline-size: 0;
    min-block-size: 9.25rem;
    padding: 1.1rem;
    border: 1px solid var(--line);
    border-radius: 1rem;
    background: var(--surface);
    text-align: start;
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease;
}

.difficulty-option[data-recommended] {
    border-color: #588a7d;
    background: #22332f;
}

.grid-icon {
    display: grid;
    grid-template-columns: repeat(var(--icon-size), 1fr);
    gap: 2px;
    width: 2rem;
    aspect-ratio: 1;
    margin-bottom: 0.4rem;
    color: var(--accent);
}

.grid-icon span {
    border-radius: 1px;
    background: currentColor;
    opacity: 0.7;
}

.grid-icon span:last-child {
    background: transparent;
    border: 1px solid currentColor;
    opacity: 0.52;
}

.difficulty-name {
    font-size: 1.1rem;
    font-weight: 700;
}

.difficulty-meta {
    color: var(--muted);
    font-size: 0.875rem;
}

.recommendation {
    position: absolute;
    inset-block-start: 1.15rem;
    inset-inline-end: 0.9rem;
    padding: 0.18rem 0.45rem;
    border-radius: 0.35rem;
    background: #324b42;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 650;
    line-height: 1.4;
}

.game {
    width: min(100%, var(--board-max), max(24rem, 100svh - 18.5rem));
    margin: 1.4rem auto 2.5rem;
}

.game h1 {
    margin: 0 0 0.9rem;
    font-size: clamp(1.65rem, 5vw, 2.25rem);
    letter-spacing: -0.055em;
    line-height: 1.15;
}

.game-stats,
.completion-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 0.8rem;
    background: var(--surface);
}

.game-stats > div,
.completion-stats > div {
    display: grid;
    gap: 0.15rem;
    padding: 0.55rem clamp(0.55rem, 3vw, 1rem);
}

.game-stats > div + div,
.completion-stats > div + div {
    border-inline-start: 1px solid var(--line);
}

dt {
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 500;
}

dd {
    margin: 0;
    font-size: clamp(1rem, 3vw, 1.25rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.board-frame {
    margin-block: 0.75rem;
    padding: 0.35rem;
    border: 1px solid var(--line);
    border-radius: 0.95rem;
    background: var(--surface);
}

.puzzle-board {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    overflow: hidden;
    isolation: isolate;
    border-radius: 0.6rem;
    background: #101416;
}

.piece,
.empty-position {
    position: absolute;
    inset: 0 auto auto 0;
    width: calc(100% / var(--grid-size));
    height: calc(100% / var(--grid-size));
}

.piece {
    display: block;
    z-index: 1;
    appearance: none;
    padding: 0;
    border: 0;
    border-radius: 0;
    background-color: #101416;
    background-image: var(--puzzle-image);
    background-repeat: no-repeat;
    background-size: var(--image-size);
    background-position: var(--image-position);
}

.piece::after,
.empty-position::after {
    content: "";
    position: absolute;
    inset: 0;
    border: 1px solid #101416a8;
    pointer-events: none;
}

.empty-position::after {
    inset: 4px;
    border: 1px dashed #597069;
    border-radius: 0.3rem;
}

.piece[aria-disabled="false"] {
    cursor: pointer;
}

.piece:focus-visible {
    z-index: 3;
    outline-offset: -4px;
}

.piece.is-sliding {
    z-index: 2;
}

.puzzle-board.is-revealing .empty-position {
    visibility: hidden;
}

.puzzle-board.is-revealing .piece::after {
    opacity: 0;
    transition: opacity 500ms ease;
}

.completed-image {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.game-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.action {
    min-height: 2.75rem;
    padding: 0.5rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: 0.55rem;
    background: var(--surface);
    font-size: 0.9rem;
    font-weight: 650;
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease;
}

.action-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-deep);
}

.action:disabled {
    opacity: 0.55;
    cursor: default;
}

.board-help,
.feedback {
    margin: 0.85rem 0 0;
    color: var(--muted);
    font-size: 0.875rem;
    line-height: 1.55;
}

.feedback:empty {
    margin: 0;
}

.feedback[data-error] {
    color: #ffb8ae;
}

.completion {
    display: grid;
    justify-items: start;
    gap: 0.85rem;
    margin-top: 1rem;
    padding: 1.05rem;
    border: 1px solid #588a7d;
    border-radius: 0.9rem;
    background: #22332f;
}

.completion h2 {
    margin: 0;
    font-size: 1.45rem;
    letter-spacing: -0.03em;
}

.completion-stats {
    width: 100%;
}

@media (hover: hover) {
    .difficulty-option:hover {
        border-color: var(--accent);
        background: #293d37;
    }

    .action:hover:not(:disabled) {
        border-color: #719286;
        background: #26332f;
    }

    .action-primary:hover:not(:disabled) {
        border-color: #c1eee0;
        background: #c1eee0;
    }

    .piece[aria-disabled="false"]:hover::after {
        border-color: #bdf9e0;
    }
}

@media (max-width: 900px) {
    .hero {
        min-height: auto;
    }
}

@media (max-width: 750px) {
    .difficulty-options {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 620px) {
    .page-width {
        width: calc(100% - 2rem);
    }

    .site-brand {
        min-height: 3.55rem;
    }

    .hero {
        grid-template-columns: 1fr;
        gap: 1.25rem;
        margin-block: 2rem 1.75rem;
    }

    .hero h1 {
        font-size: clamp(2.5rem, 9.5vw, 3.75rem);
    }

    .hero p {
        margin-top: 0.75rem;
    }

    .hero-art {
        padding: 0.9rem;
        border-radius: 1rem;
    }

    .illustration {
        width: 8.5rem;
        gap: 0.25rem;
    }

    .illustration span {
        border-radius: 0.35rem;
    }

    .difficulty-option {
        min-block-size: 7.5rem;
        padding: 0.75rem;
    }

    .recommendation {
        position: static;
        margin-top: 0.15rem;
    }

    .game {
        margin-top: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .difficulty-option,
    .action,
    .puzzle-board.is-revealing .piece::after {
        transition: none;
    }
}
