/* General Styles */
html, body {
    margin: 0;
    padding: 0 20px 0px 20px;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* Ensure footer stays at bottom if content is short */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

body.light-theme {
    background-color: #f4f4f4;
    color: #333;
}
body.dark-theme {
    background-color: #1a1a1a;
    color: #eee;
}

h1 {
    text-align: center;
    margin: 30px 0;
    font-size: 2.2em;
    flex-shrink: 0; /* Prevent h1 from shrinking */
}
body.light-theme h1 { color: #1a1a1a; }
body.dark-theme h1 { color: #ddd; }

h2 {
    border-bottom: 2px solid;
    padding-bottom: 8px;
    margin-top: 0;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    font-size: 1.4em;
}
h2 i {
    margin-right: 10px;
}
body.light-theme h2 { border-bottom-color: #ddd; color: #444; }
body.light-theme h2 i { color: #555; }
body.dark-theme h2 { border-bottom-color: #555; color: #ccc; }
body.dark-theme h2 i { color: #aaa; }

.container {
    display: flex; /* Keep flex for alignment */
    gap: 25px;
    justify-content: center;
    margin-bottom: 30px;
    flex-wrap: wrap; /* Allow columns to wrap if needed, mainly for mobile */
}

/* Style for the single column in trending view */
.container-trending {
    justify-content: center; /* Center the single column */
    /* Default State: Hidden */
    display: none;
}
.container-classic {
     /* Default State: Visible */
    display: flex;
}


.column {
    display: flex;
    flex-direction: column;
    flex: 1; /* Allow columns to grow */
    min-width: 300px;
    max-width: 450px;
    padding: 20px 25px;
    border-radius: 8px;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
    /* Set a reasonable max-height for desktop to prevent excessively tall columns */
    max-height: 75vh; /* Or a pixel value like 650px if preferred */
}

body.light-theme .column { background-color: #fff; }
body.dark-theme .column { background-color: #2c2c2c; box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3); }

.item-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1; /* Make list take available space in column */
    overflow-y: auto; /* Enable scrolling WITHIN the list */
    min-height: 100px; /* Ensure it has some height to show scrollbar */
    scrollbar-gutter: stable; /* Prevent layout shift */
}
.item-list::-webkit-scrollbar { width: 8px; }
.item-list::-webkit-scrollbar-track { background: rgba(0,0,0,0.1); border-radius: 4px; }
.item-list::-webkit-scrollbar-thumb { background: #aaa; border-radius: 4px; }
body.dark-theme .item-list::-webkit-scrollbar-thumb { background: #555; }

.item {
    padding: 15px 0;
    border-bottom: 1px solid;
    display: flex;
    /* align-items: center; */ /* Let flex handle vertical alignment better */
    justify-content: space-between;
    flex-wrap: wrap; /* Allow wrapping on small screens */
    gap: 10px; /* Gap between item-info and rating */
}
.item:last-child { border-bottom: none; }
body.light-theme .item { border-bottom-color: #eee; }
body.dark-theme .item { border-bottom-color: #444; }

.item-info {
    flex-grow: 1; /* Allow title/link to take up available space */
    margin-right: 15px; /* Space before rating */
    min-width: 150px; /* Min width before wrapping */
    display: flex; /* To potentially align things inside */
    flex-direction: column; /* Stack title/link */
}

.item-link {
    text-decoration: none;
    font-weight: bold;
    font-size: 1.1em;
    transition: color 0.2s ease;
    display: block; /* Make link take full width */
}
.item-link:hover { text-decoration: underline; }
body.light-theme .item-link { color: #0066cc; }
body.light-theme .item-link:hover { color: #004080; }
body.dark-theme .item-link { color: #80cfff; }
body.dark-theme .item-link:hover { color: #a6dfff; }

/* Placeholder for potential future descriptions */
.item-description {
    font-size: 0.95em;
    margin: 5px 0 0 0;
}
body.light-theme .item-description { color: #555; }
body.dark-theme .item-description { color: #bbb; }

/* Rating System Styles */
.rating-container { /* Container for stars + text */
   display: flex;
   flex-direction: column;
   align-items: flex-end; /* Align stars/text to the right */
   min-width: 160px; /* Ensure space for stars + text */
   text-align: right;
   flex-shrink: 0; /* Prevent shrinking */
}

.stars {
    cursor: pointer;
    display: inline-block;
    position: relative;
    white-space: nowrap; /* Keep stars on one line */
    margin-bottom: 3px; /* Space between stars and text */
}

.star {
    display: inline-block;
    padding: 0 1px;
    transition: color 0.2s ease;
    color: #ccc; /* Default empty star color */
}
.star i {
    font-size: 1.1em; /* Make stars slightly bigger */
    vertical-align: middle; /* Align icons better */
}
/* Combined hover/selected state for full stars */
.star.hovered i, .star.selected i {
    color: #f8d64e; /* Gold color */
}

/* Half star specific style */
.star.half i::before {
    /* Font Awesome 6 Pro: Use fa-star-sharp-half-stroke */
    /* content: "\e29a"; font-family: "Font Awesome 6 Sharp"; */
    /* Font Awesome 6 Free: Use solid star and clip path (more complex) or just show solid */
    /* Sticking with solid star visual for simplicity on free tier */
    content: "\f005"; /* fa-star */
    font-family: "Font Awesome 6 Free";
    font-weight: 900; /* Solid */
    color: #f8d64e; /* Gold color */
}
/* Ensure half stars get gold color when selected/hovered */
.star.half.hovered i::before, .star.half.selected i::before {
     color: #f8d64e;
}
/* Reset regular star icon if half class is removed */
.star:not(.half) i::before {
     content: "\f005"; /* fa-star */
     font-family: "Font Awesome 6 Free";
     /* Let color be determined by .selected/.hovered or default gray */
}


.rating-text-info {
    font-size: 0.9em;
    display: flex;
    flex-direction: column; /* Stack avg and message */
    align-items: flex-end;
    gap: 2px;
}

.average-rating {
    font-weight: bold;
    white-space: nowrap;
}
body.light-theme .average-rating { color: #666; }
body.dark-theme .average-rating { color: #aaa; }

.rating-message {
    font-size: 0.85em;
    font-style: italic;
    white-space: nowrap;
    min-height: 1.2em; /* Prevent jumpiness when message appears/disappears */
    opacity: 0; /* Hidden by default */
    transition: opacity 0.3s ease;
}
body.light-theme .rating-message { color: #999; }
body.dark-theme .rating-message { color: #888; }


/* Tooltip on hover */
.star[title]:hover::after {
    content: attr(title); /* Use title attribute */
    position: absolute;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    bottom: 150%; /* Position above the star */
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
}


.sorting-controls {
    text-align: center;
    margin-bottom: 30px;
    padding: 12px 15px;
    border-radius: 5px;
    transition: background-color 0.3s ease;
    flex-shrink: 0; /* Prevent controls from shrinking */
}
.sorting-controls label { margin-right: 10px; font-weight: bold; }
.sorting-controls select {
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}
body.light-theme .sorting-controls { background-color: #eee; border: 1px solid #ddd; }
body.light-theme .sorting-controls select { border-color: #ccc; background-color: #fff; color: #333; }
body.dark-theme .sorting-controls { background-color: #333; border: 1px solid #444; }
body.dark-theme .sorting-controls label { color: #eee; }
body.dark-theme .sorting-controls select { border-color: #666; background-color: #444; color: #eee; }

.ad-placeholder {
    border: 1px dashed;
    padding: 15px;
    text-align: center;
    font-weight: bold;
    margin: 30px auto;
    max-width: 728px;
    min-height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9em;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    flex-shrink: 0; /* Prevent ads from shrinking */
}
body.light-theme .ad-placeholder { background-color: #e9e9e9; color: #777; border-color: #ccc; }
body.dark-theme .ad-placeholder { background-color: #2a2a2a; color: #888; border-color: #555; }

footer, .footer { /* Combined rules */
    text-align: center !important;
    margin-top: auto !important; /* Pushes footer to bottom */
    padding: 20px 15px !important;
    border-top: 1px solid !important;
    font-size: 0.9em !important;
    flex-shrink: 0 !important; /* Prevent footer from shrinking */
    width: 100% !important;
    box-sizing: border-box !important; /* Include padding in width */
    font-family: 'Montserrat', sans-serif !important;
}
footer nav a {
    text-decoration: none !important;
    margin: 0 10px !important;
    transition: color 0.2s ease !important;
    font-family: 'Montserrat', sans-serif !important;
}
footer p {
    margin-top: 10px !important;
    margin-bottom: 0 !important;
    font-family: 'Montserrat', sans-serif !important;
}

body.light-theme footer { border-top-color: #ddd; color: #666; }
body.light-theme footer nav a { color: #007bff; }
body.light-theme footer nav a:hover { color: #0056b3; }
body.dark-theme footer { border-top-color: #444; color: #aaa; }
body.dark-theme footer nav a { color: #80cfff; }
body.dark-theme footer nav a:hover { color: #a6dfff; }

.theme-selector { text-align: center; margin-bottom: 25px; flex-shrink: 0; }
.theme-option {
    display: inline-block;
    width: 22px; height: 22px;
    border-radius: 50%;
    margin: 0 6px;
    cursor: pointer;
    border: 2px solid transparent;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: border-color 0.2s ease;
}
.theme-option.light { background-color: white; border-color: #ccc; }
.theme-option.dark { background-color: #333; border-color: #555; }
body.light-theme .theme-selector .light,
body.dark-theme .theme-selector .dark {
    border-color: #007bff; /* Highlight selected theme */
}

/* Item specific messages */
.item-message, .item-loading, .item-error {
    padding: 15px 5px;
    text-align: center;
    font-style: italic;
    width: 100%; /* Make messages take full width */
}
body.light-theme .item-message, body.light-theme .item-loading { color: #777; }
body.light-theme .item-error { color: #dc3545; font-weight: bold; }
body.dark-theme .item-message, body.dark-theme .item-loading { color: #999; }
body.dark-theme .item-error { color: #f8a5ad; font-weight: bold; }


/* --- Responsive Design --- */

@media (max-width: 992px) { /* Tablets */
    .container-classic, .container-trending {
        flex-direction: column; /* Stack columns sooner */
        align-items: center; /* Center stacked columns */
    }
    .column {
        width: 90%; /* Make columns wider when stacked */
        max-width: 600px; /* Limit max width */
        margin-bottom: 25px;
        flex-basis: auto; /* Reset flex basis */
        max-height: 600px; /* Adjust max height for tablets */
    }
    .column:last-child { margin-bottom: 0; }
}


@media (max-width: 768px) { /* Smaller Tablets / Large Phones */
    /* Container already stacks via 992px breakpoint */
    .container { gap: 20px; margin-bottom: 25px; }
    .column {
        min-width: unset; /* Remove min-width */
        max-height: 550px; /* Adjust max-height */
    }
    h1 { font-size: 1.9em; }
    h2 { font-size: 1.3em; }
}

@media (max-width: 600px) { /* Adjust breakpoint for stacking item info/rating */
    .item {
        flex-direction: column; /* Stack item info and rating */
        align-items: flex-start; /* Align to start */
    }
    .item-info {
        margin-right: 0; /* Remove right margin when stacked */
        margin-bottom: 10px; /* Add space below info */
        min-width: unset; /* Remove min-width */
        width: 100%; /* Take full width */
    }
    .rating-container {
        min-width: unset; /* Remove min-width */
        width: 100%; /* Take full width */
        align-items: flex-start; /* Align left when stacked */
    }
    .rating-text-info {
        align-items: flex-start; /* Align text left */
    }
}


@media (max-width: 480px) { /* Small Phones */
    body { padding: 0 10px 0px 10px; }
    h1 { font-size: 1.6em; margin: 20px 0; }
    h2 { font-size: 1.15em; }
    .column {
        width: 95%;
        padding: 15px 20px;
        max-height: 500px; /* Adjust max-height for phones */
    }
    .item { padding: 12px 0; }
    .item-link { font-size: 1em; }
    .rating-text-info { font-size: 0.85em; }
    .rating-message { font-size: 0.8em; }
    .sorting-controls { margin-bottom: 25px; }
    .ad-placeholder { max-width: 95%; min-height: 60px; font-size: 0.85em; }
    footer { font-size: 0.85em; margin-top: 30px; padding: 15px 10px; }
    footer nav a { margin: 0 5px; }
    .star i { font-size: 1em; } /* Slightly smaller stars on very small screens */
}