/* ==================== CSS Variables ==================== */
:root {
    --bg-dark: #333;
    --bg-light: #f5f5f5;
    --text-dark: white;
    --text-light: #24292e;
    --accent: darkgoldenrod;
    --sidebar-width: 380px;
    --info-width: 420px;
    --header-height: 68px;
    --transition: 0.3s ease;
}

/* Light mode support */
@media (prefers-color-scheme: light) {
    :root {
        --bg-dark: #f5f5f5;
        --bg-light: #0d1117;
        --text-dark: #24292e;
        --text-light: #c9d1d9;
        --accent: #909908;
    }
}

/* Font face */
@font-face {
    font-family: "Quintessential";
    src: url("font/Quintessential-Regular.ttf") format("truetype");
    font-weight: normal;
    font-style: normal;
}

/* ==================== Global & Reset ==================== */
html,
body {
    height: 100vh;
    margin: 0;
    padding: 0;
    font-family: "Quintessential", serif;
    background: black;
    color: var(--text-dark);
    overflow: hidden;
    text-transform: uppercase;
}

/* Loader */
#loader {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s;
}

#loader::after {
    content: "";
    width: 48px;
    height: 48px;
    border: 5px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==================== Layout Structure ==================== */
body {
    display: grid;
    grid-template-rows: var(--header-height) 1fr auto;
    grid-template-areas:
        "header"
        "content"
        "footer";
}

/* Header */
header#top-bar {
    grid-area: header;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(20, 15, 10, 0.99);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(184, 134, 11, 0.99);
    color: whitesmoke;
    padding-top: 5px;
}

.top-bar-content {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.2rem;
}
@media (max-width: 900px) {
    .top-bar-content {
        display: flex;
        justify-content: center; /* centers everything horizontally */
        align-items: center; /* vertical center */
        gap: 1rem; /* space between icon and title */
        padding: 0 1rem;
    }

    .menu-toggle {
        display: block;
        font-size: 2.2rem; /* slightly larger for touch */
        background: none;
        border: none;
        color: whitesmoke;
        cursor: pointer;
        padding: 0.5rem 0.8rem;
        line-height: 1;
        order: -1;
    }

    .menu-toggle:hover,
    .menu-toggle:focus {
        opacity: 0.7;
    }

    /* Title stays next to icon, no forced centering */
    #top-bar h1 {
        margin: 0;
        font-size: 0.9rem !important; /* slightly smaller on mobile if needed */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}
#top-bar h1 {
    margin: 0;
    font-size: 2rem; /* adjust size so it fits nicely */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
}

/* Mobile menu toggle */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: whitesmoke;
    font-size: 2rem;
    cursor: pointer;
}

/* Main content area (flex for sidebar + map + info) */
.app-container {
    margin: 0;
    padding: 0;
    height: 100vh;
    display: flex;
    overflow: hidden;
}
/* Left sidebar */
/*aside#sidebar {
    width: var(--sidebar-width);
    background: black;
    overflow-y: auto;
    backdrop-filter: blur(8px);
    margin-top: 0.5rem;
    padding: 0.5rem;
    z-index: 991;
    border-right: 1px solid rgba(184, 134, 11, 0.25);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.6);
}*/
aside#sidebar {
    width: var(--sidebar-width);
    background: black;
    overflow-x: hidden; /* prevent horizontal overflow */
    overflow-y: scroll; /* change from auto to scroll for consistency */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    backdrop-filter: blur(8px);
    margin-top: 0;
    padding: 10px;
    z-index: 991;
    border-right: 1px solid rgba(184, 134, 11, 0.25);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.6);
    /* ← Key fix: subtract header height from full viewport */
    max-height: calc(100vh - var(--header-height));
    box-sizing: border-box; /* include padding in size calculations */
    bottom: 0;
}
/* Chrome, Brave, Safari (WebKit) */
aside#info-panel::-webkit-scrollbar {
    display: none;
}

nav[aria-label="Sort controls"] .sort-group {
    position: relative;
    /* margin: 2px; */
    padding: 2px;
    border-radius: 10px;
    border: 1px solid darkgoldenrod;
    /* background-color: rgba(0, 0, 0, 0); */
    margin-bottom: 10px;
}

/* Create an overlay pseudo-element */
nav[aria-label="Sort controls"] .sort-group::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("/images/Ludworth.jpg");
    background-size: cover; /* or contain, as needed */
    border-radius: 10px; /* match parent border-radius */
    opacity: 0.2; /* 50% opacity */
    z-index: -1; /* Send behind content */
}
.sort-legend {
    color: var(--accent);
    font-size: 0.9rem;
    letter-spacing: 1px;
    /*margin-bottom: 0.8rem;*/
    text-transform: uppercase;
}

.sort-options {
    display: flex;
    flex-direction: column;
}
.sort-items {
    padding: 10px;
}
/* Hide the actual radio input visually but keep it functional */
.sort-item input[type="radio"] {
    position: absolute !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    pointer-events: none !important; /* prevents clicking the tiny invisible area */
}

/* Selected / checked state — make it stand out */
.sort-item input[type="radio"]:checked + .sort-label {
    background: rgba(184, 134, 11, 0.4); /* gold tint */
    border-color: var(--accent);
    font-weight: 600;
    box-shadow: 0 0 10px rgba(184, 134, 11, 0.3);
    /*margin-top: 10px;
    margin-bottom: 10px;*/
}

/* Hover and focus states */
.sort-label:hover,
.sort-label:focus {
    background: rgba(184, 134, 11, 0.2);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* Optional: add a visual checkmark for selected state */
.sort-item input[type="radio"]:checked + .sort-label::before {
    content: "✓";
    color: var(--accent);
    /*font-weight: bold;
    margin-right: 0.5rem;
    font-size: 1.2rem;*/
}

/* Make the label look and act like a button */
.sort-label {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.7rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    background: rgba(0, 0, 0, 0.3); /* default unselected state */
    border: 1px solid transparent;
    margin: 2px;
}

/* Hover and focus states */
.sort-label:hover,
.sort-label:focus {
    background: rgba(184, 134, 11, 0.2);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.sort-icon {
    width: 1.5rem;
    height: 1.5rem;
}

/* Map container fills flex space */
main#map-container {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    position: relative;
}

/* Map div absolute full-fill */
#map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Right info panel */
aside#info-panel {
    width: var(--info-width);
    background:
        linear-gradient(
            to bottom,
            rgba(0, 0, 0, 0.9),
            rgba(0, 0, 0, 0.7) 50%,
            rgba(0, 0, 0, 0.6)
        ),
        url(/images/Bodiam.jpg) center/cover no-repeat;
    border-left: 1px solid rgba(184, 134, 11, 0.25);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.6);
    overflow-y: auto;
    backdrop-filter: blur(8px);
    /*margin-top: 2rem;*/
    padding: 10px;
    z-index: 990;
    margin-top: 0;
    max-height: calc(100vh - var(--header-height) - 20px);
}
button {
    font-family: inherit;
    margin-top: 5px;
    margin-bottom: 5px;
    text-transform: uppercase;
    border-radius: 5px;
    padding: 5px;
    border-color: darkgoldenrod;
}
#hero {
    width: 100%;
    border: black;
    border-radius: 5px;
}
/* Footer */
footer#page-footer {
    grid-area: footer;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 900;
    background: rgba(20, 15, 10, 0.75);
    backdrop-filter: blur(8px);
    color: #c0b8a8;
    text-align: center;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    border-top: 1px solid rgba(184, 134, 11, 0.25);
    pointer-events: none;
}

#page-footer p {
    margin: 0;
    opacity: 0.9;
}

/* ==================== Hybrid Panel / Bottom Sheet ==================== */

/* Desktop: right-side panel */
@media (min-width: 901px) {
    aside#info-panel {
        position: relative;
        transform: translateX(0);
        transition: none;
    }

    aside#info-panel:not(.show) {
        width: 0;
        padding: 0;
        overflow: hidden;
    }
}

/* Mobile: bottom sheet + sidebar slide-in */
@media (max-width: 900px) {
    .menu-toggle {
        display: block;
    }

    aside#sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform var(--transition);
        z-index: 999;
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.5);
        margin-top: 14%;
        border-radius: 5px;
    }

    aside#sidebar.show {
        transform: translateX(0);
    }

    aside#info-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        height: 0;
        max-height: calc(100vh - 60px); /* leave room for footer */
        background: rgba(30, 25, 20, 0.95);
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
        transform: translateY(100%);
        transition:
            transform var(--transition),
            height var(--transition);
        z-index: 950;
        overflow-y: auto;
        backdrop-filter: blur(3px);
    }

    aside#info-panel.show {
        height: 65vh;
        transform: translateY(0);
    }

    /* Footer stays visible below sheet */
    footer#page-footer {
        z-index: 960;
    }
}

/* ==================== Castle List & Item Styles ==================== */

#castle-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.castle-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.8rem 0.6rem;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.2s;
    background: #333;
    margin-bottom: 10px;
    /* border-color: darkgoldenrod; */
}

.castle-item:hover,
.castle-item.active {
    background: var(--accent);
    color: white;
}

.castle-item img {
    width: 70px;
    height: 70px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
}

.castle-item strong,
.castle-item small {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.castle-item strong {
    font-weight: 600;
    font-size: 0.9rem;
}

.castle-item small {
    font-size: 0.8rem;
    opacity: 0.9;
}

/* ==================== Info Panel Details ==================== */

#detail-name {
    background: #333333b8;
    border-radius: 0.3rem;
    padding: 5px;
    margin-top: -8px;
    margin-bottom: auto;
}

#detail-desc {
    line-height: 1.6;
    margin-bottom: 1.2rem;
    line-height: 1.6;
    text-transform: math-auto;
}

#detail-footnote {
    background: rgba(218, 165, 32, 0.32);
    border-left: 4px solid var(--accent);
    padding: 0.9rem 1.1rem;
    margin: 1.2rem auto;
    border-radius: 6px;
    font-style: italic;
    color: #f0f0e8;
}

#detail-facts {
    font-weight: 900;
    /* padding: 5px; */
    border-radius: 0.3rem;
    /* margin: 0; */
    letter-spacing: -0.075em;
    line-height: 2;
}

.facts-list {
    list-style: none;
    background-color: #b8860b5e;
    border-radius: 5px;
    padding-left: 5px;
}

.facts-list li {
    margin-bottom: 0.55rem;
    padding-left: 2.2rem;
    position: relative;
}

.facts-list li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 1.4rem;
    height: 1.4rem;
    background-size: contain;
    background-repeat: no-repeat;
}

.facts-list li:nth-child(1)::before {
    background-image: url("/images/CastleIconWhite.svg");
}
.facts-list li:nth-child(2)::before {
    background-image: url("/images/EarthWhite.svg");
}
.facts-list li:nth-child(3)::before {
    background-image: url("/images/ClockfaceWhite.svg");
}

/* Buttons & actions */
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.btn {
    display: inline-block;
    padding: 5px 5px;
    /* color: white; */
    text-decoration: none;
    border-radius: 0.3rem;
    background: #fffbfb;
    font-size: 0.8rem;
    border: 2px solid gold; /* Adds a 2px golden border */
    color: black;
}

.btn:hover {
    opacity: 0.5;
}

/* ==================== Accessibility & Misc ==================== */

button:focus,
.castle-item:focus {
    outline: 2px solid var(--accent);
}
/* Force Leaflet container to be ready early */
#map-container {
    visibility: hidden; /* hide during init to avoid flash */
}

body.loaded #map-container {
    visibility: visible;
}

/* Footer always on top of map but below sheet */
footer#page-footer {
    z-index: 960;
    font-size: 0.7rem;
}
footer#page-footer a {
    pointer-events: auto !important;
    cursor: pointer !important;
}
#page-footer a {
    color: var(--accent);
    text-decoration: none;
}

#page-footer a:hover {
    text-decoration: underline;
}

/* Bottom sheet stops short of footer on mobile */
@media (max-width: 900px) {
    aside#info-panel.show {
        max-height: calc(100vh - 60px); /* leave space for footer */
        bottom: 35px; /* offset from bottom */
        background-color: rgba(0, 0, 0, 0.5);
        width: auto;
    }
    .action-buttons {
        gap: 2px;
    }
}
#page-footer a {
    color: var(--accent); /* gold */
    text-decoration: none;
    transition: color 0.2s;
}

#page-footer a:hover,
#page-footer a:focus {
    color: #ffd700; /* brighter gold on hover */
    text-decoration: underline;
}
