/* MeMori — la Mappa (Libreria → Mappa, 29/10/2026, prova in tools/prova-mappa): carta politica come
 * le carte murali (proiezione Miller, ogni paese il suo pastello, mai uguale ai confinanti, confini
 * color carta, acqua bassa lungo la costa, nomi dei paesi), dentro un riquadro «Ritagli» col bordo
 * d'inchiostro. I paesi dei tuoi autori: colore pieno e bordo d'inchiostro; gli altri più tenui.
 * Puntine: bollino con le iniziali; più autori vicini, bollino nero col numero. Sotto, i riquadri.
 * Vale solo dentro #map-view. Caratteri e colori base: ritagli.css. Codice: mappa.js. */

#map-view {
  /* Carta: mare, acqua bassa, confini, costa; i cinque pastelli (--p0…4) e la loro versione chiara
     per i paesi accesi col tema scuro (--l0…4). */
  --mp-sea: #cfe1e6;
  --mp-shallow: #e4eff1;
  --mp-border: #fffaf1;
  --mp-coast: #5f7e86;
  --p0: #f3cfc3;
  --p1: #d6dcc4;
  --p2: #f2dc9e;
  --p3: #dccbea;
  --p4: #f6cfa9;
  position: relative;
  font-family: var(--rt-body);
  color: var(--rt-ink);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #map-view {
    --mp-sea: #18232a;
    --mp-shallow: #20313a;
    --mp-border: #17171b;
    --mp-coast: #7fa3ad;
    --p0: #4a3434;
    --p1: #3b4535;
    --p2: #4b4230;
    --p3: #3d3550;
    --p4: #4d3a2c;
  }
}

:root[data-theme="dark"] #map-view {
  --mp-sea: #18232a;
  --mp-shallow: #20313a;
  --mp-border: #17171b;
  --mp-coast: #7fa3ad;
  --p0: #4a3434;
  --p1: #3b4535;
  --p2: #4b4230;
  --p3: #3d3550;
  --p4: #4d3a2c;
}

#map-view > :not(.mp-blobs) {
  position: relative;
  z-index: 1;
}

#map-view [hidden] {
  display: none;
}

#map-view a {
  color: inherit;
}

.mp-blobs {
  --mp-rise: 200px;
  position: absolute;
  inset: calc(-1 * var(--mp-rise)) 0 0 0;
  z-index: 0;
  overflow: clip;
  pointer-events: none;
}

.mp-blob {
  position: absolute;
  will-change: translate;
}

.mp-blob path {
  fill: currentColor;
}

.mp-blob-1 {
  right: -160px;
  top: calc(var(--mp-rise) - 140px);
  width: 440px;
  color: var(--rt-blush);
}

/* --- Testa ------------------------------------------------------------------------------- */
.mp-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.8rem 2rem;
  margin-bottom: 1rem;
}

.mp-head h1 {
  margin: 0;
  font: 800 clamp(2rem, 4.5vw, 3.3rem) / 1 var(--rt-display);
  letter-spacing: -0.03em;
  text-transform: none;
}

.mp-head h1 em {
  font-style: normal;
  background: linear-gradient(var(--rt-accent), var(--rt-accent)) 0 92% / 100% 0.22em no-repeat;
}

.mp-nums {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
}

.mp-nums span {
  padding: 0.35rem 0.85rem;
  border: 2px solid var(--rt-ink);
  border-radius: 999px;
  background: var(--rt-paper);
  font-size: 0.85rem;
}

.mp-nums b {
  font: 800 1.05rem var(--rt-display);
}

.mp-status:empty {
  display: none;
}

.mp-status {
  margin: 0 0 1rem;
  color: var(--muted);
}

/* --- La carta ------------------------------------------------------------------------------- */
.mp-card {
  position: relative;
  overflow: hidden;
  border: 2px solid var(--rt-ink);
  border-radius: 26px;
  background: var(--mp-sea);
  box-shadow: 6px 6px 0 var(--rt-ink);
  touch-action: none;
  user-select: none;
}

.mp-svg {
  display: block;
  width: 100%;
  height: 560px;
  cursor: grab;
}

.mp-svg:active {
  cursor: grabbing;
}

.mp-shallow {
  fill: none;
  stroke: var(--mp-shallow);
  stroke-width: 9;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.mp-country {
  fill: color-mix(in srgb, var(--pc) 45%, var(--rt-paper));
  stroke: var(--mp-border);
  stroke-width: 0.9;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

.mp-country.c0 { --pc: var(--p0); --pl: #f3cfc3; }
.mp-country.c1 { --pc: var(--p1); --pl: #d6dcc4; }
.mp-country.c2 { --pc: var(--p2); --pl: #f2dc9e; }
.mp-country.c3 { --pc: var(--p3); --pl: #dccbea; }
.mp-country.c4 { --pc: var(--p4); --pl: #f6cfa9; }

.mp-country.on {
  fill: var(--pc);
}

/* Col tema scuro i pastelli sono spenti: i paesi accesi si schiariscono, così risaltano. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .mp-country.on {
    fill: color-mix(in srgb, var(--pl) 72%, #17171b);
  }

  :root:not([data-theme="light"]) .mp-label.on {
    fill: #161616;
    stroke: rgb(241 236 226 / 0.75);
  }
}

:root[data-theme="dark"] .mp-country.on {
  fill: color-mix(in srgb, var(--pl) 72%, #17171b);
}

:root[data-theme="dark"] .mp-label.on {
  fill: #161616;
  stroke: rgb(241 236 226 / 0.75);
}

.mp-coast {
  fill: none;
  stroke: var(--mp-coast);
  stroke-width: 0.9;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.mp-outline {
  fill: none;
  stroke: var(--rt-ink);
  stroke-width: 1.6;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

/* Nomi dei paesi, come sulle carte murali: maiuscoletto spaziato, più grandi per i paesi grandi. */
.mp-label {
  fill: color-mix(in srgb, var(--rt-ink) 62%, transparent);
  font-family: var(--rt-body);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-anchor: middle;
  text-transform: uppercase;
  dominant-baseline: central;
  paint-order: stroke;
  stroke: color-mix(in srgb, var(--rt-paper) 70%, transparent);
  stroke-width: 3px;
  pointer-events: none;
}

.mp-label.on {
  fill: var(--rt-ink);
  font-weight: 800;
}

/* Puntine: bollino con le iniziali e la punta; il gruppo nero col numero e l'anello tratteggiato. */
.mp-pin {
  cursor: pointer;
  outline: none;
}

.mp-tip,
.mp-shadow {
  fill: var(--rt-ink);
}

.mp-face {
  stroke: var(--rt-ink);
  stroke-width: 2;
}

.mp-pin text {
  fill: #161616;
  font: 800 13px var(--rt-display);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.mp-pin:is(:hover, :focus-visible) .mp-face {
  stroke-width: 3.5;
}

.mp-pin.cluster .mp-face {
  fill: var(--rt-ink);
}

.mp-pin.cluster text {
  fill: var(--rt-bg);
  font-size: 14px;
}

.mp-ring {
  fill: none;
  stroke: var(--rt-ink);
  stroke-width: 2;
  stroke-dasharray: 3 3;
}

.mp-pin:focus-visible .mp-ring {
  stroke: var(--rt-accent);
  stroke-width: 3;
}

/* Comandi sopra la carta. */
.mp-ctrl {
  position: absolute;
  z-index: 2;
  display: flex;
  gap: 0.4rem;
}

.mp-views {
  top: 14px;
  left: 14px;
  flex-wrap: wrap;
}

.mp-zooms {
  top: 14px;
  right: 14px;
  flex-direction: column;
}

.mp-chip {
  padding: 0.35rem 0.8rem;
  border: 2px solid var(--rt-ink);
  border-radius: 999px;
  background: var(--rt-paper);
  color: var(--rt-ink);
  font: 700 0.82rem var(--rt-body);
  cursor: pointer;
}

.mp-chip[aria-pressed="true"] {
  background: var(--rt-ink);
  color: var(--rt-bg);
}

.mp-zoom {
  width: 38px;
  height: 38px;
  border: 2px solid var(--rt-ink);
  border-radius: 50%;
  background: var(--rt-paper);
  color: var(--rt-ink);
  font: 800 1.2rem var(--rt-display);
  box-shadow: 2px 2px 0 var(--rt-ink);
  cursor: pointer;
}

.mp-legend {
  position: absolute;
  left: 14px;
  bottom: 12px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.9rem;
  margin: 0;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--rt-paper) 85%, transparent);
  font-size: 0.75rem;
}

/* --- Scheda sopra la carta (autore, o più autori nello stesso posto) ------------------------- */
.mp-pop {
  position: absolute;
  z-index: 3;
  left: var(--pop-x, 12px);
  top: var(--pop-y, 12px);
  width: 290px;
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 0.9rem 1rem 1rem;
  border: 2px solid var(--rt-ink);
  border-radius: 20px;
  background: var(--rt-paper);
  box-shadow: 5px 5px 0 var(--rt-ink);
}

.mp-x {
  position: absolute;
  top: 8px;
  right: 10px;
  border: 0;
  background: none;
  color: var(--rt-ink);
  font-size: 1.05rem;
  cursor: pointer;
}

.mp-who {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.5rem;
  padding-right: 1.4rem;
}

.mp-who h3,
.mp-list-title {
  margin: 0;
  font: 800 1.15rem / 1.1 var(--rt-display);
  text-transform: none;
}

.mp-list-title {
  margin-bottom: 0.6rem;
  padding-right: 1.4rem;
}

.mp-years {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.mp-ini {
  display: grid;
  flex: none;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 2px solid var(--rt-ink);
  border-radius: 50%;
  background: var(--c);
  color: #161616;
  font: 800 1.15rem var(--rt-display);
  box-shadow: 3px 3px 0 var(--rt-ink);
}

.mp-ini.small {
  width: 34px;
  height: 34px;
  font-size: 0.85rem;
  box-shadow: 2px 2px 0 var(--rt-ink);
}

.mp-facts {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.15rem 0.7rem;
  margin: 0.2rem 0 0.5rem;
  font-size: 0.83rem;
}

.mp-facts dt {
  color: var(--muted);
  font-weight: 600;
}

.mp-facts dd {
  margin: 0;
}

.mp-books-n {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.mp-spines {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 58px;
  margin: 0.3rem 0 0.6rem;
}

.mp-spines i {
  width: 14px;
  height: var(--h);
  border: 1.5px solid var(--rt-ink);
  border-radius: 3px 3px 1px 1px;
  background: var(--c);
}

.mp-go {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  background: var(--rt-accent);
  color: var(--rt-accent-ink) !important;
  font-weight: 800;
  font-size: 0.85rem;
  text-decoration: none;
  box-shadow: 2px 2px 0 var(--rt-ink);
}

.mp-list {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.mp-list li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0 0.6rem;
}

.mp-list .mp-ini {
  grid-row: span 2;
}

.mp-list a {
  font-weight: 700;
}

.mp-list small {
  color: var(--muted);
}

/* --- Riquadri sotto la carta ------------------------------------------------------------- */
.mp-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 1.1rem;
  margin-top: 1.6rem;
}

.mp-box {
  grid-column: span 6;
  padding: 1.1rem 1.2rem 1.2rem;
  border-radius: 22px;
  background: var(--rt-paper);
}

.mp-box.mp-w8 {
  grid-column: span 8;
}

.mp-box.mp-w4 {
  grid-column: span 4;
}

.mp-box h2 {
  margin: 0 0 0.2rem;
  font: 800 1.25rem var(--rt-display);
  text-transform: none;
}

.mp-box h2::after {
  content: "";
  display: block;
  width: 40px;
  height: 5px;
  margin-top: 0.35rem;
  border-radius: 3px;
  background: var(--rt-accent);
}

.mp-muted {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

#map-view ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Passaporto: un francobollo per nazionalità. Foglietto dentellato (maschera: buchi tondi sul bordo,
   pieno dentro) nel pastello chiaro del paese sulla carta (--pl, anche col tema scuro: è carta),
   cornice sottile, nome in alto, sagoma del paese; timbro postale tondo col numero di autori.
   Ombra d'inchiostro sul li, così segue la dentellatura. Griglia che riempie la riga: i francobolli
   larghi almeno --stamp-w si allargano, sempre in proporzione 104 × 128. Chiuso, il passaporto mostra
   le prime STAMP_ROWS file (mappa.js, fitStamps); «Mostra tutti» (#map-stamps-more) le apre. */
.mp-stamps {
  --stamp-w: 104px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--stamp-w), 1fr));
  gap: 1rem 0.9rem;
  margin-top: 0.9rem !important;
}

.mp-stamp {
  --stamp-ink: #161616;
  --pl: #f2dc9e;
  filter: drop-shadow(3px 3px 0 var(--rt-ink));
}

.mp-stamp.c0 { --pl: #f3cfc3; }
.mp-stamp.c1 { --pl: #d6dcc4; }
.mp-stamp.c2 { --pl: #f2dc9e; }
.mp-stamp.c3 { --pl: #dccbea; }
.mp-stamp.c4 { --pl: #f6cfa9; }

.mp-stamp-face {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  aspect-ratio: 104 / 128;
  padding: 13px 11px 11px;
  background: var(--pl);
  color: var(--stamp-ink);
  /* Cornice interna come nei francobolli veri. */
  outline: 1.5px solid color-mix(in srgb, var(--stamp-ink) 55%, transparent);
  outline-offset: -9px;
  -webkit-mask: linear-gradient(#000 0 0) 5px 5px / calc(100% - 10px) calc(100% - 10px) no-repeat, radial-gradient(circle 3.6px, #0000 96%, #000) -5px -5px / 10px 10px round;
  mask: linear-gradient(#000 0 0) 5px 5px / calc(100% - 10px) calc(100% - 10px) no-repeat, radial-gradient(circle 3.6px, #0000 96%, #000) -5px -5px / 10px 10px round;
}

.mp-stamp-name {
  max-width: 100%;
  font: 800 0.6rem/1.1 var(--rt-body);
  letter-spacing: 0.06em;
  text-align: center;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.mp-stamp-shape {
  flex: 1;
  width: 100%;
  min-height: 0;
  margin-top: 4px;
}

.mp-stamp-shape path {
  fill: color-mix(in srgb, var(--pl) 45%, var(--stamp-ink));
  stroke: var(--stamp-ink);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

/* Timbro postale: cerchio d'inchiostro un po' storto, con le righe dell'annullo a sinistra. */
.mp-postmark {
  position: absolute;
  right: 6px;
  bottom: 8px;
  display: grid;
  place-items: center;
  align-content: center;
  width: 46px;
  height: 46px;
  border: 2px solid color-mix(in srgb, var(--stamp-ink) 80%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--pl) 70%, transparent);
  color: color-mix(in srgb, var(--stamp-ink) 85%, transparent);
  line-height: 1;
  transform: rotate(-14deg);
}

.mp-postmark::before {
  content: "";
  position: absolute;
  right: 100%;
  top: 50%;
  width: 34px;
  height: 14px;
  margin-top: -7px;
  background: repeating-linear-gradient(to bottom, color-mix(in srgb, var(--stamp-ink) 70%, transparent) 0 1.5px, transparent 1.5px 6px);
}

.mp-postmark b {
  font: 800 1rem/1 var(--rt-display);
}

.mp-postmark small {
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Il prossimo: un posto vuoto, tratteggiato. */
.mp-stamp[hidden] {
  display: none;
}

.mp-stamp.empty {
  display: grid;
  place-items: center;
  align-content: center;
  aspect-ratio: 104 / 128;
  border: 2px dashed var(--rt-ink);
  border-radius: 4px;
  filter: none;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  opacity: 0.45;
}

/* Telefono: tre per riga, a tutta larghezza. */
@media (max-width: 520px) {
  .mp-stamps {
    --stamp-w: 86px;
    gap: 0.9rem 0.7rem;
  }
}

.mp-more {
  margin-top: 1rem;
}

.mp-more[hidden] {
  display: none;
}

.mp-stamp.empty > span {
  display: block;
  font-size: 1.6rem;
}

/* Da un capo all'altro. */
.mp-far {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.9rem;
  text-align: center;
}

.mp-person {
  display: grid;
  justify-items: center;
  gap: 0.25rem;
  font-size: 0.88rem;
}

.mp-person small {
  color: var(--muted);
}

.mp-km {
  margin: 0;
  font: 800 1.45rem var(--rt-display);
}

.mp-km small {
  display: block;
  color: var(--muted);
  font: 600 0.75rem var(--rt-body);
}

/* Continenti. */
.mp-conts {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.8rem !important;
}

.mp-conts li {
  display: grid;
  grid-template-columns: 100px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.88rem;
  font-weight: 600;
}

.mp-conts li.zero {
  color: var(--muted);
}

.mp-bar {
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--rt-ink) 8%, transparent);
}

.mp-bar i {
  display: block;
  width: var(--w);
  height: 100%;
  border: 2px solid var(--rt-ink);
  border-radius: 999px;
  background: var(--rt-sage);
}

/* Viaggio nel tempo. */
/* Barra nativa: via padding, bordo e sfondo della regola generale dei campi (style.css), sennò Edge
   ferma il pallino prima della fine anche col valore al massimo. */
.mp-year {
  width: 100%;
  margin-top: 0.9rem;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  accent-color: var(--rt-accent);
}

.mp-ticks {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
}

.mp-year-out {
  margin: 0.4rem 0 0;
  font-weight: 700;
}

/* Nati lontano da casa. */
.mp-away {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.8rem !important;
}

.mp-away li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.1rem 0.7rem;
}

.mp-away .mp-ini {
  grid-row: span 2;
  width: 40px;
  height: 40px;
  font-size: 0.95rem;
  box-shadow: 2px 2px 0 var(--rt-ink);
}

.mp-away small {
  color: var(--muted);
}

/* Da scoprire, senza puntina: pillole. */
.mp-discover,
.mp-nopin {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.7rem !important;
}

.mp-discover a {
  display: inline-block;
  padding: 0.4rem 0.85rem;
  border: 2px solid var(--rt-ink);
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  text-decoration: none;
}

.mp-discover a::before {
  content: "";
  display: inline-block;
  width: 1.15em;
  height: 1.15em;
  vertical-align: -0.2em;
  background: currentColor;
  mask: url("icons/ph-compass.svg") center / contain no-repeat;
  margin-right: 0.35rem;
}

.mp-nopin a {
  display: inline-block;
  padding: 0.3rem 0.8rem;
  border-radius: 999px;
  background: var(--rt-blush);
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
}

/* --- Telefono ------------------------------------------------------------------------------ */
@media (max-width: 760px) {
  .mp-svg {
    height: 430px;
  }

  .mp-legend {
    display: none;
  }

  .mp-box,
  .mp-box.mp-w8,
  .mp-box.mp-w4 {
    grid-column: span 12;
  }

  /* La scheda sul telefono sta in basso, larga quanto la carta. */
  .mp-pop {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: 10px;
    width: auto;
  }
}
