#triple-triad-game-section {
    position: fixed;
    inset: 0;
    background-color: rgba(26, 26, 46, 0.9);
    backdrop-filter: blur(5px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    font-family: 'Inter', sans-serif;
    color: #e0e0e0;
    overflow: hidden;
}
#triple-triad-game-section.hidden { display: none; }

.tt-modal {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.tt-modal-content {
    background-color: rgba(31, 41, 55, 0.8);
    padding: 2rem;
    border-radius: 0.75rem;
    border: 1px solid #4b5563;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    text-align: center;
}
.tt-modal-content h2 {
    font-size: 2rem;
    font-weight: bold;
    color: #ec4899;
    margin-bottom: 1rem;
}

.tt-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    overflow-y: auto;
    padding: 1rem;
    background: rgba(0,0,0,0.2);
    border-radius: 0.5rem;
    flex-grow: 1;
}

.tt-selection-footer {
    margin-top: 1.5rem;
    display: flex;
    justify-content: space-around;
    align-items: center;
}

#tt-game-container {
    width: 95vw;
    height: 95vh;
    max-width: 1200px;
    max-height: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    gap: 1rem;
}
#tt-game-container.hidden { display: none; }

.tt-top-row,
.tt-bottom-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0 2rem;
}

.tt-ai-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.tt-win-streak-record {
    color: #a855f7;
    font-weight: 600;
}

/* Score + volume container */
#tt-score-tools {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Score box – prevent stretching on mobile */
#tt-score-display {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    white-space: nowrap;
    width: auto;
    max-width: 100%;
    font-size: 1.5rem;
    font-weight: bold;
    background: rgba(31, 41, 55, 0.7);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #4b5563;
}

.tt-score.blue { color: #60a5fa; }
.tt-score.red { color: #f87171; }

/* Volume button */
#tt-volume-toggle {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid rgba(255,255,255,.14);
    background: rgba(255,255,255,.06);
    backdrop-filter: blur(6px);
    font-size: 18px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
}
#tt-volume-toggle[data-state="off"] { opacity: .75; }

.tt-hand-container {
    display: flex;
    align-items: center;
    gap: 10px;
}
#tt-ai-hand-container { justify-content: center; min-height: 130px; }

#tt-player-hand-container {
    justify-content: flex-start;
    min-height: 130px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 5px;
    flex: 1;
    min-width: 0;
    -webkit-overflow-scrolling: touch;
}
#tt-player-hand-container::-webkit-scrollbar { height: 6px; }
#tt-player-hand-container::-webkit-scrollbar-track {
    background: rgba(45, 55, 72, 0.5);
    border-radius: 3px;
}
#tt-player-hand-container::-webkit-scrollbar-thumb {
    background: #ec4899;
    border-radius: 3px;
}

#tt-board-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 450px;
    aspect-ratio: 1 / 1;
    background-color: rgba(31, 41, 55, 0.5);
    padding: 8px;
    border-radius: 0.75rem;
}
.tt-board-cell {
    background-color: rgba(17, 24, 39, 0.7);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    cursor: pointer;
}
.tt-board-cell:not(:has(.tt-card)):hover,
.tt-board-cell.drag-over { background-color: rgba(236, 72, 153, 0.3); }

.tt-card {
    width: 100px;
    height: 120px;
    position: relative;
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    border-radius: 8px;
    background-color: #2d3748;
    cursor: pointer;
    border: 2px solid #4a5568;
    flex-shrink: 0;
    user-select: none;
}
.tt-card.selected {
    transform: translateY(-10px) scale(1.05);
    box-shadow: 0 0 15px #ec4899;
    border-color: #ec4899;
}
.tt-card.dragging { opacity: 0.5; }
.tt-card.player { border-color: #60a5fa; }
.tt-card.ai { border-color: #f87171; }

.tt-card-back {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #4f46e5, #ec4899);
    border-radius: 6px;
}

.tt-card-art-container {
    position: absolute;
    top: 5px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}
.tt-card-art { width: 100%; height: 100%; object-fit: cover; }

.tt-art-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.25rem;
    color: #f87171;
    font-size: 1rem;
    font-weight: 600;
    padding: 0.5rem;
}

.tt-art-error-name {
    font-size: 0.85rem;
    color: #fca5a5;
}

.tt-card-missing-art {
    background: rgba(148, 163, 184, 0.2);
}

.tt-card-missing-art .tt-card-art-container {
    background: rgba(30, 41, 59, 0.6);
}

.tt-card [class^="rank-"] {
    position: absolute;
    font-weight: bold;
    font-size: 1.4rem;
    color: #fff;
    text-shadow: 1px 1px 2px #000;
}
.rank-top { top: 5px; left: 50%; transform: translateX(-50%); }
.rank-left { top: 50%; left: 8px; transform: translateY(-50%); }
.rank-right { top: 50%; right: 8px; transform: translateY(-50%); }
.rank-bottom { bottom: 5px; left: 50%; transform: translateX(-50%); }

#tt-info-box {
    font-size: 1.2rem;
    font-weight: bold;
    min-height: 2rem;
    text-align: center;
    width: 15rem;
    flex-shrink: 0;
}

.tt-reward-message {
    margin-top: 0.75rem;
    font-size: 0.95rem;
    color: #f472b6;
    min-height: 1.25rem;
}

.tt-rules-text {
    text-align: left;
    overflow-y: auto;
    padding: 0 1rem;
    margin-bottom: 1.5rem;
    flex-grow: 1;
}
.tt-rules-text h3 {
    font-size: 1.25rem;
    color: #ec4899;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid #4b5563;
    padding-bottom: 0.25rem;
}
.tt-rules-text p,
.tt-rules-text li { line-height: 1.6; }
.tt-rules-text ul { list-style-type: disc; padding-left: 2rem; margin-top: 0.5rem; }
.tt-rules-text li { margin-bottom: 0.5rem; }
.tt-rules-footer {
    margin-top: 1.5rem;
    display: flex;
    justify-content: space-around;
    align-items: center;
}

/* Tablets */
@media (max-width: 1024px) {
    #tt-game-container { max-width: 100%; }
    #tt-board-container { max-width: 380px; }
}

/* Mobile */
@media (max-width: 768px) {
    #triple-triad-game-section {
        align-items: flex-start;
        padding: 1.5rem 1rem 2.5rem;
        overflow-y: auto;
    }
    .tt-modal-content { padding: 1.5rem; max-height: none; width: 100%; }
    .tt-modal { align-items: flex-start; }
    #tt-result-modal { align-items: center; }

    #tt-game-container {
        width: 100%;
        height: auto;
        max-height: none;
        padding: 1.25rem 1rem 2rem;
        gap: 1.5rem;
    }
    .tt-top-row,
    .tt-bottom-row {
        flex-direction: column;
        gap: 1rem;
        padding: 0;
        align-items: stretch;
    }

    /* Center the score group and keep compact layout */
    #tt-score-tools {
        align-self: center;
        justify-content: center;
        width: auto;
    }
    #tt-score-display { display: inline-flex; }

    #tt-ai-hand-container,
    #tt-player-hand-container {
        width: 100%;
        justify-content: center;
        overflow-x: auto;
        padding: 0.5rem 0.25rem;
    }
    #tt-player-hand-container {
        justify-content: flex-start;
        padding-left: 0.625rem;
        padding-right: 0.625rem;
    }

    #tt-board-container {
        width: min(90vw, 360px);
        max-width: none;
        margin: 0 auto;
    }
    .tt-card { width: 82px; height: 100px; }

    #tt-info-box { width: 100%; }

    .tt-card-grid { grid-template-columns: repeat(auto-fill, minmax(85px, 1fr)); }
}

/* Small phones */
@media (max-width: 480px) {
    #triple-triad-game-section { padding: 1rem 0.5rem 2rem; }
    .tt-modal-content { padding: 1.25rem; border-radius: 0.65rem; width: 100%; }

    #tt-game-container {
        width: 100%;
        height: auto;
        max-height: none;
        padding: 1rem 0.5rem 1.5rem;
        gap: 1.25rem;
    }

    .tt-top-row,
    .tt-bottom-row {
        flex-direction: column;
        gap: 1rem;
        padding: 0;
        align-items: stretch;
        width: 100%;
    }

    #tt-ai-hand-container,
    #tt-player-hand-container {
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 0.5rem 0;
    }
    .tt-hand-container { gap: 6px; }

    #tt-board-container {
        width: min(92vw, 320px);
        max-width: none;
        margin: 0 auto;
    }
    .tt-card {
        width: 68px;
        height: 86px;
        flex: 0 0 auto;
    }

    #tt-info-box { width: 100%; }

    .tt-card-grid {
        gap: 0.75rem;
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }

    #tt-volume-toggle {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }
}
