/* ============================================
   俄罗斯方块工具 —— 融入站点工具页
   外层 .tool-content 使用站点既有卡片样式
   游戏宽度占满容器，三栏弹性布局
   ============================================ */

.tool-content {
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    padding: 1.2em;
    border-radius: .6em;
    position: relative;
}

.tetris-app {
    width: 100%;
    background: linear-gradient(160deg, #111827 0%, #0a0e27 100%);
    border: 1px solid rgba(0, 212, 255, 0.28);
    border-radius: 8px;
    padding: 26px 30px 30px;
    color: #fff;
}

/* 全屏模式：占满屏幕，三栏仍居中排布 */
.tetris-app:fullscreen,
.tetris-app:-webkit-full-screen {
    width: 100vw;
    height: 100vh;
    max-width: none;
    border-radius: 0;
    border: none;
    overflow: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.tetris-app:fullscreen .tetris-main,
.tetris-app:-webkit-full-screen .tetris-main {
    flex: 1;
    align-items: center;
    justify-content: center;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

.tetris-app:fullscreen .tetris-board-wrap,
.tetris-app:-webkit-full-screen .tetris-board-wrap {
    height: 88vh;
}

/* 三栏：左栏 / 棋盘 / 右栏，棋盘居中并占主要宽度 */
.tetris-main {
    display: flex;
    gap: clamp(10px, 2vw, 24px);
    align-items: flex-start;
    justify-content: center;
    width: 100%;
}

.tetris-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.tetris-sidebar-left {
    flex: 1 1 0;
    max-width: 230px;
}

.tetris-sidebar-right {
    flex: 0 0 clamp(120px, 15%, 150px);
}

/* 棋盘：宽度自适应，canvas 等比填充 */
.tetris-board-wrap {
    position: relative;
    flex: 0 1 auto;
    width: min(360px, 42%);
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid rgba(0, 212, 255, 0.35);
    box-shadow: 0 0 30px rgba(0, 212, 255, 0.15), inset 0 0 40px rgba(0, 0, 0, 0.6);
    line-height: 0;
    aspect-ratio: 1 / 2;
}

.tetris-board-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

@keyframes tetrisFlash {
    0%, 100% {
        filter: brightness(1);
    }
    50% {
        filter: brightness(1.7);
    }
}

.tetris-flash {
    animation: tetrisFlash 0.15s ease-out;
}

.tetris-panel {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: clamp(8px, 1.4vw, 13px) 12px;
    text-align: center;
}

.tetris-panel h3 {
    font-size: clamp(9px, 1vw, 10px);
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.5);
    margin: 0 0 7px;
    font-weight: 700;
}

.tetris-value {
    font-size: clamp(20px, 2.6vw, 28px);
    font-weight: 800;
    color: #00d4ff;
    text-shadow: 0 0 14px rgba(0, 212, 255, 0.45);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.tetris-value.best {
    color: #ffd700;
    text-shadow: 0 0 14px rgba(255, 215, 0, 0.4);
    font-size: clamp(17px, 2vw, 22px);
}

.tetris-value.gain {
    color: #00ff88;
    text-shadow: 0 0 14px rgba(0, 255, 136, 0.4);
    font-size: clamp(17px, 2vw, 22px);
}

.tetris-value.small {
    font-size: clamp(15px, 1.8vw, 20px);
}

.tetris-score-panel {
    position: relative;
    overflow: visible;
}

@keyframes tetrisScorePop {
    0% {
        opacity: 1;
        transform: translate(-50%, 0) scale(0.9);
    }
    25% {
        transform: translate(-50%, -8px) scale(1.12);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -42px) scale(1);
    }
}

.tetris-score-pop {
    position: absolute;
    left: 50%;
    top: 24px;
    color: #00ff88;
    font-size: 22px;
    font-weight: 800;
    pointer-events: none;
    opacity: 0;
    white-space: nowrap;
    text-shadow: 0 0 12px rgba(0, 255, 136, 0.6);
}

.tetris-score-pop.show {
    animation: tetrisScorePop 0.9s ease-out forwards;
}

.tetris-score-table {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
}

.tetris-score-table div {
    display: flex;
    justify-content: space-between;
    padding: 3px 7px;
    color: rgba(255, 255, 255, 0.7);
    border-radius: 4px;
}

.tetris-score-table div:nth-child(odd) {
    background: rgba(255, 255, 255, 0.06);
}

.tetris-score-table b {
    color: #00d4ff;
    font-variant-numeric: tabular-nums;
}

.tetris-keys {
    display: flex;
    flex-direction: column;
    gap: 7px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.65);
}

.tetris-keys div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.tetris-keys kbd {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: monospace;
    font-size: 11px;
    color: #fff;
}

.tetris-next-canvas {
    margin: 0 auto;
    display: block;
    max-width: 100%;
    height: auto !important;
}

.tetris-controls {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 2px;
}

.tetris-controls button {
    font-family: inherit;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 9px;
    font-weight: 600;
    transition: all 0.2s ease;
    padding: 11px 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    font-size: 12px;
}

.tetris-controls button:hover {
    background: rgba(0, 212, 255, 0.18);
    border-color: #00d4ff;
    box-shadow: 0 0 15px rgba(0, 212, 255, 0.25);
}

.tetris-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 14, 39, 0.88);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    line-height: 1.5;
    text-align: center;
    padding: 20px;
}

.tetris-overlay h2 {
    font-size: clamp(20px, 2.6vw, 26px);
    margin: 0 0 8px;
    background: linear-gradient(90deg, #00d4ff, #b026ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tetris-overlay p {
    color: rgba(255, 255, 255, 0.7);
    margin: 0 0 24px;
    font-size: 13px;
}

.tetris-overlay button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    padding: 12px 32px;
    background: linear-gradient(90deg, #00d4ff, #b026ff);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    border-radius: 25px;
    box-shadow: 0 5px 20px rgba(0, 212, 255, 0.3);
}

.tetris-overlay button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 26px rgba(0, 212, 255, 0.5);
}

.tetris-mobile-controls {
    display: none;
    margin-top: 18px;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.tetris-mobile-controls button {
    font-family: inherit;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 15px 4px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 18px;
}

.tetris-mobile-controls button:active {
    background: rgba(0, 212, 255, 0.3);
}

/* ============ 移动端适配 ============ */
@media (max-width: 760px) {
    html, body {
        -webkit-text-size-adjust: 100%;
    }

    .tool-content {
        padding: 8px;
    }

    .tetris-app {
        padding: 12px;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    /* 提升三栏子块为 flex 项，便于跨容器重排 */
    .tetris-main {
        display: contents;
    }

    /* 顶部：得分信息横向紧凑排列 */
    .tetris-sidebar-left {
        order: 1;
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 7px;
        max-width: none;
    }

    .tetris-sidebar-left .tetris-panel {
        flex: 1 1 0;
        min-width: 68px;
        padding: 8px 3px;
    }

    /* 键盘操作说明在手机无意义，隐藏 */
    .tetris-sidebar-left .tetris-panel:nth-child(5) {
        display: none;
    }

    .tetris-panel h3 {
        font-size: 9px;
        letter-spacing: 0;
        margin-bottom: 4px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .tetris-value {
        font-size: 20px;
    }

    .tetris-value.best, .tetris-value.gain, .tetris-value.small {
        font-size: 15px;
    }

    /* 棋盘：宽度完全自适应父容器，不写死像素，不溢出也不偏窄 */
    .tetris-board-wrap {
        order: 2;
        width: 100%;
        max-width: 100%;
        margin: 0 auto;
        flex: none;
    }

    /* 触控键：紧贴棋盘下方并固定在屏幕底部，随时可操作 */
    .tetris-mobile-controls {
        order: 3;
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        gap: 8px;
        margin-top: 0;
        width: 100%;
        position: sticky;
        bottom: 0;
        z-index: 20;
        padding: 8px 0;
        background: rgba(10, 14, 39, 0.96);
        -webkit-backdrop-filter: blur(6px);
        backdrop-filter: blur(6px);
    }

    .tetris-mobile-controls button {
        padding: 16px 4px;
        font-size: 22px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* 底部：预览、得分表、控制按钮 */
    .tetris-sidebar-right {
        order: 4;
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        flex: none;
    }

    .tetris-sidebar-right .tetris-panel {
        flex: 1 1 120px;
    }

    .tetris-next-canvas {
        width: 90px;
        height: auto !important;
    }

    .tetris-controls {
        flex: 1 1 100%;
        flex-direction: row;
        margin-top: 0;
    }

    .tetris-controls button {
        flex: 1;
        font-size: 12px;
        padding: 10px 4px;
    }

    /* 全屏下棋盘按宽度自适应，避免被固定高度拉伸变形 */
    .tetris-app:fullscreen .tetris-board-wrap,
    .tetris-app:-webkit-full-screen .tetris-board-wrap {
        height: auto;
    }
}
