:root {
    /* Paleta de colores principal basada en CrazyGames */
    --color-bg-dark: #0c0d14;
    --color-bg-medium: #13141E;
    --color-bg-light: #1A1B28;
    --color-bg-header: #212233;
    --color-text-main: #F9FAFF;
    --color-text-secondary: #BDBFCE;
    --color-primary: #6842ff;
    --color-accent: #DA7F14;
    --color-link: #A48EFF;
    --header-height: 60px;

    /* Variables del Sidebar */
    --color-sidebar-bg: #151620;
    --sidebar-width: 50px;
    --sidebar-expanded-width: 200px;
}

/* Reset básico */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Nunito', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background-color: var(--color-bg-dark);
    color: var(--color-text-main);
    line-height: 1.5;
    background-image: url("https://www.crazygames.com/images/background2.webp");
    background-repeat: repeat;
    background-attachment: fixed;
    overflow-x: hidden;
}

body.modal-open {
    overflow: hidden;
}

/* Tipografía y Enlaces */
h1, h2, h3, h4 {
    color: var(--color-text-main);
    font-weight: 800;
}
h2 {
    font-size: 24px;
    line-height: 31px;
}
a {
    text-decoration: none;
    color: var(--color-text-main);
}
a:hover {
    color: var(--color-link);
}
button {
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    border-radius: 30px;
    transition: all 250ms ease;
    height: 35px;
}

/* =========================================
   2. LAYOUT PRINCIPAL (GRID) Y SIDEBAR DINÁMICO
   ========================================= */

.css-12gyrsz {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
    transition: grid-template-columns 0.3s ease;
}

.css-12gyrsz.sidebar-hidden {
    grid-template-columns: 0 1fr;
}

/* ⬅️ BARRA LATERAL (SIDEBAR) */
.sidebar {
    grid-column: 1 / 2;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background-color: var(--color-sidebar-bg);
    padding-top: var(--header-height);
    z-index: 50;
    box-shadow: 2px 0 5px rgba(0, 0, 0, 0.4);
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.3s ease, opacity 0.3s ease;
}

.sidebar.hidden {
    width: 0;
    opacity: 0;
    visibility: hidden;
}

.sidebar.visible {
    width: var(--sidebar-width);
    opacity: 1;
    visibility: visible;
}

.sidebar.visible:hover,
.sidebar.visible.expanded {
    width: var(--sidebar-expanded-width);
}

.sidebar::-webkit-scrollbar {
    width: 0;
}

.sidebar ul {
    list-style: none;
    padding: 10px 0;
}

.sidebar a {
    display: flex;
    align-items: center;
    height: 40px;
    padding: 0 15px;
    color: var(--color-text-secondary);
    font-size: 14px;
    transition: background-color 0.2s, color 0.2s;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar a:hover {
    background-color: var(--color-bg-light);
    color: var(--color-text-main);
}

.sidebar a img {
    width: 20px;
    height: 20px;
    margin-right: 15px;
    flex-shrink: 0;
    transition: opacity 0.3s ease;
}

.sidebar.visible a img {
    opacity: 1;
}

.sidebar a .link-text {
    transition: opacity 0.3s ease;
    opacity: 0;
}

.sidebar.visible:hover a .link-text,
.sidebar.visible.expanded a .link-text {
    opacity: 1;
}

/* ⏫ HEADER */
.css-hpaxx3 {
    grid-column: 1 / -1;
    z-index: 100;
    position: fixed;
    top: 0;
    width: 100%;
    height: var(--header-height);
    background: var(--color-bg-header);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* ⬇️ MAIN */
.css-z8nxkr {
    grid-column: 2 / 3;
    margin-top: var(--header-height);
    padding: 16px;
    min-height: calc(100vh - var(--header-height));
    max-width: 100%;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
}

.css-z8nxkr.sidebar-hidden {
    margin-left: 0;
}

.css-z8nxkr.sidebar-active {
    margin-left: var(--sidebar-expanded-width);
}

/* ------------------------------------------- */
/* 3. ELEMENTOS DEL HEADER                     */
/* ------------------------------------------- */

.logo-area {
    display: flex;
    align-items: center;
}

.logo-text-img {
    height: 20px;
}

.menu-toggle {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    width: 40px;
    margin-right: 8px;
    font-size: 0;
    position: relative;
}

.menu-toggle::before {
    content: "";
    font-size: 20px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.menu-toggle:hover {
    color: var(--color-text-main);
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
}

.search-area {
    display: flex;
    align-items: center;
}

#search-input {
    background-color: var(--color-bg-light);
    border: none;
    border-radius: 15px 0 0 15px;
    padding: 8px 12px;
    color: var(--color-text-main);
    font-size: 14px;
    width: 200px;
    transition: width 0.3s ease;
}

#search-input:focus {
    outline: none;
    width: 250px;
    background-color: var(--color-bg-medium);
}

#search-input::placeholder {
    color: var(--color-text-secondary);
}

.css-h9dwsh {
    background: transparent;
    border: none;
    color: var(--color-text-secondary);
    width: 40px;
    margin-left: -1px;
    font-size: 0;
    position: relative;
    border-radius: 0 15px 15px 0;
    background-color: var(--color-bg-light);
}

.css-h9dwsh::before {
    content: "";
    font-size: 20px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.css-h9dwsh:hover {
    color: var(--color-text-main);
    background-color: rgba(255, 255, 255, 0.1);
}

/* ------------------------------------------- */
/* 4. SECCIONES DE JUEGOS                      */
/* ------------------------------------------- */

.section-title {
    font-size: 20px;
    font-weight: 900;
    color: var(--color-text-main);
    padding: 16px 0 10px 0;
    margin-top: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.view-more {
    font-size: 14px;
    font-weight: 600;
    padding: 6px 12px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: var(--color-text-main);
    border-radius: 20px;
    text-decoration: none;
    transition: transform 0.2s, box-shadow 0.2s;
}

.view-more:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(104, 66, 255, 0.4);
}

.featured-carousel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.featured-group {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 8px;
    height: 300px;
    min-width: 0;
}

.featured-large {
    width: 100%;
    height: 300px;
    min-height: 0;
    position: relative;
}

.featured-small-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 8px;
    height: 100%;
    min-height: 0;
}

.featured-small {
    width: 100%;
    height: 140px;
    min-height: 0;
    position: relative;
}

.horizontal-carousel,
.vertical-carousel {
    overflow-x: auto;
    display: flex;
    gap: 12px;
    padding-bottom: 15px;
    scrollbar-width: none;
    min-height: 150px;
}

.horizontal-carousel::-webkit-scrollbar,
.vertical-carousel::-webkit-scrollbar {
    display: none;
}

.horizontal-game-card {
    width: 250px;
    height: 140px;
    flex-shrink: 0;
    min-height: 140px;
    position: relative;
}

.vertical-carousel {
    overflow-y: auto;
    flex-direction: column;
    max-height: 600px;
    min-height: 200px;
    gap: 12px;
}

.vertical-game-card {
    width: 200px;
    height: 280px;
    min-height: 280px;
    flex-shrink: 0;
    position: relative;
}

.vertical-game-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.grid-carousel {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    min-height: 300px;
}

.grid-game-card {
    width: 100%;
    height: 280px;
    min-height: 280px;
    position: relative;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    padding: 16px;
    min-height: 300px;
}

/* TARJETAS DE JUEGO */
.game-card {
    display: block;
    border-radius: 12px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s;
    flex-shrink: 0;
    background: var(--color-bg-light);
    cursor: pointer;
}

.game-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
}

.game-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.game-card img.horizontal {
    display: none;
}

.game-card img.vertical {
    display: block;
}

.horizontal-game-card img.horizontal,
.vertical-game-card img.vertical,
.grid-game-card img.vertical,
.featured-large img.horizontal,
.featured-small img.horizontal {
    display: block;
}

.horizontal-game-card img.vertical,
.vertical-game-card img.horizontal,
.grid-game-card img.horizontal,
.featured-large img.vertical,
.featured-small img.vertical {
    display: none;
}

.updated-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background-color: var(--color-primary);
    color: var(--color-text-main);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    z-index: 5;
}

.game-title {
    position: absolute;
    top: 8px;
    left: 8px;
    font-size: 12px;
    color: #ffffff;
    background-color: rgba(0, 0, 0, 0.6);
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 10;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 16px);
}

/* ========================================= */
/*  MODAL - CORRECCIONES SOLICITADAS         */
/* ========================================= */

.modal-overlay {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.85);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.modal-overlay.visible {
    opacity: 1;
    pointer-events: auto;
    display: flex;
}

.modal-content {
    background-color: var(--color-bg-medium);
    width: 100vw;
    height: 100vh;
    padding: 0;
    border-radius: 0;
    color: var(--color-text-main);
    position: relative;
    display: grid;
    grid-template-columns: 2fr 1fr;
    grid-template-rows: auto auto 1fr auto;
    gap: 0;
    overflow: hidden;
}

/* Título y cierre */
.modal-content h2 {
    grid-column: 1 / 2;
    margin: 20px 20px 0 20px;
    font-size: 28px;
    font-weight: 900;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-size: 28px;
    cursor: pointer;
    z-index: 2001;
    padding: 10px;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close:hover {
    background: rgba(255,255,255,0.1);
    color: var(--color-text-main);
}

/* ETIQUETAS DE GÉNERO: debajo del título, izquierda */
.modal-tags {
    grid-column: 1 / 2;
    margin: 10px 20px 15px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.modal-tags a {
    background: var(--color-bg-light);
    color: var(--color-primary);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.modal-tags a:hover {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* REPRODUCTOR */
.modal-player {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
    margin: 0 20px;
    background-color: var(--color-bg-light);
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-player-controls {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(0,0,0,0.2);
    flex-wrap: wrap;
}

.btn-control {
    appearance: none;
    border: 0;
    border-radius: 12px;
    padding: 8px 14px;
    font-weight: 800;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: white;
    box-shadow: 0 4px 10px #0007;
    font-size: 14px;
    min-height: 36px;
}

.btn-control svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.btn-play {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
}

.btn-reload,
.btn-fullscreen {
    background: linear-gradient(135deg, #0d1a30, #0b1426);
    border: 1px solid #2a3f6b;
}

.modal-player iframe {
    flex: 1;
    border: none;
    background: #000;
}

/* DESCRIPCIÓN */
.modal-description {
    grid-column: 1 / 2;
    grid-row: 4 / 5;
    margin: 20px 20px 20px 20px;
    line-height: 1.7;
    font-size: 15px;
    color: var(--color-text-secondary);
    max-height: 200px;
    overflow-y: auto;
    padding-right: 10px;
}

/* SCROLL PERSONALIZADO EN DESCRIPCIÓN */
.modal-description::-webkit-scrollbar {
    width: 6px;
}

.modal-description::-webkit-scrollbar-track {
    background: transparent;
}

.modal-description::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 3px;
}

.modal-description::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.5);
}

/* JUEGOS RELACIONADOS - ALINEADOS ARRIBA */
.modal-related {
    grid-column: 2 / 3;
    grid-row: 1 / 5;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    align-content: flex-start;
}

.modal-related h3 {
    font-size: 18px;
    font-weight: 800;
    color: var(--color-text-main);
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sidebar-column .game-card {
    width: 100%;
    height: 90px;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    transition: transform 0.2s;
}

.sidebar-column .game-card:hover {
    transform: translateY(-3px);
}

.sidebar-column .game-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sidebar-column .game-title {
    font-size: 11px;
    padding: 4px 6px;
    max-width: calc(100% - 12px);
}

/* SCROLL PERSONALIZADO EN MODAL RELATED */
.modal-related::-webkit-scrollbar {
    width: 8px;
}

.modal-related::-webkit-scrollbar-track {
    background: transparent;
}

.modal-related::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

.modal-related::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.4);
}

footer {
    grid-column: 1 / 3;
    width: 100%;
    padding: 20px;
    text-align: center;
    color: var(--color-text-secondary);
    margin-top: auto;
    background-color: var(--color-bg-medium);
    border-top: 1px solid var(--color-bg-header);
    z-index: 5;
}

footer a {
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

footer a:hover {
    color: var(--color-link);
    text-decoration: underline;
}