/* Ghost Towns Close-To-Me - Design System */

/* ==========================================
   CSS Variables / Design Tokens
   ========================================== */
:root {
    /* Colors - Earthy, vintage palette */
    --color-bg: #f5f1eb;
    --color-bg-alt: #e8e2d9;
    --color-surface: #ffffff;
    --color-text: #2c2416;
    --color-text-muted: #6b5d4d;
    --color-accent: #8b4513;
    --color-accent-hover: #a0522d;
    --color-link: #6b4423;
    --color-border: #d4c9b9;

    /* Typography */
    --font-heading: 'Playfair Display', Georgia, serif;
    --font-body: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Source Code Pro', monospace;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 2rem;
    --space-xl: 3rem;
    --space-xxl: 5rem;

    /* Layout */
    --max-width: 1200px;
    --content-width: 800px;
    --sidebar-width: 320px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 16px;
}

/* ==========================================
   Reset & Base
   ========================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    font-size: 1.125rem;
    line-height: 1.7;
    color: var(--color-text);
    background-color: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

/* ==========================================
   Typography
   ========================================== */
h1,
h2,
h3,
h4 {
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.3;
    color: var(--color-text);
}

h1 {
    font-size: clamp(2rem, 5vw, 3.5rem);
    margin-bottom: var(--space-md);
}

h2 {
    font-size: clamp(1.5rem, 3vw, 2rem);
    margin-top: var(--space-xl);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--color-border);
}

h3 {
    font-size: 1.25rem;
    margin-top: var(--space-lg);
    margin-bottom: var(--space-sm);
}

p {
    margin-bottom: var(--space-md);
}

a {
    color: var(--color-link);
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--color-accent-hover);
}

ul,
ol {
    margin-left: var(--space-lg);
    margin-bottom: var(--space-md);
}

li {
    margin-bottom: var(--space-xs);
}

strong {
    font-weight: 600;
}

/* ==========================================
   Layout
   ========================================== */
.site-header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-md) var(--space-lg);
    position: sticky;
    top: 0;
    z-index: 1000;
    /* Increased to ensure header always on top */
}

.site-header nav {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.logo {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
}

.logo:hover {
    color: var(--color-accent);
}

/* ==========================================
   Town Page
   ========================================== */
.town-page {
    max-width: var(--max-width);
    margin: 0 auto;
}

/* Hero Image */
.hero {
    position: relative;
    margin-bottom: var(--space-xl);
}

.hero img {
    width: 100%;
    max-height: 500px;
    object-fit: cover;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.hero figcaption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: white;
    padding: var(--space-lg);
    font-size: 0.875rem;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* Content */
.content {
    background: var(--color-surface);
    padding: var(--space-xl);
    margin: 0 var(--space-lg) var(--space-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

@media (max-width: 768px) {
    .content {
        margin: 0 var(--space-md) var(--space-lg);
        padding: var(--space-lg);
    }
}

.headline {
    font-size: 1.5rem;
    font-style: italic;
    color: var(--color-text-muted);
    margin-bottom: var(--space-lg);
}

/* Quick Facts */
.quick-facts {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md) var(--space-xl);
    padding: var(--space-lg);
    background: var(--color-bg-alt);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-xl);
}

.quick-facts span {
    font-size: 0.95rem;
}

/* Summary */
.summary {
    font-size: 1.2rem;
    line-height: 1.8;
    padding: var(--space-lg);
    background: linear-gradient(135deg, var(--color-bg-alt) 0%, var(--color-bg) 100%);
    border-left: 4px solid var(--color-accent);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-xl);
}

.summary p {
    margin-bottom: 0;
}

/* Content Sections */
.content-section {
    margin-bottom: var(--space-xl);
}

.content-section p {
    text-align: justify;
    hyphens: auto;
}

/* Timeline */
.timeline {
    margin-bottom: var(--space-xl);
}

.timeline-list {
    list-style: none;
    margin-left: 0;
    border-left: 3px solid var(--color-accent);
    padding-left: var(--space-lg);
}

.timeline-list li {
    position: relative;
    padding-bottom: var(--space-md);
    margin-bottom: var(--space-sm);
}

.timeline-list li::before {
    content: '';
    position: absolute;
    left: calc(-1 * var(--space-lg) - 7px);
    top: 6px;
    width: 14px;
    height: 14px;
    background: var(--color-accent);
    border-radius: 50%;
    border: 3px solid var(--color-surface);
}

.timeline-list li strong {
    color: var(--color-accent);
    font-size: 1.1rem;
}

/* Gallery */
.gallery {
    margin-bottom: var(--space-xl);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-lg);
}

.gallery figure {
    background: var(--color-bg-alt);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.gallery img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.gallery figcaption {
    padding: var(--space-md);
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* Visit Info */
.visit-info {
    margin-bottom: var(--space-xl);
}

.visit-card {
    background: var(--color-bg-alt);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-lg);
}

.visit-card p {
    margin-bottom: var(--space-sm);
}

.visit-card p:last-child {
    margin-bottom: 0;
}

/* Fun Facts */
.fun-facts {
    margin-bottom: var(--space-xl);
}

.fun-facts ul {
    list-style: none;
    margin-left: 0;
}

.fun-facts li {
    padding: var(--space-md);
    background: var(--color-bg-alt);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-sm);
    padding-left: var(--space-xl);
    position: relative;
}

.fun-facts li::before {
    content: '✦';
    position: absolute;
    left: var(--space-md);
    color: var(--color-accent);
}

/* Location */
.location {
    margin-bottom: var(--space-xl);
}

/* Map container - constrain z-index to stay below header */
#map,
.state-map {
    position: relative;
    z-index: 1;
    /* Keep below header (z-index: 1000) */
}

/* Leaflet tooltip and popup z-index fixes */
.leaflet-tooltip {
    z-index: 650 !important;
}

.leaflet-popup {
    z-index: 700 !important;
}

.leaflet-top,
.leaflet-bottom {
    z-index: 500 !important;
}

.btn {
    display: inline-block;
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-accent);
    color: white;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    transition: background 0.2s ease, transform 0.1s ease;
}

.btn:hover {
    background: var(--color-accent-hover);
    color: white;
    transform: translateY(-1px);
}

/* Sources */
.sources {
    margin-bottom: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--color-border);
}

.sources ul {
    list-style: none;
    margin-left: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm) var(--space-lg);
}

.sources li {
    margin-bottom: 0;
}

/* ==========================================
   Footer
   ========================================== */
.site-footer {
    background: var(--color-text);
    color: var(--color-bg);
    padding: var(--space-xl) var(--space-lg);
    text-align: center;
}

.site-footer p {
    margin-bottom: var(--space-sm);
    font-size: 0.9rem;
}

.site-footer a {
    color: var(--color-bg-alt);
}

.site-footer a:hover {
    color: white;
}

/* ==========================================
   Responsive
   ========================================== */
@media (max-width: 480px) {
    html {
        font-size: 15px;
    }

    .quick-facts {
        flex-direction: column;
        gap: var(--space-sm);
    }

    .hero img {
        max-height: 300px;
    }
}

/* ==========================================
   Print Styles
   ========================================== */
@media print {

    .site-header,
    .site-footer,
    .btn {
        display: none;
    }

    .content {
        box-shadow: none;
        margin: 0;
    }

    .hero img {
        max-height: 300px;
    }
}

/* ==========================================
   Ad Zones (Placeholder)
   ========================================== */
.ad-zone {
    background: var(--color-bg-alt);
    border: 2px dashed var(--color-border);
    padding: var(--space-lg);
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    border-radius: var(--radius-md);
    margin: var(--space-lg) 0;
}

/* ==========================================
   State Pages
   ========================================== */
.state-page {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: var(--space-lg);
}

.state-page h1 {
    text-align: center;
    margin-bottom: var(--space-sm);
}

.state-count {
    text-align: center;
    color: var(--color-text-muted);
    font-size: 1.1rem;
    margin-bottom: var(--space-xl);
}

.state-intro {
    background: var(--color-surface);
    padding: var(--space-xl);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--space-xl);
}

.state-intro h2 {
    margin-top: 0;
    border-bottom: none;
}

/* Town Grid - Consistent card sizing */
.town-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-lg);
}

.town-card {
    background: var(--color-surface);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.town-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    color: inherit;
}

/* CRITICAL: Fixed height image containers for consistent sizing */
.town-card-image {
    width: 100%;
    height: 200px;
    overflow: hidden;
    background: var(--color-bg-alt);
    display: flex;
    align-items: center;
    justify-content: center;
}

.town-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.town-card:hover .town-card-image img {
    transform: scale(1.05);
}

/* Placeholder for towns without images */
.town-card-image.no-image {
    background: linear-gradient(135deg, var(--color-bg-alt) 0%, var(--color-border) 100%);
    color: var(--color-text-muted);
    font-size: 3rem;
}

.town-card-image.no-image::after {
    content: 'No Image';
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.town-card-content {
    padding: var(--space-lg);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.town-card h3 {
    margin: 0 0 var(--space-sm);
    font-size: 1.25rem;
}

.town-card h3 a {
    text-decoration: none;
    color: var(--color-text);
}

.town-card h3 a:hover {
    color: var(--color-accent);
}

.town-card-meta {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: var(--space-sm);
}

.town-card-summary {
    flex: 1;
    font-size: 0.95rem;
    color: var(--color-text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* States Index Grid */
.states-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-md);
}

.state-card {
    background: var(--color-surface);
    padding: var(--space-lg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.state-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.state-card a {
    text-decoration: none;
    color: var(--color-text);
    display: block;
}

.state-card a:hover {
    color: var(--color-accent);
}

.state-card-count {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* ==========================================
   Search Bar
   ========================================== */
.search-container {
    max-width: 600px;
    margin: 0 auto var(--space-xl);
    position: relative;
}

.search-input {
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    font-size: 1.1rem;
    font-family: var(--font-body);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(139, 69, 19, 0.1);
}

.search-input::placeholder {
    color: var(--color-text-muted);
}

/* Search Results Dropdown */
.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    margin-top: var(--space-xs);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background 0.1s ease;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background: var(--color-bg-alt);
}

.search-result-item a {
    text-decoration: none;
    display: block;
}

.search-result-name {
    font-weight: 600;
    color: var(--color-text);
}

.search-result-location {
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

/* ==========================================
   Location Links
   ========================================== */
.location-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.btn-secondary {
    background: var(--color-bg-alt);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-border);
    color: var(--color-text);
}