/* General settings for a more predictable layout */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    touch-action: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#map {
    width: 100%;
    height: 100%;
    z-index: 1; /* Map is at the bottom */
}

#compass-overlay, #compass-interaction-layer, #shen-sha-overlay {
    position: absolute;
    z-index: 10; /* Compass layers are above the map */
    transition: width 0.2s ease-in-out, height 0.2s ease-in-out, top 0.2s ease-in-out, left 0.2s ease-in-out;
    pointer-events: none;
}

#compass-overlay {
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

#compass-interaction-layer {
     cursor: grab;
     border-radius: 50%;
     pointer-events: auto;
}

#compass-interaction-layer:active {
    cursor: grabbing;
}

#rotation-handle {
    position: absolute;
    width: 30px;
    height: 30px;
    background-color: rgba(59, 130, 246, 0.9);
    border-radius: 50%;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    bottom: -15px;
    left: 50%;
    transform: translateX(-50%);
    cursor: alias;
    pointer-events: auto;
    transition: transform 0.2s ease-in-out, background-color 0.2s ease-in-out;
}

#rotation-handle:hover {
    transform: translateX(-50%) scale(1.1);
    background-color: rgba(37, 99, 235, 1);
}

#north-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    height: 50%;
    background-color: #ef4444; /* red-500 */
    transform-origin: bottom center;
    transform: translateX(-50%) translateY(-100%);
    pointer-events: none;
    box-shadow: 0 0 8px rgba(0,0,0,0.3);
    z-index: 11; /* Needle is on top of everything */
}

/* Add a small circle to the top of the indicator */
#north-indicator::before {
    content: '';
    position: absolute;
    top: -4px;
    left: -3px;
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    border: 1px solid white;
}


.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Ensure Leaflet controls are above the panel */
.leaflet-control-container {
    z-index: 30 !important;
}

/* --- Refined UI Styles --- */

/* Custom switch styles */
.toggle-label {
    transition: background-color 0.2s ease-in-out;
}
.toggle-checkbox {
    transition: right 0.2s ease-in-out;
}
.toggle-checkbox:checked {
    right: 0;
    border-color: #3b82f6; /* blue-500 */
}
.toggle-checkbox:checked + .toggle-label {
    background-color: #3b82f6; /* blue-500 */
}

/* Custom Range Slider Styles */
input[type=range] {
    -webkit-appearance: none;
    background: transparent;
    cursor: pointer;
    width: 100%;
}
/* Track */
input[type=range]::-webkit-slider-runnable-track {
    background: #e5e7eb; /* gray-200 */
    height: 0.5rem;
    border-radius: 0.25rem;
}
input[type=range]::-moz-range-track {
    background: #e5e7eb; /* gray-200 */
    height: 0.5rem;
    border-radius: 0.25rem;
}
/* Thumb */
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    margin-top: -0.25rem;
    background-color: #3b82f6; /* blue-500 */
    height: 1rem;
    width: 1rem;
    border-radius: 9999px;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: background-color 0.2s ease-in-out;
}
input[type=range]::-moz-range-thumb {
    border: none;
    border-radius: 9999px;
    background-color: #3b82f6; /* blue-500 */
    height: 1rem;
    width: 1rem;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    transition: background-color 0.2s ease-in-out;
}
input[type=range]:hover::-webkit-slider-thumb {
    background-color: #2563eb; /* blue-600 */
}
input[type=range]:hover::-moz-range-thumb {
    background-color: #2563eb; /* blue-600 */
}

/* Control Panel Transition */
#control-panel {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 320px; /* Even smaller width to avoid zoom controls */
}

/* Copyright Branding Style */
#copyright-brand {
    position: absolute;
    bottom: 15px;
    right: 15px;
    transform: none; /* Ensure text is horizontal */
    background-color: rgba(255, 255, 255, 0.7);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px; /* Base size, adjusted by JS */
    color: #333;
    pointer-events: none;
    white-space: nowrap;
    z-index: 12;
}

/* Ruler Style */
#ruler {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 2px;
    background-color: #16a34a; /* green-600 */
    transform-origin: bottom center;
    pointer-events: none;
    z-index: 12;
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
}

#ruler-handle {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    width: 30px;
    height: 30px;
    background-color: rgba(22, 163, 74, 0.9);
    border-radius: 50%;
    border: 2px solid white;
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.2s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 10px;
    font-weight: bold;
}
#ruler-handle:hover {
    transform: translateX(-50%) scale(1.1);
}

/* Action Buttons */
#action-buttons {
    top: 6rem; /* Move down to avoid layer control */
}

.action-btn {
    background-color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    position: relative; /* For tooltip */
    color: #374151; /* gray-700 */
}

.action-btn:hover {
    background-color: #f3f4f6; /* gray-100 */
    transform: scale(1.1);
}

/* Tooltip styles */
.action-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: -10px;
    top: 50%;
    transform: translateY(-50%) translateX(-100%);
    background-color: #1f2937; /* gray-800 */
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
}

.action-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Active state for toggle buttons */
.action-btn.active {
    background-color: #dbeafe; /* blue-100 */
    color: #2563eb; /* blue-600 */
}

/* Shen Sha SVG */
#shen-sha-svg {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

/* Shen Sha Buttons */
.shen-sha-btn {
    font-size: 10px;
    font-weight: bold;
}

.shen-sha-color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    border: 1px solid rgba(0,0,0,0.1);
}

/* Flying Star Chart */
#flying-star-chart {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30%; /* Relative to parent */
    height: 30%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    border: 1px solid #cbd5e1; /* gray-300 */
    background-color: rgba(255, 255, 255, 0.8);
    pointer-events: none;
}

.star-cell {
    border: 1px solid #e2e8f0; /* gray-200 */
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(4px + 1vw); /* Responsive font size */
}

.mountain-star {
    position: absolute;
    top: 5%;
    left: 5%;
    color: #475569; /* slate-600 */
}

.facing-star {
    position: absolute;
    top: 5%;
    right: 5%;
    color: #059669; /* emerald-600 */
}

.period-star {
    color: #db2777; /* pink-600 */
    font-weight: bold;
}
