@font-face {
    font-family: "AaManHuaJia";
    src: url("../fonts/AaManHuaJia-subset.woff2") format("woff2");
    font-style: normal;
    font-weight: 400;
    font-display: swap;
}

:root {
    color-scheme: light;
    --ink: #3d2630;
    --ink-soft: #604852;
    --muted: #896f74;
    --surface: rgba(255, 253, 250, 0.9);
    --surface-solid: #fffdfa;
    --surface-soft: rgba(255, 248, 243, 0.9);
    --surface-pink: #fff0ed;
    --line: rgba(112, 71, 79, 0.14);
    --accent: #d75b67;
    --accent-dark: #ad3f52;
    --accent-soft: #ffe0dc;
    --gold: #e5a03f;
    --red: #e15b63;
    --white-tile: #fffdf8;
    --board-ink: #492a38;
    --shadow: 0 28px 80px rgba(102, 49, 61, 0.2), 0 4px 14px rgba(102, 49, 61, 0.08);
    --soft-shadow: 0 12px 30px rgba(112, 71, 79, 0.11);
    --theme-desktop-image: none;
    --theme-mobile-image: none;
    --theme-win-image: none;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 0;
    background: #fff8f3;
}

body {
    min-width: 0;
    min-height: 100vh;
    margin: 0;
    padding: max(28px, var(--safe-area-inset-top, env(safe-area-inset-top, 0px))) 16px max(48px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
    color: var(--ink);
    font-family: "AaManHuaJia", "Microsoft YaHei", "PingFang SC", sans-serif;
    font-size: 16px;
    letter-spacing: 0.015em;
    background-color: #fff8f3;
    background-image:
        linear-gradient(rgba(255, 248, 243, 0.55), rgba(255, 248, 243, 0.68)),
        var(--theme-desktop-image),
        radial-gradient(circle at 12% 12%, rgba(255, 223, 215, 0.7), transparent 30%),
        linear-gradient(145deg, #fff4ee 0%, #fffaf4 52%, #f9eff1 100%);
    background-position: center;
    background-size: cover;
    background-attachment: fixed;
    transition: background-color 0.35s ease;
}

button,
input,
select {
    font: inherit;
}

button,
select,
input[type="range"] {
    -webkit-tap-highlight-color: transparent;
}

button,
select,
.image-picker {
    touch-action: manipulation;
}

.container {
    position: relative;
    width: min(100%, 980px);
    margin: 0 auto;
    padding: clamp(22px, 4vw, 44px);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 34px;
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
}

.container::before,
.container::after {
    position: absolute;
    z-index: -1;
    display: block;
    width: 180px;
    height: 180px;
    border-radius: 50%;
    content: "";
    filter: blur(3px);
    opacity: 0.55;
    pointer-events: none;
}

.container::before {
    top: -90px;
    right: -50px;
    background: rgba(255, 198, 180, 0.55);
}

.container::after {
    bottom: 170px;
    left: -110px;
    background: rgba(247, 211, 225, 0.5);
}

.hero {
    position: relative;
    margin-bottom: 30px;
    text-align: center;
}

.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px;
    padding: 8px 14px;
    color: var(--accent-dark);
    border: 1px solid rgba(215, 91, 103, 0.18);
    border-radius: 999px;
    background: rgba(255, 238, 234, 0.85);
    box-shadow: 0 6px 18px rgba(215, 91, 103, 0.1);
    font-size: 0.86rem;
    font-weight: 400;
}

.badge-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gold);
    box-shadow: 0 0 0 4px rgba(229, 160, 63, 0.15);
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--accent-dark);
    font-size: 0.86rem;
    font-weight: 400;
    letter-spacing: 0.14em;
}

h1,
h2,
p {
    margin-top: 0;
}

h1,
h2,
strong,
.button,
label,
.stat-label,
.instruction-kicker {
    font-weight: 400;
}

h1 {
    margin-bottom: 10px;
    color: var(--ink);
    font-size: clamp(3rem, 9vw, 6.2rem);
    line-height: 0.95;
    letter-spacing: 0.04em;
    text-shadow: 3px 4px 0 rgba(215, 91, 103, 0.11);
}

h2 {
    margin-bottom: 0;
    font-size: clamp(1.55rem, 3vw, 2rem);
    line-height: 1.15;
    letter-spacing: 0.04em;
}

.subtitle,
.section-description,
#game-instructions,
.hint-status,
.footer-note {
    color: var(--muted);
}

.subtitle {
    max-width: 520px;
    margin: 0 auto;
    font-size: 1.05rem;
    line-height: 1.65;
}

.controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.control-group {
    min-width: 0;
    padding: 17px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 249, 245, 0.76);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.control-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 11px;
}

.control-group label {
    display: block;
    color: var(--ink-soft);
    font-size: 0.98rem;
}

.control-icon {
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    color: var(--accent);
    border-radius: 9px;
    background: rgba(215, 91, 103, 0.11);
    font-family: sans-serif;
    font-size: 0.82rem;
}

.range-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    cursor: pointer;
}

#size-value {
    min-width: 48px;
    color: var(--accent-dark);
    font-size: 1.08rem;
    text-align: right;
}

select {
    width: 100%;
    min-height: 44px;
    padding: 8px 34px 8px 12px;
    color: var(--ink);
    border: 1px solid rgba(112, 71, 79, 0.18);
    border-radius: 13px;
    outline: none;
    background-color: var(--surface-solid);
    cursor: pointer;
}

select:focus,
button:focus-visible,
input:focus-visible + .picker-copy {
    outline: 3px solid rgba(215, 91, 103, 0.3);
    outline-offset: 3px;
}

.image-settings {
    margin: 18px 0;
    padding: 22px;
    border: 1px solid rgba(215, 91, 103, 0.14);
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(255, 241, 237, 0.9), rgba(255, 250, 246, 0.88));
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.section-description {
    margin: 12px 0 18px;
    font-size: 0.95rem;
    line-height: 1.65;
}

.image-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.image-picker {
    display: flex;
    align-items: center;
    gap: 13px;
    min-width: 0;
    min-height: 78px;
    padding: 11px;
    border: 1px dashed rgba(173, 63, 82, 0.32);
    border-radius: 17px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.78);
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.image-picker:hover {
    border-color: var(--accent);
    background: #fff;
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(215, 91, 103, 0.13);
}

.image-picker:has(input:focus-visible) {
    outline: 3px solid rgba(215, 91, 103, 0.25);
    outline-offset: 3px;
}

.image-picker input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.image-preview {
    display: block;
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    border: 1px solid rgba(61, 38, 48, 0.12);
    border-radius: 15px;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.35);
}

.preview-red {
    background-color: var(--red);
}

.preview-white {
    background-color: var(--white-tile);
}

.picker-copy {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.picker-copy strong {
    font-size: 1rem;
}

.picker-copy small {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.84rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stats {
    display: grid;
    grid-template-columns: 108px 108px 1fr;
    gap: 10px;
    align-items: stretch;
    margin: 20px 0;
}

.stat-card,
.instruction-card {
    min-height: 98px;
    padding: 17px 18px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(255, 253, 250, 0.9);
    box-shadow: var(--soft-shadow);
}

.stat-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.stat-label,
.instruction-kicker {
    color: var(--muted);
    font-size: 0.84rem;
    letter-spacing: 0.12em;
}

#move-count,
#time-count {
    margin-top: 4px;
    color: var(--accent-dark);
    font-size: 2rem;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.instruction-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: linear-gradient(135deg, rgba(255, 240, 237, 0.95), rgba(255, 251, 245, 0.92));
}

#game-instructions {
    margin: 7px 0 0;
    font-size: 0.98rem;
    line-height: 1.6;
}

.hint-status {
    grid-column: 1 / -1;
    margin: 0;
    padding: 11px 15px;
    color: var(--accent-dark);
    border-radius: 13px;
    background: rgba(255, 224, 220, 0.58);
    font-size: 0.9rem;
    line-height: 1.5;
    text-align: center;
}

.board {
    display: grid;
    width: min(100%, 660px);
    margin: 28px auto;
    padding: 11px;
    gap: 7px;
    border: 1px solid rgba(255, 255, 255, 0.26);
    border-radius: 26px;
    background: linear-gradient(145deg, #5a3544, var(--board-ink));
    box-shadow: 0 20px 38px rgba(73, 42, 56, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.13);
}

.cell {
    display: block;
    width: 100%;
    aspect-ratio: 1;
    padding: 0;
    border: 0;
    border-radius: clamp(7px, 1.4vw, 15px);
    cursor: pointer;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    box-shadow: inset 0 0 0 1px rgba(61, 38, 48, 0.12), 0 4px 0 rgba(61, 38, 48, 0.1);
    transition: transform 0.16s ease, filter 0.16s ease, background-color 0.2s ease, box-shadow 0.16s ease;
}

.cell.red {
    background-color: var(--red);
}

.cell.white {
    background-color: var(--white-tile);
}

.cell:hover,
.cell:focus-visible {
    filter: brightness(1.07) saturate(1.04);
    transform: translateY(-2px) scale(0.97);
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.6), 0 5px 0 rgba(61, 38, 48, 0.11);
}

.cell:active {
    transform: translateY(1px) scale(0.95);
}

.actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 11px;
}

.button {
    min-height: 48px;
    padding: 10px 21px;
    border: 0;
    border-radius: 15px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s ease, transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.button:hover:not(:disabled) {
    transform: translateY(-2px);
}

.button:active:not(:disabled) {
    transform: translateY(1px) scale(0.98);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.button-primary {
    color: #fffaf8;
    background: linear-gradient(135deg, var(--accent), #c74f64);
    box-shadow: 0 10px 20px rgba(215, 91, 103, 0.28);
}

.button-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #e36b72, var(--accent-dark));
    box-shadow: 0 13px 25px rgba(215, 91, 103, 0.34);
}

.button-secondary {
    color: var(--ink-soft);
    border: 1px solid rgba(112, 71, 79, 0.16);
    background: rgba(255, 255, 255, 0.86);
    box-shadow: 0 5px 14px rgba(112, 71, 79, 0.08);
}

.button-secondary:hover:not(:disabled) {
    color: var(--accent-dark);
    background: #fff;
}

.button-small {
    min-height: 42px;
    padding: 8px 15px;
    font-size: 0.9rem;
}

.button-primary span {
    display: inline-block;
    margin-right: 4px;
    font-family: sans-serif;
    font-size: 0.82em;
}

.footer-note {
    margin: 19px 0 0;
    font-size: 0.82rem;
    text-align: center;
}

.victory-effect {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(92vw, 820px);
    aspect-ratio: 1;
    pointer-events: none;
    background-image: var(--theme-win-image);
    background-position: center;
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0.86;
    transform: translate(-50%, -50%) scale(0.78);
    animation: none;
}

.victory-effect.is-active {
    animation: victory-pop 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

.game-over {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    padding: max(20px, var(--safe-area-inset-top, env(safe-area-inset-top, 0px))) max(20px, var(--safe-area-inset-right, env(safe-area-inset-right, 0px))) max(20px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))) max(20px, var(--safe-area-inset-left, env(safe-area-inset-left, 0px)));
    background: rgba(57, 32, 42, 0.64);
    backdrop-filter: blur(9px);
}

.game-over-content {
    position: relative;
    z-index: 1;
    width: min(100%, 430px);
    padding: 36px 30px 30px;
    border: 1px solid rgba(255, 255, 255, 0.86);
    border-radius: 28px;
    text-align: center;
    background: rgba(255, 253, 250, 0.96);
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.3);
}

.game-over-content h2 {
    margin: 0 0 10px;
    font-size: clamp(2rem, 7vw, 3rem);
}

.game-over-content p:not(.eyebrow) {
    margin-bottom: 23px;
    color: var(--muted);
    line-height: 1.65;
}

@keyframes victory-pop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.62) rotate(-4deg);
    }

    55% {
        opacity: 0.95;
        transform: translate(-50%, -50%) scale(1.04) rotate(2deg);
    }

    100% {
        opacity: 0.86;
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
    }
}

@media (max-width: 820px) {
    .controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 700px) {
    body {
        padding: max(12px, var(--safe-area-inset-top, env(safe-area-inset-top, 0px))) 10px max(28px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
        background-image:
            linear-gradient(rgba(255, 248, 243, 0.5), rgba(255, 248, 243, 0.7)),
            var(--theme-mobile-image),
            radial-gradient(circle at 10% 10%, rgba(255, 223, 215, 0.65), transparent 33%),
            linear-gradient(145deg, #fff4ee 0%, #fffaf4 52%, #f9eff1 100%);
        background-attachment: scroll;
    }

    .container {
        padding: 23px 14px 28px;
        border-radius: 25px;
    }

    .hero {
        margin-bottom: 24px;
    }

    .hero-badge {
        margin-bottom: 12px;
        font-size: 0.8rem;
    }

    h1 {
        font-size: clamp(2.9rem, 17vw, 4.6rem);
    }

    .subtitle {
        padding: 0 10px;
        font-size: 0.96rem;
    }

    .controls,
    .image-controls {
        grid-template-columns: 1fr;
    }

    .control-group {
        padding: 15px;
    }

    .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .section-heading .button {
        align-self: flex-start;
    }

    .stats {
        grid-template-columns: 1fr 1fr;
    }

    .stat-card,
    .instruction-card {
        min-height: 90px;
        padding: 14px;
    }

    .instruction-card {
        grid-column: 1 / -1;
        min-height: auto;
    }

    .board {
        gap: 4px;
        padding: 7px;
        border-radius: 19px;
    }

    .actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .actions .button {
        width: 100%;
        padding-inline: 10px;
    }

    .game-over-content {
        padding: 31px 22px 24px;
    }
}

@media (max-width: 380px) {
    .stats {
        grid-template-columns: 1fr;
    }

    .instruction-card {
        grid-column: auto;
    }

    .actions {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
