:root {
    /* --- PALETA DE COLORES CENTRALIZADA --- */

    /* Paleta Principal */
    --color-bg-page: #8b94b1;
    --color-bg-container: #E6E6E6;
    --color-text-primary: #333333;
    --color-text-secundary: #666; 
    --color-accent-green: #27ae60;
    
    /* Paleta Heatmap */
    --color-rating-low: #CB644E;
    --color-rating-mid: #FEE09F;
    --color-rating-high: #27ae60;

    /* Colores de UI */
    --color-bg-light: #ffffff;
    --color-border-neutral: #d8e0e0; 
    --color-bg-table-header: #eef3f3; 
    --color-text-muted: #6c757d;
    --color-text-footer: rgba(255, 255, 255, 0.85);

    /* Colores Específicos de Componentes */
    --color-switch-inactive: #ccc;
    --color-bg-no-rating: #f5f5f5;
    --color-shadow-main: rgba(0, 0, 0, 0.15);
    --color-shadow-focus: rgba(39, 174, 96, 0.2);
}

html {
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: inherit;
}

body {
    font-family: "Poppins", sans-serif;
    line-height: 1.6;
    margin: 0;
    background-color: var(--color-bg-page);
    color: var(--color-text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.page-wrapper {
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 20px;
    flex-grow: 1;
}

.app-container {
    background: var(--color-bg-container);
    width: 100%;
    max-width: 1200px;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 10px 35px var(--color-shadow-main);
    margin: 20px 0;
}

h1 {
    text-align: center;
    margin-top: 0;
    margin-bottom: 30px;
    font-size: 2.6em;
    font-weight: 700;
}

.results-title {
    text-align: center;
    margin-top: 20px;
    margin-bottom: 20px;
    font-size: 1.5em;
    font-weight: 600;
}

.search-section {
    display: flex;
    justify-content: center;
    margin-bottom: 35px;
}

.search-container {
    display: flex;
    width: 100%;
    max-width: 500px;
}

#seriesNameInput {
    padding: 12px 15px;
    font-size: 1em;
    border: 1px solid var(--color-border-neutral);
    border-radius: 6px 0 0 6px;
    width: 70%;
}
#seriesNameInput:focus {
    border-color: var(--color-accent-green);
    box-shadow: 0 0 0 3px var(--color-shadow-focus);
    outline: none;
}

#searchButton {
    padding: 12px 20px;
    font-size: 1em;
    background-color: var(--color-accent-green);
    border: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    font-weight: 600;
    color: var(--color-bg-light); 
}

#tableControlsContainer { display: flex; justify-content: center; align-items: flex-start; gap: 50px; margin-bottom: 25px; padding: 10px 0; flex-wrap: wrap; }
.control-wrapper { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.main-control-label { font-size: .9em; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.control-group { display: flex; align-items: center; gap: 15px; }
.control-label { font-size: 1.1em; font-weight: 500; cursor: default; transition: color .2s ease-in-out; color: var(--color-text-muted); }
.control-label.active { font-weight: 700; color: var(--color-text-primary); }
.switch { position: relative; display: inline-block; width: 50px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; inset: 0; background-color: var(--color-switch-inactive); transition: .4s; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px; background-color: var(--color-bg-light); transition: .4s; }
.switch input:checked + .slider { background-color: var(--color-accent-green); }
.switch input:checked + .slider:before { transform: translateX(26px); }
.slider.round { border-radius: 24px; }
.slider.round:before { border-radius: 50%; }

.search-results-list { list-style: none; padding: 0; margin: 0; }
.search-results-list li { padding: 12px 15px; border: 1px solid var(--color-border-neutral); background-color: var(--color-bg-light); margin-bottom: 10px; border-radius: 6px; cursor: pointer; }

.series-info-full {
    display: flex;
    align-items: flex-start;
    gap: 25px;
    margin-bottom: 30px;
    padding: 25px; 
    border-radius: 6px;
    background-color: var(--color-bg-light);
    border: 1px solid var(--color-border-neutral);
    position: relative; 
    overflow: hidden;
    transition: max-height 0.5s ease-in-out;
    max-height: 5000px;
}

.series-info-full img.series-poster,
.series-info-full .series-details-text {
    opacity: 1;
    transition: max-height 0.3s 0.2s, max-width 0.3s 0.2s, opacity 0.3s 0.2s, margin 0.3s 0.2s, padding 0.3s 0.2s;
}

.expand-prompt {
    position: absolute;
    left: 25px;
    right: 50px;
    top: 15px; 
    height: 24px; 
    display: flex;
    align-items: center;
    margin: 0;
    font-weight: 500;
    color: var(--color-text-secundary);
    opacity: 0;
    transition: opacity 0.3s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toggle-details-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: 5;
    width: 24px;
    height: 24px;
    transition: transform 0.4s ease-in-out;
}
.toggle-details-btn img {
    width: 100%;
    height: 100%;
}

.series-info-full.collapsed {
    max-height: 54px; 
}
.series-info-full.collapsed .expand-prompt {
    opacity: 1;
    transition-delay: 0.2s;
}
.series-info-full.collapsed img.series-poster,
.series-info-full.collapsed .series-details-text {
    max-height: 0;
    max-width: 0;
    opacity: 0;
    padding: 0;
    margin: 0;
    border: 0;
    transition: max-height 0.3s, max-width 0.3s, opacity 0.2s, margin 0.3s, padding 0.3s;
}
.series-info-full.collapsed .toggle-details-btn {
    transform: rotate(180deg);
}

#ratingsTableContainer { overflow-x: auto; }
.ratings-table { border-collapse: collapse; margin: 0 auto; width: 100%;}
.ratings-table th, .ratings-table td { border: 1px solid var(--color-border-neutral); text-align: center; min-width: 60px; min-height: 60px; padding: 2px; vertical-align: middle; position: relative; }
.ratings-table th { background-color: var(--color-bg-table-header); }
.ratings-table th.table-main-header, .ratings-table td.chapter-label { background-color: var(--color-bg-table-header); position: sticky; left: 0; z-index: 10; }
.ratings-table th.table-main-header { z-index: 20; }
.ratings-table th.season-header { writing-mode: vertical-rl; text-orientation: mixed; }
.ratings-table td.chapter-label { font-weight: 600; }
.rating-cell-content { display: flex; flex-direction: column; justify-content: center; align-items: center; }
.rating-value { font-size: 1.3em; font-weight: bold; color: var(--color-text-secundary); }
.episode-name-display { font-size: .65em; max-height: 4.4em; overflow: hidden; display: none; margin-top: 2px; }
.ratings-table.show-episode-names .episode-name-display { display: block; }
.ratings-table td.no-rating { background-color: var(--color-bg-no-rating); }

#loading, #error { text-align: center; margin: 20px; font-weight: bold; }
.site-footer { text-align: center; padding: 20px 0; margin-top: 20px; font-size: 0.9em; color: var(--color-text-footer); font-weight: 500; flex-shrink: 0; }


.top-episodes-section {
    margin-top: 40px;
    padding: 25px;
    background-color: var(--color-bg-light);
    border-radius: 6px;
    border: 1px solid var(--color-border-neutral);
}

.top-episodes-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
}

.top-episodes-table th, 
.top-episodes-table td {
    padding: 12px 15px;
    border: 1px solid var(--color-border-neutral);
    text-align: center;
}

.top-episodes-table thead th {
    background-color: var(--color-bg-table-header);
    font-weight: 600;
}

.top-episodes-table tbody tr:nth-of-type(even) {
    background-color: var(--color-bg-no-rating);
}

.top-episodes-table td[data-label="Calificación"],
.top-episodes-table td[data-label="#"] {
    font-weight: bold;
    text-align: center;
}


@media (max-width: 768px) {
    .page-wrapper { padding: 0 15px; }
    .app-container { padding: 20px; }
    .series-info-full { flex-direction: column; align-items: center; text-align: center; padding: 20px; }
    .series-info-full.collapsed {
        padding-top: 15px;
        padding-bottom: 15px;
    }
    .series-info-full.collapsed .expand-prompt { left: 10%; transform: translateX(-10%); top: 15px; }
    .series-info-full.collapsed .series-poster { max-height: 0; margin-left: 0; margin-bottom: -25px; }
    .series-info-full img.series-poster { width: 160px; height: auto; max-width: 160px; max-height: 240px; }
    #searchResultsListContainer { width: 90%; }
    
    .top-episodes-section { padding: 15px; }
    .top-episodes-table { font-size: .8em; }
    .top-episodes-table thead { display: none; }
    .top-episodes-table, .top-episodes-table tbody, .top-episodes-table tr, .top-episodes-table td {
        display: block;
        width: 100%;
    }
    .top-episodes-table tr {
        margin-bottom: 15px;
        border: 1px solid var(--color-border-neutral);
        border-radius: 4px;
        overflow: hidden;
    }
    .top-episodes-table td {
        text-align: right;
        padding-left: 50%;
        position: relative;
        border: none;
        border-bottom: 1px solid var(--color-bg-container);
    }
    .top-episodes-table td:before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        width: calc(50% - 20px);
        padding-right: 10px;
        white-space: nowrap;
        text-align: left;
        font-weight: bold;
    }
    .top-episodes-table td:last-child { border-bottom: 0; }
    .top-episodes-table td[data-label="Calificación"],
    .top-episodes-table td[data-label="#"] { text-align: right; }
}

@media (max-width: 576px) {
    h1 { font-size: 1.9em; }
    .search-container { flex-direction: column; }
    #seriesNameInput, #searchButton { width: 100%; border-radius: 6px; }
    #seriesNameInput { margin-bottom: 10px; }
    #tableControlsContainer { gap: 20px; }
    .series-info-full img.series-poster { width: 140px; max-width: 140px; }
    #searchResultsListContainer { width: 95%; margin: 20px auto; }
    .search-results-list li { padding: 10px; font-size: .9em; }
}

/* --- TOOLTIP PERSONALIZADO (SOLO ESCRITORIO) --- */
.custom-tooltip {
    position: fixed;
    z-index: 1000;
    background-color: #333;
    color: #fff;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.85em;
    max-width: 400px;
    text-align: left;
    white-space: pre-wrap;
    display: none;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

/* --- ESTILOS DEL MODAL DE EPISODIO (MÓVIL) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 15px;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}
.modal-content {
    background: var(--color-bg-light);
    color: var(--color-text-primary);
    padding: 25px;
    border-radius: 8px;
    max-width: 500px;
    width: 100%;
    position: relative;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    transform: scale(0.9);
    transition: transform 0.3s ease-in-out;
}
#modalEpisodeDetails h4 {
    margin-top: 0;
    font-size: 1.4em;
    color: var(--color-text-primary);
}
#modalEpisodeDetails p {
    margin-bottom: 10px;
    line-height: 1.5;
}
#modalEpisodeDetails .modal-synopsis {
    margin-top: 15px;
    font-size: 0.95em;
    color: var(--color-text-secundary);
}

.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 2em;
    line-height: 1;
    color: #999;
    cursor: pointer;
}