/* QuakesPH: flat, minimal, dark. Same palette as the DLBB forum.
   One accent colour (red). No shadows or gradients. */

:root {
    --bg: #121212;
    --surface: #1a1a1a;
    --surface-2: #212121;
    --surface-3: #2c2c2c;
    --text: #dddddd;
    --muted: #9f9f9f;
    --accent: #d32f2f;
    --accent-bright: #ef5350;   /* for small marks on dark tiles (better contrast) */
    --on-accent: #ffffff;
    --radius: 16px;

    /* Magnitude colours. These are the fallbacks; config.js sets the real ones. */
    --mag-minor: #5dade2;
    --mag-light: #ffd54f;
    --mag-moderate: #ff9800;
    --mag-strong: #ff5252;
    --mag-major: #e040fb;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.5;
}

a { color: inherit; }
h1, h2 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; }
[hidden] { display: none !important; }

.skip {
    position: absolute; left: 12px; top: -60px; z-index: 1000;
    padding: 10px 14px; border-radius: 10px;
    background: var(--accent); color: var(--on-accent); text-decoration: none;
}
.skip:focus { top: 12px; }

/* ---------- header ---------- */
.top { text-align: center; padding: 36px 20px 8px; }
.brand { display: inline-flex; align-items: center; gap: 14px; }
.brand h1 { font-size: clamp(2rem, 6vw, 2.75rem); font-weight: 800; }
.tagline { margin: 8px 0 0; color: var(--muted); font-size: 1.05rem; }
.live {
    display: inline-flex; align-items: center; gap: 8px;
    margin: 14px 0 0; color: var(--muted); font-size: 0.85rem;
}
.live__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: blink 1.6s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---------- layout ---------- */
.page {
    flex: 1;
    width: 100%;
    max-width: 1080px;
    margin: 0 auto;
    padding: 20px 20px 40px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ---------- summary tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat {
    display: flex; flex-direction: column; gap: 2px; min-width: 0;
    padding: 16px 18px; border-radius: var(--radius); background: var(--surface);
}
.stat__label { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; }
.stat__value { font-size: clamp(1.15rem, 4.8vw, 2.1rem); font-weight: 700; line-height: 1.15; white-space: nowrap; }
.stat__sub { color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#controls { display: flex; flex-direction: column; gap: 14px; }

/* ---------- filters (centered, like the header and the legend) ---------- */
#controls { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.filters { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px 24px; width: 100%; }
.seg { border: 0; margin: 0; padding: 0; min-width: 0; }
.seg legend { display: block; width: 100%; padding: 0; margin: 0 0 6px; text-align: center; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; }
.seg__options { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface); }
.seg label, .chip { position: relative; }
.seg input, .chip input {
    position: absolute; inset: 0; width: 100%; height: 100%;
    margin: 0; opacity: 0; cursor: pointer;
}
.seg span, .chip span {
    position: relative; display: block; padding: 8px 14px; border-radius: 9px;
    color: var(--muted); font-size: 0.9rem; white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}
@media (hover: hover) {
    .seg input:not(:checked):hover + span, .chip input:not(:checked):hover + span { background: var(--surface-2); color: var(--text); }
}
/* Selected = lighter tile, white text and a short red bar. Red fills are kept for the one main button. */
.seg input:checked + span, .chip input:checked + span { background: var(--surface-3); color: #ffffff; }
.seg input:checked + span::after {
    content: ""; position: absolute; left: 30%; right: 30%; bottom: 3px; height: 2px; border-radius: 2px; background: var(--accent-bright);
}
.seg input:focus-visible + span, .chip input:focus-visible + span { outline: 3px solid var(--text); outline-offset: 2px; }

/* ---------- buttons ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; width: 100%; }
.chip span { background: var(--surface); padding: 10px 16px; border-radius: 12px; }
.chip input:checked + span::before { content: "\2713\00a0"; color: var(--accent-bright); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border: 0; border-radius: 12px;
    background: var(--surface-2); color: var(--text); font: inherit; font-size: 0.9rem; cursor: pointer;
    transition: background-color 0.15s;
}
.btn:hover { background: var(--surface-3); }
.btn:disabled { opacity: 0.5; cursor: wait; }
.btn--accent { background: var(--accent); color: var(--on-accent); }
.btn--accent:hover { background: #b71c1c; }
.btn--wide { width: 100%; padding: 14px; margin-top: 8px; }
.btn:focus-visible, a:focus-visible, .quake__main:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }

.distance { max-width: 62ch; margin: 0 auto; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* ---------- map ---------- */
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface); }
#map { height: clamp(340px, 58vh, 580px); background: var(--surface); }
.map-notice, .map-fallback {
    position: absolute; left: 12px; right: 12px; bottom: 34px; z-index: 1000;
    margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 0.85rem;
}
.map-fallback { position: static; padding: 40px 20px; text-align: center; color: var(--muted); }

/* Leaflet, restyled flat and dark */
.leaflet-container { background: var(--surface); font: inherit; }
.leaflet-bar { border: 0; box-shadow: none; border-radius: 12px; overflow: hidden; }
.leaflet-bar a, .leaflet-bar a:hover { width: 36px; height: 36px; line-height: 36px; background-color: var(--surface-2); color: var(--text); border-bottom: 1px solid var(--surface-3); }
.leaflet-bar a:hover { background-color: var(--surface-3); }
.leaflet-container .leaflet-control-attribution { background: rgba(18, 18, 18, 0.8); color: var(--muted); font-size: 11px; }
.leaflet-container .leaflet-control-attribution a { color: var(--text); }
.quake-popup .leaflet-popup-content-wrapper, .quake-popup .leaflet-popup-tip { background: var(--surface-2); color: var(--text); box-shadow: none; }
.quake-popup .leaflet-popup-content-wrapper { border-radius: 12px; }
.quake-popup .leaflet-popup-content { margin: 14px 16px; font: inherit; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

.popup__head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.popup__place { font-size: 0.95rem; line-height: 1.3; }
.popup__facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0 0 10px; font-size: 0.85rem; }
.popup__facts dt { color: var(--muted); }
.popup__facts dd { margin: 0; }
.popup__link { color: var(--text); font-size: 0.85rem; }

/* Pulsing ring on the latest quake, and the "you are here" dot */
.pulse, .me { background: none; border: 0; }
.pulse span { display: block; width: 100%; height: 100%; border-radius: 50%; border: 2px solid var(--pulse, var(--accent)); animation: pulse 1.9s ease-out infinite; }
.pulse--minor { --pulse: var(--mag-minor); } .pulse--light { --pulse: var(--mag-light); }
.pulse--moderate { --pulse: var(--mag-moderate); } .pulse--strong { --pulse: var(--mag-strong); } .pulse--major { --pulse: var(--mag-major); }
@keyframes pulse { from { transform: scale(0.3); opacity: 0.95; } to { transform: scale(1.5); opacity: 0; } }
.me span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #ffffff; border: 4px solid var(--accent); }

/* ---------- legend ---------- */
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 18px; color: var(--muted); font-size: 0.85rem; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend small { opacity: 0.8; }
.legend b { color: var(--text); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot--minor { background: var(--mag-minor); } .dot--light { background: var(--mag-light); } .dot--moderate { background: var(--mag-moderate); }
.dot--strong { background: var(--mag-strong); } .dot--major { background: var(--mag-major); }

/* ---------- messages ---------- */
.messages { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.messages:not(:has(:not([hidden]))) { display: none; }
.status, .notice { margin: 0; padding: 10px 14px; border-radius: 10px; background: var(--surface); font-size: 0.9rem; border-left: 3px solid var(--muted); }
.status[data-kind="error"], .notice { border-left-color: var(--accent); }

/* ---------- quake list ---------- */
h2 { font-size: 1.25rem; margin: 8px 0 12px; }
.quakes { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.quake { display: flex; align-items: center; border-radius: 12px; background: var(--surface); }
.quake__main {
    flex: 1; min-width: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px;
    padding: 12px 14px; border: 0; border-radius: 12px; background: none;
    color: inherit; font: inherit; text-align: left; cursor: pointer;
}
@media (hover: hover) { .quake__main:hover { background: var(--surface-2); } }
.quake__body { min-width: 0; }
.quake__place { display: block; font-weight: 600; overflow-wrap: anywhere; }
.quake__meta, .quake__ago { color: var(--muted); font-size: 0.85rem; }
.quake__meta { display: block; }
.quake__ago { white-space: nowrap; }
.quake__link { margin-right: 12px; padding: 6px 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 0.8rem; text-decoration: none; }
.quake__link:hover { color: var(--text); background: var(--surface-3); }

.mag {
    display: inline-grid; place-items: center; min-width: 48px; height: 36px; padding: 0 8px;
    border-radius: 10px; background: var(--c, var(--surface-3)); color: #121212; font-weight: 700; font-variant-numeric: tabular-nums;
}
.mag--minor { --c: var(--mag-minor); } .mag--light { --c: var(--mag-light); } .mag--moderate { --c: var(--mag-moderate); }
.mag--strong { --c: var(--mag-strong); } .mag--major { --c: var(--mag-major); }
.empty { margin: 0; padding: 28px 16px; border-radius: 12px; background: var(--surface); color: var(--muted); text-align: center; }

/* ---------- footer ---------- */
.foot { padding: 28px 20px calc(28px + env(safe-area-inset-bottom, 0px)); text-align: center; color: var(--muted); font-size: 0.85rem; }
.foot p { margin: 0 0 6px; }
.foot b { color: var(--text); }
.foot__small { max-width: 640px; margin-inline: auto !important; font-size: 0.8rem; }
.foot__links { display: flex; justify-content: center; gap: 8px; margin-bottom: 12px; }
.foot__links a { display: inline-flex; padding: 8px; border-radius: 8px; color: var(--muted); }
.foot__links a:hover, .foot a:hover { color: var(--text); }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
    .top { padding-top: 28px; }
    .page { padding: 16px 14px 32px; }
    .stats { gap: 8px; }
    .stat { padding: 12px 12px; }
    .filters { gap: 12px; }
    .toolbar { display: grid; grid-template-columns: 1fr 1fr; }
    #locate { grid-column: 1 / -1; }
    .toolbar .btn, .chip span { width: 100%; text-align: center; }
    .seg { width: 100%; }
    .seg__options { width: 100%; }
    .seg label { flex: 1; }
    .seg span { padding: 8px 6px; text-align: center; font-size: 0.85rem; }
    .quake__main { grid-template-columns: auto 1fr; gap: 12px; }
    .quake__ago { display: none; }
}

@keyframes breathe { 50% { opacity: 0.35; } }

/* "Reduce motion" is on: no movement or growing rings, only a slow fade. */
@media (prefers-reduced-motion: reduce) {
    .live__dot, .pulse span { animation: breathe 2.4s ease-in-out infinite; }
    .pulse span { transform: none; }
    .seg span, .chip span, .btn { transition: none; }
}
