@font-face { font-family: 'Anton'; src: url('../ruta/fonts/anton.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Newsreader'; src: url('../ruta/fonts/newsreader.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Plex Mono'; src: url('../ruta/fonts/plexmono.woff2') format('woff2'); font-weight: 500; font-display: swap; }

:root { --paper: #f4edde; --paper-2: #ebe2cf; --ink: #21201c; --red: #e4572e; --blue: #355e8c; --panel: clamp(236px, 26vw, 330px); }
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { background: var(--paper); color: var(--ink); font-family: 'Newsreader', Georgia, serif; font-size: 17px; line-height: 1.45; }
button { font: inherit; color: inherit; cursor: pointer; }
.mono { font-family: 'Plex Mono', ui-monospace, Menlo, monospace; font-weight: 500; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.salto { position: absolute; left: -999px; top: 8px; z-index: 50; background: var(--ink); color: var(--paper); padding: 8px 12px; }
.salto:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

#app { display: flex; height: 100%; }

/* ---------- Foto ---------- */
#escena { position: relative; flex: 1; min-width: 0; min-height: 0; background-color: var(--paper-2); background-image: radial-gradient(var(--ink) 1.1px, transparent 1.2px); background-size: 10px 10px; }
#visor { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
#visor.agarra { cursor: grabbing; }
#visor:focus-visible { outline-offset: -4px; }
#lienzo { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; border: 2px solid var(--ink); }
#lienzo.suave { transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1); }
#foto { display: block; width: 100%; height: 100%; pointer-events: none; }
#marcas { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
#marcas .aro { fill: none; stroke-width: 7; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 0; }
#marcas .aro.rojo { stroke: var(--red); }
#marcas .aro.azul { stroke: var(--blue); }
#marcas .nueva .aro { animation: trazo 480ms ease-out both; }
#marcas .zona { fill: rgba(53, 94, 140, 0.14); stroke: var(--blue); stroke-width: 8; stroke-dasharray: 26 20; }
#marcas .tache { stroke: var(--ink); stroke-width: 7; stroke-linecap: round; animation: fuera 900ms ease-in both; }
@keyframes trazo { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes fuera { 0%, 55% { opacity: 1; } 100% { opacity: 0; } }

#mira { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border: 2px solid var(--ink); border-radius: 50%; box-shadow: 0 0 0 2px var(--paper); display: none; pointer-events: none; }
#mira::before, #mira::after { content: ''; position: absolute; background: var(--ink); }
#mira::before { left: 50%; top: -8px; bottom: -8px; width: 2px; margin-left: -1px; }
#mira::after { top: 50%; left: -8px; right: -8px; height: 2px; margin-top: -1px; }
#visor.teclas #mira { display: block; }

#aviso { position: absolute; left: 50%; top: 14px; transform: translate(-50%, -8px); max-width: calc(100% - 28px); background: var(--ink); color: var(--paper); padding: 9px 14px; opacity: 0; pointer-events: none; transition: opacity 160ms, transform 160ms; text-align: center; }
#aviso.ver { opacity: 1; transform: translate(-50%, 0); }

.zoom { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 6px; }
.zoom button { min-width: 44px; height: 44px; padding: 0 12px; background: var(--paper); border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); font-family: 'Plex Mono', ui-monospace, Menlo, monospace; font-weight: 500; font-size: 26px; line-height: 1; }
.zoom button.mono { font-family: 'Plex Mono', ui-monospace, Menlo, monospace; font-size: 12px; }
.zoom button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }

/* ---------- Panel ---------- */
#panel { width: var(--panel); flex: none; display: flex; flex-direction: column; border-left: 2px solid var(--ink); background: var(--paper); min-height: 0; }
.barra { display: none; }
#cuerpo { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cabeza { padding: 14px 16px 12px; border-bottom: 2px solid var(--ink); }
.volver { color: var(--ink); text-decoration: none; display: inline-block; padding: 4px 0; }
.volver:hover { color: var(--red); }
h1 { font-family: 'Anton', Impact, sans-serif; font-weight: 400; text-transform: uppercase; font-size: clamp(2.6rem, 4.6vw, 3.9rem); line-height: 0.95; letter-spacing: 0.01em; text-shadow: 3px 3px 0 var(--red); margin: 4px 0 8px; }
.datos { font-size: 13px; white-space: nowrap; }

.modos { display: flex; border-bottom: 2px solid var(--ink); }
.modos button { flex: 1; min-height: 44px; background: var(--paper); border: 0; border-right: 1px solid var(--ink); }
.modos button:last-child { border-right: 0; }
.modos button[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
.modos button:focus-visible { outline-offset: -4px; }

#misiones { flex: 1; min-height: 0; overflow-y: auto; }

/* Lista: la hoja de casillas del libro */
.lista { list-style: none; }
.lista li { border-bottom: 1px solid rgba(33, 32, 28, 0.3); }
.mision { display: grid; grid-template-columns: 22px 1fr; column-gap: 12px; align-items: start; width: 100%; min-height: 44px; padding: 10px 16px; background: none; border: 0; text-align: left; }
.mision .caja { width: 20px; height: 20px; margin-top: 2px; border: 2px solid var(--ink); background: var(--paper); position: relative; }
.mision.hecha .caja::after { content: ''; position: absolute; left: 3px; top: -5px; width: 8px; height: 17px; border: solid var(--red); border-width: 0 4px 4px 0; transform: rotate(40deg); }
.mision.hecha .txt { text-decoration: line-through; text-decoration-thickness: 1.5px; opacity: 0.62; }
.mision.sel { background: var(--paper-2); box-shadow: inset 5px 0 0 var(--red); }
.mision:focus-visible { outline-offset: -3px; }

/* Album: estampas que se pegan al hallar */
.album-caja { padding: 14px 16px; }
.album { list-style: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px 8px; }
.estampa { display: block; width: 100%; aspect-ratio: 1; border-radius: 50%; border: 2px dashed var(--ink); background: var(--paper-2); position: relative; overflow: hidden; padding: 0; font-family: 'Anton', Impact, sans-serif; font-size: 20px; color: var(--ink); }
.estampa.hecha { border-style: solid; background-color: var(--paper); background-repeat: no-repeat; }
.estampa.hecha.nueva { animation: sello 320ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.estampa.sel { box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--red); }
@keyframes sello { from { transform: scale(1.5) rotate(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }
.pie { margin-top: 16px; padding-top: 12px; border-top: 1px solid rgba(33, 32, 28, 0.3); }
.pie .mono { display: block; margin-bottom: 4px; }

/* Recados: uno a la vez, con voz */
.recado { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.recado .num { font-family: 'Anton', Impact, sans-serif; font-size: 3.4rem; line-height: 0.9; color: var(--red); text-shadow: 2px 2px 0 var(--blue); }
.recado .dicho { font-size: 20px; line-height: 1.35; }
.recado .que { opacity: 0.72; font-size: 15px; }
.sello { display: inline-block; align-self: flex-start; border: 1.5px dashed var(--ink); border-radius: 999px; padding: 4px 14px; transform: rotate(-2deg); }
.paso { display: flex; gap: 8px; }
.paso button { flex: 1; min-height: 44px; background: var(--paper); border: 2px solid var(--ink); }
.puntos { display: flex; gap: 6px; flex-wrap: wrap; list-style: none; }
.puntos li { width: 14px; height: 14px; border: 2px solid var(--ink); border-radius: 50%; }
.puntos li.hecha { background: var(--red); }
.puntos li.sel { box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink); }

.acciones { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 2px solid var(--ink); }
.acciones button, .boton, .hoja button { min-height: 44px; padding: 10px 16px; background: var(--paper); border: 2px solid var(--ink); color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; transition: transform 100ms, box-shadow 100ms; }
.acciones button { flex: 1; }
.fuerte { background: var(--red) !important; }
.acciones button:hover, .boton:hover, .hoja button:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
button:disabled { opacity: 0.45; cursor: default; transform: none !important; box-shadow: none !important; }

/* ---------- Hojas ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 18px; background: rgba(33, 32, 28, 0.62); }
.modal[hidden] { display: none; }
.hoja { width: min(100%, 460px); max-height: 100%; overflow: auto; background: var(--paper); border: 2px solid var(--ink); box-shadow: 8px 8px 0 var(--ink); padding: clamp(18px, 4vw, 30px); display: flex; flex-direction: column; gap: 12px; animation: cae 200ms ease-out both; }
.hoja h2 { font-family: 'Anton', Impact, sans-serif; font-weight: 400; text-transform: uppercase; font-size: clamp(2.8rem, 9vw, 4.6rem); line-height: 0.95; text-shadow: 3px 3px 0 var(--red); }
.hoja .texto { max-width: 30em; }
.fila { display: flex; gap: 8px; flex-wrap: wrap; }
@keyframes cae { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Telefono vertical: foto a pantalla completa y hoja de misiones que sube ---------- */
@media (orientation: portrait) and (max-width: 820px) {
  :root { --barra: 64px; }
  #app { flex-direction: column; padding-bottom: calc(var(--barra) + env(safe-area-inset-bottom)); }
  #panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; width: auto; height: min(80%, 680px); border-left: 0; border-top: 2px solid var(--ink); padding-bottom: env(safe-area-inset-bottom); transform: translateY(calc(100% - var(--barra) - env(safe-area-inset-bottom))); transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1); }
  #panel.abierto { transform: none; }
  .barra { display: flex; flex: none; height: var(--barra); border-bottom: 2px solid var(--ink); }
  #asa { flex: 1; min-width: 0; display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 10px; padding: 6px 12px 6px 16px; background: var(--paper); border: 0; text-align: left; position: relative; }
  #asa::before { content: ''; position: absolute; left: 50%; top: 5px; width: 44px; height: 4px; margin-left: -22px; background: var(--ink); }
  #asa .mono { grid-column: 1; margin-top: 8px; font-size: 12px; }
  #asa .busca { grid-column: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 17px; line-height: 1.25; }
  #asa .flecha { grid-column: 2; grid-row: 1 / span 2; width: 12px; height: 12px; border: solid var(--ink); border-width: 3px 3px 0 0; transform: translateY(4px) rotate(-45deg); transition: transform 200ms; }
  #panel.abierto #asa .flecha { transform: translateY(-3px) rotate(135deg); }
  #asa:focus-visible { outline-offset: -4px; }
  #pista-b { flex: none; min-width: 92px; background: var(--red); border: 0; border-left: 2px solid var(--ink); }
  #pista-b:focus-visible { outline-offset: -4px; }
  .cabeza { display: flex; align-items: baseline; gap: 12px; padding: 8px 16px; }
  .cabeza .datos { display: none; }
  h1 { font-size: 1.7rem; margin: 0; text-shadow: 2px 2px 0 var(--red); order: -1; flex: 1; }
  .mision { padding: 8px 16px; }
  .acciones { padding: 8px 16px; }
  .acciones #pista { display: none; }
  .zoom { bottom: 10px; }
}
/* ---------- Telefono acostado ---------- */
@media (orientation: landscape) and (max-height: 520px) {
  body { font-size: 15px; }
  .cabeza { padding: 6px 12px; display: grid; grid-template-columns: 1fr auto; align-items: end; column-gap: 8px; }
  .volver { grid-column: 1 / -1; padding: 0; }
  h1 { font-size: 1.9rem; margin: 0; text-shadow: 2px 2px 0 var(--red); }
  .datos { grid-column: 1 / -1; white-space: nowrap; }
  .modos button { letter-spacing: 0.04em; }
  .mision { padding: 7px 12px; }
  .acciones { padding: 8px 12px; }
  .recado { padding: 10px 12px; gap: 8px; }
  .recado .num { display: none; }
  .paso button { padding: 6px; letter-spacing: 0.04em; }
  .recado .dicho { font-size: 16px; }
  .album-caja { padding: 10px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
