/* Laboratorio de criaturas — marca «Pedro Alfonso» en versión nocturna de laboratorio */
:root {
  --tinta: #071014; --tinta-2: #0d1a1e; --tinta-3: #132428;
  --lino: #F3ECE2; --lino-2: #B8C2BE; --savia: #A3C596; --savia-osc: #46643F;
  --oro: #D6B25E; --barro: #DE8A61; --barro-osc: #A54E2C; --noche: #AEBBE0;
  --glow: #7fe6cf; --ok: #7CC7CC; --bad: #F2907F;
  --panel: rgba(9, 20, 23, 0.82); --borde: rgba(127, 230, 207, 0.18);
  --f-tit: "Fraunces", Georgia, serif;
  --f-txt: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --st: env(safe-area-inset-top, 0px); --sr: env(safe-area-inset-right, 0px); --sb: env(safe-area-inset-bottom, 0px); --sl: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; min-width: 0; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--tinta); color: var(--lino); font: 16px/1.5 var(--f-txt); -webkit-font-smoothing: antialiased; }
body { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
#scene { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--oro); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.kicker { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--glow); margin: 0 0 10px; font-weight: 700; }
.title { font: 500 clamp(42px, 7vw, 78px)/1 var(--f-tit); letter-spacing: -0.02em; margin: 0 0 16px; text-wrap: balance; }
.title em { color: var(--savia); }
.btn { min-height: 48px; padding: 12px 22px; border-radius: 999px; border: 1.5px solid transparent; font-weight: 700; font-size: 15px; transition: transform .12s, background .15s, box-shadow .2s; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--barro); color: #1E140F; }
.btn.primary.alt { background: var(--glow); color: #04201a; }
.btn.ghost { background: rgba(243, 236, 226, 0.06); border-color: rgba(243, 236, 226, 0.4); }
.btn.ghost:hover { background: rgba(243, 236, 226, 0.12); }
.btn.small { min-height: 42px; padding: 9px 16px; font-size: 14px; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--borde); background: var(--panel); display: grid; place-items: center; flex: none; font-size: 22px; line-height: 1; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.icon-btn svg { width: 22px; height: 22px; }

/* Carga */
#loading { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 24px; background: radial-gradient(90% 70% at 50% 60%, #0f2a2c, var(--tinta)); }
.load-box { width: min(460px, 100%); text-align: center; }
.bar { height: 5px; border-radius: 999px; background: rgba(127, 230, 207, 0.15); overflow: hidden; margin: 22px 0 12px; }
#load-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--savia-osc), var(--glow)); transition: width .25s; }
#load-text { color: var(--lino-2); margin: 0; font-size: 15px; }

/* Menú */
#menu { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; padding: calc(24px + var(--st)) calc(24px + var(--sr)) calc(56px + var(--sb)) calc(24px + var(--sl)); background: linear-gradient(90deg, rgba(4, 10, 12, 0.92) 0%, rgba(4, 10, 12, 0.6) 38%, rgba(4, 10, 12, 0) 66%); }
.menu-inner { width: min(560px, 100%); padding-left: clamp(0px, 4vw, 56px); }
.lede { font-size: 18px; max-width: 44ch; margin: 0 0 26px; color: var(--lino); }
.menu-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.menu-links { display: flex; gap: 18px; }
.link { background: none; border: 0; padding: 8px 2px; color: var(--lino-2); text-decoration: underline; text-underline-offset: 4px; font-size: 15px; min-height: 44px; }
.credit { position: absolute; left: 0; right: 0; bottom: calc(14px + var(--sb)); text-align: center; font-size: 13px; color: var(--lino-2); }
@media (max-width: 700px) {
  #menu { align-items: flex-end; background: linear-gradient(0deg, rgba(4, 10, 12, 0.95) 0%, rgba(4, 10, 12, 0.75) 55%, rgba(4, 10, 12, 0) 85%); }
  .menu-inner { padding-left: 0; }
  .lede { font-size: 16px; margin-bottom: 18px; }
  .title { font-size: 44px; }
}

/* Barra superior */
.topbar { position: fixed; z-index: 15; top: calc(12px + var(--st)); left: calc(12px + var(--sl)); right: calc(12px + var(--sr)); display: flex; align-items: center; gap: 8px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.tb-title { flex: 1; font: 600 18px/1.2 var(--f-tit); padding: 0 6px; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.goal { position: fixed; z-index: 15; top: calc(64px + var(--st)); left: calc(12px + var(--sl)); max-width: min(420px, calc(100vw - 24px)); text-align: left; padding: 9px 14px; border-radius: 14px; background: rgba(214, 178, 94, 0.14); border: 1px solid rgba(214, 178, 94, 0.55); font-size: 14.5px; line-height: 1.35; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.goal strong { color: var(--oro); margin-right: 6px; }
.chips { position: fixed; z-index: 14; left: calc(12px + var(--sl)); bottom: calc(14px + var(--sb)); display: flex; flex-direction: column; align-items: flex-start; gap: 6px; pointer-events: none; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--borde); font-size: 13px; color: var(--lino-2); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.chip.change { opacity: 0; transform: translateY(6px); color: var(--lino); max-width: min(380px, 60vw); }
.chip.change.on { animation: chipIn 3.2s ease forwards; }
@keyframes chipIn { 0% { opacity: 0; transform: translateY(6px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* Panel de piezas */
#panel { position: fixed; z-index: 16; top: calc(70px + var(--st)); right: calc(12px + var(--sr)); bottom: calc(12px + var(--sb)); width: min(410px, 44vw); display: flex; flex-direction: column; gap: 10px; padding: 14px; border-radius: 20px; background: var(--panel); border: 1px solid var(--borde); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
#steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.step { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 6px; text-align: left; padding: 6px 8px; border-radius: 12px; border: 1px solid rgba(243, 236, 226, 0.12); background: rgba(243, 236, 226, 0.04); min-height: 48px; }
.step .n { grid-row: span 2; align-self: center; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; background: rgba(243, 236, 226, 0.12); }
.step .l { font-size: 12px; color: var(--lino-2); font-weight: 700; }
.step .v { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.step.done .n { background: var(--savia-osc); color: var(--lino); }
.step.cur { border-color: var(--glow); background: rgba(127, 230, 207, 0.1); }
.step[disabled] { opacity: 0.4; cursor: default; }
#step-title { margin: 4px 0 0; font: 600 21px/1.2 var(--f-tit); }
#options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; overflow-y: auto; align-content: start; flex: 1; padding: 2px; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.opt { display: grid; grid-template-columns: 40px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: left; padding: 10px 12px; border-radius: 14px; border: 1.5px solid rgba(243, 236, 226, 0.16); background: rgba(243, 236, 226, 0.05); min-height: 64px; transition: border-color .15s, background .15s, transform .12s; }
.opt:hover { background: rgba(243, 236, 226, 0.1); }
.opt:active { transform: scale(0.98); }
.opt svg { grid-row: span 2; width: 40px; height: 40px; color: var(--glow); stroke-width: 1.5; }
.opt .ol { font-weight: 700; font-size: 15px; line-height: 1.2; }
.opt .oh { font-size: 12.5px; color: var(--lino-2); line-height: 1.3; }
.opt.sel { border-color: var(--glow); background: rgba(127, 230, 207, 0.14); box-shadow: 0 0 0 1px rgba(127, 230, 207, 0.3) inset; }
.btn.life { width: 100%; min-height: 54px; font-size: 17px; background: var(--barro); color: #1E140F; box-shadow: 0 0 24px rgba(222, 138, 97, 0.35); }
.btn.life:not([disabled]) { animation: lifeGlow 1.8s ease-in-out infinite; }
.btn.life[disabled] { background: rgba(243, 236, 226, 0.1); color: var(--lino-2); box-shadow: none; }
@keyframes lifeGlow { 50% { box-shadow: 0 0 36px rgba(222, 138, 97, 0.65); } }

/* Resultado */
#result { position: fixed; z-index: 16; right: calc(12px + var(--sr)); top: calc(70px + var(--st)); width: min(400px, 44vw); max-height: calc(100% - 84px - var(--st) - var(--sb)); overflow-y: auto; padding: 18px; border-radius: 20px; background: var(--panel); border: 1px solid var(--borde); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); touch-action: pan-y; }
#result.in { animation: cardIn .45s cubic-bezier(.2, .8, .2, 1); }
@keyframes cardIn { from { opacity: 0; transform: translateY(14px); } }
#result h2 { font: 600 30px/1.1 var(--f-tit); margin: 6px 0 8px; }
.badge { display: inline-block; margin: 0; padding: 5px 12px; border-radius: 999px; font-weight: 700; font-size: 13px; letter-spacing: 0.04em; }
.badge.ok { background: rgba(124, 199, 204, 0.18); color: var(--ok); border: 1px solid var(--ok); }
.badge.bad { background: rgba(242, 144, 127, 0.15); color: var(--bad); border: 1px solid var(--bad); }
.kchip { display: inline-block; margin: 0 0 10px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--k); color: var(--k); font-weight: 700; font-size: 13px; }
.like { margin: 0 0 8px; font-size: 15px; }
.fact { margin: 0 0 10px; font-size: 15px; line-height: 1.5; color: var(--lino); }
.tip { margin: 0 0 10px; color: var(--lino-2); font-size: 14px; }
.reto { margin: 0 0 10px; padding: 9px 12px; border-radius: 12px; background: rgba(214, 178, 94, 0.12); border: 1px solid rgba(214, 178, 94, 0.5); font-size: 14px; }
.reto.ok { background: rgba(124, 199, 204, 0.14); border-color: var(--ok); color: var(--ok); font-weight: 700; }
.r-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
#result.mini { width: auto; padding: 8px; top: auto; bottom: calc(12px + var(--sb)); }
#result.mini #result-body, #result.mini #w-edit, #result.mini #w-new, #result.mini #w-next { display: none; }
#result.mini .r-actions { margin: 0; }

/* Pantallas: retos y árbol */
.screen { position: fixed; inset: 0; z-index: 22; overflow-y: auto; padding: calc(16px + var(--st)) calc(16px + var(--sr)) calc(24px + var(--sb)) calc(16px + var(--sl)); background: rgba(4, 10, 12, 0.86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); touch-action: pan-y; }
.screen-head { display: flex; align-items: center; gap: 14px; max-width: 1100px; margin: 0 auto 16px; }
.screen-head h2 { margin: 0; font: 600 30px/1.1 var(--f-tit); }
.screen-head p { margin: 2px 0 0; color: var(--lino-2); font-size: 14px; }
#retos-grid { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); gap: 10px; }
.reto-card { position: relative; display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 14px 16px; border-radius: 16px; border: 1px solid var(--borde); background: var(--tinta-2); min-height: 120px; }
.reto-card:hover { border-color: var(--glow); }
.reto-card .rn { font: 600 26px/1 var(--f-tit); color: var(--glow); }
.reto-card .rt { font-weight: 700; font-size: 16px; }
.reto-card .rg { font-size: 14px; color: var(--lino-2); line-height: 1.35; }
.reto-card .rk { position: absolute; top: 12px; right: 14px; width: 28px; height: 28px; border-radius: 50%; background: var(--ok); color: #04201a; display: grid; place-items: center; font-weight: 700; }
.reto-card.done { border-color: rgba(124, 199, 204, 0.5); }
#tree-grid { max-width: 1200px; margin: 0 auto; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 12px; align-items: start; }
.branch { padding: 12px; border-radius: 16px; background: var(--tinta-2); border-top: 4px solid var(--k); }
.branch h3 { margin: 0 0 10px; font: 600 20px/1.1 var(--f-tit); color: var(--k); }
.leaf { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 12px; background: var(--tinta-3); margin-bottom: 8px; }
.leaf .th { width: 58px; height: 58px; border-radius: 12px; overflow: hidden; flex: none; background: #0a1517; display: grid; place-items: center; font: 600 24px var(--f-tit); color: var(--lino-2); }
.leaf .th img { width: 100%; height: 100%; object-fit: cover; }
.leaf strong { display: block; font-size: 14.5px; }
.leaf span { display: block; font-size: 12.5px; color: var(--lino-2); line-height: 1.3; }
.leaf.locked { opacity: 0.55; }

/* Ventanas */
#modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(2, 6, 8, 0.6); }
.modal-card { width: min(620px, 100%); max-height: 100%; overflow-y: auto; padding: 18px 20px 20px; border-radius: 20px; background: var(--tinta-2); border: 1px solid var(--borde); touch-action: pan-y; }
.m-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.m-head h2 { margin: 0; font: 600 24px/1.15 var(--f-tit); }
#modal-body p { margin: 0 0 10px; }
.howto { padding-left: 20px; margin: 0 0 12px; }
.howto li { margin-bottom: 6px; }
.note { font-size: 13.5px; color: var(--lino-2); }
.set-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--borde); }
.set-row select, .set-row input { font: inherit; font-size: 16px; min-height: 40px; background: var(--tinta-3); color: var(--lino); border: 1.5px solid #5a7a74; border-radius: 10px; padding: 4px 8px; }
#toast { position: fixed; z-index: 50; left: 50%; top: calc(70px + var(--st)); transform: translate(-50%, -8px); padding: 10px 16px; border-radius: 14px; background: rgba(9, 20, 23, 0.92); border: 1px solid var(--glow); font-weight: 700; font-size: 14.5px; opacity: 0; transition: opacity .3s, transform .3s; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#fade { position: fixed; inset: 0; z-index: 30; background: radial-gradient(circle, #e8fff8 0%, #7fe6cf 40%, #071014 100%); opacity: 0; pointer-events: none; transition: opacity .5s ease; }
#fade.on { opacity: 1; }
#fatal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 30px; background: var(--tinta); text-align: center; font-size: 17px; }

/* Móvil en vertical: panel abajo */
@media (orientation: portrait) and (max-width: 820px) {
  #panel { left: 0; right: 0; bottom: 0; top: auto; width: auto; height: min(52vh, 470px); border-radius: 22px 22px 0 0; padding: 12px 12px calc(12px + var(--sb)); }
  #result { left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 52vh; border-radius: 22px 22px 0 0; padding: 16px 16px calc(14px + var(--sb)); }
  #result.mini { left: auto; right: 12px; bottom: calc(12px + var(--sb)); border-radius: 20px; }
  .chips { bottom: calc(min(52vh, 470px) + 10px); }
  .opt { min-height: 58px; padding: 8px 10px; }
  .opt svg { width: 34px; height: 34px; }
  #step-title { font-size: 18px; }
  .goal { font-size: 13.5px; }
}
/* Móvil en horizontal: compacto */
@media (max-height: 520px) {
  #panel { top: calc(8px + var(--st)); bottom: calc(8px + var(--sb)); width: min(440px, 52vw); padding: 10px; gap: 7px; }
  #steps { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
  .step { grid-template-columns: 1fr; padding: 4px; min-height: 40px; text-align: center; }
  .step .n { grid-row: auto; margin: 0 auto; width: 20px; height: 20px; }
  .step .l { font-size: 10.5px; } .step .v { display: none; }
  #step-title { font-size: 16px; margin: 0; }
  .opt { min-height: 52px; padding: 7px 9px; grid-template-columns: 30px 1fr; }
  .opt svg { width: 30px; height: 30px; }
  .opt .oh { font-size: 11.5px; }
  .btn.life { min-height: 46px; font-size: 15px; }
  .topbar { right: calc(52vw + 20px + var(--sr)); }
  .goal { top: calc(60px + var(--st)); max-width: calc(48vw - 30px); font-size: 13px; }
  #result { top: calc(8px + var(--st)); width: min(420px, 50vw); max-height: calc(100% - 16px); padding: 12px 14px; }
  #result h2 { font-size: 24px; }
  .fact { font-size: 14px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #menu { padding-top: calc(14px + var(--st)); padding-bottom: calc(34px + var(--sb)); align-items: center; }
  #menu .title { font-size: 36px; margin-bottom: 8px; }
  #menu .kicker { margin-bottom: 4px; }
  .lede { font-size: 14.5px; margin-bottom: 12px; max-width: 40ch; }
  .menu-actions .btn { min-height: 44px; padding: 9px 16px; }
  .credit { bottom: calc(6px + var(--sb)); font-size: 12px; }
  #toast { left: calc(12px + var(--sl)); top: calc(62px + var(--st)); transform: none; max-width: 44vw; }
  #toast.on { transform: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
