:root {
    /* Color Variables */
    --max-width: 1080px;
    --bg-light: #f5f6f7;
    --bg-dark: #121212;
    --text-light: #333;
    --text-dark: #e0e0e0;
    --text-muted: #555;
    --accent: #2c3e50;
    --link-primary: #0056b3;
    --link-hover: #a4d4ff;
    --card-bg-light: #f8f9fa;
    --border-color-light: #ddd;
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-dark: rgba(255, 255, 255, 0.05);

    color-scheme: light dark;
}

/* -------------------------------------------------------------------------- */
/* BASE STYLES & ACCESSIBILITY */
/* -------------------------------------------------------------------------- */

/* Accessibility */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Base HTML */
html,
body {
    height: 100%;
    margin: 0;
}

body {
    font-family: system-ui, sans-serif;
    background: var(--bg-light);
    color: var(--text-light);
}

/* Links */
a {
    color: var(--link-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover,
a:focus {
    color: var(--accent);
    text-decoration: underline;
}

/* Layout */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 0 1rem;
}

/* Background Overlay */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background: url('cover.png') center/cover;
    opacity: 0.08;
    z-index: -1;
    pointer-events: none;
}

/* -------------------------------------------------------------------------- */
/* HEADER & NAVIGATION */
/* -------------------------------------------------------------------------- */

/* Header */
#em-header {
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-align: center;
    font-size: 1.8rem;
    font-weight: 700;
    margin: 1.25rem 0 1rem;
}

.header-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: inherit;
    text-decoration: none;
}

.header-logo {
    height: 64px;
    width: auto;
    transition: transform 0.2s ease-in-out;
}

.header-logo:hover {
    animation: shake 0.4s ease-in-out;
}

/* Map Controls */
.em-map-controls {
    background: var(--card-bg-light);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

.em-map-controls select {
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0.45rem 0.75rem;
}

/* -------------------------------------------------------------------------- */
/* MAP & LEGEND */
/* -------------------------------------------------------------------------- */

/* Map */
#em-map-container {
    height: 55vh;
    width: 100%;
    min-height: 360px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 10px var(--shadow-light);
    margin-bottom: 1rem;
}

#em-map {
    height: 100%;
    width: 100%;
}

/* Status & Legend */
#em-nearest-quake {
    text-align: center;
    margin: 0.5rem 0;
}

#nearest-status {
    display: block;
    color: var(--text-light);
}

#em-legend {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 0.5rem 0;
    font-size: 0.9rem;
}

.em-legend-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    opacity: 0.3;
    transition: opacity 0.2s;
}

.em-legend-item.active {
    opacity: 1;
}

.em-legend-color {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    display: inline-block;
}

/* -------------------------------------------------------------------------- */
/* DATA TABLE */
/* -------------------------------------------------------------------------- */

#em-list-container {
    max-width: var(--max-width);
    margin: 1rem 0 1.25rem;
    overflow-x: auto;
}

#em-quake-count {
    text-align: center;
    font-weight: 600;
    margin-bottom: 4px;
}

#em-refresh-status {
    color: var(--text-muted);
    text-align: center;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

#em-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid var(--border-color-light);
    border-radius: 8px;
    overflow: hidden;
    font-size: 0.95rem;
}

#em-table th,
#em-table td {
    padding: 0.6rem;
    text-align: center;
    border-bottom: 1px solid #eee;
}

#em-table th {
    background: var(--card-bg-light);
}

#em-table td:nth-child(4) {
    text-align: left;
}

.quake-row:hover {
    background-color: rgba(200, 200, 200, 0.3);
    cursor: pointer;
}

/* -------------------------------------------------------------------------- */
/* FOOTER */
/* -------------------------------------------------------------------------- */

#em-footer {
    max-width: var(--max-width);
    margin: 2rem auto 1rem;
    padding: 1rem;
    border-top: 1px solid var(--border-color-light);
    color: var(--text-light);
    display: flex;
    justify-content: center;
    text-align: center;
    font-size: 0.9rem;
    line-height: 1.6;
}

#em-footer a {
    color: var(--link-primary);
    text-decoration: none;
    margin: 0 0.25rem;
    transition: color 0.2s ease;
    /* Reset from previous social icon block to avoid redundant declarations */
    display: inline-flex;
    align-items: center;
    font-size: 1.25rem;
    margin: 0;
    padding: 0 0.5rem;
    color: var(--text-muted);
    transition: color 0.2s ease, transform 0.2s ease;
    text-decoration: none !important;
}

#em-footer a:hover,
#em-footer a:focus {
    color: var(--accent);
    text-decoration: none;
    transform: scale(1.1);
}

/* Footer Social Icons Styling */
#em-footer .footer-center p:first-child {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
}

#em-footer .separator {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Specific brand color overrides on hover */
#em-footer a[aria-label="QuakesPH on Facebook"]:hover {
    color: #1877F2; /* Facebook Brand Color */
}

#em-footer a[aria-label="QuakesPH on GitHub"]:hover {
    color: #6e5494; /* GitHub Brand Color */
}

/* -------------------------------------------------------------------------- */
/* KEYFRAMES / ANIMATIONS */
/* -------------------------------------------------------------------------- */

@keyframes shake {
    0%, 100% {
        transform: rotate(0);
    }
    20% {
        transform: rotate(-10deg);
    }
    40% {
        transform: rotate(10deg);
    }
    60% {
        transform: rotate(-8deg);
    }
    80% {
        transform: rotate(8deg);
    }
}

@keyframes blink {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.blinking-marker,
.blinking-text {
    animation: blink 1s infinite;
}

.blinking-text {
    animation-duration: 1.5s;
    animation-timing-function: step-start;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    100% {
        transform: scale(1.6);
        opacity: 0;
    }
}

.user-location-marker {
    margin-left: -8px;
    margin-top: -8px;
}

.user-location-marker div {
    animation: pulse 1.5s infinite;
}

@keyframes dash-animation {
    to {
        stroke-dashoffset: 0;
    }
}

.animated-path {
    stroke-dasharray: 5;
    stroke-dashoffset: 50;
    animation: dash-animation 2s linear infinite;
}

/* -------------------------------------------------------------------------- */
/* DARK MODE (prefers-color-scheme: dark) */
/* -------------------------------------------------------------------------- */

@media (prefers-color-scheme: dark) {
    body {
        background: var(--bg-dark);
        color: var(--text-dark);
    }

    /* Links */
    a {
        color: var(--link-dark, #80bfff);
    }

    a:hover,
    a:focus {
        color: var(--link-hover);
    }

    /* Header & Status */
    #em-header {
        color: #f5f5f5;
    }

    #nearest-status {
        color: #ccc;
    }

    /* Controls */
    .em-map-controls {
        background: rgba(30, 30, 30, 0.8);
        box-shadow: 0 2px 6px rgba(255, 255, 255, 0.03);
    }

    .em-map-controls select {
        background: rgba(42, 42, 42, 0.8);
        color: var(--text-dark);
        border-color: #444;
    }

    /* Map */
    #em-map-container {
        box-shadow: 0 4px 10px var(--shadow-dark);
    }

    /* Table */
    #em-table {
        background: rgba(28, 28, 28, 0.6);
        border-color: rgba(255, 255, 255, 0.1);
        backdrop-filter: blur(6px);
    }

    #em-table th {
        background: #222222;
        color: #ddd;
    }

    #em-table td {
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }

    .quake-row:hover {
        background-color: rgba(200, 200, 200, 0.1);
    }

    /* Footer, Legend, Status */
    #em-refresh-status,
    #em-legend,
    #em-quake-count,
    #em-footer {
        color: #ccc;
    }
    
    #em-footer {
        border-top-color: #444;
    }

    /* Footer Links */
    #em-footer a {
        color: var(--text-dark);
    }
    
    #em-footer .separator {
        color: var(--text-dark);
    }
    
    #em-footer a[aria-label="QuakesPH on GitHub"]:hover {
        color: #f5f5f5;
    }
}

/* -------------------------------------------------------------------------- */
/* MEDIA QUERIES (Responsiveness) */
/* -------------------------------------------------------------------------- */

@media (max-width: 768px) {
    #em-header {
        font-size: 1.5rem;
    }

    .em-map-controls select {
        font-size: 0.85rem;
        padding: 0.4rem 0.6rem;
    }

    #em-map-container {
        height: 50vh;
    }

    #em-table th,
    #em-table td {
        padding: 0.4rem;
        font-size: 0.85rem;
    }

    #em-footer {
        flex-direction: column;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    #em-header {
        font-size: 1.2rem;
    }

    .em-map-controls {
        flex-direction: column;
        gap: 0.5rem;
    }

    #em-map-container {
        height: 45vh;
    }

    #em-table th,
    #em-table td {
        font-size: 0.75rem;
        padding: 0.3rem;
    }
}