/* --- General Styles --- */
html {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Default space for standard pages */
body {
    margin: 0;
    padding: 0;
    padding-bottom: 120px;
    background-color: #555;
}

img, video {
    max-width: 100%;
    height: auto;
    display: block;
}

/* --- Links & Hover Logic --- */
a:link, a:visited {
    color: #2c2c2c;
    text-decoration: none;
    transition: color 0.2s ease;
}

/* General hover for links */
a:hover {
    color: #FF0000 !important;
}

/* Link becomes red when the table cell is hovered */
.section-table td:hover a {
    color: #FF0000 !important;
}

/* Specific to the links page: Only affect rows that contain an image cell (excludes bottom nav) */
#page-links .section-table tr:has(img):hover td a {
    color: #FF0000 !important;
}

/* --- Fonts (Cera Pro Family) --- */
@font-face {
    font-family: 'Cera Pro Bold';
    src: url('../fonts/CeraPro-Bold.woff2') format('woff2'),
         url('../fonts/CeraPro-Bold.woff') format('woff');
    font-weight: 700;
}

@font-face {
    font-family: 'Cera Pro';
    src: url('../fonts/CeraPro-Medium.woff2') format('woff2'),
         url('../fonts/CeraPro-Medium.woff') format('woff');
    font-weight: 500;
}

@font-face {
    font-family: 'Cera Pro';
    src: url('../fonts/CeraPro-Regular.woff2') format('woff2'),
         url('../fonts/CeraPro-Regular.woff') format('woff');
    font-weight: 400;
}

@font-face {
    font-family: 'Cera Pro Italic';
    src: url('../fonts/CeraPro-BoldItalic.woff2') format('woff2'),
         url('../fonts/CeraPro-BoldItalic.woff') format('woff');
    font-weight: 700;
    font-style: italic;
}

/* Horizontal rules matching text color */
hr {
    border: 0;
    border-top: 1px solid #2c2c2c;
    margin: 10px 0;
    opacity: 0.3;
}

/* --- Layout Structure --- */
.header, .section {
    max-width: 900px;
    width: 100%;
    margin: 15px auto 0 auto; /* 15px top, auto right, 0 bottom, auto left to avoid layout conflicts */
    font-family: 'Cera Pro', sans-serif;
}

.header-table, .section-table {
    width: 100%;
    background-color: #dddddd;
    color: #2c2c2c;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 10px;
    font-size: 1rem;
    line-height: 1.4;
    margin: 0 auto;
}

.section-table td {
    text-align: justify;
    vertical-align: middle;
    hyphens: auto;
}

/* Force video rows to take full width in fixed table layouts */
.section-table tr:has(.video-wrapper) td {
    width: 100%;
}

/* --- Bottom navigation --- */
.nav-left { text-align: left !important; }
.nav-center { text-align: center !important; }
.nav-right { text-align: right !important; }

/* --- Banners and titles centered --- */
.section-table td[colspan="2"] img {
    margin: 0 auto; 
}

.section-table-bold { font-size: 1.2em; font-weight: 500; }
.section-table-medium { font-size: 0.95em; font-weight: 500; }

.section-table-bold-italic {
    font-family: 'Cera Pro Italic', sans-serif;
    font-size: 1.2em;
    font-weight: 700;
    text-align: center !important;
}

/* --- Video Player Styles --- */
.video-wrapper {
    position: relative;
    width: 200px;
    height: 112px;
    background-color: #000;
    cursor: pointer;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: width 0.3s ease, height 0.3s ease;
    margin-left: 0;
}

/* Responsive expansion without fixed pixel breaking points */
.video-wrapper.video-open {
    width: 100% !important;
    max-width: 880px;
    height: auto !important;
    aspect-ratio: 16 / 9;
    cursor: default;
}

/* Force the video element injected by JS to fill the fluid container */
.video-wrapper.video-open video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

.video-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.play-icon {
    position: absolute;
    z-index: 2;
    width: 0; height: 0;
    border-style: solid;
    border-width: 11px 0 11px 18px;
    border-color: transparent transparent transparent rgba(255, 255, 255, 0.9);
}

.close-btn {
    position: absolute;
    top: 10px; right: 15px;
    font-size: 32px; color: white;
    font-weight: bold; z-index: 100;
    cursor: pointer;
    text-shadow: 0 0 8px rgba(0,0,0,0.9);
}

.close-btn:hover { color: #ff0000; }

.video-caption {
    display: block;
    margin-top: 8px;
    color: #2c2c2c;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.2s ease;
}

/* --- Video Captions Logic --- */

/* PC: Hover directly on the text */
.video-caption:hover {
    color: #FF0000 !important;
}

/* PC: Text becomes red when the cell or image is hovered */
.section-table td:hover .video-caption {
    color: #FF0000 !important;
}

/* --- Responsive Optimization --- */
@media (max-width: 600px) {
    /* Force table elements to behave like blocks */
    .header-table tbody, .header-table tr, .header-table td,
    .section-table tbody, .section-table tr, .section-table td {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box;
    }
    
    .header-table td { text-align: center !important; }
    .header-table img { margin: 0 auto; display: inline-block; }
    
    .section-table td { 
        text-align: justify !important; 
        text-justify: inter-word;
        padding: 5px; 
        hyphens: auto; 
    }
    
    .section-table-bold,
    .section-table-medium,
    .section-table td.section-table-bold-italic {
        display: block;
        text-align: left !important;
        width: 100%;
    }

    .nav-left, .nav-center, .nav-right {
        text-align: center !important;
    }

    .section-table td[colspan="2"] img {
        margin: 10px auto !important;
        display: block;
    }

    .video-caption { white-space: normal; text-align: left !important; }
    .video-wrapper.video-open { width: 100% !important; height: auto; aspect-ratio: 16 / 9; }
    
    /* Text becomes red when the cell is touched */
    .section-table td:active .video-caption {
        color: #FF0000 !important;
    }

    .section-table td img[width="150"] { 
        width: 180px !important; 
        margin: 0 auto 10px auto; 
    }
    
    .section-table td:has(img[width="150"]) { 
        text-align: center !important; 
    }
    
    .section-table tr td[height] { display: none; }
    
    .section-table td:has(a[href*="LEGO-"]) { 
        text-align: center !important; 
    }
    
    .section-table { font-size: 14px; line-height: 1.5; }

    /* Override centering rules strictly for the links page */
    #page-links .section-table td:has(img[width="150"]) { 
        text-align: left !important; 
    }
    
    #page-links .section-table td img[width="150"] { 
        margin: 0 0 10px 0 !important; 
        display: inline-block;
    }

    /* Force global centering strictly for the sets page */
    #page-sets .section-table td {
        text-align: center !important;
    }

    #page-sets .section-table td.section-table-bold-italic {
        text-align: center !important;
    }

    #page-sets .section-table-medium {
        text-align: center !important;
    }

    #page-sets .section-table td img {
        margin: 0 auto !important;
        display: block;
    }

    /* Standardize vertical spacing between LEGO boxes on mobile */
    #page-sets .section-table td:has(a[href*="LEGO-"]) {
        margin-bottom: 30px !important;
        padding-bottom: 10px;
    }

    /* Hide the old spacer rows to avoid double spacing */
    #page-sets .section-table tr:has(td[height="30"]),
    #page-sets .section-table tr:has(td[height="20"]) {
        display: none !important;
    }

    /* Adjust font size relation between LEGO reference and set name */
    #page-sets .section-table-medium {
        font-size: 16px !important;
        margin-top: 4px;
    }
}

/* --- Specific Scrolling Room for Minifigures Bottom Menu --- */
#page-minifigures .section:last-of-type {
    margin-bottom: 80vh !important; /* Creates the scrolling space exactly below the last navigation table */
}
