/* ===== Tetris Modal Game ===== */

/* --- Floating Button --- */
#tmg-open-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 99990;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 16px 10px 12px;
    background: #e63946;
    color: #fff;
    border: none;
    border-radius: 50px;
    font-size: 14px;
    font-weight: 700;
    font-family: 'Segoe UI', Arial, sans-serif;
    letter-spacing: 0.05em;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(230,57,70,0.45);
    transition: background 0.18s, transform 0.15s, box-shadow 0.18s;
    text-transform: uppercase;
}
#tmg-open-btn:hover {
    background: #c1121f;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(230,57,70,0.55);
}
#tmg-open-btn:active {
    transform: translateY(0);
}
#tmg-open-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* --- Overlay --- */
#tmg-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    backdrop-filter: blur(3px);
}
#tmg-overlay.tmg-visible {
    opacity: 1;
    pointer-events: all;
}

/* --- Modal Box --- */
#tmg-modal {
    background: #1a1a2e;
    border: 2px solid #e63946;
    border-radius: 14px;
    padding: 0;
    width: 480px;
    max-width: 98vw;
    max-height: 96vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,0.7), 0 0 0 1px rgba(230,57,70,0.2);
    transform: scale(0.93);
    transition: transform 0.22s ease;
}
#tmg-overlay.tmg-visible #tmg-modal {
    transform: scale(1);
}

/* --- Header --- */
#tmg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: #e63946;
}
#tmg-title {
    color: #fff;
    font-size: 18px;
    font-weight: 900;
    font-family: 'Segoe UI', Arial, sans-serif;
    letter-spacing: 0.18em;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
#tmg-close-btn {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    opacity: 0.85;
    transition: opacity 0.15s, transform 0.15s;
}
#tmg-close-btn:hover {
    opacity: 1;
    transform: scale(1.15);
}

/* --- Body --- */
#tmg-body {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 14px;
    padding: 16px 14px 10px;
    flex: 1;
    overflow: hidden;
}

/* --- Canvas Wrap --- */
#tmg-canvas-wrap {
    position: relative;
    flex-shrink: 0;
}
#tmg-canvas {
    display: block;
    background: #0d0d1a;
    border: 2px solid #333355;
    border-radius: 4px;
    image-rendering: pixelated;
}

/* --- Game Over Overlay on Canvas --- */
#tmg-overlay-msg {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.78);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    border-radius: 4px;
}
#tmg-overlay-msg.tmg-hidden {
    display: none;
}
#tmg-msg-text {
    color: #e63946;
    font-size: 26px;
    font-weight: 900;
    font-family: 'Segoe UI', Arial, sans-serif;
    letter-spacing: 0.12em;
    text-shadow: 0 0 12px rgba(230,57,70,0.7);
}
#tmg-restart-btn {
    padding: 10px 22px;
    background: #e63946;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 700;
    font-family: 'Segoe UI', Arial, sans-serif;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: background 0.15s;
}
#tmg-restart-btn:hover {
    background: #c1121f;
}

/* --- Sidebars --- */
#tmg-sidebar-left,
#tmg-sidebar-right {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 80px;
}
.tmg-panel {
    background: #0d0d1a;
    border: 1px solid #333355;
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
}
.tmg-label {
    color: #888aaa;
    font-size: 10px;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 6px;
}
#tmg-score,
#tmg-level,
#tmg-lines {
    color: #e0e0ff;
    font-size: 22px;
    font-weight: 900;
    font-family: 'Courier New', monospace;
}
#tmg-next-canvas {
    display: block;
    background: #0d0d1a;
    border-radius: 2px;
    margin: 0 auto;
}
.tmg-controls-info {
    text-align: left;
}
.tmg-key-row {
    color: #aaaacc;
    font-size: 11px;
    font-family: 'Segoe UI', Arial, sans-serif;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.tmg-key-row kbd {
    background: #222240;
    border: 1px solid #444466;
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 10px;
    color: #ccccee;
    font-family: 'Courier New', monospace;
    min-width: 28px;
    text-align: center;
    flex-shrink: 0;
}

/* --- Touch Controls --- */
#tmg-touch-controls {
    display: none;
    justify-content: center;
    gap: 10px;
    padding: 10px 14px 14px;
    background: #0d0d1a;
    border-top: 1px solid #222240;
}
.tmg-touch-btn {
    width: 56px;
    height: 56px;
    background: #1e1e3a;
    border: 2px solid #e63946;
    border-radius: 10px;
    color: #e63946;
    font-size: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.tmg-touch-btn:active {
    background: #e63946;
    color: #fff;
}

/* --- Responsive --- */
@media (max-width: 520px) {
    #tmg-modal {
        width: 100vw;
        max-width: 100vw;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    #tmg-body {
        gap: 8px;
        padding: 10px 6px 6px;
    }
    #tmg-canvas {
        width: 180px;
        height: 360px;
    }
    #tmg-sidebar-left,
    #tmg-sidebar-right {
        min-width: 60px;
    }
    #tmg-score, #tmg-level, #tmg-lines {
        font-size: 16px;
    }
    .tmg-controls-info {
        display: none;
    }
    #tmg-touch-controls {
        display: flex;
    }
    #tmg-open-btn span {
        display: none;
    }
    #tmg-open-btn {
        padding: 10px 12px;
        border-radius: 50%;
    }
}
