/* Brand palette */
:root {
    --brand-paper: #F7F5F0;
    --brand-stone: #EAE7DF;
    --brand-sage: #8A9A86;
    --brand-charcoal: #2C2C2C;
    --brand-muted: #595959;
}

/* Base document and layout */
html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: "Jost", sans-serif;
    overflow: hidden;
    background-color: var(--brand-paper);
}

#container {
    display: flex;
    width: 100%;
    height: 100%;
    flex-direction: row;
    position: relative;
}

#map {
    flex-grow: 1;
    height: 100%;
    position: relative;
}

/* Sidebar and course navigation */
#sidebar {
    width: 230px;
    background: var(--brand-paper);
    padding: 15px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    z-index: 10;
    box-shadow: 2px 0 5px rgba(44, 44, 44, 0.14);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 2px;
}

.sidebar-header h3 {
    margin: 0;
}

#course-title {
    margin: 0;
}

#sidebar h3 {
    color: #2C2C2C;
    margin: 0 0 2px 0;
    font-size: 16px;
    text-align: center;
    text-transform: uppercase;
}

#sidebar p {
    color: #2C2C2C;
    margin: 0 0 6px 0;
    font-size: 16px;
    text-align: center;
}

.home-link {
    color: var(--brand-sage);
    display: flex;
    align-items: center;
    text-decoration: none;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.home-link:hover {
    filter: brightness(1.3);
    transform: scale(1.1);
}

#course-status {
    min-height: 16px;
    margin: -2px 0 4px;
    color: var(--brand-muted);
    font-size: 11px;
    line-height: 1.3;
    text-align: center;
}

#course-status.loading {
    color: var(--brand-sage);
}

#course-status.error {
    color: var(--brand-charcoal);
}

#course-status button {
    margin-left: 5px;
    padding: 2px 6px;
    border: 1px solid var(--brand-charcoal);
    border-radius: 4px;
    background: transparent;
    color: var(--brand-charcoal);
    cursor: pointer;
    font-size: 10px;
    font-weight: 700;
}

#all-courses-btn,
.hole-btn {
    width: 100%;
    background: var(--brand-stone);
    color: var(--brand-charcoal);
    border: 2px solid var(--brand-sage);
    border-radius: 6px;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}

#all-courses-btn {
    display: none;
}

#all-courses-btn:hover,
.hole-btn:hover {
    background: var(--brand-paper);
    border-color: var(--brand-charcoal);
    box-shadow: 0 0 8px rgba(138, 154, 134, 0.35);
}

#search-box {
    display: flex;
    align-items: center;
    background: var(--brand-stone);
    border: 2px solid var(--brand-sage);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 8px;
    transition: all 0.2s ease;
}

#search-box:focus-within {
    border-color: var(--brand-charcoal);
    background: var(--brand-paper);
    box-shadow: 0 0 8px rgba(138, 154, 134, 0.35);
}

#course-search-input {
    background: transparent;
    border: none;
    color: var(--brand-charcoal);
    font-size: 13px;
    width: 100%;
    outline: none;
}

#course-search-input::placeholder {
    color: var(--brand-muted);
}

#search-clear-btn {
    background: none;
    border: none;
    color: var(--brand-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 0 0 0 8px;
    display: none;
    line-height: 1;
}

#search-clear-btn:hover {
    color: var(--brand-charcoal);
}

#button-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#button-container .course-intro {
    color: var(--brand-muted);
    font-size: 12px;
    text-align: center;
    margin-top: 20px;
}

.hole-btn {
    transition: all 0.2s ease;
    text-align: left;
    outline: none;
    z-index: 2;
    position: relative;
}

.hole-btn:hover {
    transform: translateX(3px);
}

.hole-btn.active {
    background: var(--brand-paper);
    border-color: var(--brand-charcoal);
    box-shadow: 0 0 8px rgba(138, 154, 134, 0.35);
    transform: none;
}

.hole-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.3s ease;
    background: var(--brand-stone);
    border-radius: 0 0 6px 6px;
    margin-top: -12px;
    color: var(--brand-muted);
    font-size: 11px;
    display: flex;
    justify-content: space-around;
    text-align: center;
    opacity: 0;
}

.hole-details.open {
    max-height: 60px;
    padding: 18px 5px 10px 5px;
    margin-bottom: 4px;
    opacity: 1;
}

.hole-details span {
    display: block;
    color: var(--brand-charcoal);
    font-weight: bold;
    font-size: 14px;
    margin-top: 2px;
}

.course-overview-title {
    font-weight: bold;
    display: flex;
    align-items: center;
}

.course-overview-location {
    font-size: 10px;
    opacity: 0.8;
    font-weight: normal;
    margin-top: 2px;
}

.course-badge-3d {
    background: #f9f0cd;
    color: var(--brand-charcoal);
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 9px;
    margin-left: 6px;
    font-weight: 900;
    line-height: 1;
}

.no-courses-message {
    color: var(--brand-charcoal);
    font-size: 12px;
    text-align: center;
    margin-top: 15px;
    padding: 0 10px;
}

/* Measurement overlays */
.measure-point {
    width: 14px;
    height: 14px;
    background-color: var(--brand-paper);
    border: 3px solid var(--brand-sage);
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.measure-point:active {
    cursor: grabbing;
}

.distance-label {
    padding: 4px 8px;
    border: 1px solid rgba(247, 245, 240, 0.55);
    border-radius: 999px;
    background: rgba(44, 44, 44, 0.9);
    color: var(--brand-paper);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.32);
}

/* Map attribution */
.map-attribution {
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 7px;
    background: var(--brand-sage);
    border: 1px solid rgba(44, 44, 44, 0.16);
    border-radius: 4px;
    color: var(--brand-charcoal);
    font-size: 10px;
    line-height: 1.2;
    pointer-events: none;
}

.map-attribution.collapsed .attribution-details {
    display: none;
}

.map-attribution-toggle {
    border: 0;
    padding: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    pointer-events: auto;
}

.map-attribution-toggle:hover {
    color: var(--brand-paper);
}

.attribution-details {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.map-attribution a {
    color: inherit;
    text-decoration: none;
    pointer-events: auto;
}

.map-attribution a:hover {
    color: var(--brand-paper);
}

/* Map tools and custom controls */
#custom-controls {
    position: absolute;
    top: 150px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 10;
}

#three-d-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 10;
    display: none;
    background: #ffc107;
    color: var(--brand-charcoal);
    border: none;
    font-size: 16px;
    font-weight: 900;
    text-decoration: none;
}

#three-d-btn span {
    line-height: 1;
}

#three-d-btn:hover {
    background: #e0a800;
    color: var(--brand-charcoal);
    border-color: var(--brand-paper);
}

.tools-group {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tools-dropdown-menu {
    display: none;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
    animation: slideDown 0.15s ease-out;
}

.tools-dropdown-menu.open {
    display: flex;
}

.layers-control {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.map-ui-btn {
    width: 35px;
    height: 35px;
    background: var(--brand-charcoal);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: var(--brand-paper);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 0;
    outline: none;
}

.map-ui-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    transition: transform 0.2s ease;
}

#tools-btn svg {
    fill: none;
}

#info-btn {
    display: none;
    background: #dba802;
    color: var(--brand-paper);
}

#scorecard-btn {
    display: none;
    background: #e60026;
    color: var(--brand-paper);
}

#clear-btn {
    display: none;
}

#info-btn:hover {
    background: #007C7C;
    color: #fafafa;
}

#scorecard-btn:hover {
    background: #C93D58;
    color: #fafafa;
}

.map-ui-btn:hover {
    background: var(--brand-sage);
    color: var(--brand-charcoal);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px #F7F5F0;
}

.map-ui-btn:active {
    transform: translateY(0);
}

.map-ui-btn.active {
    background: var(--brand-sage);
    color: var(--brand-charcoal);
    box-shadow: 0 0 10px rgba(44, 44, 44, 0.25);
}

#layers-menu {
    display: none;
    position: absolute;
    top: 0;
    right: 38px;
    background: var(--brand-sage);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(44, 44, 44, 0.2);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--brand-charcoal);
    width: 120px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    flex-direction: column;
    gap: 6px;
    font-size: 11px;
    z-index: 20;
    animation: fadeIn 0.15s ease-out;
}

#layers-menu.open {
    display: flex;
}

#layers-menu .menu-title {
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--brand-charcoal);
    border-bottom: 1px solid rgba(44, 44, 44, 0.15);
    padding-bottom: 3px;
    margin-bottom: 2px;
}

.basemap-label {
    color: var(--brand-muted);
    font-weight: 500;
}

/* MapLibre controls */
.maplibregl-ctrl-top-right {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 10px 10px 0 0 !important;
}

.maplibregl-ctrl-top-right .maplibregl-ctrl {
    margin: 0 !important;
    float: none !important;
}

.maplibregl-ctrl-bottom-right {
    margin: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 10;
}

.maplibregl-ctrl-bottom-right .maplibregl-ctrl {
    margin: 0 !important;
}

.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button {
    width: 30px !important;
    height: 30px !important;
}

.maplibregl-ctrl-group {
    background: transparent !important;
    box-shadow: none !important;
    display: flex !important;
    flex-direction: column;
    gap: 4px;
}

.maplibregl-ctrl-group button {
    width: 35px !important;
    height: 35px !important;
    background: var(--brand-charcoal) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    border: none !important;
    border-radius: 6px !important;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25) !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    display: block;
}

.maplibregl-ctrl-group button:hover {
    background: var(--brand-sage) !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35) !important;
}

.maplibregl-ctrl-group button:active {
    transform: translateY(0) !important;
}

.maplibregl-ctrl-icon {
    filter: brightness(0) saturate(100%) invert(100%) !important;
    transition: filter 0.2s ease !important;
    transform: scale(0.85);
}

.maplibregl-ctrl-group button:hover .maplibregl-ctrl-icon {
    filter: brightness(0) saturate(100%) !important;
}

.maplibregl-ctrl-group button.maplibregl-ctrl-geolocate-active,
.maplibregl-ctrl-group button.maplibregl-ctrl-geolocate-waiting {
    background: var(--brand-sage) !important;
    box-shadow: 0 0 10px rgba(44, 44, 44, 0.25) !important;
}

.maplibregl-ctrl-group button.maplibregl-ctrl-geolocate-active .maplibregl-ctrl-icon,
.maplibregl-ctrl-group button.maplibregl-ctrl-geolocate-waiting .maplibregl-ctrl-icon {
    filter: brightness(0) saturate(100%) invert(100%) !important;
}

.maplibregl-user-location-accuracy-circle {
    background-color: transparent !important;
}

.maplibregl-user-location-dot,
.maplibregl-user-location-dot:before {
    background-color: #2db9f5 !important;
}

.maplibregl-ctrl-group button+button {
    border-top: none !important;
}

.maplibregl-ctrl-logo {
    display: none !important;
}

/* Information drawer and scorecard modal */
#info-drawer {
    position: absolute;
    top: 0;
    right: -400px;
    width: 350px;
    height: 100%;
    background: var(--brand-paper);
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.5);
    z-index: 100;
    transition: right 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
    color: var(--brand-charcoal);
}

#info-drawer.open {
    right: 0;
}

#close-drawer {
    align-self: flex-end;
    background: none;
    border: none;
    color: var(--brand-charcoal);
    font-size: 24px;
    cursor: pointer;
    transition: color 0.2s;
    padding: 0;
    line-height: 1;
}

#close-drawer:hover {
    color: var(--brand-sage);
}

#info-drawer h2 {
    margin-top: 0;
    font-size: 20px;
    text-transform: uppercase;
    border-bottom: 2px solid var(--brand-sage);
    padding-bottom: 10px;
}

.drawer-content {
    overflow-y: auto;
    font-size: 14px;
    color: var(--brand-muted);
    line-height: 1.6;
    padding-right: 10px;
}

.drawer-location {
    color: var(--brand-muted);
    font-weight: bold;
    margin-bottom: 8px;
}

.drawer-overview {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    align-items: stretch;
}

.drawer-course-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.drawer-sponsor {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 10px;
    border: 1px dashed var(--brand-sage);
    border-radius: 6px;
    background: rgba(234, 231, 223, 0.55);
    color: var(--brand-charcoal);
    text-decoration: none;
}

.drawer-sponsor-label {
    color: var(--brand-muted);
    font-size: 10px;
    font-weight: bold;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.drawer-sponsor strong {
    font-size: 13px;
    line-height: 1.3;
}

.drawer-sponsor-link {
    color: #397D3E;
    font-size: 12px;
    font-weight: bold;
}

.drawer-sponsor:hover {
    border-style: solid;
    background: rgba(234, 231, 223, 0.9);
}

.drawer-sponsor-active {
    border-style: solid;
    gap: 2px;
    padding-block: 5px;
}

.drawer-sponsor-identity {
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    color: inherit;
    text-decoration: none;
}

.drawer-sponsor-active .drawer-sponsor-identity {
    gap: 3px;
}

.drawer-sponsor-identity img {
    width: 100%;
    max-height: 64px;
    border-radius: 4px;
    object-fit: contain;
}

.drawer-sponsor-active .drawer-sponsor-identity img {
    max-height: 92px;
}

.drawer-sponsor-identity strong {
    overflow-wrap: anywhere;
}

.drawer-sponsor-active p {
    margin: 0;
    font-size: 12px;
    line-height: 1.35;
}

.drawer-directions {
    display: inline-block;
    background: #F4B942;
    color: var(--brand-charcoal);
    padding: 6px 12px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 13px;
    margin-bottom: 12px;
    font-weight: bold;
    border: 1px solid var(--brand-charcoal);
    transition: background 0.2s;
}

.drawer-directions:hover {
    background: #D99200;
    color: var(--brand-charcoal);
}

#scorecard-modal {
    position: absolute;
    inset: 0;
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.55);
}

#scorecard-modal.open {
    display: flex;
}

.scorecard-modal-panel {
    position: relative;
    width: min(980px, 100%);
    height: min(900px, 100%);
    overflow: hidden;
    border: 1px solid rgba(44, 44, 44, 0.25);
    border-radius: 8px;
    background: var(--brand-paper);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
}

#scorecard-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: var(--brand-paper);
}

#close-scorecard {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 1;
    width: 32px;
    height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    background: rgba(247, 245, 240, 0.95);
    color: var(--brand-charcoal);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

#close-scorecard:hover {
    background: var(--brand-sage);
}

/* Responsive layout */
@media (max-width: 600px) {
    #map {
        width: 100%;
        height: 100dvh;
        position: fixed;
        top: 0;
        left: 0;
    }

    #map.scorecard-open {
        z-index: 201;
    }

    #container {
        flex-direction: column;
        width: 100%;
        height: 100%;
    }

    .maplibregl-ctrl-bottom-right {
        margin: 0 0 74px 0 !important;
    }

    #sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        padding: 10px 12px 14px;
        gap: 8px;
        z-index: 150;
        background: rgba(247, 245, 240, 0.94);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.35);
        border-top: 1px solid rgba(44, 44, 44, 0.18);
        scrollbar-width: none;
    }

    #sidebar::-webkit-scrollbar {
        display: none;
    }

    #sidebar h3,
    #sidebar p {
        display: none;
    }

    #course-status,
    #all-courses-btn {
        flex-shrink: 0;
        width: auto;
        margin: 0;
    }

    #course-status {
        max-width: 130px;
        white-space: normal;
    }

    #all-courses-btn {
        border-radius: 20px;
        padding: 8px 14px;
    }

    #search-box {
        flex-shrink: 0;
        width: 180px;
        border-radius: 20px;
        padding: 8px 14px;
        margin-bottom: 0;
        font-size: 13px;
    }

    #button-container {
        flex-direction: row;
        width: max-content;
        flex-shrink: 0;
    }

    .hole-btn {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        width: auto;
        padding: 8px 14px;
        font-size: 12px;
        border-radius: 20px;
        white-space: nowrap;
        flex-shrink: 0;
        transform: none !important;
        margin-bottom: 0;
    }

    .hole-btn:hover {
        transform: none;
    }

    .hole-btn.active {
        background: var(--brand-paper);
        border-color: var(--brand-charcoal);
    }

    .hole-details {
        display: none !important;
    }

    #mobile-hole-info {
        display: none;
        position: fixed;
        bottom: 65px;
        left: 0;
        right: 0;
        padding: 8px 40px 8px 24px;
        background: rgba(247, 245, 240, 0.97);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-top: 1px solid rgba(44, 44, 44, 0.18);
        z-index: 160;
        justify-content: space-around;
        align-items: center;
        text-align: center;
        font-size: 11px;
        color: var(--brand-muted);
        animation: slideUpDetails 0.2s ease;
    }

    #mobile-hole-info.visible {
        display: flex;
    }

    #mobile-hole-info .mhi-cell {
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    #mobile-hole-info .mhi-cell span {
        display: block;
        color: var(--brand-charcoal);
        font-weight: bold;
        font-size: 15px;
        margin-top: 2px;
    }

    #mobile-hole-info .mhi-close {
        position: absolute;
        right: 12px;
        top: 50%;
        transform: translateY(-50%);
        background: none;
        border: none;
        color: var(--brand-muted);
        font-size: 16px;
        cursor: pointer;
        padding: 4px;
        line-height: 1;
    }

    #mobile-hole-info .mhi-close:hover {
        color: var(--brand-charcoal);
    }

    @keyframes slideUpDetails {
        from {
            transform: translateY(8px);
            opacity: 0;
        }

        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    #info-drawer {
        width: 100%;
        right: -100%;
        z-index: 170;
    }

    .drawer-overview {
        gap: 10px;
    }

    #scorecard-modal {
        padding: 8px;
    }

    .scorecard-modal-panel {
        height: 100%;
        border-radius: 6px;
    }

    .map-attribution {
        bottom: 78px;
        left: 8px;
        font-size: 9px;
    }

    #button-container {
        flex-direction: row !important;
        gap: 8px !important;
    }
}

@media (max-width: 380px) {
    .drawer-overview {
        grid-template-columns: 1fr;
    }
}
