/* Kizi Template Responsive Layout Fixes */

/* Game Container Responsive Improvements */
#ava-game_container {
    height: auto;
    min-height: 500px;
    aspect-ratio: 16/9;
    max-height: 720px;
    position: relative;
    overflow: hidden;
    border-radius: 12px;
}

/* 更大的游戏容器 - 针对不同屏幕尺寸 */
@media screen and (min-width: 768px) {
    #ava-game_container {
        min-height: 600px;
        max-height: 800px;
    }
}

@media screen and (min-width: 1024px) {
    #ava-game_container {
        min-height: 650px;
        max-height: 900px;
    }
}

@media screen and (min-width: 1440px) {
    #ava-game_container {
        min-height: 720px;
        max-height: 1000px;
    }
}

/* Game Layout Grid System */
#game-col {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 15px;
    justify-content: center;
    align-items: start;
}

/* 平板竖屏 - 单列布局 */
@media screen and (min-width: 768px) and (max-width: 1023px) {
    #game-col {
        grid-template-columns: 1fr;
        max-width: 800px;
        gap: 20px;
        padding: 0 20px;
    }

    /* 平板下游戏容器优化 */
    .game-info {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }

    /* 平板下侧边栏改为水平排列 */
    .game-left, .game-right {
        order: 3;
        float: none !important;
        width: 100% !important;
        margin: 0 !important;
    }

    .game-left {
        order: 2;
    }
}

/* 平板横屏和小桌面 */
@media screen and (min-width: 1024px) and (max-width: 1199px) {
    #game-col {
        grid-template-columns: 280px 1fr 280px;
        max-width: 1200px;
        gap: 15px;
    }
}

/* 标准桌面 */
@media screen and (min-width: 1200px) and (max-width: 1439px) {
    #game-col {
        grid-template-columns: 300px 1fr 300px;
        gap: 20px;
        max-width: 1400px;
    }
}

/* 大桌面 */
@media screen and (min-width: 1440px) and (max-width: 1919px) {
    #game-col {
        grid-template-columns: 350px 1fr 350px;
        max-width: 1800px;
        gap: 30px;
    }
}

/* 超大屏幕 */
@media screen and (min-width: 1920px) {
    #game-col {
        grid-template-columns: 380px 1fr 380px;
        max-width: 2000px;
        gap: 40px;
    }
}

/* Game Info Section */
.game-info {
    order: 1;
    margin: 0;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    padding: 0;
    width: 100%;
    max-width: 100%;
    justify-self: center;
}

@media screen and (min-width: 768px) {
    .game-info {
        order: 2;
    }
}

/* 确保游戏容器在中间区域完美居中 */
#ava-game_container {
    margin: 0 auto;
    width: 100%;
    max-width: 100%;
    display: block;
}

/* 游戏标题区域居中 */
.gametitle {
    background: linear-gradient(135deg, #035193, #0680e0);
    padding: 15px 20px;
    margin: 0;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 15px;
    text-align: center;
    width: 100%;
}

@media screen and (min-width: 768px) {
    .gametitle {
        justify-content: space-between;
        text-align: left;
    }
}

/* Left Sidebar Improvements */
.game-left {
    order: 2;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

@media screen and (min-width: 768px) {
    .game-left {
        order: 1;
    }
}

/* Right Sidebar Improvements */
.game-right {
    order: 3;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Ad Container - Prevent Layout Shift */
.ad300, .adsmall {
    width: 100%;
    max-width: 300px;
    min-height: 250px;
    background: #f8f9fa;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    contain: layout;
    overflow: hidden;
}

.ad300 {
    display: none;
}

.ad300:first-child {
    display: flex;
}

.adsmall {
    display: none;
    min-height: 90px;
}

.adsmall:first-child {
    display: flex;
}

/* Related Games Container */
.relategames {
    background: #ffffff;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin: 0;
}

.relategames h3, .relategames h2 {
    color: #035193;
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 15px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid #f0f0f0;
}

/* Related Games Grid - 默认移动端 */
.relategames ul {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 0;
    margin: 0;
    list-style: none;
}

/* 平板竖屏 - 水平滚动网格 */
@media screen and (min-width: 768px) and (max-width: 1023px) {
    .relategames ul {
        grid-template-columns: repeat(6, 1fr);
        gap: 12px;
        overflow-x: auto;
        padding-bottom: 10px;
        scrollbar-width: thin;
        scrollbar-color: #ccc #f0f0f0;
    }

    .relategames ul::-webkit-scrollbar {
        height: 6px;
    }

    .relategames ul::-webkit-scrollbar-track {
        background: #f0f0f0;
        border-radius: 3px;
    }

    .relategames ul::-webkit-scrollbar-thumb {
        background: #ccc;
        border-radius: 3px;
    }

    /* 平板下侧边栏样式调整 */
    .game-left .relategames,
    .game-right .relategames {
        margin-bottom: 20px;
    }
}

/* 小桌面 */
@media screen and (min-width: 1024px) and (max-width: 1199px) {
    .relategames ul {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
}

/* 标准桌面及以上 */
@media screen and (min-width: 1200px) {
    .relategames ul {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }
}

.relategames li {
    margin: 0 !important;
    position: relative;
    display: block;
    aspect-ratio: 1;
}

.relategames li a {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 10px;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.relategames li a:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.relategames li img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: 2px solid #fff;
    border-radius: 10px;
    transition: border-color 0.2s ease;
}

.relategames li a:hover img {
    border-color: #fc0;
}

/* Game Title Header */
.gametitle {
    background: linear-gradient(135deg, #035193, #0680e0);
    padding: 15px 20px;
    margin: 0;
    border-radius: 16px 16px 0 0;
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 15px;
}

.gametitle .l-link {
    display: flex;
    gap: 10px;
    align-items: center;
}

.gametitle .gamename {
    color: #fff;
    font-size: clamp(16px, 4vw, 24px);
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
    flex: 1;
    min-width: 0;
}

.gamename span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.game-share {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Game Controls Responsive */
.game-zoom {
    display: flex;
    gap: 10px;
    align-items: center;
}

#gameFull, #gameReplay {
    width: 28px;
    height: 28px;
    background-size: contain;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    margin: 0;
}

#gameFull:hover, #gameReplay:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Game Description Section */
#game-bottom {
    background: #ffffff;
    border-radius: 16px;
    padding: 25px;
    margin-top: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.game-dec {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 0;
}

@media screen and (min-width: 768px) {
    .game-dec {
        flex-direction: row;
        align-items: flex-start;
    }
}

.game-dec .thumb {
    width: 200px;
    height: 200px;
    flex-shrink: 0;
    margin: 0 auto;
}

@media screen and (min-width: 768px) {
    .game-dec .thumb {
        margin: 0;
    }
}

.game-dec .description {
    flex: 1;
    width: auto;
    height: auto;
    margin-left: 0;
    overflow: visible;
    max-height: none;
}

@media screen and (min-width: 768px) {
    .game-dec .description {
        margin-left: 20px;
    }
}

.game-dec .description .pl {
    color: #035193;
    font-size: clamp(20px, 5vw, 28px);
    font-weight: 700;
    margin-bottom: 15px;
    line-height: 1.3;
}

.game-dec .description .d-text {
    color: #666;
    font-size: 16px;
    line-height: 1.6;
    margin: 0;
}

/* Game Tags Responsive */
.game-tags {
    width: 100%;
    height: auto;
    max-height: none;
    overflow: visible;
    text-align: left;
    margin-top: 20px;
}

.game-tags ul {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.game-tags ul li {
    line-height: 1;
}

.game-tags ul li a {
    display: inline-block;
    padding: 8px 16px;
    background-color: #FFADD9;
    color: #043856;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.game-tags ul li a:hover {
    background-color: #ff8dc7;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 173, 217, 0.4);
}

/* Similar Games Bottom Section */
.play-game-bottom {
    background: #ffffff;
    border-radius: 16px;
    padding: 25px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.play-game-bottom h2 {
    color: #035193;
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 20px 0;
    text-align: center;
    border-left: none;
    text-indent: 0;
    position: relative;
    padding-bottom: 15px;
}

.play-game-bottom h2:after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 3px;
    background: #ffda19;
    border-radius: 2px;
}

.play-game-bottom ul {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 15px;
    padding: 0;
    margin: 0;
    list-style: none;
    max-width: 800px;
    margin: 0 auto;
}

@media screen and (min-width: 480px) {
    .play-game-bottom ul {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    }
}

@media screen and (min-width: 768px) {
    .play-game-bottom ul {
        grid-template-columns: repeat(6, 1fr);
    }
}

.play-game-bottom li {
    position: relative;
    aspect-ratio: 1;
}

.play-game-bottom li a {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.play-game-bottom li a:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.play-game-bottom li img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border: 2px solid #fff;
    border-radius: 12px;
}

.play-game-bottom li a:hover img {
    border-color: #fc0;
}

/* Mobile-specific Improvements */
@media screen and (max-width: 767px) {
    #game-col {
        padding: 0 10px;
        gap: 15px;
    }

    .gametitle {
        padding: 12px 15px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .game-share {
        align-self: flex-end;
        margin-top: -35px;
    }

    .relategames {
        padding: 15px;
    }

    #game-bottom {
        padding: 20px;
    }

    .play-game-bottom {
        padding: 20px;
    }
}

/* Header Ad Improvements */
#topad {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    background: transparent;
}

.adbox {
    max-width: 728px;
    width: 100%;
    min-height: 90px;
    background: #f8f9fa;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    contain: layout;
    overflow: hidden;
}

.ad728 {
    width: 100%;
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Game iframe responsive improvements */
#gamePlay-content {
    aspect-ratio: 16/9;
    width: 100%;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
}

#game-box {
    width: 100%;
    height: 100%;
}

#game-box iframe {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 12px;
}

/* Loading and preloader improvements */
.gamePlay-bg {
    border-radius: 12px;
}

.gamePlay-icon {
    border-radius: 50%;
    box-shadow: 0 0 30px rgba(255, 255, 255, 0.3);
}

.gamePlay-button {
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Fix ad rotation to prevent layout shift */
.ad300, .adsmall {
    transition: opacity 0.5s ease-in-out;
}

/* Walkthrough section improvements */
.game-walkthrough {
    background: #ffffff;
    border-radius: 16px;
    padding: 25px;
    margin-top: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.game-walkthrough p {
    color: #666;
    font-size: 16px;
    line-height: 1.6;
    margin: 0 0 20px 0;
}

.game-walkthrough hr {
    border: none;
    height: 2px;
    background: linear-gradient(to right, transparent, #ddd, transparent);
    margin: 20px 0;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .game-info,
    .relategames,
    #game-bottom,
    .play-game-bottom,
    .game-walkthrough {
        background: #2a2a2a;
        color: #fff;
    }

    .game-dec .description .d-text {
        color: #ccc;
    }

    .game-walkthrough p {
        color: #ccc;
    }
}

/* Print styles */
@media print {
    .game-left,
    .game-right,
    .ad300,
    .adsmall,
    .adbox {
        display: none !important;
    }

    #game-col {
        grid-template-columns: 1fr;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode improvements */
@media (prefers-contrast: high) {
    .relategames li img,
    .play-game-bottom li img {
        border-width: 3px;
        border-color: #000;
    }

    .game-tags ul li a {
        border: 2px solid #000;
    }
}

/* Focus indicators for accessibility */
.relategames li a:focus,
.play-game-bottom li a:focus,
.game-tags ul li a:focus,
#gameFull:focus,
#gameReplay:focus {
    outline: 3px solid #007AFF;
    outline-offset: 2px;
}

/* Container query support where available */
@supports (container-type: inline-size) {
    .relategames {
        container-type: inline-size;
    }

    @container (max-width: 250px) {
        .relategames ul {
            grid-template-columns: repeat(2, 1fr);
        }
    }

    @container (min-width: 300px) {
        .relategames ul {
            grid-template-columns: repeat(3, 1fr);
        }
    }
}