/* --- Variables & Theming --- */
:root { 
    --primary-color: #ff6699; 
    --bg-color: #f4f6f9; 
    --text-color: #333;
    --text-muted: #666;
    --card-bg: rgba(255, 255, 255, 0.85); 
    --border-color: #eee;
    --th-bg: rgba(252, 252, 252, 0.6); 
    --highlight-bg: #fff3cd;
    --hover-bg: rgba(255, 240, 245, 0.8); /* Made hover slightly transparent too */
}

/* Dark Mode Variables */
body.dark-mode {
    --primary-color: #ff88b3;
    --bg-color: #121212;
    --text-color: #f5f5f5; /* Pure bright text */
    --text-muted: #bbbbbb; /* Brighter muted text */
    --card-bg: rgba(30, 30, 30, 0.9); 
    --border-color: #444;
    --th-bg: rgba(45, 45, 45, 0.8); 
    --highlight-bg: #443c22;
    --hover-bg: rgba(50, 40, 45, 0.9); 
}

/* --- Global Styles --- */
body { 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    background-color: var(--bg-color); 
    color: var(--text-color); 
    margin: 0; 
    padding: 20px; 
    transition: background-color 0.3s, color 0.3s;
}

.container { 
    max-width: 1200px; 
    margin: auto; 
    position: relative;
    z-index: 1; /* Keeps content above background */
}

/* --- THE BACKGROUND IMAGE (Faded in Center, Solid on Edges) --- */
.bg-image {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -10; 
    background: url('./background_mumu.webp') no-repeat center center;
    background-size: cover;
    
    /* THE MAGICAL HORIZONTAL FADE MASK */
    /* rgba(0,0,0,1) = Image is 100% visible 
       rgba(0,0,0,0) = Image is completely invisible (faded out)
    */
    -webkit-mask-image: linear-gradient(
        to right, 
        rgba(0,0,0,1) 0%,       /* Left edge: Solid image */
        rgba(0,0,0,0) 25%,      /* 25% inward: Fully faded out */
        rgba(0,0,0,0) 75%,      /* 75% inward: Stays fully faded out across the middle */
        rgba(0,0,0,1) 100%      /* Right edge: Solid image */
    );
    mask-image: linear-gradient(
        to right, 
        rgba(0,0,0,1) 0%, 
        rgba(0,0,0,0) 25%, 
        rgba(0,0,0,0) 75%, 
        rgba(0,0,0,1) 100%
    );
}

/* Ensure container content sits cleanly above the background */
.container { 
    max-width: 1200px; 
    margin: auto; 
    position: relative;
    z-index: 1;
}

/* --- Top Bar (Theme & Lang Controls) --- */
.top-bar {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    gap: 10px;
    z-index: 10;
}

.icon-btn {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 1.2em;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.icon-btn:hover {
    transform: scale(1.1);
    border-color: var(--primary-color);
}

/* --- Header & Profile --- */
.header { 
    text-align: center; 
    background: var(--card-bg); 
    padding: 30px; 
    border-radius: 12px; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.05); 
    margin-bottom: 20px; 
    margin-top: 40px;
    transition: background 0.3s;
}

.avatar { 
    width: 120px; 
    height: 120px; 
    border-radius: 50%; 
    border: 4px solid var(--primary-color); 
    object-fit: cover; 
}

.stats { 
    display: flex; 
    justify-content: center; 
    gap: 40px; 
    margin: 20px 0; 
    color: var(--text-muted); 
}

/* --- Buttons --- */
.btn { 
    padding: 10px 20px; 
    text-decoration: none; 
    color: white !important; 
    border-radius: 8px; 
    display: inline-block; 
    font-weight: bold; 
    cursor: pointer; 
    border: none; 
    font-size: 1em; 
    transition: all 0.2s ease-in-out; 
}

.btn:hover { 
    opacity: 0.85; 
    transform: translateY(-2px);
}

.header-btn {
    background: var(--primary-color);
    margin: 5px;
}

/* --- Live Stream Previews --- */
.streams-container { 
    display: flex; 
    flex-wrap: wrap; 
    justify-content: space-between; 
    gap: 20px; 
    margin-bottom: 30px; 
}

.stream-card { 
    background: var(--card-bg); 
    flex: 1; 
    min-width: 300px; 
    padding: 20px; 
    border-radius: 12px; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.05); 
    text-align: center; 
    border-top: 5px solid var(--brand-color, #ccc);
    display: flex;
    flex-direction: column;
    transition: background 0.3s;
}

.stream-card h3 { 
    margin-top: 0; 
    font-size: 1.2em; 
    color: var(--text-color); 
}

.stream-card .btn {
    background: var(--brand-color);
    margin-top: 15px;
    width: 80%;
    align-self: center;
}

.bilibili-theme { --brand-color: #fb7299; }
.youtube-theme  { --brand-color: #ff0000; }
.twitch-theme   { --brand-color: #9146ff; }

.iframe-wrapper { 
    position: relative; 
    width: 100%; 
    padding-bottom: 56.25%; 
    height: 0; 
    overflow: hidden; 
    border-radius: 8px; 
    background: #000; 
}

.responsive-iframe { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    border: none; 
}

/* --- Search & Controls --- */
.controls { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 20px; 
    flex-wrap: wrap; 
    gap: 10px; 
}

.search-bar { 
    padding: 12px; 
    width: 100%; 
    max-width: 400px; 
    border: 1px solid var(--border-color); 
    border-radius: 8px; 
    font-size: 1em; 
    background: var(--card-bg);
    color: var(--text-color);
    transition: background 0.3s, color 0.3s;
}

/* --- Song List Table --- */
/* Add smooth transitions to the table rows */
tbody tr {
    transition: all 0.2s ease-in-out;
    position: relative; /* Required for the pop-up shadow to overlap other rows */
}

/* The actual "Pop Up" effect when hovered */
tbody tr:hover {
    background-color: var(--hover-bg);
    transform: scale(1.01) translateY(-2px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.08);
    z-index: 2;
}

/* Hide the bottom border when hovering so it looks like a floating card */
tbody tr:hover td {
    border-bottom-color: transparent;
}

.song-table-wrapper { 
    background: var(--card-bg); 
    border-radius: 12px; 
    padding: 20px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.05); 
    overflow-x: auto; 
    transition: background 0.3s;
    
    /* THE MAGICAL FROSTED GLASS EFFECT */
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

table { 
    width: 100%; 
    border-collapse: collapse; 
    min-width: 600px; 
}

th, td { 
    padding: 15px; 
    text-align: left; 
    border-bottom: 1px solid var(--border-color); 
}

th { 
    background-color: var(--th-bg); 
    color: var(--text-muted); 
    transition: background 0.3s;
}

.song-name { 
    cursor: pointer; 
    color: #007bff; 
    text-decoration: none; 
    font-weight: 500; 
    transition: color 0.2s; 
}

body.dark-mode .song-name {
    color: #5ea8ff;
}

.song-name:hover { 
    color: var(--primary-color); 
    text-decoration: underline; 
}

.copy-hint { 
    font-size: 0.85em; 
    color: #28a745; 
    margin-left: 8px; 
    font-weight: bold;
    pointer-events: none; 
}

.loading-text { 
    text-align: center; 
    padding: 20px; 
    color: var(--text-muted); 
    font-style: italic; 
}

/* --- Footer --- */
.footer { 
    text-align: center; 
    margin-top: 40px; 
    font-size: 0.9em; 
    color: var(--text-muted); 
    line-height: 1.8; 
}

.footer a { 
    color: var(--primary-color); 
    text-decoration: none; 
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    /* Maximize screen real estate */
    body { 
        padding: 10px; 
    }
    
    /* Adjust top buttons so they don't overlap the header */
    .top-bar { 
        top: 10px; 
        right: 10px; 
    }
    .icon-btn { 
        width: 36px; 
        height: 36px; 
        font-size: 1em; 
    }

    /* Shrink the header profile slightly */
    .header { 
        padding: 20px 15px; 
        margin-top: 50px; /* Pushes header down so top-bar buttons don't clip it */
    }
    .avatar { 
        width: 90px; 
        height: 90px; 
    }
    .stats { 
        gap: 20px; 
        font-size: 0.9em; 
    }

    /* Stack the stream cards properly */
    .streams-container { 
        flex-direction: column; 
    }
    .stream-card { 
        min-width: 100%; 
        padding: 15px; 
    }

    /* Make the search bar take up the full width */
    .controls { 
        flex-direction: column; 
        align-items: stretch; 
    }
    .search-bar { 
        max-width: 100%; 
        margin-bottom: 10px;
    }
    .controls .btn {
        width: 100%;
        margin: 0;
    }

    /* Mobile Table Fixes */
    .song-table-wrapper { 
        padding: 10px; 
        -webkit-overflow-scrolling: touch; /* Enables buttery-smooth momentum scrolling on iOS/Android */
    }
    table { 
        min-width: 500px; /* Allows it to be a bit smaller before forcing a scroll */
    }
    th, td { 
        padding: 10px 8px; 
        font-size: 0.9em; 
        white-space: nowrap; /* Prevents text from stacking vertically into unreadable columns */
    }
    /* Let the song title wrap if it's super long, but keep other columns neat */
    td:nth-child(2) { 
        white-space: normal; 
        min-width: 180px; 
    }
}

/* --- Navigation Cards (Subpages) --- */
.nav-cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.nav-card {
    background: var(--card-bg);
    padding: 30px 20px;
    border-radius: 12px;
    text-align: center;
    text-decoration: none;
    color: var(--text-color);
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
    border: 2px solid transparent;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.nav-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    background: var(--hover-bg);
}

.nav-card-icon {
    font-size: 3em;
    margin-bottom: 15px;
}

.nav-card-title {
    font-size: 1.3em;
    font-weight: bold;
    margin-bottom: 10px;
}

.nav-card-desc {
    font-size: 0.9em;
    color: var(--text-muted);
}

/* A simple back button for subpages */
.back-btn {
    display: inline-block;
    margin-bottom: 20px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: bold;
    transition: color 0.2s;
}
.back-btn:hover {
    color: var(--primary-color);
}

/* --- Offline/Online Stream States --- */
.offline-img {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    z-index: 5; /* Image on top initially */
    transition: opacity 0.8s ease-in-out;
}

.iframe-wrapper.is-live .offline-img {
    opacity: 0;
    pointer-events: none;
}

.responsive-iframe {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 1; /* Iframe stays underneath */
}

/* --- Jigsaw Mini Game --- */
.stats-bar {
    display: flex;
    justify-content: space-around;
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 15px;
    color: var(--text-color);
}

.difficulty-selector .btn {
    background: transparent;
    color: var(--primary-color) !important;
    border: 2px solid var(--primary-color);
    margin: 5px;
    transition: all 0.2s ease;
}

.difficulty-selector .btn:hover {
    background: var(--primary-color);
    color: #fff !important; /* White text only on hover when background is pink */
    transform: translateY(-2px);
}

.difficulty-selector .btn.active {
    background: var(--primary-color);
    color: #fff !important;
    box-shadow: 0 4px 10px rgba(255, 102, 153, 0.3);
}

.puzzle-board {
    width: 100%;
    max-width: 500px;
    aspect-ratio: 2 / 3; /* Forces the perfect portrait ratio */
    margin: 0 auto;
    position: relative;
    background: var(--bg-color);
    border: 3px solid var(--primary-color);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    
    /* CRITICAL FOR MOBILE: Prevents the page from scrolling when dragging pieces */
    touch-action: none; 
}

.puzzle-piece {
    position: absolute;
    background-image: url('./jigsaw-source.webp');
    transition: left 0.15s ease-out, top 0.15s ease-out; /* Buttery smooth sliding */
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15); /* Adds grid lines */
}

/* Hide the empty slot during gameplay */
.puzzle-piece.empty {
    opacity: 0;
    pointer-events: none;
}

/* --- Jigsaw Stats & Text Fix --- */
.stats-bar {
    display: flex;
    justify-content: space-around;
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 15px;
    color: var(--text-color); /* Ensures it follows Theme colors */
}

/* --- Victory Modal Pop-up Fix --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.7); /* Darker overlay for focus */
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(8px);
}

.modal-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    color: var(--text-color);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    max-width: 90%;
    width: 380px;
    border: 1px solid var(--border-color);
}

.modal-content h2 {
    color: var(--primary-color);
    margin-top: 0;
}

/* Fix for the "Play Again" button in the modal */
.modal-content .btn {
    background: var(--primary-color);
    color: #fff !important; /* Forces white text on the pink background */
    padding: 12px 30px;
    font-size: 1.1em;
    margin-top: 20px;
    display: inline-block;
    box-shadow: 0 4px 15px rgba(255, 102, 153, 0.4);
}

/* Fix for standard body text inside the modal */
.modal-content p {
    color: var(--text-color);
    margin: 10px 0;
    font-size: 1.1em;
}

.modal-content p strong {
    color: var(--text-muted);
}