/* Power Law geographic bubble map.
 *
 * Used on /power-law-outcomes/ (full universe) and on every sector page
 * (filtered to that sector via the citiesBySector data block). The
 * page just needs:
 *   <link rel="stylesheet" href="/css/power-law-geo-map.css">
 *   <div id="powerLawGeoMap"
 *        data-sector-slug=""              (omit or empty for global)
 *        data-eyebrow="01 · Geographic map"
 *        data-title="Power Law outcomes around the world"
 *        data-subtitle="Every Power Law outcome city, plotted by company concentration. Hover any bubble for the city total."></div>
 *   <script src="/js/power-law-geo-map.js" defer></script>
 *
 * Dark mode by default; land-on-ocean is tuned to sit inside the
 * Power Law page's navy system without looking like a separate embed.
 */

.pl-geo-section {
    --pl-geo-sea: #11192e;
    --pl-geo-land: #3d486a;
    --pl-geo-land-stroke: rgba(190, 205, 235, 0.22);
    --pl-geo-rule: rgba(255, 255, 255, 0.035);
    padding: 4rem 0;
}
.pl-geo-section-inner { max-width: 1240px; margin: 0 auto; padding: 0 1.5rem; }
.pl-geo-section-head { margin-bottom: 1.5rem; }
.pl-geo-eyebrow { font-family: var(--font-display, 'Source Sans 3', system-ui, sans-serif); font-size: 0.9375rem; font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--eyebrow); margin-bottom: 0.45rem; }
.pl-geo-title { font-family: var(--font-display, 'Source Sans 3', system-ui, sans-serif); font-size: clamp(1.8rem, 3.3vw, 2.8rem); font-weight: 600; line-height: 1.12; letter-spacing: -0.015em; color: var(--white); margin: 0 0 0.65rem; }
.pl-geo-sub { font-size: 0.9875rem; line-height: 1.7; color: var(--text-light, rgba(255,255,255,0.72)); max-width: 680px; margin: 0; }

.pl-geo-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0 0 1rem;
}
.pl-geo-pill {
    appearance: none;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.72);
    font: 600 0.8125rem/1 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    padding: 0.5rem 0.85rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.pl-geo-pill:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.28);
}
.pl-geo-pill.active {
    background: rgba(59, 130, 246, 0.22);
    border-color: rgba(59, 130, 246, 0.6);
    color: #fff;
}

.pl-geo-card {
    background: var(--pl-geo-sea);
    border: 1px solid rgba(255,255,255,0.075);
    border-radius: 14px;
    padding: 0;
    overflow: hidden;
}

/* In-card toolbar: outcome-type + vintage segmented toggles on the left,
   live companies/cities readout on the right. */
.pl-geo-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem 1rem;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(255, 255, 255, 0.02);
}
.pl-geo-toolbar[hidden] { display: none; }
.pl-geo-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.pl-geo-seg {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.11);
    border-radius: 999px;
}
.pl-geo-seg-btn {
    appearance: none;
    background: transparent;
    border: 0;
    border-radius: 999px;
    color: rgba(255, 255, 255, 0.62);
    font: 600 0.78rem/1 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    padding: 0.4rem 0.72rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}
.pl-geo-seg-btn:hover { color: #fff; }
.pl-geo-seg-btn.active {
    background: rgba(59, 130, 246, 0.26);
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.55);
    color: #fff;
}
.pl-geo-stat {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.58);
    white-space: nowrap;
}
.pl-geo-stat-num {
    color: #fff;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.pl-geo-stat-region { color: rgba(255, 255, 255, 0.82); font-weight: 600; }
.pl-geo-stat-period { color: rgba(132, 173, 255, 0.9); font-weight: 600; }
.pl-geo-wrap {
    position: relative;
    width: 100%;
    height: 540px;
    background: var(--pl-geo-sea);
}
.pl-geo-svg { width: 100%; height: 100%; display: block; }
.pl-geo-country { fill: var(--pl-geo-land); stroke: var(--pl-geo-land-stroke); stroke-width: 0.4; }
.pl-geo-graticule { fill: none; stroke: var(--pl-geo-rule); stroke-width: 0.4; }
.pl-geo-marker-glow { fill-opacity: 0.10; }
.pl-geo-marker-core {
    fill-opacity: 0.55;
    stroke: #fff;
    stroke-width: 0.6;
    stroke-opacity: 0.18;
    cursor: pointer;
    transition: fill-opacity 0.15s, stroke-opacity 0.15s, stroke-width 0.15s;
}
.pl-geo-marker-core:hover { fill-opacity: 0.9; stroke-opacity: 1; stroke-width: 1.6; }
.pl-geo-marker-label { fill: #fff; font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif; font-weight: 800; font-size: 11px; text-anchor: middle; pointer-events: none; }
.pl-geo-city-label {
    fill: rgba(226, 236, 255, 0.94);
    stroke: rgba(9, 14, 26, 0.85);
    stroke-width: 3px;
    paint-order: stroke;
    stroke-linejoin: round;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.015em;
    text-anchor: middle;
    pointer-events: none;
}
.pl-geo-tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(20,27,45,0.96);
    border: 1px solid rgba(255,255,255,0.1);
    color: #fff;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.85rem;
    line-height: 1.35;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    box-shadow: 0 6px 28px rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity 0.12s;
    z-index: 5;
    white-space: nowrap;
}
.pl-geo-tooltip.visible { opacity: 1; }
.pl-geo-tooltip-name { font-weight: 700; }
.pl-geo-tooltip-detail { color: rgba(255,255,255,0.7); font-size: 0.78rem; }
.pl-geo-tooltip-split {
    color: rgba(255,255,255,0.52);
    font-size: 0.72rem;
    margin-top: 0.28rem;
    padding-top: 0.28rem;
    border-top: 1px solid rgba(255,255,255,0.09);
}

/* Centered notice when the active filter combination has no bubbles
   (e.g. Thoroughbreds × New in 2026 before annual revenue lands). */
.pl-geo-note {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    max-width: 380px;
    background: rgba(20, 27, 45, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
    border-radius: 10px;
    padding: 0.85rem 1.1rem;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.84rem;
    line-height: 1.55;
    color: rgba(255, 255, 255, 0.82);
    text-align: center;
    z-index: 4;
}
.pl-geo-note[hidden] { display: none; }
.pl-geo-note strong { color: #fff; }

/* Bottom-left chip while the 1:10m coastline file streams in. */
.pl-geo-loading {
    position: absolute;
    bottom: 14px;
    left: 16px;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: rgba(20, 27, 45, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    border-radius: 999px;
    padding: 0.32rem 0.7rem;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.72);
    z-index: 4;
}
.pl-geo-loading[hidden] { display: none; }
.pl-geo-loading-spin {
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 999px;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-top-color: rgba(255, 255, 255, 0.85);
    animation: pl-geo-spin 0.8s linear infinite;
}
@keyframes pl-geo-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .pl-geo-loading-spin { animation: none; }
    .pl-geo-seg-btn { transition: none; }
}
.pl-geo-legend {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(20,27,45,0.82);
    border: 1px solid rgba(255,255,255,0.095);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    padding: 0.6rem 0.9rem;
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 0.72rem;
    color: rgba(255,255,255,0.85);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.pl-geo-legend-title { font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: rgba(255,255,255,0.55); font-size: 0.65rem; }
.pl-geo-legend-row { display: flex; flex-wrap: nowrap; gap: 0.5rem 0.7rem; white-space: nowrap; }
.pl-geo-legend-item { display: flex; align-items: center; gap: 0.3rem; }
.pl-geo-legend-dot { width: 0.6rem; height: 0.6rem; border-radius: 999px; }
.pl-geo-legend-def {
    font-size: 0.64rem;
    line-height: 1.45;
    color: rgba(255,255,255,0.44);
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 0.4rem;
    max-width: 250px;
    white-space: normal;
}
.pl-geo-legend-def[hidden] { display: none; }
.pl-geo-empty { display: flex; align-items: center; justify-content: center; height: 100%; color: rgba(255,255,255,0.5); font-size: 0.95rem; padding: 2rem; text-align: center; }

html[data-theme="light"] .pl-geo-section {
    --pl-geo-sea: #EEF4FB;
    --pl-geo-land: #CDD9EA;
    --pl-geo-land-stroke: rgba(83, 101, 132, 0.28);
    --pl-geo-rule: rgba(100, 116, 139, 0.16);
}
html[data-theme="light"] .pl-geo-pills {
    gap: 0.42rem;
    margin-bottom: 1.2rem;
}
html[data-theme="light"] .pl-geo-pill {
    background: rgba(255,255,255,0.62) !important;
    border: 1px solid rgba(16,24,40,0.08) !important;
    box-shadow: 0 1px 2px rgba(16,24,40,0.035);
    color: rgba(16,24,40,0.66) !important;
    font-size: 0.78rem;
    padding: 0.44rem 0.78rem;
}
html[data-theme="light"] .pl-geo-pill:hover {
    background: #fff !important;
    border-color: rgba(62,100,224,0.22) !important;
    color: #101828 !important;
}
html[data-theme="light"] .pl-geo-pill.active,
html[data-theme="light"] .pl-geo-pill[aria-selected="true"],
html[data-theme="light"] .pl-geo-pill[aria-pressed="true"] {
    background: #3E64E0 !important;
    border-color: #3E64E0 !important;
    box-shadow: 0 8px 18px rgba(62,100,224,0.18);
    color: #fff !important;
}
html[data-theme="light"] .pl-geo-card {
    background: var(--pl-geo-sea) !important;
    border: 1px solid rgba(16,24,40,0.10) !important;
    box-shadow: 0 18px 44px rgba(16,24,40,0.10) !important;
}
html[data-theme="light"] .pl-geo-wrap {
    background:
        radial-gradient(circle at 50% 42%, rgba(255,255,255,0.82), transparent 46%),
        linear-gradient(180deg, #F8FBFF 0%, #EEF4FB 100%),
        var(--pl-geo-sea) !important;
}
/* PNG export (.agent-exporting = the cloned card): html2canvas mis-composites
   the layered radial sheen above into a grey blob on the exported slide —
   flatten the export background to one solid sea tone. */
.agent-exporting .pl-geo-wrap,
html[data-theme="light"] .agent-exporting .pl-geo-wrap {
    background: #F3F7FD !important; /* theme-guardrail-allow: export-only flattening of the sheen gradient above */
}
html[data-theme="light"] .pl-geo-legend {
    background: rgba(255,255,255,0.86) !important;
    border: 1px solid rgba(16,24,40,0.12) !important;
    box-shadow: 0 18px 36px rgba(16,24,40,0.14) !important;
    color: rgba(16,24,40,0.78) !important;
}
html[data-theme="light"] .pl-geo-legend-title {
    color: rgba(16,24,40,0.48) !important;
}
html[data-theme="light"] .pl-geo-legend-item {
    color: rgba(16,24,40,0.76) !important;
}
html[data-theme="light"] .pl-geo-marker-core {
    fill-opacity: 0.68;
    stroke: #fff;
    stroke-opacity: 0.78;
    stroke-width: 0.75;
}
html[data-theme="light"] .pl-geo-marker-glow {
    fill-opacity: 0.16;
}
html[data-theme="light"] .pl-geo-marker-label {
    fill: #fff;
    stroke: rgba(15, 23, 42, 0.55);
    stroke-width: 2px;
    paint-order: stroke;
}
html[data-theme="light"] .pl-geo-tooltip {
    background: rgba(255,255,255,0.96);
    border-color: rgba(16,24,40,0.12);
    color: #111827;
    box-shadow: 0 12px 34px rgba(16,24,40,0.18);
}
html[data-theme="light"] .pl-geo-tooltip-detail {
    color: rgba(16,24,40,0.58);
}
html[data-theme="light"] .pl-geo-tooltip-split {
    color: rgba(16,24,40,0.5);
    border-top-color: rgba(16,24,40,0.1);
}
html[data-theme="light"] .pl-geo-toolbar {
    border-bottom: 1px solid rgba(16,24,40,0.08);
    background: rgba(255,255,255,0.55);
}
html[data-theme="light"] .pl-geo-seg {
    background: rgba(16,24,40,0.045);
    border-color: rgba(16,24,40,0.1);
}
html[data-theme="light"] .pl-geo-seg-btn {
    color: rgba(16,24,40,0.62);
}
html[data-theme="light"] .pl-geo-seg-btn:hover { color: #101828; }
html[data-theme="light"] .pl-geo-seg-btn.active {
    background: #3E64E0;
    box-shadow: 0 6px 14px rgba(62,100,224,0.22);
    color: #fff;
}
html[data-theme="light"] .pl-geo-stat { color: rgba(16,24,40,0.55); }
html[data-theme="light"] .pl-geo-stat-num { color: #101828; }
html[data-theme="light"] .pl-geo-stat-region { color: rgba(16,24,40,0.78); }
html[data-theme="light"] .pl-geo-stat-period { color: #3E64E0; }
html[data-theme="light"] .pl-geo-legend-def {
    color: rgba(16,24,40,0.46);
    border-top-color: rgba(16,24,40,0.1);
}
html[data-theme="light"] .pl-geo-city-label {
    fill: #16233c;
    stroke: rgba(255,255,255,0.88);
}
html[data-theme="light"] .pl-geo-note {
    background: rgba(255,255,255,0.94);
    border-color: rgba(16,24,40,0.12);
    color: rgba(16,24,40,0.78);
    box-shadow: 0 16px 40px rgba(16,24,40,0.16);
}
html[data-theme="light"] .pl-geo-note strong { color: #101828; }
html[data-theme="light"] .pl-geo-loading {
    background: rgba(255,255,255,0.9);
    border-color: rgba(16,24,40,0.12);
    color: rgba(16,24,40,0.65);
}
html[data-theme="light"] .pl-geo-loading-spin {
    border-color: rgba(16,24,40,0.2);
    border-top-color: rgba(16,24,40,0.7);
}

@media (max-width: 768px) {
    .pl-geo-section { padding: 2.5rem 0; }
    .pl-geo-wrap { height: 360px; }
    .pl-geo-legend { top: 8px; right: 8px; padding: 0.4rem 0.55rem; gap: 0.3rem; font-size: 0.66rem; }
    .pl-geo-legend-row { flex-wrap: wrap; max-width: 168px; gap: 0.25rem 0.5rem; white-space: normal; }
    /* The definition line is toolbar-tooltip territory on small screens —
       reclaim the map area. */
    .pl-geo-legend-def { display: none; }
    .pl-geo-toolbar { padding: 0.55rem 0.75rem; gap: 0.45rem 0.75rem; }
    .pl-geo-seg-btn { padding: 0.34rem 0.55rem; font-size: 0.7rem; }
    .pl-geo-stat { font-size: 0.72rem; white-space: normal; }
    .pl-geo-note { max-width: calc(100% - 48px); font-size: 0.78rem; }
}
