/* Basic Reset & Body Layout */
/*
 * Viewport-sized wrapper for modal positioning fallback (avoid critical position:fixed reliance).
 * - Wrapper uses position:fixed to size to viewport without 100vh/100dvh direct reliance.
 * - Modal and controls positioned inside using transform for iOS Safari 26 stability.
 * - Combines env(safe-area-inset-*), --vh, --custom-safari-bottom-offset for safe areas.
 * - --custom-safari-bottom-offset = max(0, window.innerHeight - visualViewport.height) to account for dynamic Safari UI.
 */
body {
    margin: 0;
    font-family: sans-serif;
    background-color: #f0f0f0;
    overflow: hidden; /* Prevent body scroll, managed by wrapper */
}

#viewport-container {
    position: fixed; /* Fixed positioning for wrapper to anchor to viewport, avoiding critical fixed on interactive elements */
    top: 0;
    left: 0;
    width: 100%;
    height: calc(var(--vh) * 100); /* Viewport-sized height using --vh, not direct 100vh/100dvh */
    display: flex;
    flex-direction: column;
    z-index: 0;
}

/* Protection Zones - Safe Buffer Areas
 * These are reserved safe zones at top and bottom of viewport.
 * Must not be used for interactive content - they serve as buffers
 * for device UI elements (notches, rounded corners, system bars).
 * All critical controls should be placed outside these zones.
 *
 * Safe area handling:
 * - Header respects top safe area to avoid notches
 * - Footer respects bottom safe area but allows background overlay on Safari (non-interactive)
 * - Interactive content in main area stays above system UI
 */
.safe-zone {
    background-color: #c0392b;
    color: white;
    font-weight: bold;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    box-sizing: border-box;
    min-height: 0;
    /* Header: respect top safe area */
    padding-top: env(safe-area-inset-top);
}

/* Footer-specific layout */
/*
 * Footer allows background overlay on Safari bottom UI (non-interactive visual),
 * but ensures any interactive elements (none here) would stay above system UI.
 */
footer.safe-zone .header-text {
    font-size: calc(var(--vh) * 5); /* Use --vh only */
}

/* Footer respects combined bottom safe area */
footer.safe-zone {
    padding-bottom: calc(env(safe-area-inset-bottom) + var(--custom-safari-bottom-offset, 0px));
}

.header-text {
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Main Map Area */
/*
 * Main area is flexible and ensures interactive content (buttons) stays above system UI.
 * Uses safe area insets to provide padding from device edges.
 */
.map-area {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: #5a8d5a;
    min-height: 0;
    /* Ensure main content respects safe areas, especially bottom for interactive elements */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    /* Removed padding-bottom to prevent height exceeding viewport and causing collapse */
}

.map-placeholder {
    color: white;
    font-weight: bold;
    text-align: center;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Top controls strip */
 /*
   * Top controls strip overlaying map area.
   * Uses safe area padding.
   * When modal open, made inert via JS to prevent interaction without visual change.
   */
.map-controls-strip {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: calc(var(--vh) * 1); /* Use --vh only */
    width: 100%;
    min-height: 0;
    /* Safe area padding */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    box-sizing: border-box;
    z-index: 10;
}

.menu-trigger {
    border: 2px solid white;
    background-color: transparent;
    color: white;
    font-weight: bold;
    cursor: pointer;
    border-radius: 99px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

#b1, #b2 {
}

#route-button {
    background-color: #f1c40f;
    color: #333;
    border-color: #f1c40f;
}

/* Scroll locking for modal */
 /*
  * Prevents background scrolling when modal is open without breaking keyboard behavior.
  * JS sets wrapper overflow:hidden conditionally (not when keyboard open).
  * Uses touch-action and preventDefault for iOS-safe locking.
  */

/* Modal Styles (adapted for safe areas) */
/*
 * Modals must respect safe areas on all sides to prevent content from being cut off.
 * Overlay covers full viewport including safe areas.
 * Container is centered but constrained within safe areas.
 * Visibility controlled by .is-open class for better accessibility and maintainability.
 */
.modal-overlay {
    position: fixed;
    top: var(--offset, 0px); /* iOS Safari toolbar offset to prevent drift */
    left: 0;
    width: 100%;
    height: calc(var(--vh) * 100); /* Use --vh only, avoids direct 100vh/100dvh */
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    /* Overlay covers safe areas on sides only (top/bottom handled by --offset/--vh) */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    box-sizing: border-box;
    display: none; /* Hidden by default */
}

.modal-overlay.is-open {
    display: block;
}

.modal-container {
    position: absolute; /* Avoid fixed reliance; positioned relative to overlay for iOS stability */
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #f1c40f;
    border-radius: 25px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    z-index: 1001;
    width: 80%;
    max-width: 400px;
    color: #333;
    font-weight: bold;
    justify-content: center;
    align-items: center;
    /* Modal content stays within safe areas */
    max-height: calc(var(--vh) * 100 - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px); /* Use --vh only */
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    display: none; /* Hidden by default */
}

.modal-container.is-open {
    display: block;
}

.modal-close-button {
    position: absolute;
    top: calc(10px + env(safe-area-inset-top));
    right: calc(15px + env(safe-area-inset-right));
    background: none;
    border: none;
    font-size: 2.5rem;
    line-height: 1;
    cursor: pointer;
    color: #333;
}

.modal-content {
    padding: 1.5rem;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%; /* Full height since no internal floating controls */
}



/* Fallback styles for browsers without safe-area-inset support */
/*
 * For older browsers, provide basic fallbacks.
 * Modern browsers will use the env() values; older ones ignore them.
 */
@supports not (padding: env(safe-area-inset-top)) {
    #viewport-container {
        height: calc(var(--vh) * 100); /* Fallback without env() */
    }

    .modal-container {
    }
}

/* SmartSafeArea utilities */
.safe-top { margin-top: var(--safe-top); }
.safe-right { margin-right: var(--safe-right); }
.safe-bottom { margin-bottom: var(--safe-bottom); }
.safe-left { margin-left: var(--safe-left); }
.overlay-zone {
    /* Custom overlay styles - transparent overlay for safe area demarcation */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: rgba(0, 255, 0, 0.1); /* Debug green tint, remove in prod */
}