:root {
    color-scheme: dark;
    --bg-gradient: radial-gradient(circle at top left, #273285, #0b1220 45%, #05070d 100%);
    --panel-bg: rgba(16, 24, 40, 0.74);
    --panel-border: rgba(93, 116, 196, 0.35);
    --panel-border-hover: rgba(129, 152, 237, 0.85);
    --accent: #90b2ff;
    --accent-strong: #567dff;
    --text-primary: #f6f7fb;
    --text-secondary: rgba(214, 224, 255, 0.76);
    --subtle: rgba(144, 178, 255, 0.32);
    --focus-ring: 0 0 0 3px rgba(86, 125, 255, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont,
        'Segoe UI', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

main {
    width: min(1200px, 100%);
    padding: clamp(1.5rem, 3vw, 3rem);
}

header {
    margin-bottom: clamp(2rem, 4vw, 3.5rem);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.headline {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

h1 {
    margin: 0;
    font-size: clamp(2.1rem, 5vw, 3rem);
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tagline {
    margin: 0;
    color: var(--text-secondary);
    max-width: 60ch;
    font-size: clamp(1rem, 2.4vw, 1.1rem);
    line-height: 1.6;
}

.filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.filter label {
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.filter input {
    flex: 1 0 220px;
    background: rgba(10, 15, 28, 0.55);
    border: 1px solid var(--panel-border);
    border-radius: 999px;
    color: inherit;
    padding: 0.75rem 1.15rem;
    font-size: 0.95rem;
    transition: border 0.2s ease, box-shadow 0.2s ease;
}

.filter input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

.toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle .switch {
    position: relative;
    width: 46px;
    height: 26px;
    border-radius: 999px;
    background: rgba(35, 48, 82, 0.75);
    border: 1px solid var(--panel-border);
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.toggle .switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-primary);
    box-shadow: 0 2px 6px rgba(4, 8, 22, 0.35);
    transition: transform 0.2s ease;
}

.toggle input:checked + .switch {
    background: var(--accent-strong);
    border-color: var(--accent-strong);
}

.toggle input:checked + .switch::after {
    transform: translateX(20px);
}

.toggle input:focus-visible + .switch {
    box-shadow: var(--focus-ring);
}

.toggle .toggle-label {
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.region-groups {
    display: flex;
    flex-direction: column;
    gap: clamp(2.5rem, 4vw, 3.5rem);
    margin-top: clamp(1.5rem, 3vw, 2.5rem);
}

.region-section {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.region-section.hidden {
    display: none !important;
}

.region-section-header {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.region-section h2 {
    margin: 0;
    font-size: clamp(1.3rem, 3vw, 1.6rem);
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.region-section p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.region-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: clamp(1rem, 2.5vw, 1.7rem);
}

.region-card {
    position: relative;
    display: grid;
    grid-template-columns: 44px 1fr;
    gap: 0.9rem;
    align-items: center;
    padding: 1rem 1.1rem;
    border-radius: 18px;
    border: 1px solid var(--panel-border);
    background: var(--panel-bg);
    box-shadow: 0 18px 40px rgba(4, 8, 22, 0.35);
    transition: transform 0.25s ease, border-color 0.25s ease,
        box-shadow 0.25s ease;
}

.region-card:hover,
.region-card:focus-within {
    transform: translateY(-4px);
    border-color: var(--panel-border-hover);
    box-shadow: 0 24px 48px rgba(8, 12, 32, 0.45);
}

.latency-dot {
    width: 36px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 0;
    background: transparent;
    border: none;
}

.latency-dot iframe {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 999px;
    overflow: hidden;
    background: transparent;
}

.latency-value {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1;
    margin-top: 2px;
    text-align: center;
    width: 100%;
}

.latency-number {
    font-weight: 600;
    font-size: 0.85rem;
    line-height: 1;
}

.latency-unit {
    font-size: 0.65rem;
    opacity: 0.9;
    line-height: 1;
    margin-top: -2px;
}

.region-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.region-name {
    color: inherit;
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    transition: color 0.2s ease;
}

.region-name:hover,
.region-name:focus {
    color: var(--accent-strong);
    text-decoration: underline;
}

.region-code {
    opacity: 0.65;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.region-location {
    font-size: 0.85rem;
    color: rgba(196, 211, 255, 0.78);
}

.hidden {
    display: none !important;
}

.region-card.filtered-out {
    display: none !important;
}

body.active-only .region-card[data-active-region="false"] {
    display: none !important;
}

footer {
    margin-top: clamp(3rem, 6vw, 4.5rem);
    color: rgba(193, 209, 255, 0.45);
    font-size: 0.85rem;
    text-align: center;
}

footer a {
    color: inherit;
    text-decoration: underline;
}

@media (max-width: 640px) {
    header {
        align-items: stretch;
    }

    .region-card {
        grid-template-columns: 44px 1fr;
        padding: 0.9rem 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0s !important;
        transition-duration: 0s !important;
    }
}
