/**
 * Oyun zemini ve nesne (prop) katmanı.
 *
 * Mimari:
 *   - .cell                → zemin (background-image olarak tile)
 *   - .cell .cell-object   → tile ÜSTÜNE konan prop (%70 boyut, ortalı, etkileşim yok)
 *
 * Default zemin: düz çimen rengi. Öğretmen editörde tile atadıysa o görsel kullanılır.
 */

/* Pano */
.game-board {
    position: relative !important;
    background: #74b94d !important;
    border: 4px solid #2d6a30 !important;
    border-radius: 10px !important;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18), inset 0 0 0 2px rgba(0, 0, 0, 0.08) !important;
    overflow: visible !important;
}

/* Tüm hücreler */
.cell {
    border-right: none !important;
    border-bottom: none !important;
    background-color: #74b94d !important;
    background-size: 100% 100% !important;
    background-repeat: no-repeat !important;
    background-position: center center !important;
    image-rendering: auto;
    position: relative;
    overflow: visible !important;
}

.cell:hover {
    box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, 0.2);
    filter: brightness(1.06);
}

/* Izgara — zemin ile nesneler arasında; bitiş bayrağı üstte kalır */
.cell-grid-lines {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    box-sizing: border-box;
    border-right: 2px solid rgba(255, 255, 255, 0.42);
    border-bottom: 2px solid rgba(255, 255, 255, 0.42);
}

.game-board:not(.show-grid) .cell-grid-lines {
    display: none;
}

.game-board.show-grid .cell:hover {
    box-shadow: inset 0 0 0 9999px rgba(255, 255, 255, 0.18) !important;
    filter: brightness(1.06);
}

/* Öğretmenin atadığı zemin tile'ı — JS `<img class="cell-tile">` ekler */
.cell.tile-custom {
    background-color: transparent !important;
}

.cell-tile {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: fill;
    pointer-events: none;
    z-index: 0;
    image-rendering: auto;
}

/* Su katmanı (eski mavi pattern kaldırıldı; tile veya solid mavi gösterir) */
.cell.water {
    background-color: #3aa6dc !important;
}

.cell.water::before { content: none !important; background: none !important; animation: none !important; }

/* Köprü — yalnızca prop PNG; hücrede ek CSS tahta/su katmanı yok */
.cell.bridge,
.cell.bridge::before,
.cell.bridge::after {
    background: none !important;
    animation: none !important;
    box-shadow: none !important;
}
.cell.bridge::before,
.cell.bridge::after {
    content: none !important;
}

/* Ayak izi — yön inline transform ile ayarlanır */
.cell .trail-icon {
    position: absolute;
    left: 50%;
    top: 54%;
    display: inline-block;
    font-family: "Font Awesome 6 Free" !important;
    font-weight: 900 !important;
    font-style: normal;
    font-size: clamp(12px, 48%, 26px);
    color: #d4b896;
    z-index: 1;
    pointer-events: none;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.35);
}

/* =====================================================
   NESNE (PROP) KATMANI — tile üstüne yerleşir, küçük
   ===================================================== */
.cell-object {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 88%;
    height: 88%;
    pointer-events: none;
    object-fit: contain;
    image-rendering: -webkit-optimize-contrast;
    z-index: 2;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.22));
}

/* Portal — genel .cell-object boyutundan ayrı, küçük; numara üstte */
.cell-portal {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 4;
}

.cell-portal .cell-object.cell-object--portal {
    left: 50%;
    top: 30%;
    width: 87%;
    height: 87%;
    transform: translate(-50%, -50%);
    object-fit: contain;
    z-index: 1;
    filter: none;
}

.cell-portal__label {
    position: absolute;
    left: 50%;
    top: 30%;
    transform: translate(-50%, -50%);
    font-weight: 900;
    font-size: clamp(11px, 50%, 26px);
    line-height: 1;
    letter-spacing: -0.02em;
    color: #fff;
    -webkit-text-stroke: 0.05em rgba(15, 23, 42, 0.85);
    paint-order: stroke fill;
    text-shadow:
        0 0 3px rgba(15, 23, 42, 0.95),
        0 1px 5px rgba(15, 23, 42, 0.9),
        0 0 12px rgba(255, 255, 255, 0.45);
    pointer-events: none;
    z-index: 6;
}

/* Köprü — hücreyi daha iyi doldurur (üstünden geçilebilir) */
.cell-object[data-kind="bridge"] {
    width: 112%;
    height: 112%;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* Bitiş bayrağı — hücre sınırını aşabilir */
.cell-object--finish {
    width: 118%;
    height: 118%;
    top: 12%;
    transform: translate(-50%, -50%);
    z-index: 90;
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.28));
}

.game-board .cell:has(.cell-object--finish) {
    z-index: 80;
    overflow: visible !important;
}

.cell-obstacle-wrap {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    container-type: size;
}

.cell-obstacle-wrap .cell-object {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 82%;
    height: 82%;
}

.cell-obstacle-label--random {
    z-index: 5;
}

.cell-chest-wrap {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 88%;
    height: 88%;
    z-index: 2;
    pointer-events: none;
    container-type: size;
}

.cell-chest-wrap .cell-object--chest {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    width: 100%;
    height: 100%;
}

.cell-chest-label {
    position: absolute;
    left: 50%;
    top: 0;
    z-index: 4;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translate(-50%, -52%);
}

.cell-chest-label--random {
    width: min(36cqmin, 22px);
    height: min(36cqmin, 22px);
    min-width: 14px;
    min-height: 14px;
    max-width: 22px;
    max-height: 22px;
    border-radius: 50%;
    background: linear-gradient(165deg, #fde68a 0%, #f59e0b 42%, #d97706 100%);
    border: 1.5px solid rgba(255, 255, 255, 0.92);
    box-shadow:
        0 2px 5px rgba(120, 53, 15, 0.4),
        0 1px 2px rgba(0, 0, 0, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.55);
    color: #fff;
    font-size: min(13cqmin, 11px);
    font-weight: 900;
    line-height: 1;
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    letter-spacing: -0.04em;
    text-shadow: 0 1px 2px rgba(146, 64, 14, 0.55);
    animation: chest-random-badge-pulse 2.4s ease-in-out infinite;
}

/* Taş/kütük ve hücre üstü rozetler — cqmin kapsayıcısız şişmesin diye sabit üst sınır */
.game-board .cell > .cell-chest-label--random,
.game-board .cell-obstacle-label--random {
    width: 18px;
    height: 18px;
    min-width: 14px;
    min-height: 14px;
    max-width: 20px;
    max-height: 20px;
    font-size: 10px;
    border-width: 1.5px;
}

@media (prefers-reduced-motion: reduce) {
    .cell-chest-label--random {
        animation: none;
    }
}

@keyframes chest-random-badge-pulse {
    0%, 100% {
        transform: translate(-50%, -52%) scale(1);
        box-shadow:
            0 3px 8px rgba(120, 53, 15, 0.45),
            0 1px 2px rgba(0, 0, 0, 0.2),
            inset 0 1px 0 rgba(255, 255, 255, 0.55);
    }
    50% {
        transform: translate(-50%, -56%) scale(1.06);
        box-shadow:
            0 5px 12px rgba(180, 83, 9, 0.5),
            0 2px 4px rgba(0, 0, 0, 0.22),
            inset 0 1px 0 rgba(255, 255, 255, 0.65);
    }
}

.cell-object--chest {
    width: 88%;
    height: 88%;
    z-index: 2;
}

.chest-counter__icon {
    flex-shrink: 0;
    object-fit: contain;
    display: block;
}

.cell-object--chest-open {
    opacity: 0.95;
}

.cell-object--broken-stone {
    width: 88%;
    height: 88%;
    z-index: 2;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18));
}

.cell-object--broken-stump {
    width: 82%;
    height: 82%;
    z-index: 2;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.16));
}

/* Sandık toplanınca hücreden yükselen altın animasyonu */
.gold-collect-float {
    position: absolute;
    left: 50%;
    top: 38%;
    transform: translate(-50%, 0) scale(0.85);
    z-index: 8;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(255, 251, 235, 0.96);
    border: 1px solid #fcd34d;
    color: #b45309;
    font-weight: 700;
    font-size: clamp(11px, 3.2vmin, 15px);
    pointer-events: none;
    opacity: 0;
    box-shadow: 0 6px 16px rgba(180, 83, 9, 0.22);
    transition: opacity 0.18s ease, transform 0.95s cubic-bezier(0.22, 1, 0.36, 1);
}

.gold-collect-float.is-active {
    opacity: 1;
    transform: translate(-50%, -72%) scale(1.05);
}

.gold-collect-float i {
    color: #d97706;
}

#totalScore.coin-pulse {
    animation: coinPulse 0.85s ease;
}

@keyframes coinPulse {
    0% { transform: scale(1); color: inherit; }
    35% { transform: scale(1.22); color: #d97706; }
    100% { transform: scale(1); color: inherit; }
}

/* Oyuncu — tiles/hero.png (süzülme katmanı) */
.game-player-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    overflow: visible;
}

/* Kamp ateşi görseli — karakterin üstünde, zemin tile'ının altında */
.game-campfire-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 105;
    overflow: visible;
}

.game-campfire-layer__slot {
    position: absolute;
    left: calc(var(--cx, 0) * 100% / var(--grid-cols, 1));
    top: calc(var(--cy, 0) * 100% / var(--grid-rows, 1));
    width: calc(100% / var(--grid-cols, 1));
    height: calc(100% / var(--grid-rows, 1));
    overflow: visible;
}

.game-player-layer .player-icon {
    position: absolute;
    left: calc((var(--px, 0) + 0.5 + var(--px-off, 0)) * 100% / var(--grid-cols, 1));
    top: calc((var(--py, 0) + 0.5 + var(--py-off, 0)) * 100% / var(--grid-rows, 1));
    /* Boyut = tek hücrenin ~%198'i */
    width: calc(100% / var(--grid-cols, 8) * 1.98);
    height: calc(100% / var(--grid-rows, 8) * 1.98);
    transform: translate(-50%, calc(-50% + var(--bridge-lift-y, 0px))) rotate(var(--rotation, 0deg))
        scale(var(--bridge-scale, 1));
    transform-origin: center center;
    z-index: 1;
    pointer-events: none;
}

.game-player-layer .player-icon.is-sliding {
    transition:
        left var(--slide-ms, 400ms) cubic-bezier(0.25, 0.46, 0.45, 0.94),
        top var(--slide-ms, 400ms) cubic-bezier(0.25, 0.46, 0.45, 0.94),
        transform var(--slide-ms, 400ms) cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.game-player-layer .player-icon.is-turning {
    transition: transform 0.22s ease;
}

.game-player-layer .player-icon.is-striking {
    transition: left var(--slide-ms, 400ms) cubic-bezier(0.25, 0.46, 0.45, 0.94),
        top var(--slide-ms, 400ms) cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.game-player-layer .player-icon.is-striking .player-hero-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.game-player-layer .player-icon.is-sprite-mode {
    --sprite-lift: 9%;
    transform: translate(-50%, calc(-50% - var(--sprite-lift, 0%) + var(--bridge-lift-y, 0px)))
        scale(var(--bridge-scale, 1));
    transform-origin: center center;
}

/* Ön / arka (yukarı-aşağı hareket) — ayak hizası */
.game-player-layer .player-icon.is-sprite-mode.facing-axis {
    --sprite-lift: 11%;
}

.game-player-layer .player-icon.is-sprite-mode.facing-axis .player-hero-image {
    object-position: center 58%;
}

/* Sağ / sol — biraz daha yukarı */
.game-player-layer .player-icon.is-sprite-mode.facing-side {
    --sprite-lift: 17%;
}

.game-player-layer .player-icon.is-sprite-mode.facing-side .player-hero-image {
    object-position: center 62%;
}

.game-player-layer .player-icon.is-sprite-mode.is-striking,
.game-player-layer .player-icon.is-sprite-mode.is-hurt {
    transition: none;
}

.game-player-layer .player-icon.is-sprite-mode.bump {
    animation: playerBumpSprite 0.34s ease-out;
}

@keyframes playerBumpSprite {
    0%, 100% {
        transform: translate(-50%, calc(-50% - var(--sprite-lift, 0%) + var(--bridge-lift-y, 0px)))
            scale(var(--bridge-scale, 1));
    }
    45% {
        transform: translate(
            calc(-50% + var(--bump-x, 0) * 14px),
            calc(-50% - var(--sprite-lift, 0%) + var(--bridge-lift-y, 0px) + var(--bump-y, 0) * 14px)
        ) scale(var(--bridge-scale, 1));
    }
}

.game-player-layer .player-icon.is-sprite-mode.is-turning {
    transition: none;
}

.game-player-layer .player-icon.is-sprite-mode.is-sliding {
    transition:
        left var(--slide-ms, 400ms) cubic-bezier(0.25, 0.46, 0.45, 0.94),
        top var(--slide-ms, 400ms) cubic-bezier(0.25, 0.46, 0.45, 0.94),
        transform var(--slide-ms, 400ms) cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.game-player-layer .player-icon .player-hero-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    image-rendering: -webkit-optimize-contrast;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.28));
    transition: none;
    transform: scale(var(--hero-sprite-scale, 1));
    transform-origin: center 62%;
}

.game-player-layer .player-icon.bump {
    animation: playerBump 0.3s ease-out;
}

.game-player-layer .player-icon.splash {
    animation: playerSplash 1s ease-in-out forwards;
}

/* Suya düşüş — halkalar (hücre içi) */
.cell .water-drown-ripples {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 6;
    overflow: visible;
}

.cell .water-drown-ripple {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 32%;
    height: 32%;
    margin-left: -16%;
    margin-top: -16%;
    border: 3px solid rgba(52, 152, 219, 0.82);
    border-radius: 50%;
    box-sizing: border-box;
    animation: waterDrownRippleExpand 1.35s ease-out forwards;
    opacity: 0;
}

.cell .water-drown-ripple:nth-child(1) { animation-delay: 0s; }
.cell .water-drown-ripple:nth-child(2) { animation-delay: 0.3s; }
.cell .water-drown-ripple:nth-child(3) { animation-delay: 0.6s; }
.cell .water-drown-ripple:nth-child(4) { animation-delay: 0.9s; }

@keyframes waterDrownRippleExpand {
    0% {
        transform: scale(0.4);
        opacity: 0.95;
    }
    65% {
        opacity: 0.4;
    }
    100% {
        transform: scale(2.6);
        opacity: 0;
    }
}

/* Suya düşüş — yalnızca aşağı batma (diğer kahramanlar) */
.game-player-layer .player-icon.is-drowning:not(.is-drowning-hero-art) {
    animation: playerWaterDrownSink 2.4s ease-in forwards !important;
    transition: none !important;
    transform-origin: center 75%;
    z-index: 2;
}

.game-player-layer .player-icon.is-sprite-mode.is-drowning:not(.is-drowning-hero-art) {
    animation: playerWaterDrownSinkSprite 2.4s ease-in forwards !important;
    transform-origin: center 78%;
}

@keyframes playerWaterDrownSink {
    0% {
        transform: translate(-50%, calc(-50% + var(--bridge-lift-y, 0px))) rotate(var(--rotation, 0deg))
            scale(var(--bridge-scale, 1));
        opacity: 1;
    }
    100% {
        transform: translate(-50%, calc(-50% + 44px + var(--bridge-lift-y, 0px))) rotate(var(--rotation, 0deg))
            scale(0.12);
        opacity: 0;
    }
}

@keyframes playerWaterDrownSinkSprite {
    0% {
        transform: translate(-50%, calc(-50% - var(--sprite-lift, 0%) + var(--bridge-lift-y, 0px)))
            scale(var(--bridge-scale, 1));
        opacity: 1;
    }
    100% {
        transform: translate(-50%, calc(-50% - var(--sprite-lift, 0%) + 44px + var(--bridge-lift-y, 0px)))
            scale(0.12);
        opacity: 0;
    }
}

/* Kahraman boğulma PNG — characters/<klasör>/*-boguluyor.png, sadece batma */
.game-player-layer .player-icon.is-drowning-hero-art {
    animation: none !important;
    z-index: 2;
}

.game-player-layer .player-icon.is-drowning-hero-art .player-hero-image {
    visibility: hidden !important;
    opacity: 0 !important;
    animation: none !important;
}

/* player-icon ~1.98× hücre; görsel tam 1 hücre (100% / 1.98) */
.game-player-layer .water-drown-hero {
    position: absolute;
    left: 50%;
    top: 50%;
    width: calc(100% / 1.98);
    height: calc(100% / 1.98);
    transform: translate(-50%, -50%);
    object-fit: contain;
    pointer-events: none;
    z-index: 3;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.22));
    animation: heroWaterDrownSink 2.4s ease-in forwards;
    transform-origin: center 72%;
}

@keyframes heroWaterDrownSink {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, calc(-50% + 22%)) scale(0.92);
        opacity: 0;
    }
}

.game-player-layer .player-icon.is-portal-vanish {
    opacity: 0 !important;
    transform: translate(-50%, -50%) rotate(var(--rotation, 0deg)) scale(0.12) !important;
    transform-origin: center center;
    transition: opacity 0.45s ease, transform 0.45s ease !important;
}

.game-player-layer .player-icon.is-sprite-mode.is-portal-vanish {
    --sprite-lift: 0% !important;
    transform: translate(-50%, -50%) scale(0.12) !important;
    transform-origin: center center;
}

.game-player-layer .player-icon.is-portal-hidden {
    opacity: 0 !important;
    visibility: hidden;
    transform: translate(-50%, -50%) rotate(var(--rotation, 0deg)) scale(0.12) !important;
    transform-origin: center center;
    transition: none !important;
}

.game-player-layer .player-icon.is-sprite-mode.is-portal-hidden {
    --sprite-lift: 0% !important;
    transform: translate(-50%, -50%) scale(0.12) !important;
    transform-origin: center center;
}

.game-player-layer .player-icon.is-portal-appear {
    opacity: 0 !important;
    transform: translate(-50%, -50%) rotate(var(--rotation, 0deg)) scale(0.12) !important;
    transition: none !important;
}

.game-player-layer .player-icon.is-sprite-mode.is-portal-appear {
    transform: translate(-50%, calc(-50% - var(--sprite-lift, 0%))) scale(0.12) !important;
}

.game-player-layer .player-icon.is-portal-appear.is-portal-appear-active {
    opacity: 1 !important;
    visibility: visible;
    transform: translate(-50%, -50%) rotate(var(--rotation, 0deg)) scale(1) !important;
    transition: opacity 0.45s ease, transform 0.45s ease !important;
}

.game-player-layer .player-icon.is-sprite-mode.is-portal-appear.is-portal-appear-active {
    transform: translate(-50%, calc(-50% - var(--sprite-lift, 0%))) scale(1) !important;
}

/* Hücre içi oyuncu (eski — artık kullanılmıyor) */
.cell .player-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    width: max(40px, calc(117% - 20px));
    height: max(40px, calc(117% - 20px));
    transform: translate(-50%, -50%) rotate(var(--rotation, 0deg));
    z-index: 5;
    pointer-events: none;
}

.cell .player-icon .player-hero-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    image-rendering: -webkit-optimize-contrast;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.28));
    transform: scale(var(--hero-sprite-scale, 1));
    transform-origin: center 62%;
}

.cell .player-icon.bump {
    animation: playerBump 0.3s ease-out;
}

.cell .player-icon.splash {
    animation: playerSplash 1s ease-in-out forwards;
}

@keyframes playerBump {
    0%, 100% {
        transform: translate(-50%, -50%) rotate(var(--rotation, 0deg));
    }
    50% {
        transform: translate(
            calc(-50% + var(--bump-x, 0) * 12px),
            calc(-50% + var(--bump-y, 0) * 12px)
        ) rotate(var(--rotation, 0deg));
    }
}

@keyframes playerSplash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; transform: translate(-50%, -50%) rotate(var(--rotation, 0deg)) scale(0.92); }
}

/* Çok hücreli nesneler (2×2, 3×3) */
#gameBoard .cell {
    overflow: visible;
}

#gameBoard .cell-obstacle-wrap--2x2 {
    width: 200%;
    height: 200%;
    z-index: 4;
    overflow: hidden;
    box-sizing: border-box;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 4%;
}

#gameBoard .cell-obstacle-wrap--2x2 .cell-object {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: left bottom;
}

#gameBoard .cell-obstacle-wrap--3x3 {
    width: 300%;
    height: 300%;
    z-index: 5;
    overflow: hidden;
    box-sizing: border-box;
    display: flex;
    align-items: flex-end;
    justify-content: flex-start;
    padding: 3%;
}

#gameBoard .cell-obstacle-wrap--3x3 .cell-object {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    object-position: left bottom;
}

/* Player/apple ikonları nesne katmanının üstünde kalsın */
.cell .apple-icon {
