/* ============ Botánica — cuaderno de campo ============ */

/* Tipografías opcionales (ver README): para incluir 'IM Fell English' y 'Caveat' sin conexión,
   copia los .woff2 a /fonts y descomenta estas líneas. Mientras tanto se usan fuentes del sistema.
@font-face { font-family: 'IM Fell English'; src: url('../fonts/im-fell-english-latin-400-normal.woff2') format('woff2'); font-display: swap; }
@font-face { font-family: 'Caveat'; src: url('../fonts/caveat-latin-400-normal.woff2') format('woff2'); font-display: swap; }
*/

:root {
  --paper: #efe4c4;
  --paper-2: #e2d2a8;
  --card: #f7f0da;
  --ink: #3a3024;
  --ink-soft: #6b5a44;
  --red: #b0342b;
  --green: #4d7c3a;
  --kraft: #cdb98c;
  --gap: 10px;
  --pad: 12px;
  --vpad: 8px;
  --serif: 'IM Fell English', 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --hand: 'Caveat', 'Segoe Script', 'Bradley Hand', 'Snell Roundhand', 'Comic Sans MS', cursive;
  --noise: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .35  0 0 0 0 .27  0 0 0 0 .15  0 0 0 .22 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: #b9a67c;
  font-family: var(--serif);
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

#app {
  position: relative;
  height: 100vh; height: 100dvh;
  max-width: 520px; margin: 0 auto;
  display: flex; flex-direction: column;
  overflow: hidden;
  background:
    var(--noise),
    radial-gradient(ellipse at 50% 35%, rgba(255,250,232,.55), rgba(150,110,55,.30) 100%),
    var(--paper);
  box-shadow: 0 0 40px rgba(60,40,10,.45);
}

/* ---------- HUD ---------- */
#hud {
  display: flex; align-items: center; gap: 14px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  border-bottom: 1.5px solid rgba(58,48,36,.55);
  background: linear-gradient(rgba(255,255,255,.18), transparent);
}
#lives { display: flex; gap: 4px; margin-right: auto; }
#lives svg { width: 24px; height: 24px; transition: transform .25s, opacity .25s; }
#lives svg.lost { opacity: .45; transform: rotate(18deg) scale(.85); }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1; min-width: 38px; }
.stat .k { font-size: .62rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-soft); }
.stat .v { font-family: var(--hand); font-weight: 400; font-size: 1.55rem; margin-top: 2px; }
#streakBox.hot .v { color: var(--red); }

.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: rgba(255,255,255,.35); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 5px 8px 6px 9px / 8px 5px 9px 6px;
  cursor: pointer; padding: 0;
}
.icon-btn:active { transform: translateY(1px); background: rgba(255,255,255,.6); }

/* ---------- Tablero ---------- */
#board {
  position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden;
}
.lanes {
  position: absolute; inset: 0; display: grid; grid-template-columns: repeat(4, 1fr);
  gap: var(--gap); padding: 0 var(--pad); pointer-events: none;
}
.lanes i {
  background: rgba(120,90,50,.055);
  border-left: 1px dashed rgba(90,70,45,.35);
  border-right: 1px dashed rgba(90,70,45,.35);
}

.row {
  position: absolute; left: 0; right: 0; top: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: var(--gap); padding: var(--vpad) var(--pad);
  will-change: transform; transform: translate3d(0,-200px,0);
}

/* casilla */
.cell {
  position: relative; aspect-ratio: 1; overflow: hidden;
  background: var(--card);
  border: 1.6px solid var(--ink);
  border-radius: 3px 7px 4px 6px / 6px 3px 7px 4px;
  box-shadow: 1px 2px 0 rgba(60,45,25,.28), inset 0 0 14px rgba(150,110,50,.2);
  transition: opacity .25s, filter .25s;
}
.cell img.plant { position: absolute; inset: 5%; width: 90%; height: 90%; object-fit: contain; pointer-events: none; }
.cover {
  position: absolute; inset: 0; display: grid; place-items: center;
  background:
    repeating-linear-gradient(45deg,  transparent 0 5px, rgba(70,52,30,.26) 5px 6px),
    repeating-linear-gradient(-45deg, transparent 0 9px, rgba(70,52,30,.16) 9px 10px),
    var(--kraft);
  transition: opacity .08s linear;
  font-family: var(--hand); font-weight: 400; font-size: 2.3rem; color: rgba(58,48,36,.5);
}
.cell.show .cover { opacity: 0; }
.cell.dim { opacity: .5; filter: saturate(.6); }
.cell.ok  { box-shadow: 0 0 0 3px rgba(77,124,58,.55), 1px 2px 0 rgba(60,45,25,.28); }
.cell.bad { box-shadow: 0 0 0 3px rgba(176,52,43,.5), 1px 2px 0 rgba(60,45,25,.28); }
.mark { position: absolute; inset: 0; pointer-events: none; }
.mark svg { width: 100%; height: 100%; overflow: visible; }
.mark path, .mark ellipse { stroke-dasharray: 200; stroke-dashoffset: 200; animation: draw .45s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

/* marcador rojo, trazado a lápiz de color */
.sel {
  position: absolute; top: var(--vpad); left: var(--pad);
  width: calc((100% - 2 * var(--pad) - 3 * var(--gap)) / 4); aspect-ratio: 1;
  transform: translateX(calc(var(--col, 0) * (100% + var(--gap))));
  border: 3.5px solid var(--red);
  border-radius: 5px 3px 7px 4px / 4px 6px 3px 7px;
  box-shadow: 0 0 0 2px rgba(176,52,43,.16), inset 0 0 0 1px rgba(255,255,255,.4);
  transition: transform .07s ease-out, opacity .2s;
  pointer-events: none;
}
.sel.jump { transition: none; }
.sel.hidden { opacity: 0; }
.sel::before, .sel::after {
  content: ''; position: absolute; width: 10px; height: 10px; border: 2px solid var(--red);
}
.sel::before { top: -8px; left: -8px; border-right: 0; border-bottom: 0; }
.sel::after  { bottom: -8px; right: -8px; border-left: 0; border-top: 0; }

/* ---------- Ficha objetivo ---------- */
#target {
  position: relative; flex: 0 0 auto;
  padding: 4px 12px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1.5px solid rgba(58,48,36,.55);
  background: linear-gradient(transparent, rgba(120,85,40,.13));
}
.label {
  font-family: var(--hand); font-weight: 400; font-size: 1.3rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center;
  color: var(--ink-soft); height: 1.7rem; line-height: 1.7rem; margin-bottom: 10px; transition: color .2s;
}
.label.ok { color: var(--green); } .label.bad { color: var(--red); }
.card {
  position: relative; display: flex; gap: 12px; align-items: center;
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 3px 5px 4px 6px / 5px 3px 6px 4px;
  padding: 10px 12px;
  box-shadow: 2px 3px 0 rgba(60,45,25,.3), inset 0 0 18px rgba(150,110,50,.18);
}
.card.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.96) rotate(-.6deg); } 60% { transform: scale(1.02); } 100% { transform: none; } }
.tape { position: absolute; width: 46px; height: 16px; background: rgba(214,190,120,.75); border: 1px solid rgba(120,95,40,.25); top: -9px; }
.tape.t1 { left: 10px; transform: rotate(-6deg); } .tape.t2 { right: 10px; transform: rotate(5deg); }
.tart { flex: 0 0 92px; height: 92px; }
.tart img { width: 100%; height: 100%; object-fit: contain; }
.tinfo { min-width: 0; }
.tinfo h2 { margin: 0; font-size: 1.3rem; font-weight: 400; line-height: 1.1; }
.latin { margin: 2px 0 5px; font-style: italic; font-size: .85rem; color: var(--ink-soft); }
.desc { margin: 0; font-family: var(--hand); font-weight: 400; font-size: 1.02rem; line-height: 1.12; color: #4a3d2c; }

/* ---------- Superposiciones ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 10; display: none; align-items: center; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
  background: rgba(226,210,168,.86);
  backdrop-filter: blur(1.5px); -webkit-backdrop-filter: blur(1.5px);
}
.overlay.show { display: flex; animation: fade .25s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--card); border: 1.8px solid var(--ink);
  border-radius: 4px 8px 5px 9px / 8px 4px 9px 5px;
  padding: 22px 20px 18px;
  box-shadow: 3px 4px 0 rgba(60,45,25,.35), inset 0 0 26px rgba(150,110,50,.2);
  background-image: var(--noise);
}
.cover-sheet { max-height: 100%; overflow: auto; }
.sheet.tall { max-height: 100%; display: flex; flex-direction: column; }
.kicker { margin: 0; font-size: .78rem; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-soft); }
h1 { margin: 4px 0 2px; font-size: 3.1rem; font-weight: 400; letter-spacing: .04em; line-height: 1.05; }
h2 { margin: 0; font-weight: 400; font-size: 1.7rem; }
.rule { height: 0; margin: 10px auto 12px; width: 70%; border-top: 1.5px solid var(--ink); position: relative; }
.rule::after { content: ''; position: absolute; left: 0; right: 0; top: 3px; border-top: 1px solid var(--ink); }
.howto { margin: 6px 0 16px; font-size: .95rem; line-height: 1.35; }
.hand { font-family: var(--hand); font-weight: 400; font-size: 1.25rem; color: var(--ink-soft); margin: 6px 0 14px; }
.big { font-family: var(--hand); font-weight: 400; font-size: 4.2rem; margin: 6px 0 0; line-height: 1; color: var(--red); }

.menu-art { display: flex; justify-content: center; align-items: flex-end; height: 92px; margin: 2px 0 8px; }
.menu-art img { width: 30%; max-width: 96px; height: auto; margin: 0 -2%; }
.menu-art img:nth-child(1) { transform: rotate(-8deg); }
.menu-art img:nth-child(2) { transform: translateY(-4px) rotate(2deg); }
.menu-art img:nth-child(3) { transform: rotate(9deg); }

.btn {
  display: block; width: 100%; margin: 8px 0 0; padding: 12px 14px;
  font: inherit; font-size: 1.1rem; color: var(--ink); cursor: pointer;
  background: rgba(255,255,255,.4);
  border: 1.8px solid var(--ink);
  border-radius: 5px 9px 6px 8px / 9px 5px 8px 6px;
  box-shadow: 2px 2px 0 rgba(60,45,25,.35);
}
.btn small { font-family: var(--hand); font-size: 1.1rem; color: var(--ink-soft); margin-left: 4px; }
.btn.primary { background: var(--red); color: #fbf3df; border-color: #6d1d17; }
.btn.tiny { width: auto; margin: 0; padding: 6px 12px; font-size: .95rem; }
.btn:active { transform: translate(1px, 2px); box-shadow: 0 0 0 rgba(0,0,0,0); }
.menu-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-family: var(--hand); font-weight: 400; font-size: 1.15rem; color: var(--ink-soft); }
.menu-actions { display: flex; align-items: center; gap: 6px; }
.foot-sep { opacity: .5; user-select: none; }
.pause-foot { margin-top: 14px; font-family: var(--hand); font-size: 1.15rem; color: var(--ink-soft); }
.link-btn { font: inherit; color: inherit; background: none; border: 0; border-bottom: 1.5px dashed currentColor; cursor: pointer; padding: 0 0 1px; }

/* herbario */
.herb-head { display: flex; align-items: center; justify-content: space-between; }
#herbGrid { overflow: auto; margin: 0 -6px; padding: 2px 6px 6px; display: grid; gap: 12px; text-align: left; }
.hcard { display: flex; gap: 10px; align-items: center; padding: 8px; border: 1.4px solid var(--ink); background: rgba(255,255,255,.35); border-radius: 3px 6px 4px 5px / 5px 3px 6px 4px; }
.hcard .ha { flex: 0 0 74px; height: 74px; position: relative; }
.hcard .ha img { width: 100%; height: 100%; object-fit: contain; }
.hcard.locked .ha { background: repeating-linear-gradient(45deg, transparent 0 5px, rgba(70,52,30,.26) 5px 6px), var(--kraft); border: 1.2px solid var(--ink); }
.hcard.locked .ha img { display: none; }
.hcard h3 { margin: 0; font-weight: 400; font-size: 1.1rem; }
.hcard .latin { margin: 0 0 3px; }
.hcard p.d { margin: 0; font-family: var(--hand); font-weight: 400; font-size: 1rem; line-height: 1.1; }

@media (max-height: 640px) {
  .tart { flex-basis: 70px; height: 70px; }
  .desc { display: none; }
  h1 { font-size: 2.4rem; }
  .menu-art { height: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  .mark path, .mark ellipse { animation: none; stroke-dashoffset: 0; }
  .overlay.show, .card.pop { animation: none; }
}

/* ============ Modo «Los nombres» ============ */
.quiz { display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; }
#app.names #hud, #app.names #board, #app.names #target { display: none; }
#app.names .quiz { display: flex; }

.qhud {
  display: flex; align-items: center; gap: 14px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  border-bottom: 1.5px solid rgba(58,48,36,.55);
  background: linear-gradient(rgba(255,255,255,.18), transparent);
}
.qhud .icon-btn { margin-right: auto; }

.qstage {
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 16px 16px 4px;
}
.qcard {
  position: relative; flex: 0 0 auto;
  width: min(70vw, 40vh, 320px); aspect-ratio: 1;
  background: var(--card);
  border: 1.6px solid var(--ink);
  border-radius: 3px 7px 4px 6px / 6px 3px 7px 4px;
  box-shadow: 2px 3px 0 rgba(60,45,25,.3), inset 0 0 20px rgba(150,110,50,.22);
  transform: rotate(-1deg);
}
.qcard.pop { animation: qpop .35s ease-out; }
@keyframes qpop { 0% { transform: rotate(-3deg) scale(.95); opacity: .4; } 100% { transform: rotate(-1deg) scale(1); opacity: 1; } }

/* sin catalogar: blanco y negro; al acertar, el color vuelve poco a poco */
.qimg {
  position: absolute; inset: 5%; width: 90%; height: 90%; object-fit: contain; pointer-events: none;
  filter: grayscale(0) contrast(1); transition: filter 1.1s ease;
}
.qimg.gray { filter: grayscale(1) contrast(1.12); }

.qstamp {
  position: absolute; right: -10px; bottom: -12px; transform: rotate(-8deg);
  font-family: var(--hand); font-size: 1.15rem; line-height: 1; padding: 4px 10px;
  color: #7a6c58; background: rgba(247,240,218,.94);
  border: 2px dashed currentColor; border-radius: 4px; transition: color .3s;
}
.qstamp.ok { color: var(--green); }
.qstamp.pop { animation: stamp .55s ease-out; }
@keyframes stamp { 0% { transform: rotate(-8deg) scale(2.2); opacity: 0; } 60% { transform: rotate(-8deg) scale(.9); opacity: 1; } 100% { transform: rotate(-8deg) scale(1); } }

#qMsg { margin: 6px 0 0; }
.qdesc {
  margin: 0; min-height: 3.6em; max-width: 360px; text-align: center;
  font-family: var(--hand); font-size: 1.05rem; line-height: 1.12; color: #4a3d2c;
}
.qdesc b { font-weight: 400; font-family: var(--serif); font-size: 1.05rem; }

.qbottom { flex: 0 0 auto; padding: 6px 14px calc(env(safe-area-inset-bottom) + 14px); }
.qopts { display: grid; gap: 9px; }
.qnext { display: none; margin-top: 10px; }
.qnext.show { display: block; animation: fade .25s ease-out; }
.opt {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%; min-height: 58px;
  padding: 8px 12px; text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  background: var(--card);
  border: 1.7px solid var(--ink);
  border-radius: 5px 9px 6px 8px / 9px 5px 8px 6px;
  box-shadow: 2px 2px 0 rgba(60,45,25,.35);
  transition: background .2s, border-color .2s, opacity .2s, transform .08s;
}
.opt:active { transform: translate(1px, 2px); box-shadow: 0 0 0 rgba(0,0,0,0); }
.opt .oletter { flex: 0 0 1.1em; font-family: var(--hand); font-size: 1.5rem; color: var(--ink-soft); }
.opt .otxt { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.opt .oname { font-size: 1.15rem; }
.opt .olat { font-style: italic; font-size: .88rem; color: var(--ink-soft); }
.opt .omark { margin-left: auto; flex: 0 0 30px; width: 30px; height: 30px; }
.omark svg { width: 100%; height: 100%; overflow: visible; }
.omark path, .omark ellipse { stroke-dasharray: 200; stroke-dashoffset: 200; animation: draw .45s ease-out forwards; }
.opt.ok  { background: #e1ecc9; border-color: #3f7a32; }
.opt.bad { background: #f1d3cd; border-color: var(--red); }
.opt.dim { opacity: .5; }
.opt.locked { pointer-events: none; }

/* menú: botones de modalidad */
.btn.mode { text-align: center; }
.btn.mode b { display: block; font-weight: 400; font-size: 1.2rem; }
.btn.mode span { display: block; margin-top: 2px; font-size: .8rem; line-height: 1.2; opacity: .92; }
.btn.alt { background: var(--green); border-color: #2c4f21; }

@media (max-height: 800px) {
  .qstage { overflow-y: auto; }
  .qcard { width: min(56vw, 30vh, 260px); }
  .opt { min-height: 50px; padding: 6px 12px; }
  .qopts { gap: 7px; }
  .qnext { margin-top: 8px; padding: 10px 14px; }
  .qdesc { font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  .qcard.pop, .qstamp.pop { animation: none; }
  .omark path, .omark ellipse { animation: none; stroke-dashoffset: 0; }
}

/* ============ Fondo de cuaderno: bocetos a lápiz ============ */
.bg { position: absolute; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bgi { position: absolute; }
.bgi img { display: block; width: 100%; height: auto; opacity: .2; mix-blend-mode: multiply; filter: contrast(.9); }
.bgi span {
  display: block; margin-top: -4px; text-align: center; white-space: nowrap;
  font-family: var(--hand); font-size: .95rem; color: var(--ink); opacity: .3;
}
.bgi span i { font-style: italic; }
/* el contenido del juego queda por encima del fondo */
#hud, .quiz { position: relative; z-index: 1; }
#board, #target { z-index: 1; }

/* ============ Efectos al acertar ============ */
#fx { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 6; pointer-events: none; }
.glow { animation: glowpulse 1.3s ease-out; }
@keyframes glowpulse {
  0%   { box-shadow: 0 0 0 0 rgba(240,200,80,0); }
  25%  { box-shadow: 0 0 30px 10px rgba(240,200,80,.55); }
  100% { box-shadow: 0 0 0 0 rgba(240,200,80,0); }
}
@media (prefers-reduced-motion: reduce) { .glow { animation: none; } #fx { display: none; } }

/* atenuado sin transparencia, para que el fondo no se vea a través de casillas y etiquetas */
.cell.dim { opacity: 1; filter: saturate(.5) brightness(.93) contrast(.92); }
.opt.dim { opacity: 1; background: #e6dabb; }
.opt.dim .oletter, .opt.dim .oname, .opt.dim .olat { opacity: .55; }
.bgi span { opacity: .24; }
