:root {
    color-scheme: light;
    --page: #f6f1e8;
    --surface: #fffdf8;
    --surface-quiet: #eee5d8;
    --ink: #26221e;
    --muted: #71685f;
    --accent: #a64f2f;
    --copy: #71685f;
    --soft: #eee5d8;
    --warm-soft: #eee5d8;
    --board: #ded1c1;
    --cell: rgba(255, 253, 248, 0.58);
    --focus: #1e6651;
    --max: 1200px;
    --header-height: 128px;
}

[data-theme="dark"] {
    color-scheme: dark;
    --page: #1e1b18;
    --surface: #28231f;
    --surface-quiet: #352e28;
    --ink: #f8f1e7;
    --muted: #c1b4a6;
    --accent: #ed9a70;
    --copy: #c1b4a6;
    --soft: #352e28;
    --warm-soft: #352e28;
    --board: #3d342c;
    --cell: rgba(255, 250, 242, 0.08);
    --focus: #83d2b7;
}

.variant-doge {
    --level-sprite: url("../images/variants/doge/level-sprites.jpg");
}
.variant-princess {
    --page: #faf3f0;
    --surface: #fffaf4;
    --surface-quiet: #eee0e5;
    --ink: #30252e;
    --muted: #766972;
    --accent: #8d4161;
    --copy: #766972;
    --soft: #eee0e5;
    --warm-soft: #eee0e5;
    --board: #dfd1d7;
    --cell: rgba(255, 250, 244, 0.6);
    --focus: #6e3450;
    --level-sprite: url("../images/variants/princess/level-sprites.jpg");
}
[data-theme="dark"] .variant-princess {
    --page: #211a20;
    --surface: #2c222a;
    --surface-quiet: #3a2d36;
    --ink: #fbf0f5;
    --muted: #cbb9c3;
    --accent: #eda6c2;
    --copy: #cbb9c3;
    --soft: #3a2d36;
    --warm-soft: #3a2d36;
    --board: #42343d;
    --cell: rgba(255, 250, 244, 0.08);
    --focus: #deb0c2;
}

html {
    scroll-padding-top: calc(var(--header-height) + 28px);
}
body {
    background: var(--page);
    color: var(--ink);
    line-height: 1.6;
}
.icon-button {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}
.icon-button:hover {
    background: var(--surface-quiet);
}
.icon-button:disabled {
    opacity: 0.34;
    cursor: not-allowed;
}
.icon-button svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
main {
    display: block;
    width: min(var(--max), calc(100% - (var(--page-gutter) * 2)));
    max-width: var(--max);
    margin: 128px auto 0;
    padding: 0;
}
.variant-hero,
.game-section,
.content-section {
    width: 100%;
    max-width: none;
    margin: 0 0 var(--section-gap);
    padding: clamp(36px, 6vw, 72px);
    border-radius: 32px;
    background: var(--surface);
}
.variant-hero {
    padding-block: clamp(44px, 7vw, 72px);
    text-align: center;
}
.variant-hero .hero-content {
    max-width: 860px;
}
.variant-hero .hero-subtitle {
    max-width: 760px;
}
.variant-hero .text-link {
    margin-top: 20px;
}
.eyebrow {
    margin: 0 0 12px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    line-height: 1.3;
    text-transform: uppercase;
}
h1,
h2,
h3,
p {
    margin-top: 0;
}
.variant-hero h1 {
    max-width: 800px;
    margin: 0 auto 20px;
    font-size: clamp(38px, 5vw, 56px);
    line-height: 1.08;
    letter-spacing: -0.03em;
}
.text-link {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    min-height: 44px;
    color: var(--accent);
    font-weight: 750;
    text-underline-offset: 5px;
}

.game-section,
.content-section {
    scroll-margin-top: calc(var(--header-height) + 28px);
    padding-block: clamp(56px, 8vw, 96px);
}
.section-heading {
    display: grid;
    grid-template-columns: minmax(0, 0.9fr) minmax(280px, 0.72fr);
    align-items: end;
    gap: 48px;
    margin-bottom: 40px;
}
.section-heading h2 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.7rem);
    line-height: 1;
    letter-spacing: -0.045em;
}
.section-heading > p {
    margin: 0;
    color: var(--muted);
}
.compact-heading {
    align-items: center;
}
.compact-heading > p {
    justify-self: end;
    text-align: right;
}
.play-layout {
    display: grid;
    grid-template-columns: minmax(0, 720px) minmax(260px, 1fr);
    gap: clamp(28px, 5vw, 64px);
    align-items: start;
}
.play-panel {
    width: auto;
    min-width: 0;
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
}
.score-strip {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    margin: 0 0 16px;
    padding: 0;
    background: var(--surface-quiet);
}
.score-strip div {
    min-width: 0;
    display: grid;
    place-items: center;
    align-content: center;
    min-height: 72px;
    padding: 10px;
    text-align: center;
}
.score-strip dt {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 750;
    letter-spacing: 0.1em;
    line-height: 1.2;
    text-transform: uppercase;
}
.score-strip dd {
    display: flex;
    align-items: baseline;
    justify-content: center;
    min-height: 30px;
    margin: 2px 0 0;
    font-size: 1.25rem;
    font-weight: 850;
    font-variant-numeric: tabular-nums;
}
#score-addition {
    color: var(--accent);
    font-size: 0.76rem;
    margin-left: 5px;
    opacity: 0;
    transform: translateY(5px);
}
#score-addition.is-visible {
    animation: score-in 0.55s ease;
}
@keyframes score-in {
    25% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-10px);
    }
}
.game-shell {
    position: relative;
}
.game-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: row;
    width: fit-content;
    gap: 8px;
    padding: 4px;
    margin: 0 auto 12px;
    border-radius: 28px;
    background: var(--soft);
    position: static;
    opacity: 1;
    pointer-events: auto;
    transform: none;
}
.game-board {
    position: relative;
    width: 100%;
    max-width: none;
    aspect-ratio: 1;
    padding: clamp(8px, 2%, 14px);
    overflow: hidden;
    background: var(--board);
    touch-action: none;
    user-select: none;
}
.board-grid,
.tile-layer {
    position: absolute;
    inset: clamp(8px, 2%, 14px);
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: clamp(6px, 1.6%, 12px);
}
.board-grid span {
    background: var(--cell);
}
.game-tile {
    position: relative;
    z-index: 2;
    display: grid;
    overflow: hidden;
    background: #fffdf8;
    transform: translate(var(--slide-x, 0), var(--slide-y, 0));
    transition: transform 145ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.game-tile.is-new {
    animation: appear 0.16s ease-out;
}
.game-tile.is-merged {
    animation: merge 0.2s ease-out;
}
.game-tile.is-sliding {
    transform: translate(var(--slide-x, 0), var(--slide-y, 0));
}
.game-tile:not(.is-sliding) {
    transform: none;
}
@keyframes appear {
    from {
        opacity: 0;
        transform: scale(0.78);
    }
}
@keyframes merge {
    45% {
        transform: scale(1.07);
    }
}
.level-art {
    display: block;
    background-image: var(--level-sprite);
    background-size: 400% 400%;
    background-position: var(--sprite-x, 0) var(--sprite-y, 0);
    background-repeat: no-repeat;
}
.game-tile__art {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.game-tile__value {
    position: absolute;
    right: 6px;
    bottom: 5px;
    min-width: 26px;
    padding: 2px 5px;
    background: rgba(255, 255, 255, 0.82);
    color: #2b241e;
    font-size: clamp(0.62rem, 2.4vw, 0.88rem);
    font-weight: 900;
    line-height: 1.3;
    text-align: center;
}
.board-help {
    margin: 14px auto 0;
    max-width: 580px;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}
.progress-panel {
    position: sticky;
    top: calc(var(--header-height) + 28px);
    display: block;
    width: auto;
    margin: 0;
    padding: 8px 0 0;
    border-radius: 0;
    background: transparent;
}
.current-level {
    display: grid;
    grid-template-columns: 112px 1fr;
    gap: 20px;
    align-items: center;
    margin: 18px 0 28px;
}
.current-art {
    width: 112px;
    aspect-ratio: 1;
    background-color: #fffdf8;
}
.current-level strong {
    display: block;
    color: var(--accent);
    font-size: 0.92rem;
    font-variant-numeric: tabular-nums;
}
.current-level h2 {
    margin: 2px 0 0;
    font-size: clamp(1.45rem, 3vw, 2.25rem);
    line-height: 1.05;
    letter-spacing: -0.04em;
}
.next-goal {
    padding: 22px;
    background: var(--surface-quiet);
}
.next-goal h3 {
    margin-bottom: 12px;
    font-size: 0.76rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
.next-goal p {
    margin-bottom: 6px;
}
.next-goal p:last-child,
.progress-note {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.9rem;
}
.next-goal strong {
    color: var(--accent);
    font-size: 1.25rem;
    margin-right: 6px;
}
.progress-note {
    margin-top: 16px;
}

.level-track {
    display: grid;
    grid-template-columns: repeat(13, minmax(78px, 1fr));
    gap: 12px;
    margin: 0;
    padding: 0 0 10px;
    overflow-x: auto;
    list-style: none;
    scrollbar-width: thin;
}
.level-track li {
    min-width: 0;
}
.track-art {
    width: 100%;
    aspect-ratio: 1;
    background-color: #fffdf8;
}
.track-meta {
    display: flex;
    gap: 5px;
    align-items: baseline;
    justify-content: center;
    margin-top: 8px;
    white-space: nowrap;
}
.track-meta strong {
    color: var(--accent);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}
.track-meta span {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.72rem;
    text-overflow: ellipsis;
}
.level-track li:not(.is-reached) .track-art {
    filter: grayscale(1);
    opacity: 0.28;
}
.level-track li.is-current .track-meta span {
    color: var(--ink);
    font-weight: 800;
}
.guide-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(28px, 4vw, 56px);
    margin-bottom: 56px;
}
.guide-grid article > span {
    display: block;
    margin-bottom: 24px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 850;
}
.guide-grid h3 {
    margin-bottom: 8px;
    font-size: 1.25rem;
}
.guide-grid p {
    margin: 0;
    color: var(--muted);
}
.faq-list {
    max-width: 820px;
}
.faq-list details {
    padding: 22px 0;
}
.faq-list summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    font-weight: 780;
    cursor: pointer;
    list-style: none;
}
.faq-list summary::-webkit-details-marker {
    display: none;
}
.faq-list summary::after {
    content: "+";
    color: var(--accent);
    font-size: 1.5rem;
    font-weight: 400;
}
.faq-list details[open] summary::after {
    content: "−";
}
.faq-list p {
    max-width: 700px;
    margin: 10px 0 0;
    color: var(--muted);
}

dialog {
    width: min(520px, calc(100% - 32px));
    max-height: calc(100dvh - 32px);
    margin: auto;
    padding: 0;
    overflow: auto;
    color: var(--ink);
    background: transparent;
    border: 0;
}
dialog::backdrop {
    background: rgba(20, 17, 15, 0.68);
}
.dialog-card {
    margin: 0;
    padding: clamp(26px, 6vw, 44px);
    background: var(--surface);
}
.dialog-card h2 {
    margin-bottom: 12px;
    font-size: clamp(1.7rem, 5vw, 2.5rem);
    line-height: 1.05;
    letter-spacing: -0.04em;
}
.dialog-card > p:not(.eyebrow) {
    color: var(--muted);
}
.dialog-card label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 18px 0;
    cursor: pointer;
}
.dialog-card label span {
    display: grid;
}
.dialog-card small {
    color: var(--muted);
}
.dialog-card input {
    width: 24px;
    height: 24px;
    accent-color: var(--accent);
}
.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 28px;
}
.primary-button,
.text-button {
    min-height: 44px;
    padding: 10px 18px;
    border: 0;
    cursor: pointer;
    font-weight: 780;
}
.primary-button {
    background: var(--accent);
    color: #fff;
}
.text-button {
    background: var(--surface-quiet);
    color: var(--ink);
}
.result-card {
    text-align: center;
}
.result-art {
    width: 144px;
    aspect-ratio: 1;
    margin: 0 auto 24px;
    background-color: #fffdf8;
}
.result-card .dialog-actions {
    justify-content: center;
}
.announcer {
    position: fixed;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

@media (max-width: 820px) {
    main {
        width: min(var(--max), calc(100% - 32px));
    }
    .variant-hero,
    .game-section,
    .content-section {
        padding-inline: clamp(20px, 6vw, 40px);
    }
    .section-heading,
    .play-layout {
        grid-template-columns: 1fr;
        gap: 22px;
    }
    .compact-heading > p {
        justify-self: start;
        text-align: left;
    }
    .progress-panel {
        position: static;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 16px;
        align-items: center;
        padding: 12px 0 0;
    }
    .progress-panel > .eyebrow,
    .progress-note {
        grid-column: 1 / -1;
    }
    .current-level {
        margin: 0;
    }
    .guide-grid {
        grid-template-columns: 1fr;
        gap: 30px;
    }
    .guide-grid article > span {
        margin-bottom: 10px;
    }
}

@media (max-width: 520px) {
    .score-strip div {
        min-height: 64px;
    }
    .progress-panel {
        grid-template-columns: 1fr;
    }
    .progress-panel > .eyebrow,
    .progress-note {
        grid-column: auto;
    }
    .current-level {
        grid-template-columns: 88px 1fr;
    }
    .current-art {
        width: 88px;
    }
    .next-goal {
        padding: 18px;
    }
    .dialog-actions {
        display: grid;
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
