/* ---------- Colores y tipografía del pergamino ---------- */
:root {
  color-scheme: only light;
  --parchment: #e8d6ae;
  --parchment-dark: #d9c193;
  --ink: #3a2716;
  --ink-soft: #6b4a2b;
  --seal: #9b3d27;
  --gold: #b8892f;
  --title: "IM Fell English SC", Georgia, serif;
  --text: "IM Fell English", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--parchment); color: var(--ink); font-family: var(--text); -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; color: inherit; cursor: pointer; }

/* ---------- Mapa: fondo de papel envejecido ---------- */
#map {
  position: fixed; inset: 0;
  background-color: var(--parchment);
  /* grano del papel: ruido generado con un filtro SVG */
  background-image:
    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='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .25 0 0 0 0 .12 0 0 0 .11 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    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='.004' numOctaves='3'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .32 0 0 0 0 .15 0 0 0 .16 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E");
}
.leaflet-container { background: transparent; font-family: var(--text); }
.leaflet-control-attribution { background: rgba(232,214,174,.75) !important; color: var(--ink-soft) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--ink-soft) !important; }

/* manchas oscuras en los bordes, como un mapa viejo */
.vignette { position: fixed; inset: 0; pointer-events: none; z-index: 500;
  background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(90,55,20,.28) 100%); }

.rose { position: fixed; right: 14px; bottom: 150px; width: 76px; height: 76px; color: var(--ink-soft); opacity: .55; z-index: 510; pointer-events: none; }

/* ---------- Jugador ---------- */
.player { width: 34px; height: 34px; }
.player .body { width: 100%; height: 100%; transition: transform .25s; }

/* ---------- Marcador superior ---------- */
.hud { position: fixed; top: 0; left: 0; right: 0; z-index: 900; padding: calc(env(safe-area-inset-top) + 10px) 12px 0; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.cartouche { padding: 4px 22px; border: 1.5px solid var(--ink-soft); outline: 1px solid var(--ink-soft); outline-offset: 3px; background: rgba(232,214,174,.92); }
.cartouche .title { font-family: var(--title); font-size: 21px; letter-spacing: .12em; }
.stats { display: flex; gap: 6px; width: 100%; max-width: 460px; }
.stat { flex: 1; background: rgba(232,214,174,.9); border: 1px solid rgba(107,74,43,.5); border-radius: 3px; padding: 5px 8px 6px; text-align: center; box-shadow: 0 2px 6px rgba(80,50,20,.15); }
.stat .lbl { display: block; font-family: var(--title); font-size: 12px; letter-spacing: .06em; color: var(--ink-soft); }
.stat b { display: block; font-size: 19px; font-weight: normal; line-height: 1.1; }
.bar { display: block; height: 4px; margin-top: 4px; background: rgba(107,74,43,.18); border-radius: 2px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--seal)); transition: width .6s; }
.gps { font-style: italic; font-size: 13px; color: var(--ink-soft); background: rgba(232,214,174,.85); padding: 1px 10px; border-radius: 10px; }
.gps:empty { display: none; }

/* ---------- Botones redondos ---------- */
.corner { position: fixed; right: 14px; bottom: calc(env(safe-area-inset-bottom) + 28px); z-index: 900; display: flex; flex-direction: column; gap: 10px; }
.round { width: 50px; height: 50px; border-radius: 50%; border: 1.5px solid var(--ink-soft); background: var(--parchment); display: grid; place-items: center; box-shadow: 0 3px 10px rgba(80,50,20,.3); }
.round.active { color: var(--seal); border-color: var(--seal); }

/* ---------- Flechas del modo desarrollador ---------- */
.dpad { position: fixed; left: 14px; bottom: calc(env(safe-area-inset-bottom) + 24px); z-index: 900; display: grid; grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(3, 54px); gap: 4px; touch-action: none; user-select: none; -webkit-user-select: none; }
.dpad[hidden] { display: none; }
.dpad button { border: 1.5px solid var(--ink-soft); background: rgba(232,214,174,.95); border-radius: 10px; font-size: 20px; box-shadow: 0 3px 8px rgba(80,50,20,.3); }
.dpad button.on { background: var(--ink-soft); color: var(--parchment); }
.dpad [data-dir=up] { grid-column: 2; grid-row: 1; }
.dpad [data-dir=left] { grid-column: 1; grid-row: 2; }
.dpad .speed { grid-column: 2; grid-row: 2; font-size: 12px; font-family: var(--title); line-height: 1; padding: 0 2px; }
.dpad [data-dir=right] { grid-column: 3; grid-row: 2; }
.dpad [data-dir=down] { grid-column: 2; grid-row: 3; }

/* ---------- Panel de ajustes ---------- */
.sheet { position: fixed; inset: 0; z-index: 1000; background: rgba(40,25,10,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.card { width: 100%; max-width: 480px; background: var(--parchment); border-top: 2px solid var(--ink-soft); padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px); border-radius: 14px 14px 0 0; box-shadow: 0 -6px 30px rgba(40,25,10,.35); }
.card h2 { font-family: var(--title); font-weight: normal; margin: 0 0 14px; font-size: 24px; letter-spacing: .06em; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed rgba(107,74,43,.4); }
.row small { display: block; color: var(--ink-soft); font-style: italic; }
.row input { width: 22px; height: 22px; accent-color: var(--seal); }
.sub { font-family: var(--title); color: var(--ink-soft); margin: 16px 0 8px; letter-spacing: .05em; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; }
.btns button, .close { border: 1px solid var(--ink-soft); background: rgba(255,255,255,.25); padding: 8px 12px; border-radius: 6px; font-size: 15px; }
.btns .danger { color: var(--seal); border-color: var(--seal); }
.close { display: block; width: 100%; margin-top: 18px; font-family: var(--title); font-size: 17px; letter-spacing: .05em; }

/* ---------- Pantalla de bienvenida ---------- */
.splash { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(ellipse at center, var(--parchment) 40%, var(--parchment-dark) 100%); transition: opacity .6s; }
.splash.gone { opacity: 0; pointer-events: none; }
.scroll { text-align: center; max-width: 360px; }
.scroll h1 { font-family: var(--title); font-weight: normal; font-size: 40px; letter-spacing: .1em; margin: 0 0 6px; }
.tag { font-style: italic; color: var(--ink-soft); margin: 0 0 28px; }
#splashMsg { min-height: 2.6em; }
.scroll button { margin-top: 10px; font-family: var(--title); font-size: 19px; letter-spacing: .06em; padding: 12px 28px; border: 1.5px solid var(--ink); background: transparent; border-radius: 4px; }
.scroll button:hover { background: rgba(58,39,22,.08); }

/* =====================================================================
   Fase 2: crónica, lugares, perfil y avatares
   ===================================================================== */
button.stat { font: inherit; color: inherit; cursor: pointer; pointer-events: auto; }
button.stat:active { transform: translateY(1px); }
.stat small { display: block; font-size: 10.5px; color: var(--ink-soft); font-style: italic; margin-top: 2px; white-space: nowrap; }

/* Ficha del jugador: avatar + flecha de dirección que gira alrededor */
.player { width: 48px; height: 48px; }
.player .tok { position: relative; width: 48px; height: 48px; filter: drop-shadow(0 2px 3px rgba(60,35,10,.45)); }
.player .tok svg { width: 100%; height: 100%; display: block; }
.player .dir { position: absolute; inset: -9px; transition: transform .25s; pointer-events: none; }
.player .dir::before { content: ""; position: absolute; left: 50%; top: 0; transform: translateX(-50%);
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 9px solid var(--seal); }

/* La calle donde estás */
.here { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 22px); z-index: 880;
  background: var(--parchment); border: 1.5px solid var(--ink-soft); border-radius: 3px; padding: 4px 16px 6px; text-align: center;
  box-shadow: 0 3px 10px rgba(80,50,20,.25); max-width: calc(100vw - 260px); min-width: 140px; pointer-events: none; }
.here .lbl { display: block; font-family: var(--title); font-size: 11px; color: var(--ink-soft); letter-spacing: .08em; }
.here b { font-weight: normal; font-style: italic; font-size: 17px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.here[hidden] { display: none; }
@media (max-width: 520px) { .here { bottom: calc(env(safe-area-inset-bottom) + 200px); max-width: calc(100vw - 100px); } body:not(.dev) .here { bottom: calc(env(safe-area-inset-bottom) + 22px); } }

/* Aviso flotante */
.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 150px); transform: translateX(-50%); z-index: 950;
  display: flex; align-items: center; gap: 10px; background: var(--parchment); border: 1.5px solid var(--seal); border-radius: 4px;
  padding: 8px 16px 8px 10px; box-shadow: 0 6px 20px rgba(60,35,10,.35); animation: drop .4s ease-out; max-width: 90vw; }
.toast[hidden] { display: none; }
.toast .ti { width: 36px; height: 36px; flex: none; }
.toast small { display: block; font-family: var(--title); color: var(--seal); letter-spacing: .06em; font-size: 12px; }
.toast b { font-weight: normal; font-size: 17px; }
@keyframes drop { from { opacity: 0; transform: translate(-50%, -14px); } }

/* Lugares de interés en el mapa */
.poi { width: 44px; height: 44px; }
.poi .pin { position: relative; width: 44px; height: 44px; display: grid; place-items: center; }
.poi .disc { width: 38px; height: 38px; border-radius: 50%; background: var(--parchment); border: 1.5px solid var(--ink-soft);
  box-shadow: 0 2px 5px rgba(60,35,10,.35); display: grid; place-items: center; }
.poi .disc svg { width: 28px; height: 28px; }
.poi .pname { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); white-space: nowrap; margin-bottom: 1px;
  font-family: var(--text); font-style: italic; font-size: 13px; color: var(--ink);
  text-shadow: 0 0 3px var(--parchment), 0 0 3px var(--parchment), 0 0 2px var(--parchment); pointer-events: none; }
.poi.unknown .disc { border-style: dashed; opacity: .75; font-family: var(--title); font-size: 20px; color: var(--ink-soft); }
.poi.fresh .disc { animation: glow 1.6s ease-out 2; }
@keyframes glow { 0% { box-shadow: 0 0 0 0 rgba(155,61,39,.7); } 100% { box-shadow: 0 0 0 16px rgba(155,61,39,0); } }
.zoomed-out .poi .pname { display: none; }
.zoomed-out .poi .disc { transform: scale(.75); }

/* Paneles altos con scroll */
.card.tall { max-height: 86vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chsum { margin: -6px 0 12px; color: var(--ink-soft); font-style: italic; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab { flex: 1; border: 1px solid var(--ink-soft); background: transparent; padding: 7px; border-radius: 4px; font-family: var(--title); font-size: 15px; letter-spacing: .04em; }
.tab.on { background: var(--ink-soft); color: var(--parchment); }
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; border-bottom: 1px dashed rgba(107,74,43,.35);
  background: transparent; padding: 9px 2px; font-size: 16px; }
.item:active { background: rgba(107,74,43,.08); }
.item .it { width: 30px; height: 30px; flex: none; }
.item .main { flex: 1; min-width: 0; }
.item .main b { display: block; font-weight: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .main small { color: var(--ink-soft); font-style: italic; font-size: 13px; }
.item .pct { font-family: var(--title); font-size: 14px; color: var(--ink-soft); text-align: right; min-width: 52px; }
.item .pct i { display: block; height: 3px; margin-top: 3px; background: rgba(107,74,43,.2); border-radius: 2px; overflow: hidden; }
.item .pct i i { display: block; height: 100%; background: var(--seal); }
.empty { color: var(--ink-soft); font-style: italic; text-align: center; padding: 22px 6px; }

/* Ficha de lugar */
.placehead, .prohead { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.placehead h2, .prohead h2 { margin: 0; }
.picon { width: 56px; height: 56px; flex: none; border-radius: 50%; border: 1.5px solid var(--ink-soft); display: grid; place-items: center; background: rgba(255,255,255,.2); }
.picon svg { width: 40px; height: 40px; }
.plmeta { margin: 2px 0 0; color: var(--ink-soft); font-style: italic; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.photos button { padding: 0; border: 1px solid rgba(107,74,43,.5); background: var(--parchment-dark); aspect-ratio: 4 / 3; overflow: hidden; border-radius: 3px; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; filter: sepia(.25) contrast(.95); transition: filter .3s; }
.photos button:hover img { filter: none; }
.photos .msg { grid-column: 1 / -1; color: var(--ink-soft); font-style: italic; text-align: center; padding: 18px 4px; }
.credit { font-size: 12px; color: var(--ink-soft); margin: 10px 0 0; }
.credit a { color: inherit; }
.lightbox { position: fixed; inset: 0; z-index: 3000; background: rgba(25,15,5,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 82vh; border: 3px solid var(--parchment); }
.lightbox p { color: var(--parchment); font-size: 13px; text-align: center; max-width: 640px; }
.lightbox a { color: var(--parchment); }

/* Perfil */
.avatar-btn { padding: 0; overflow: hidden; }
.avatar-btn svg { width: 46px; height: 46px; display: block; }
.bigavatar { width: 84px; height: 84px; flex: none; filter: drop-shadow(0 3px 5px rgba(60,35,10,.35)); }
.bigavatar svg { width: 100%; height: 100%; }
.field { display: block; margin: 0 0 10px; }
.field span { display: block; font-family: var(--title); font-size: 13px; color: var(--ink-soft); letter-spacing: .05em; margin-bottom: 3px; }
.field input { width: 100%; font: inherit; font-size: 17px; color: var(--ink); background: rgba(255,255,255,.35); border: 1px solid rgba(107,74,43,.55); border-radius: 4px; padding: 8px 10px; }
.field input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.avatars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.avatars button { border: 1.5px solid transparent; background: transparent; border-radius: 8px; padding: 4px 2px; text-align: center; font-size: 13px; }
.avatars button svg { width: 100%; max-width: 64px; display: block; margin: 0 auto 2px; }
.avatars button.on { border-color: var(--seal); background: rgba(155,61,39,.08); }
.avdesc { font-style: italic; color: var(--ink-soft); text-align: center; margin: 6px 0 0; min-height: 1.3em; }
.feats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.feat { border: 1px solid rgba(107,74,43,.45); border-radius: 4px; padding: 8px 10px; text-align: center; background: rgba(255,255,255,.18); }
.feat b { display: block; font-weight: normal; font-size: 22px; }
.feat span { font-family: var(--title); font-size: 12px; color: var(--ink-soft); letter-spacing: .04em; }
.photos .retry { display: block; margin: 10px auto 0; font-family: var(--title); border: 1px solid var(--ink-soft); background: transparent; padding: 6px 14px; border-radius: 4px; }
