/* Sobrio, como un manuscrito de cancilleria del siglo XIV:
   vitela gastada, tinta ferrogalica y un solo acento de rojo apagado.
   Letra gotica (textura) para los titulos y caligrafia para el resto. */
:root {
  --gotica: "UnifrakturCook", "Almendra SC", serif;
  /* grano de la vitela y manchas de humedad: ruido de SVG, sin imagenes */
  --grano: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .33 0 0 0 0 .22 0 0 0 0 .1 .55 0 0 0 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --manchas: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='900'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.00667' numOctaves='4' seed='7' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .36 0 0 0 0 .22 0 0 0 0 .08 1.8 0 0 0 -.95'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E");
  --vitela: #f1e6cc;
  --vitela-osc: #ddcba4;
  --tinta: #2b2118;
  --tinta-suave: #6b5a45;
  --regla: rgba(43, 33, 24, .22);
  --rojo: #6e2a1e;
  --sombra: 0 4px 16px rgba(20, 12, 4, .45);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--tinta);
  color: var(--tinta);
  font: 16px/1.35 Almendra, Georgia, serif;
  overflow: hidden;
}
button { font: inherit; color: inherit; }

/* ---- mapa a pantalla completa, sin poder copiar ni arrastrar la imagen */
#map { position: fixed; inset: 0; background: #1c1f5c; } /* color del mar: se ve mientras cargan los pedazos al hacer zoom */
.leaflet-container { font-family: Almendra, Georgia, serif; -webkit-user-select: none; user-select: none; }
.leaflet-tile { -webkit-user-drag: none; pointer-events: none; }
.leaflet-tile-pane { filter: sepia(.1) brightness(1.12); } /* tinta un poco vieja, sin oscurecer */
.capa-pixel .leaflet-tile { image-rendering: pixelated; } /* colores y fronteras: bordes de chunk nitidos al acercar */
body.dibujando .leaflet-container { cursor: crosshair; }

/* ---- marco: el mapa termina en un borde roto y quemado. Una banda del color de la mesa con su
   orilla de pergamino tostado, deformada por el filtro #roto (index.html) para que quede irregular. */
#marco {
  position: fixed; inset: -24px; z-index: 800; pointer-events: none;
  border: 32px solid #1d150e;
  box-shadow: inset 0 0 0 1px #3e2410, inset 0 0 0 3px #8a6234, inset 0 0 8px 3px rgba(66, 36, 10, .75), inset 0 0 60px rgba(50, 32, 12, .22);
  filter: url(#roto);
}

/* ---- desgaste: grano y manchas sobre todo el mapa, debajo del marco */
#desgaste {
  position: fixed; inset: 0; z-index: 790; pointer-events: none;
  background: var(--manchas), var(--grano);
  background-size: cover, auto;
  mix-blend-mode: multiply; opacity: .22;
}

/* ---- piezas de vitela */
#barra, #hoja, #informe, #estrategia, #coords, .menu {
  background: var(--grano), var(--manchas), var(--vitela);
  border: 1px solid var(--tinta);
  border-top: 3px solid var(--rojo); /* filete rojo de rubrica arriba de cada pieza */
  box-shadow: var(--sombra), inset 0 0 22px rgba(96, 60, 22, .3); /* bordes tostados */
}
#coords { border-top-width: 1px; border-top-color: var(--tinta); }

/* ---- cabecera con menu desplegable */
#barra {
  position: fixed; top: 30px; left: 34px; z-index: 950;
  display: flex; align-items: center; gap: 12px;
  max-width: calc(100% - 110px); padding: 6px 12px;
  outline: 1px solid var(--tinta); outline-offset: -5px;
}
#opciones { flex: none; position: relative; }
#opciones summary {
  list-style: none; cursor: pointer; user-select: none;
  padding: 6px 12px; border: 1px solid var(--tinta);
  font: 600 13px "Almendra SC", serif; letter-spacing: .12em; text-transform: uppercase;
}
#opciones summary::-webkit-details-marker { display: none; }
#opciones summary::after { content: " ▾"; }
#opciones[open] summary { background: var(--rojo); border-color: var(--rojo); color: var(--vitela); }
#opciones[open] summary::after { content: " ▴"; }
#opciones summary:focus-visible { outline: 2px solid var(--rojo); outline-offset: 2px; }
.menu {
  position: absolute; top: calc(100% + 12px); left: -13px; z-index: 970;
  display: grid; gap: 12px; width: max-content; max-width: calc(100vw - 44px);
  padding: 14px 16px;
}
.menu .grupo { flex-wrap: wrap; }
.menu .grupo legend { float: none; display: block; width: 100%; margin: 0 0 4px; padding-bottom: 2px; border-bottom: 1px solid var(--regla); }

/* ---- globo de Discord */
#discord {
  position: fixed; top: 30px; right: 34px; z-index: 950;
  width: 54px; height: 54px; display: grid; place-items: center;
  background: var(--vitela); color: #5865f2;
  border: 1px solid var(--tinta); border-radius: 50% 50% 50% 6px; /* globo con su piquito */
  box-shadow: var(--sombra);
  transition: transform .15s;
}
#discord svg { width: 28px; height: 28px; }
#discord:hover { transform: translateY(-2px) scale(1.06); }
#discord:focus-visible { outline: 2px solid var(--rojo); outline-offset: 2px; }
.marca {
  flex: none; padding-right: 12px; border-right: 1px solid var(--regla);
  font: 700 27px/1 var(--gotica); letter-spacing: .02em; color: var(--tinta);
}
.marca::first-letter { color: var(--rojo); font-size: 1.25em; }
.marca small {
  display: block; margin-top: 3px;
  font: italic 12px Almendra, serif; letter-spacing: .04em; text-transform: none; color: var(--tinta-suave);
}
.grupo { flex: none; display: flex; align-items: center; gap: 2px; border: 0; margin: 0; padding: 0; }
.grupo legend {
  float: left; margin-right: 6px; padding: 0;
  font: 600 10px "Almendra SC", serif; letter-spacing: .14em; text-transform: uppercase; color: var(--tinta-suave);
}
.grupo label { cursor: pointer; }
.grupo input { position: absolute; opacity: 0; pointer-events: none; }
.grupo span {
  display: block; padding: 4px 7px; white-space: nowrap;
  font-size: 15px; border: 1px solid transparent;
}
.grupo label:hover span { border-color: var(--regla); }
.grupo input:checked + span { background: var(--rojo); color: var(--vitela); }
.grupo input:focus-visible + span { outline: 2px solid var(--rojo); outline-offset: 1px; }
#estado-guerra {
  flex: none; margin-left: auto; padding: 4px 10px;
  font: 600 12px "Almendra SC", serif; letter-spacing: .1em; text-transform: uppercase;
  color: var(--vitela); background: var(--rojo);
  animation: latido 2s ease-in-out infinite;
}
@keyframes latido { 50% { opacity: .65; } }
@media (prefers-reduced-motion: reduce) { #estado-guerra { animation: none; } }

/* ---- paneles laterales */
#hoja, #informe {
  position: fixed; top: 106px; z-index: 900; overflow-y: auto;
  max-height: calc(100% - 216px);
  scrollbar-color: var(--tinta-suave) transparent;
}
#hoja { left: 34px; width: 280px; padding: 14px 18px 16px; }
#informe { right: 34px; width: 330px; padding: 20px 22px 18px; outline: 1px solid var(--tinta); outline-offset: -6px; }
.cerrar {
  position: absolute; top: 6px; right: 8px;
  width: 30px; height: 30px; padding: 0;
  background: none; border: 0; cursor: pointer;
  font-size: 26px; line-height: 1; color: var(--tinta-suave);
}
.cerrar:hover { color: var(--rojo); }
.cerrar:focus-visible { outline: 2px solid var(--rojo); }

.rubrica {
  margin: 0; text-align: center;
  font: 700 21px var(--gotica); letter-spacing: .02em;
}
.rubrica::first-letter { color: var(--rojo); }
.cuenta {
  text-align: center; font-style: italic; color: var(--tinta-suave); font-size: 14px;
  padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--tinta);
  box-shadow: 0 3px 0 -2px var(--tinta);
}
#buscar {
  width: 100%; padding: 5px 2px; margin-bottom: 6px;
  font: italic 15px Almendra, serif; color: var(--tinta);
  background: transparent; border: 0; border-bottom: 1px dashed var(--tinta-suave);
}
#buscar:focus { outline: none; border-bottom-color: var(--rojo); }
#lista-reinos { list-style: none; margin: 0; padding: 0; }
#lista-reinos li {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 5px 2px; border-bottom: 1px solid var(--regla);
}
#lista-reinos li:hover { background: rgba(110, 42, 30, .08); }
#lista-reinos li:hover span { color: var(--rojo); }
#lista-reinos i { /* escudo */
  flex: none; width: 14px; height: 17px;
  clip-path: path("M0 0 H14 V8.5 C14 13 7 17 7 17 C7 17 0 13 0 8.5 Z");
  box-shadow: inset 0 0 0 1.5px rgba(0, 0, 0, .5);
}
#lista-reinos .bandera { /* tela de la bandera, gastada como el resto */
  flex: none; width: 26px; height: 18px; object-fit: cover;
  border: 1px solid var(--tinta); filter: sepia(.18) saturate(.9);
}
#lista-reinos span { flex: 1; min-width: 0; }
#lista-reinos small { display: block; font-style: italic; color: var(--tinta-suave); font-size: 13px; }
#lista-reinos em { font-style: normal; font-size: 13px; color: var(--tinta-suave); }

/* ---- carta del reino */
#informe h1 { font: 700 28px/1.15 var(--gotica); margin: 0; text-align: center; }
#informe h1::first-letter { color: var(--rojo); font-size: 1.3em; }
#informe h2 {
  font: 600 12px "Almendra SC", serif; letter-spacing: .14em; text-transform: uppercase; color: var(--tinta);
  margin: 16px 0 6px; display: flex; align-items: center; gap: 8px;
}
#informe h2::after { content: ""; flex: 1; border-bottom: 1px solid var(--tinta); order: 1; }
#informe h2 span { order: 2; color: var(--tinta-suave); }
.sub { text-align: center; font-style: italic; color: var(--tinta-suave); margin: 2px 0 6px; }
.vacio { font-style: italic; color: var(--tinta-suave); margin: 0; }
.escudo {
  width: 42px; height: 50px; margin: 0 auto 8px;
  background: var(--c);
  clip-path: path("M0 0 H42 V28 C42 41 21 50 21 50 C21 50 0 41 0 28 Z");
  box-shadow: inset 0 0 0 2px var(--tinta), inset 0 0 0 4px rgba(235, 223, 195, .35);
}
.bandera-grande {
  display: block; max-width: 96px; max-height: 70px; margin: 0 auto 10px;
  border: 1px solid var(--tinta); box-shadow: 0 2px 6px rgba(20, 12, 4, .35); filter: sepia(.18) saturate(.9);
}
.ocupado { color: var(--rojo); font-style: italic; text-align: center; margin: 6px 0 0; }
.kv { list-style: none; margin: 0; padding: 0; font-size: 15px; }
.kv li { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px dotted var(--regla); }
.kv li span { color: var(--tinta-suave); white-space: nowrap; }
.kv li b { font-weight: 400; text-align: right; }
.fichas { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 5px; }
.fichas li { display: flex; align-items: center; gap: 4px; padding: 2px 7px 2px 4px; border: 1px solid var(--regla); background: rgba(255, 250, 235, .35); font-size: 14px; }
.fichas img { width: 16px; height: 16px; image-rendering: pixelated; }
.fichas small { color: var(--tinta-suave); font-size: 11px; }
.gente { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.gente li.lider::before { content: "♛ "; color: var(--rojo); }

/* ---- herramientas de estrategia */
#estrategia {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 950;
  display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap; justify-content: center;
  max-width: calc(100% - 44px); padding: 7px 12px;
}
#estrategia button {
  cursor: pointer; padding: 4px 9px; min-height: 32px;
  background: transparent; border: 1px solid var(--regla); font-size: 15px;
}
#estrategia button:hover { border-color: var(--tinta); }
#estrategia button[aria-pressed="true"] { background: var(--tinta); color: var(--vitela); border-color: var(--tinta); }
#estrategia button:focus-visible { outline: 2px solid var(--rojo); outline-offset: 1px; }
.herramientas, .tintas, .acciones { display: flex; gap: 4px; }
.tintas { padding: 0 10px; border-left: 1px solid var(--regla); border-right: 1px solid var(--regla); }
.tintas button { width: 28px; min-height: 28px !important; padding: 0 !important; border-radius: 50%; background: var(--c) !important; }
.tintas button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--vitela), 0 0 0 3px var(--tinta); }
#descargar.principal { background: var(--rojo); color: var(--vitela); border-color: var(--rojo); }
#estrategia .ayuda { flex-basis: 100%; margin: 0; text-align: center; font-style: italic; font-size: 13px; color: var(--tinta-suave); }

/* ---- rosa de los vientos y coordenadas */
#pie {
  position: fixed; left: 38px; bottom: 36px; z-index: 900;
  display: flex; align-items: center; gap: 10px; pointer-events: none;
}
.rosa { width: 80px; height: 80px; color: #d2ab55; pointer-events: auto; cursor: pointer; filter: drop-shadow(0 0 2px #000) drop-shadow(0 0 1px #000); } /* oro */
#coords { font: 600 13px "Almendra SC", serif; letter-spacing: .06em; font-variant-numeric: tabular-nums; padding: 4px 12px; }

/* ---- etiquetas del mapa */
.etiqueta-nacion span {
  display: block; transform: translate(-50%, -50%); white-space: nowrap;
  font: 700 15px "Almendra SC", serif; letter-spacing: .12em; text-transform: uppercase;
  color: #f4ead2; text-shadow: 0 0 3px #000, 0 0 6px #000;
  pointer-events: none;
}
.etiqueta-impasable span {
  display: block; transform: translate(-50%, -50%); white-space: nowrap;
  font: italic 18px Almendra, serif; letter-spacing: .08em;
  color: #b9a888; text-shadow: 0 0 4px #000;
  pointer-events: none;
}
.etiqueta-ciudad {
  transform: translate(-6px, -50%); white-space: nowrap;
  font: 600 13px "Almendra SC", serif; color: #f4ead2; text-shadow: 0 0 3px #000, 0 0 5px #000;
}
.recurso {
  display: flex; align-items: center; justify-content: center; gap: 1px; font-size: 13px; line-height: 1;
  background: var(--vitela); border: 1px solid var(--tinta); border-radius: 11px;
}
.recurso img { width: 16px; height: 16px; image-rendering: pixelated; }
.recurso img.menor { width: 11px; height: 11px; }
.marca-estrategia span {
  display: block; transform: translate(-50%, -50%); white-space: nowrap;
  font: 700 22px/1 "Almendra SC", serif; color: var(--c);
  text-shadow: 0 0 2px var(--vitela), 0 0 4px var(--vitela), 0 0 6px var(--vitela);
}
.marca-estrategia.nota span { font: italic 17px Almendra, serif; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--vitela); color: var(--tinta); border-radius: 0; }
.leaflet-popup-content { font: 15px Almendra, serif; }

/* zoom */
.leaflet-right.leaflet-bottom { right: 38px; bottom: 36px; }
.leaflet-touch .leaflet-bar, .leaflet-bar { border: 1px solid var(--tinta); border-radius: 0; box-shadow: var(--sombra); }
.leaflet-bar a, .leaflet-touch .leaflet-bar a {
  width: 34px; height: 34px; line-height: 32px; border-radius: 0 !important;
  background: var(--vitela); color: var(--tinta); border-color: var(--regla); font: 700 18px "Almendra SC", serif;
}
.leaflet-bar a:hover { background: var(--vitela-osc); }

/* ---- apertura: la portada de vitela se desvanece y el mapa aparece debajo, como al desplegarlo */
#apertura {
  position: fixed; inset: 0; z-index: 3000; pointer-events: none;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(90, 58, 24, .45)), var(--manchas), var(--grano), var(--vitela);
  background-size: auto, cover, auto, auto; /* manchas estiradas: sin costura */
  animation: portada .9s ease-in-out 1.7s forwards;
}
#apertura .portada {
  text-align: center; padding: 34px 56px 28px;
  border: 1px solid var(--tinta); outline: 1px solid var(--tinta); outline-offset: 6px;
  animation: tinta .9s ease-out .15s both;
}
#apertura .titulo { font: 700 72px/1 var(--gotica); color: var(--tinta); }
#apertura .titulo::first-letter { color: var(--rojo); }
#apertura .lema { margin-top: 10px; font: italic 19px Almendra, serif; color: var(--tinta-suave); letter-spacing: .04em; }
#apertura .sello {
  width: 54px; height: 54px; margin: 18px auto 0; border-radius: 50%;
  display: grid; place-items: center; font: 700 20px var(--gotica); color: #f1dcc0;
  background: radial-gradient(circle at 38% 34%, #a8402e, #6e2a1e 60%, #4a1a12);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .4), inset 0 0 0 4px rgba(0, 0, 0, .18);
  animation: sello .35s cubic-bezier(.3, 1.6, .6, 1) .85s both;
}
@keyframes tinta { from { opacity: 0; filter: blur(3px); } }
@keyframes sello { from { opacity: 0; transform: scale(1.8); } }
@keyframes portada { to { opacity: 0; visibility: hidden; transform: scale(1.04); } }
#map { animation: desplegar 1.1s ease-out 1.7s both; }
@keyframes desplegar { from { transform: scale(1.06); filter: blur(5px); } }
#barra, #discord, #hoja, #pie, .leaflet-control-container { animation: aparecer .6s ease-out 2.3s both; }
@keyframes aparecer { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  #apertura { display: none; }
  #map, #barra, #discord, #hoja, #pie, .leaflet-control-container { animation: none; }
}

/* ---- celular */
@media (max-width: 800px) {
  #marco { inset: -24px; border-width: 30px; }
  #barra { top: 22px; left: 22px; max-width: calc(100% - 100px); padding: 5px 8px; gap: 8px; }
  .marca { font-size: 20px; padding-right: 8px; }
  #apertura .titulo { font-size: 46px; }
  #apertura .portada { padding: 26px 26px 22px; margin: 0 16px; }
  .marca small { display: none; }
  #opciones summary { padding: 8px 10px; font-size: 12px; }
  .menu { position: fixed; top: 74px; left: 12px; right: 12px; width: auto; max-width: none; max-height: calc(100vh - 90px); overflow-y: auto; }
  .grupo span { padding: 7px 10px; } /* botones comodos para el dedo */
  #estado-guerra { position: fixed; top: 70px; left: 12px; margin: 0; }
  #discord { top: 22px; right: 22px; width: 48px; height: 48px; }
  #hoja { left: 12px; right: 12px; width: auto; top: 76px; max-height: calc(100% - 150px); }
  #informe { left: 12px; right: 12px; width: auto; top: auto; bottom: 12px; max-height: 55%; z-index: 960; }
  #estrategia {
    left: 8px; right: 8px; bottom: 8px; transform: none; max-width: none;
    flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; scrollbar-width: none; padding: 6px 8px;
  }
  #estrategia .herramientas, #estrategia .acciones, #estrategia .tintas { flex: none; }
  #estrategia button { min-height: 40px; }
  #estrategia .ayuda { display: none; }
  #pie { left: 24px; bottom: 24px; }
  .rosa { width: 52px; height: 52px; }
  .leaflet-right.leaflet-bottom { right: 24px; bottom: 24px; }
}
/* pantallas tactiles: se hace zoom con dos dedos y no hay puntero para las coordenadas */
@media (hover: none) {
  #coords, .leaflet-control-zoom { display: none; }
}
