:root {
    --tile-scale: 1;
    --tile-width: calc(36px * var(--tile-scale));
    --tile-height: calc(48px * var(--tile-scale));
    --tile-x-offset: calc(var(--tile-width) / 2);
    --tile-y-offset: calc(var(--tile-height) / 2);
    --tile-z-offset: calc(6px * var(--tile-scale));
    --board-width: calc(360px * var(--tile-scale));
    --board-height: calc(480px * var(--tile-scale));
    --tile-border-radius: calc(6px * var(--tile-scale));
    --tile-shadow-blur: calc(8px * var(--tile-scale));
    --tile-shadow-spread: calc(4px * var(--tile-scale));
}

@media (min-width: 768px) {
    :root {
        --tile-scale: 1.5;
    }
}

@media (min-width: 1024px) {
    :root {
        --tile-scale: 1.25;
    }
}

.mahjong-board {
    position: relative;
    width: var(--board-width);
    height: var(--board-height);
    margin: 1.5rem auto;
    transition: width 0.3s ease, height 0.3s ease;
}

.mahjong-tile {
    position: absolute;
    width: var(--tile-width);
    height: var(--tile-height);
    border-radius: var(--tile-border-radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    box-shadow: 0 calc(4px * var(--tile-scale)) var(--tile-shadow-blur) rgba(0, 0, 0, 0.2);
    filter: drop-shadow(calc(2px * var(--tile-scale)) calc(2px * var(--tile-scale)) var(--tile-shadow-spread) rgba(0, 0, 0, 0.3));
    padding: 0;
    aspect-ratio: 3/4;
    border: none;
    padding-bottom: calc(5px * var(--tile-scale));
    --tx: 0;
    --ty: 0;
    --tz: 0;
    --ty-offset: 0px;
    --scale: 1;
    transform: translate3d(calc(var(--tx) * var(--tile-x-offset)),
            calc(var(--ty) * var(--tile-y-offset) - var(--tz) * var(--tile-z-offset) + var(--ty-offset)),
            0) scale(var(--scale));
    transition: transform 0.2s ease-out, opacity 0.2s ease-out, box-shadow 0.2s ease-out;
    will-change: auto;
    cursor: pointer;
}

.mahjong-tile::before {
    content: '';
    width: var(--tile-width);
    height: var(--tile-height);
    border-radius: var(--tile-border-radius);
    position: absolute;
    bottom: 0;
    background: #cfb192;
    z-index: -1;
}

.mahjong-tile.locked {
    cursor: not-allowed;
    background: linear-gradient(135deg, #a8a196 0%, #8e8070 100%);
}

.mahjong-tile.locked::before {
    background: #585143;
}

.mahjong-tile.locked .mahjong-tile-image {
    background: linear-gradient(135deg, #f8f4ed 0%, #e9ceb2 100%);
    opacity: 0.4;
}

.mahjong-tile.removable {
    opacity: 1;
    cursor: pointer;
}

.mahjong-tile.removable:hover:not(.selected) {
    --scale: 1.05;
    --ty-offset: calc(-5px * var(--tile-scale));
    box-shadow: 0 calc(8px * var(--tile-scale)) calc(25px * var(--tile-scale)) rgba(0, 0, 0, 0.3);
}

.mahjong-tile.selected {
    --scale: 1.1;
    --ty-offset: calc(-12px * var(--tile-scale));
    box-shadow:
        0 0 calc(20px * var(--tile-scale)) rgba(255, 215, 0, 0.8),
        0 calc(8px * var(--tile-scale)) calc(25px * var(--tile-scale)) rgba(0, 0, 0, 0.3);
    outline: solid calc(2px * var(--tile-scale)) gold;
    outline-offset: calc(-1px * var(--tile-scale));
    z-index: 1000 !important;
}

.mahjong-tile.hidden {
    display: none;
}


.mahjong-tile-image {
    border-radius: var(--tile-border-radius);
    background: linear-gradient(135deg, #fffaf0 0%, #eddebe 100%);
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: opacity 0.2s ease-out;
}

.mahjong-board.shuffling .mahjong-tile {
    transition: transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.mahjong-tile.hint {
    box-shadow:
        0 0 calc(10px * var(--tile-scale)) calc(5px * var(--tile-scale)) #FFEB3B,
        inset 0 0 calc(10px * var(--tile-scale)) calc(5px * var(--tile-scale)) #FFEB3B;
    outline: calc(2px * var(--tile-scale)) solid #FFC107;
    animation: tilePop 0.6s ease-in-out;
}

.mahjong-tile.hint img {
    background: gold;
}

.mahjong-tile.hint::before {
    background: darkgoldenrod;
}

.matched-animation {
    animation: tileMatchPop 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tilePop {

    0%,
    100% {
        transform: translate3d(calc(var(--tx) * var(--tile-x-offset)),
                calc(var(--ty) * var(--tile-y-offset) - var(--tz) * var(--tile-z-offset) + var(--ty-offset)),
                0) scale(1);
    }

    40% {
        transform: translate3d(calc(var(--tx) * var(--tile-x-offset)),
                calc(var(--ty) * var(--tile-y-offset) - var(--tz) * var(--tile-z-offset) + var(--ty-offset)),
                0) scale(1.15);
    }
}

@keyframes tileMatchPop {
    0% {
        transform: translate3d(calc(var(--tx) * var(--tile-x-offset)),
                calc(var(--ty) * var(--tile-y-offset) - var(--tz) * var(--tile-z-offset) - 12px * var(--tile-scale)),
                0) scale(1.1);
        opacity: 1;
    }

    30% {
        transform: translate3d(calc(var(--tx) * var(--tile-x-offset)),
                calc(var(--ty) * var(--tile-y-offset) - var(--tz) * var(--tile-z-offset) - 12px * var(--tile-scale)),
                0) scale(1.15);
        opacity: 1;
    }

    52.5% {
        transform: translate3d(calc(var(--tx) * var(--tile-x-offset)),
                calc(var(--ty) * var(--tile-y-offset) - var(--tz) * var(--tile-z-offset) - 12px * var(--tile-scale)),
                0) scale(0.95);
        opacity: 1;
    }

    67.5% {
        transform: translate3d(calc(var(--tx) * var(--tile-x-offset)),
                calc(var(--ty) * var(--tile-y-offset) - var(--tz) * var(--tile-z-offset) - 12px * var(--tile-scale)),
                0) scale(1.05);
        opacity: 1;
    }

    100% {
        transform: translate3d(calc(var(--tx) * var(--tile-x-offset)),
                calc(var(--ty) * var(--tile-y-offset) - var(--tz) * var(--tile-z-offset) - 12px * var(--tile-scale)),
                0) scale(1.2);
        opacity: 0;
    }
}

.mahjong-overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: 15px;
}

.mahjong-overlay-content {
    background: #fff;
    padding: calc(30px * var(--tile-scale, 1));
    border-radius: calc(10px * var(--tile-scale, 1));
    text-align: center;
    color: #333;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
}

.mahjong-feedback-toast {
    position: absolute;
    bottom: calc(90px * var(--tile-scale, 1));
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(30, 190, 30, 0.9);
    color: white;
    padding: calc(12px * var(--tile-scale, 1)) calc(24px * var(--tile-scale, 1));
    border-radius: calc(25px * var(--tile-scale, 1));
    font-size: calc(1.1em * var(--tile-scale, 1));
    font-weight: bold;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.4s, bottom 0.4s;
    pointer-events: none;
}

.mahjong-feedback-toast.show {
    opacity: 1;
    bottom: calc(110px * var(--tile-scale, 1));
}

#gameRoot.levels-screen.mahjong .level-button {
    align-items: baseline;
    gap: 0.5rem;
}

#gameRoot.levels-screen.mahjong .level-label {
    font-weight: bold;
}



.mahjong-mini-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    gap: 1px;
    width: 60px;
    height: 60px;
    margin: 0 auto 10px auto;
    pointer-events: none;
}

.mahjong-mini-pixel {
    width: 100%;
    height: 100%;
    background-color: transparent;
    border-radius: 1px;
}

.mahjong-mini-pixel.active {
    background-color: #e0cda5;
    box-shadow: inset 0 0 1px rgba(0, 0, 0, 0.3);
}

.level-button:hover .mahjong-mini-pixel.active {
    background-color: #ffd700;
}


.game-instructions {
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1), 1px 1px 5px rgba(0, 0, 0, 0.1), 0 0px 10px rgba(0, 0, 0, 0.1);
    color: #fff;
}