    :root {
        --bg: #f8f5ef;
        --card: #fffef9;
        --ink: #71525a;
        --muted: #9b7b83;
        --accent: #9d72d7;
        --soft: #f7ebe7;
        --bad: #ff6b7f;
        --good: #2fb875;
        --shadow: 0 14px 34px rgba(92, 64, 68, .12);
        --gap: clamp(5px, 1.8vw, 12px);
        --board-size: min(100%, calc(100dvh - 270px), 600px);
        --grid-size: 4;
        font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    }

    * {
        box-sizing: border-box;
        -webkit-tap-highlight-color: transparent;
    }

    body {
        min-height: 100dvh;
        margin: 0;
        display: grid;
        place-items: center;
        background:
            radial-gradient(circle at 20% 10%, rgba(255, 255, 255, .8), transparent 25%),
            linear-gradient(180deg, var(--bg), #f2eee6);
        color: var(--ink);
        touch-action: manipulation;
        user-select: none;
    }

    .app {
        width: min(100vw, 770px);
        height: 100dvh;
        max-height: 100dvh;
        padding: max(12px, env(safe-area-inset-top)) clamp(12px, 3.5vw, 24px) max(12px, env(safe-area-inset-bottom));
        display: flex;
        flex-direction: column;
        gap: clamp(10px, 2.2dvh, 18px);
        overflow: hidden;
    }

    header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: clamp(6px, 2vw, 12px);
    }

    .pill,
    .icon-btn,
    .mini-btn {
        border: 0;
        background: var(--card);
        box-shadow: var(--shadow);
        color: var(--ink);
    }

    .pill {
        min-width: clamp(72px, 24vw, 96px);
        padding: clamp(8px, 2vw, 10px) clamp(10px, 3vw, 16px);
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        font-size: clamp(17px, 5vw, 22px);
        font-weight: 800;
    }

    .score-pill {
        min-width: clamp(94px, 27vw, 126px);
    }

    .score-details {
        display: grid;
        line-height: 1.05;
        text-align: left;
    }

    #score {
        margin-top: 4px;
        color: var(--muted);
        font-size: clamp(10px, 2.7vw, 13px);
        white-space: nowrap;
    }

    h1 {
        margin: 0;
        font-size: clamp(19px, 5.4vw, 32px);
        letter-spacing: .02em;
        text-align: center;
        white-space: nowrap;
    }

    .level-nav {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: clamp(6px, 2vw, 10px);
        min-width: 0;
    }

    .icon-btn {
        width: clamp(42px, 12vw, 54px);
        height: clamp(42px, 12vw, 54px);
        border-radius: 50%;
        font-size: clamp(22px, 6vw, 28px);
        cursor: pointer;
    }

    .mini-btn {
        width: clamp(28px, 8vw, 42px);
        height: clamp(28px, 8vw, 42px);
        border-radius: 50%;
        font-size: clamp(20px, 6vw, 30px);
        line-height: 1;
        cursor: pointer;
    }

    .mini-btn:disabled {
        opacity: .36;
        cursor: default;
    }

    .rules {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: clamp(6px, 1.8vw, 10px);
        background: var(--card);
        border-radius: 18px;
        padding: clamp(8px, 2vw, 12px);
        box-shadow: var(--shadow);
        flex: 0 0 auto;
    }

    .rule {
        min-height: clamp(48px, 9dvh, 74px);
        display: grid;
        place-items: center;
        text-align: center;
        padding: clamp(6px, 1.6vw, 10px) 8px;
        border-radius: 12px;
        background: var(--soft);
        font-weight: 750;
        font-size: clamp(11px, 3vw, 16px);
        line-height: 1.2;
    }

    .board-wrap {
        width: 100%;
        max-width: 100%;
        background: var(--card);
        border-radius: 20px;
        padding: clamp(9px, 2.2vw, 18px);
        box-shadow: var(--shadow);
        display: grid;
        place-items: center;
        flex: 1 1 auto;
        min-width: 0;
        min-height: 0;
        overflow: hidden;
    }

    .board {
        display: grid;
        grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
        grid-template-rows: repeat(var(--grid-size), minmax(0, 1fr));
        gap: var(--gap);
        aspect-ratio: 1;
        width: var(--board-size);
        height: auto;
        max-width: 100%;
        max-height: 100%;
        min-width: 0;
        min-height: 0;
    }

    .cell {
        position: relative;
        container-type: inline-size;
        min-width: 0;
        min-height: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        border: 0;
        border-radius: clamp(8px, 2vw, 12px);
        display: grid;
        place-items: center;
        cursor: pointer;
        font-size: clamp(24px, 11vw, 54px);
        line-height: 1;
        transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
        box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .04);
    }

    .cell:active {
        transform: scale(.94);
    }

    .cell.selected {
        outline: 4px solid rgba(255, 255, 255, .85);
        box-shadow: 0 0 0 4px rgba(113, 82, 90, .18);
    }

    .cell.conflict {
        animation: wiggle .28s both;
        box-shadow: 0 0 0 4px rgba(255, 107, 127, .55), inset 0 -2px 0 rgba(0, 0, 0, .04);
    }

    .cell.locked {
        cursor: default;
    }

    .solved-ahan {
        display: inline-block;
        max-width: 100%;
        max-height: 100%;
        font-size: var(--ahan-size);
        line-height: 1;
        animation: solved-ahan-spin 3s linear infinite;
        will-change: transform;
    }

    .cell .ahan {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        aspect-ratio: 1;
        border-radius: inherit;
        display: grid;
        place-items: center;
        overflow: hidden;
    }

    .cell .ahan img,
    .cell .ahan svg {
        width: 100%;
        height: 100%;
        object-fit: cover;
        display: block;
    }

    .cell .ahan-muted img,
    .cell .ahan-muted svg {
        filter: grayscale(1);
        opacity: .42;
        transform: rotate(180deg);
    }

    .region-a {
        background: #eac242;
    }

    .region-b {
        background: #c55685;
    }

    .region-c {
        background: #8c73cf;
    }

    .region-d {
        background: #58b8a8;
    }

    .region-e {
        background: #ee8b45;
    }

    .region-f {
        background: #6aa6d8;
    }

    .region-g {
        background: #86bf5d;
    }

    .region-h {
        background: #d86b62;
    }

    .region-i {
        background: #b59f41;
    }

    .status {
        min-height: 1.25em;
        text-align: center;
        color: var(--muted);
        font-weight: 750;
        font-size: clamp(12px, 3.2vw, 16px);
        line-height: 1.25;
        flex: 0 0 auto;
    }

    .toast {
        position: fixed;
        left: 50%;
        bottom: calc(18px + env(safe-area-inset-bottom));
        transform: translateX(-50%) translateY(120px);
        background: rgba(113, 82, 90, .96);
        color: white;
        padding: 12px 16px;
        border-radius: 999px;
        font-weight: 800;
        box-shadow: var(--shadow);
        transition: transform .25s ease;
        pointer-events: none;
        white-space: nowrap;
    }

    .toast.show {
        transform: translateX(-50%) translateY(0);
    }

    @keyframes wiggle {

        0%,
        100% {
            transform: translateX(0);
        }

        25% {
            transform: translateX(-4px);
        }

        75% {
            transform: translateX(4px);
        }
    }

    @keyframes solved-ahan-spin {
        from {
            transform: rotate(var(--start-angle));
        }

        to {
            transform: rotate(calc(var(--start-angle) + 360deg));
        }
    }

    @media (hover:hover) {

        .cell:hover,
        .icon-btn:hover,
        .mini-btn:not(:disabled):hover {
            filter: brightness(1.03);
        }
    }

    @media (max-width: 370px) {
        :root {
            --board-size: min(100%, calc(100dvh - 255px), 600px);
        }

        .rules {
            gap: 7px;
            padding: 9px;
        }

        .rule {
            min-height: 64px;
        }
    }
