:root {
    --bg: #faf8f3;
    --surface: #ffffff;
    --text: #1a1a1a;
    --text-muted: #6b6b6b;
    --border: #e8e3d8;
    --border-strong: #d4cec0;
    --accent: #1e40af;
    --accent-light: #eff6ff;
    --accent-border: #bfdbfe;
    --map-fill: #7c8fa6;
    --map-selected: #dc3545;
    --map-hover: #1e40af;
    --map-equivalent: rgba(30, 64, 175, 0.18);
    --transition: 0.18s ease;
    --radius: 6px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100%;
}

/* ─── Header ──────────────────────────────────────────────────── */
header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    z-index: 10;
    flex-shrink: 0;
}

.title-container {
    display: flex;
    align-items: baseline;
    gap: 0.65rem;
    flex-shrink: 0;
}

.back-link {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1px;
    transition: color var(--transition), border-color var(--transition);
    white-space: nowrap;
}

.back-link:hover { color: var(--accent); border-color: var(--accent); }

.main-title {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 400;
    font-size: 1.3rem;
    letter-spacing: -0.01em;
    margin: 0;
    color: var(--text);
    line-height: 1;
}

.main-title em { font-style: italic; color: var(--accent); }

.subtitle {
    font-size: 0.76rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.reset-button {
    padding: 0.28rem 0.7rem;
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 500;
    color: var(--text);
    background: transparent;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    cursor: pointer;
    transition: all var(--transition);
}

.reset-button:hover { color: var(--accent); border-color: var(--accent); }

.info-button {
    padding: 0.28rem 0.7rem;
    font-family: inherit;
    font-size: 0.76rem;
    font-weight: 500;
    background: var(--accent-light);
    border: 1px solid var(--accent-border);
    border-radius: 999px;
    cursor: pointer;
    transition: all var(--transition);
    color: #1e3a8a;
    flex-shrink: 0;
}

.info-button:hover {
    background: #bfdbfe;
    border-color: var(--accent);
}

/* ─── Main layout ─────────────────────────────────────────────── */
main {
    flex: 1;
    display: flex;
    padding: 0.65rem;
    gap: 0.65rem;
    min-height: 0;
    overflow: hidden;
}

.map-wrapper {
    flex: 7;
    position: relative;
    min-height: 0;
    display: flex;
}

svg {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* ─── Map countries ───────────────────────────────────────────── */
.country {
    fill: var(--map-fill);
    stroke: var(--bg);
    stroke-width: 0.5px;
    transition: fill var(--transition), opacity var(--transition);
    opacity: 0.72;
    cursor: pointer;
}

.country:hover { opacity: 0.88; }

/* !important required — .country:hover has higher specificity than .hover-country */
.selected-country {
    fill: var(--map-selected) !important;
    opacity: 0.9 !important;
    stroke: var(--surface);
    stroke-width: 1.5px;
    cursor: default;
}

.hover-country {
    fill: var(--map-hover) !important;
    opacity: 0.85 !important;
    stroke: var(--surface);
    stroke-width: 1.5px;
}

.hover-country.paused {
    opacity: 0.9 !important;
    cursor: default;
}

.equivalent-area {
    fill: var(--map-equivalent);
    stroke: var(--map-hover);
    stroke-width: 0.8px;
    pointer-events: none;
}

/* ─── Legend panel ────────────────────────────────────────────── */
#legend {
    flex: 3;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-y: auto;
    min-width: 220px;
    max-width: 300px;
    padding: 1rem;
    font-size: 0.84rem;
}

#legend::-webkit-scrollbar { width: 3px; }
#legend::-webkit-scrollbar-track { background: transparent; }
#legend::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
#legend::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

.legend-heading {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 400;
    font-size: 1rem;
    color: var(--text);
    margin: 0 0 0.2rem;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.legend-hint {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin: 0;
    line-height: 1.4;
}

.legend-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.7rem 0;
}

.country-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 0.7rem;
    margin: 0.45rem 0;
}

.country-card.selected-card { border-left: 3px solid var(--map-selected); }
.country-card.hover-card    { border-left: 3px solid var(--map-hover); }

.country-name {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 400;
    font-size: 0.92rem;
    color: var(--text);
    margin: 0 0 0.2rem;
    line-height: 1.25;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.country-meta {
    color: var(--text-muted);
    font-size: 0.74rem;
    margin: 0.05rem 0;
    line-height: 1.4;
}

.country-area {
    font-size: 0.82rem;
    color: var(--text);
    font-weight: 500;
    margin-top: 0.2rem;
}

.comparison-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 0 0 0.35rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.22rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
}

.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-muted); }
.stat-value { font-weight: 500; color: var(--text); }

.insight-card {
    background: var(--accent-light);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius);
    padding: 0.55rem 0.7rem;
    margin-top: 0.45rem;
    font-size: 0.78rem;
    color: #1e3a8a;
    line-height: 1.5;
}

.frozen-note {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.45rem 0.7rem;
    margin-top: 0.45rem;
    font-size: 0.76rem;
    color: var(--text-muted);
    text-align: center;
}

.equiv-countries-list {
    list-style: none;
    padding: 0;
    margin: 0.45rem 0 0;
}

.equiv-country-item {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.25rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text);
}

.equiv-country-item:last-child { border-bottom: none; }

.equiv-country-item .flag-icon {
    width: 20px;
    height: 14px;
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.equiv-country-area {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.74rem;
    white-space: nowrap;
}

/* ─── Footer ──────────────────────────────────────────────────── */
footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.5rem 1.25rem;
    font-size: 0.76rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    gap: 0.5rem;
}

footer a {
    color: var(--text);
    text-decoration: none;
    border-bottom: 1px solid var(--border-strong);
    transition: border-color var(--transition);
}

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

/* ─── Modal ───────────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin: 6% auto;
    padding: 1.6rem 1.75rem;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 8px 32px rgba(40, 30, 20, 0.1);
    position: relative;
}

.modal-content h2 {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 400;
    font-size: 1.3rem;
    letter-spacing: -0.01em;
    margin: 0 0 1.1rem;
    color: var(--text);
    padding-right: 2.5rem;
}

.close-button {
    position: absolute;
    right: 0.9rem;
    top: 0.9rem;
    width: 28px;
    height: 28px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: var(--text-muted);
    transition: all var(--transition);
    padding: 0;
    line-height: 1;
}

.close-button:hover { background: var(--border); color: var(--text); }

.instruction-steps { display: flex; flex-direction: column; gap: 0.6rem; }

.step {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.8rem 0.9rem;
}

.step h3 {
    font-family: 'Fraunces', Georgia, serif;
    font-weight: 400;
    font-size: 0.9rem;
    color: var(--text);
    margin: 0 0 0.35rem;
}

.step p, .step li {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin: 0.15rem 0;
    line-height: 1.5;
}

.step ul { margin: 0; padding-left: 1.1rem; }

.color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
    flex-shrink: 0;
}

.selected-dot { background: var(--map-selected); }
.hover-dot { background: var(--map-hover); }
.equiv-dot { background: var(--map-equivalent); border: 1px solid var(--map-hover); }

/* ─── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
    body { overflow-y: auto; height: auto; min-height: 100dvh; }
    .container { height: auto; min-height: 100dvh; }

    header { padding: 0.5rem 0.75rem; }

    .title-container { gap: 0.45rem; }
    .main-title { font-size: 1.1rem; }
    .subtitle { display: none; }

    main {
        flex-direction: column;
        padding: 0.5rem;
        gap: 0.5rem;
        overflow: visible;
        min-height: 0;
    }

    .map-wrapper {
        flex: none;
        height: 56vw;
        min-height: 200px;
        max-height: 380px;
    }

    #legend {
        flex: none;
        max-width: 100%;
        min-width: unset;
        width: 100%;
        max-height: 280px;
    }

    footer {
        flex-wrap: wrap;
        padding: 0.45rem 0.75rem;
    }

    .modal-content {
        margin: 12% auto;
        padding: 1.3rem 1.4rem;
    }
}

@media (max-width: 480px) {
    .back-link { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

.hidden { display: none !important; }
