/* Succession map (/map). Loaded only on that page. */
.map-shell {
  position: relative;
  /* Reserve the map's space up front so nothing shifts when it loads. */
  height: clamp(420px, 72vh, 720px);
  border-radius: 10px;
  border: 1px solid rgb(var(--line));
  background: rgb(var(--wash));
  overflow: hidden;
  contain: layout paint;
}
@media (max-width: 639px) {
  .map-shell { height: clamp(380px, 68vh, 560px); }
}
.map-canvas { position: absolute; inset: 0; }
.map-status {
  position: absolute; inset: 0; display: grid; place-items: center;
  padding: 1.5rem; text-align: center; font-size: 0.875rem; color: rgb(var(--brand));
}
.map-tooltip {
  position: absolute; left: 0; top: 0; z-index: 5; pointer-events: none;
  min-width: 11rem; max-width: 17rem; padding: 0.625rem 0.75rem;
  border: 1px solid rgb(var(--line)); border-radius: 8px;
  background: rgb(var(--surface)); color: rgb(var(--ink));
  box-shadow: 0 8px 24px -6px rgb(0 0 0 / 0.18), 0 2px 6px rgb(0 0 0 / 0.08);
  font-size: 0.8125rem; line-height: 1.35;
}
.map-card-name { font-weight: 600; }
.map-card-ja { font-weight: 400; color: rgb(var(--brand)); }
.map-card-label { margin-top: 0.25rem; color: rgb(var(--brand)); font-size: 0.75rem; }
.map-card-value { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.map-card-meta { margin-top: 0.125rem; color: rgb(var(--brand-dark)); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.map-card-note { margin-top: 0.375rem; color: rgb(var(--brand)); font-size: 0.75rem; }
.map-card-hint { color: rgb(var(--brand)); font-size: 0.875rem; }

.map-panel { border: 1px solid rgb(var(--line)); border-radius: 10px; background: rgb(var(--surface)); padding: 1rem 1.125rem; }
.map-layer-group + .map-layer-group { margin-top: 0.875rem; }
.map-layer-group-title { font-size: 0.6875rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600; color: rgb(var(--brand)); }
.map-layer-option {
  display: flex; gap: 0.625rem; align-items: flex-start; margin-top: 0.375rem;
  padding: 0.5rem 0.625rem; border-radius: 6px; border: 1px solid transparent; cursor: pointer;
}
.map-layer-option:hover { background: rgb(var(--wash)); }
.map-layer-option:has(input:checked) { border-color: rgb(var(--ink)); background: rgb(var(--wash)); }
.map-layer-option input { margin-top: 0.2rem; accent-color: rgb(var(--ink)); }
.map-layer-option input:focus-visible { outline: 2px solid rgb(var(--ink)); outline-offset: 2px; }
.map-layer-name { display: block; font-size: 0.875rem; font-weight: 500; line-height: 1.3; }
.map-layer-ja { display: block; font-size: 0.75rem; color: rgb(var(--brand)); }

.map-segs { display: inline-flex; padding: 3px; gap: 3px; border-radius: 8px; background: rgb(var(--wash)); border: 1px solid rgb(var(--line)); }
.map-seg { min-height: 2.25rem; padding: 0 0.875rem; border-radius: 6px; font-size: 0.8125rem; font-weight: 500; color: rgb(var(--brand)); }
.map-seg[aria-pressed="true"] { background: rgb(var(--surface)); color: rgb(var(--ink)); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08); }
.map-seg:focus-visible { outline: 2px solid rgb(var(--ink)); outline-offset: 1px; }

.map-stage { display: grid; gap: 1rem; }
.map-main { position: relative; min-width: 0; }
@media (min-width: 1180px) {
  /* Ranked bars beside the map on wide screens, the same height as the map. */
  .map-stage { grid-template-columns: minmax(0, 1fr) 14.5rem; }
  .map-ranking { height: clamp(420px, 72vh, 720px); }
}
.map-measure-note { margin-top: 0.75rem; max-width: 46rem; font-size: 0.875rem; line-height: 1.5; color: rgb(var(--brand-dark)); }
.map-measure-note:empty { display: none; }
.map-segs { flex-wrap: wrap; }

.map-ranking {
  display: flex; flex-direction: column; min-height: 0; max-height: 26rem;
  border: 1px solid rgb(var(--line)); border-radius: 10px; background: rgb(var(--surface)); font-size: 0.75rem;
}
@media (min-width: 1180px) { .map-ranking { max-height: none; } }
.map-ranking:empty { display: none; }
.map-rank-head { padding: 0.625rem 0.75rem 0.5rem; border-bottom: 1px solid rgb(var(--line)); }
.map-rank-title { font-weight: 600; font-size: 0.8125rem; }
.map-rank-sub { color: rgb(var(--brand-dark)); }
.map-rank-key { margin-top: 0.125rem; color: rgb(var(--brand)); }
.map-rank-list { overflow-y: auto; padding: 0.25rem 0; flex: 1; min-height: 0; }
.map-rank-row {
  display: grid; grid-template-columns: 1.5rem 4.9rem 1fr 2.9rem; align-items: center; gap: 0.375rem;
  width: 100%; padding: 0.125rem 0.75rem; min-height: 1.25rem; text-align: left; font: inherit; color: inherit;
  font-variant-numeric: tabular-nums;
}
.map-rank-row:hover, .map-rank-row.is-hover, .map-rank-list li.is-selected .map-rank-row { background: rgb(var(--wash)); }
.map-rank-list li.is-selected .map-rank-name { font-weight: 600; }
.map-rank-row:focus-visible { outline: 2px solid rgb(var(--ink)); outline-offset: -2px; }
.map-rank-n { color: rgb(var(--brand)); text-align: right; }
.map-rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-rank-track { position: relative; height: 0.625rem; }
.map-rank-bar { position: absolute; top: 0; bottom: 0; border-radius: 1px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12); }
.map-rank-line { position: absolute; top: -0.25rem; bottom: -0.25rem; width: 0; border-left: 1px dashed rgb(var(--ink) / 0.55); z-index: 1; }
.map-rank-val { text-align: right; color: rgb(var(--brand-dark)); }
.map-card-compare { margin-top: 0.125rem; font-size: 0.75rem; font-weight: 600; }
.map-legend-mid {
  display: flex; align-items: center; gap: 0.375rem; color: rgb(var(--brand-dark)); font-size: 0.6875rem; font-weight: 600;
}
.map-legend-mid::before, .map-legend-mid::after { content: ""; flex: 1; border-top: 1px dashed rgb(var(--ink) / 0.45); }
/* Over the empty Pacific (bottom right) on wider screens; below the map on phones. */
.map-legend {
  position: absolute; right: 0.75rem; bottom: 0.75rem; z-index: 4; max-width: min(17rem, calc(100% - 1.5rem));
  padding: 0.625rem 0.75rem; border-radius: 8px; border: 1px solid rgb(var(--line));
  background: rgb(var(--surface) / 0.94); font-size: 0.75rem; line-height: 1.3;
}
.map-legend:empty { display: none; }
.map-legend-title { font-weight: 600; margin-bottom: 0.375rem; }
.map-legend-list { display: grid; gap: 0.25rem; }
.map-legend-item { display: flex; align-items: center; gap: 0.5rem; font-variant-numeric: tabular-nums; }
.map-legend-swatch { width: 1.125rem; height: 0.75rem; border-radius: 2px; flex: none; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08); }
.map-legend-circle { display: inline-block; flex: none; border-radius: 9999px; opacity: 0.75; border: 1px solid rgb(var(--surface)); }
.map-legend-count { margin-left: auto; color: rgb(var(--brand)); }
.map-legend-note { margin-top: 0.375rem; color: rgb(var(--brand)); }
.map-legend-national { margin-top: 0.25rem; font-weight: 600; }
@media (max-width: 639px) {
  .map-legend { position: static; max-width: none; margin-top: 0.5rem; background: rgb(var(--surface)); }
  .map-legend-list { grid-template-columns: 1fr 1fr; column-gap: 1rem; }
  .map-legend-mid { grid-column: 1 / -1; }
}

.map-source-list { display: grid; grid-template-columns: max-content 1fr; gap: 0.375rem 1rem; margin-top: 1rem; font-size: 0.875rem; }
.map-source-list dt { color: rgb(var(--brand)); }
.map-source-list dd { color: rgb(var(--brand-dark)); overflow-wrap: anywhere; }
.map-caveats { margin-top: 0.5rem; padding-left: 1.1rem; list-style: disc; font-size: 0.875rem; color: rgb(var(--brand-dark)); display: grid; gap: 0.375rem; }
@media (max-width: 639px) { .map-source-list { grid-template-columns: 1fr; } .map-source-list dd { margin-bottom: 0.375rem; } }

.map-table-wrap { overflow-x: auto; border: 1px solid rgb(var(--line)); border-radius: 10px; }
.map-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.map-table th, .map-table td { padding: 0.5rem 0.875rem; border-bottom: 1px solid rgb(var(--line)); text-align: left; white-space: nowrap; }
.map-table thead th { position: sticky; top: 0; background: rgb(var(--wash)); font-weight: 600; font-size: 0.75rem; }
.map-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.map-table tbody th { font-weight: 500; }
.map-table tfoot th, .map-table tfoot td { font-weight: 600; border-bottom: 0; background: rgb(var(--wash)); }
.map-table tr.is-selected { background: rgb(var(--wash)); }
.map-sort { font: inherit; color: inherit; text-align: inherit; width: 100%; }
.map-sort:hover, .map-pref:hover { text-decoration: underline; text-underline-offset: 3px; }
.map-pref { font: inherit; color: inherit; text-align: left; }
.map-pref-ja { color: rgb(var(--brand)); font-weight: 400; }
.map-sort:focus-visible, .map-pref:focus-visible { outline: 2px solid rgb(var(--ink)); outline-offset: 2px; border-radius: 2px; }

/* MapLibre controls in the site palette */
.map-shell .maplibregl-ctrl-group { border-radius: 6px; box-shadow: none; border: 1px solid rgb(var(--line)); }
.dark .map-shell .maplibregl-ctrl-group { background: rgb(var(--surface)); }
.dark .map-shell .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
.map-shell .maplibregl-ctrl-attrib { font-size: 10px; }
/* Keep the expanded credit clear of the legend in the bottom-right corner. */
@media (min-width: 640px) { .map-shell .maplibregl-ctrl-attrib.maplibregl-compact-show { max-width: calc(100% - 19rem); } }
.dark .map-shell .maplibregl-ctrl-attrib { background: rgb(var(--surface) / 0.85); color: rgb(var(--brand)); }
.dark .map-shell .maplibregl-ctrl-attrib a { color: rgb(var(--brand-dark)); }
@media (max-width: 639px) {
  /* Hold the legend's space before the script fills it (no layout shift). */
  .map-legend, .map-legend:empty { display: block; min-height: 8.5rem; }
}

/* ---- Phones and tablets (below the lg sidebar layout): layer chips above the map. ---- */
.map-chips-bar { display: none; }
.map-title-ja { display: none; }
@media (max-width: 1023px) {
  .map-layer-panel { display: none; }
  .map-chips-bar {
    display: block; position: sticky; z-index: 30;
    top: calc(4rem + 1px + env(safe-area-inset-top));
    margin: 0 -1.25rem 0.75rem; padding: 0.5rem 0;
    background: rgb(var(--surface));
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  .map-chips-bar.is-stuck { border-bottom-color: rgb(var(--line)); box-shadow: 0 6px 12px -10px rgb(0 0 0 / 0.35); }
  .map-chips {
    display: flex; gap: 0.5rem; overflow-x: auto; padding: 0.125rem 1.25rem;
    scroll-padding-inline: 1.25rem; scroll-snap-type: x proximity; scrollbar-width: none;
    -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
  }
  .map-chips::-webkit-scrollbar { display: none; }
  .map-chip {
    position: relative; flex: none; display: inline-flex; align-items: center; gap: 0.4rem;
    min-height: 2.75rem; padding: 0 0.95rem 0 0.8rem; border-radius: 9999px; scroll-snap-align: start;
    border: 1px solid rgb(var(--line)); background: rgb(var(--surface)); color: rgb(var(--brand-dark));
    font-size: 0.875rem; font-weight: 500; white-space: nowrap; cursor: pointer; user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .map-chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
  .map-chip svg { color: rgb(var(--brand)); }
  .map-chip:hover { background: rgb(var(--wash)); }
  .map-chip:has(input:checked) { background: rgb(var(--ink)); border-color: rgb(var(--ink)); color: rgb(var(--surface)); }
  .map-chip:has(input:checked) svg { color: rgb(var(--surface)); }
  .map-chip:has(input:focus-visible) { outline: 2px solid rgb(var(--ink)); outline-offset: 2px; }
  .map-title-ja { display: block; margin-top: 0.125rem; font-size: 0.8125rem; color: rgb(var(--brand)); }
  .map-title-ja:empty { display: none; }
}
@media (max-width: 639px) {
  .map-chips-bar { margin-left: -1.25rem; margin-right: -1.25rem; }
}
@media (min-width: 640px) and (max-width: 1023px) {
  .map-chips-bar { margin-left: -2rem; margin-right: -2rem; }
  .map-chips { padding-inline: 2rem; scroll-padding-inline: 2rem; }
}

/* Reset-view icon button inside the map (phones); the text button is used on wider screens. */
.map-reset-ctrl, .map-shell .map-reset-group { display: none; }
@media (max-width: 639px) {
  .map-reset-btn { display: none; }
  .map-shell .map-reset-group { display: block; }
  .map-shell .maplibregl-ctrl-group .map-reset-ctrl { display: grid; place-items: center; width: 29px; height: 29px; color: rgb(var(--ink)); }
  /* Measure options: one row that scrolls sideways instead of wrapping into a block. */
  .map-controls { width: 100%; min-width: 0; }
  .map-segs {
    display: flex; flex-wrap: nowrap; max-width: 100%; overflow-x: auto;
    scrollbar-width: none; scroll-snap-type: x proximity; overscroll-behavior-x: contain;
  }
  .map-segs::-webkit-scrollbar { display: none; }
  .map-seg { flex: none; min-height: 2.75rem; white-space: nowrap; scroll-snap-align: start; }
}
/* Larger touch targets for the zoom and reset buttons on touch screens. */
@media (max-width: 639px) and (pointer: coarse) {
  .map-shell .maplibregl-ctrl-group button { width: 40px; height: 40px; }
  .map-shell .maplibregl-ctrl-group .map-reset-ctrl { width: 40px; height: 40px; }
}

/* Phones: the legend is a slim bar under the map that opens to the full key. */
.map-legend-bar { display: none; }
@media (max-width: 639px) {
  .map-legend, .map-legend:empty { min-height: 2.75rem; padding: 0; }
  .map-legend-bar {
    display: flex; align-items: center; gap: 0.625rem; width: 100%; min-height: 2.75rem;
    padding: 0.375rem 0.75rem; text-align: left; font: inherit; color: inherit; border-radius: 8px;
  }
  .map-legend-bar:focus-visible { outline: 2px solid rgb(var(--ink)); outline-offset: 2px; }
  .map-legend-strip { display: flex; flex: none; width: 4.5rem; height: 0.75rem; border-radius: 2px; overflow: hidden; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08); }
  .map-legend-strip span { flex: 1; }
  .map-legend-strip.is-circles { width: auto; height: auto; align-items: flex-end; gap: 3px; box-shadow: none; overflow: visible; }
  .map-legend-strip.is-circles span { flex: none; border-radius: 9999px; opacity: 0.75; }
  .map-legend-bar-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
  .map-legend-bar-cue { display: inline-flex; align-items: center; gap: 0.25rem; flex: none; color: rgb(var(--brand)); font-weight: 500; }
  .map-legend-bar-cue svg { transition: transform 0.15s; transform: rotate(90deg); }
  .map-legend.is-open .map-legend-bar-cue svg { transform: rotate(-90deg); }
  .map-legend-body { display: none; padding: 0 0.75rem 0.625rem; }
  .map-legend.is-open .map-legend-body { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  .map-chips-bar, .map-legend-bar-cue svg { transition: none; }
}
@media (max-width: 639px) {
  .map-legend-body .map-legend-title { display: none; }
  .map-legend.is-open .map-legend-bar-text { white-space: normal; }
}
