/* Damas: estilos de la interfaz (sobre el lienzo 3D). */
:root {
  --bg: #2a1640; --bg2: #1b0d2b; --panel: #3a2158; --panel2: #4b2c70; --line: rgba(220,190,255,.2); --text: #fff8ef; --muted: #cdb9e6;
  --accent: #ffd23f; --accent2: #ff9a3c; --accent-text: #2a1a05; --mint: #47d96b; --mint2: #22a84a; --danger: #ff5a5a; --hot: #ff7a3c;
  --font: 'Fredoka', 'Baloo 2', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overflow: hidden; }
#app { position: fixed; inset: 0; overflow: hidden; background: radial-gradient(120% 90% at 50% 25%, #8a4fa8 0%, #5a2d7a 45%, #2a1640 100%); touch-action: none; }
#c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--accent2); outline-offset: 3px; }
a { color: var(--accent); }

/* ---------- botones ---------- */
.btn { position: relative; display: inline-flex; align-items: center; justify-content: center; gap: .5em; min-height: 52px; padding: .45em 1.3em; border-radius: 18px; font-size: 1.12rem; font-weight: 700; letter-spacing: .02em; color: var(--accent-text); text-decoration: none;
  background: linear-gradient(180deg, #fff1a6, var(--accent) 55%, #f2a922); box-shadow: 0 5px 0 #b77812, 0 10px 22px rgba(0,0,0,.25), inset 0 2px 0 rgba(255,255,255,.6); transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b77812, inset 0 2px 0 rgba(255,255,255,.6); }
.btn svg { width: 1.25em; height: 1.25em; flex: none; }
.btn span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
.btn small { font-size: .62em; font-weight: 600; opacity: .8; letter-spacing: 0; margin-top: .15em; }
.btn.mint { color: #06301a; background: linear-gradient(180deg, #b9ffc9, var(--mint) 55%, var(--mint2)); box-shadow: 0 5px 0 #157233, 0 10px 22px rgba(0,0,0,.25), inset 0 2px 0 rgba(255,255,255,.6); }
.btn.mint:active { box-shadow: 0 1px 0 #157233, inset 0 2px 0 rgba(255,255,255,.6); }
.btn.ghost { color: var(--text); background: rgba(255,255,255,.1); box-shadow: inset 0 0 0 2px var(--line); }
.btn.ghost:active { transform: translateY(2px); }
.btn.big { min-height: 64px; font-size: 1.4rem; padding: .4em 1.4em; border-radius: 22px; }
.btn.small { min-height: 40px; font-size: .92rem; padding: .3em .9em; border-radius: 13px; }
.btn[disabled] { filter: grayscale(.7) brightness(.85); pointer-events: none; }
.icon-btn { width: 50px; height: 50px; border-radius: 16px; display: grid; place-items: center; color: var(--text); background: rgba(42,22,64,.72); box-shadow: inset 0 0 0 2px var(--line), 0 4px 12px rgba(0,0,0,.2); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); flex: none; }
.icon-btn svg { width: 26px; height: 26px; }
.icon-btn:active { transform: scale(.94); }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }

/* ---------- pantallas ---------- */
#screens { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.screen { position: absolute; inset: 0; pointer-events: auto; display: flex; flex-direction: column; align-items: center; animation: in .25s ease-out both; padding: calc(14px + var(--safe-t)) calc(14px + var(--safe-r)) calc(14px + var(--safe-b)) calc(14px + var(--safe-l)); }
.screen.out { animation: out .2s ease-in both; pointer-events: none; }
@keyframes in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes out { to { opacity: 0; transform: scale(.98); } }
.overlay { justify-content: center; background: rgba(27,13,43,.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.card { width: min(440px, 100%); max-height: 100%; overflow: auto; padding: 22px 20px; border-radius: 26px; background: linear-gradient(180deg, var(--panel2), var(--panel)); box-shadow: inset 0 0 0 2px var(--line), 0 20px 50px rgba(0,0,0,.4); text-align: center; display: flex; flex-direction: column; gap: 14px; }
.card h2 { margin: 0; font-size: 1.9rem; line-height: 1.1; color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.25); }
.card .sub { margin: 0; color: var(--muted); font-size: 1rem; }
.card.scroll { max-height: min(86vh, 720px); }

/* portada */
.title-screen { justify-content: space-between; pointer-events: none; }
.title-screen > * { pointer-events: auto; }
.logo { text-align: center; margin-top: 1vh; filter: drop-shadow(0 6px 0 rgba(0,0,0,.18)); pointer-events: none !important; }
.logo .h1 { display: flex; flex-direction: column; align-items: center; line-height: .9; font-weight: 700; }
.logo .l1 { font-size: clamp(3.6rem, 17vw, 6.8rem); color: #fff3d6; -webkit-text-stroke: 4px #7a2d18; paint-order: stroke fill; text-shadow: 0 7px 0 #7a2d18, 0 12px 24px rgba(0,0,0,.3); letter-spacing: .01em; transform: rotate(-3deg); }
.logo p { margin: .5em auto 0; display: inline-block; padding: .3em .9em; border-radius: 99px; background: rgba(42,22,64,.75); font-weight: 600; font-size: 1.05rem; }
.title-bottom { display: flex; flex-direction: column; gap: 12px; align-items: stretch; width: min(380px, 100%); margin-bottom: 1vh; }
.title-bottom .btn.big { justify-content: flex-start; }
.title-bottom .btn.ghost { background: rgba(42,22,64,.78); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.portal-link { position: absolute; left: calc(12px + var(--safe-l)); top: calc(12px + var(--safe-t)); display: flex; align-items: center; gap: 6px; padding: 6px 12px 6px 6px; border-radius: 99px; background: rgba(42,22,64,.75); color: var(--text); text-decoration: none; font-weight: 600; font-size: .9rem; }
.portal-link svg { width: 28px; height: 28px; }

/* elegir nivel y color */
.setup .card { gap: 10px; }
.rules-note b { color: var(--accent); }
.setup-label { font-weight: 700; text-align: left; color: var(--muted); font-size: .95rem; margin-top: 2px; }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.lvl { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; border-radius: 14px; background: rgba(255,255,255,.07); box-shadow: inset 0 0 0 2px var(--line); }
.lvl .stars { color: var(--accent); font-size: .62rem; letter-spacing: -1px; min-height: 1em; }
.lvl b { font-size: .9rem; }
.lvl small { font-size: .66rem; color: var(--muted); line-height: 1.1; }
.lvl.on { background: linear-gradient(180deg, #fff1a6, var(--accent) 60%, #f2a922); color: var(--accent-text); box-shadow: 0 3px 0 #b77812; }
.lvl.on small, .lvl.on .stars { color: #6a4310; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.col-btn { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 8px 4px; border-radius: 14px; background: rgba(255,255,255,.07); box-shadow: inset 0 0 0 2px var(--line); font-weight: 700; font-size: .95rem; }
.col-btn .chip { width: 30px; height: 30px; }
.col-btn.on { background: rgba(71,217,107,.25); box-shadow: inset 0 0 0 3px var(--mint); }

/* marcador */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.hud-top { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l)); }
.hud-top > * { pointer-events: auto; }
.pcards { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; min-width: 0; pointer-events: none !important; }
.pcard { display: flex; align-items: center; gap: 6px; padding: 6px 10px 6px 6px; border-radius: 18px; background: rgba(42,22,64,.78); box-shadow: inset 0 0 0 2px var(--line); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); min-width: 0; transition: box-shadow .25s, transform .25s, background .25s; }
.pcard .chip { width: 34px; height: 34px; flex: none; }
.pc-txt { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.1; }
.pc-txt b { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-sub { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 1em; }
.pc-n { font-size: 1.35rem; font-weight: 700; min-width: 1.4em; text-align: right; }
.pc-n.bump { animation: bump .3s; }
.pcard.turn { background: rgba(75,44,112,.92); box-shadow: inset 0 0 0 3px var(--accent), 0 0 18px rgba(255,210,63,.45); transform: translateY(1px) scale(1.02); }
.pcard.turn .pc-sub { color: var(--accent); font-weight: 600; }
@keyframes bump { 40% { transform: scale(1.25); } }
.helpbar { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b)); display: flex; gap: 12px; pointer-events: auto; }
.hbtn { position: relative; display: flex; align-items: center; gap: 8px; min-height: 54px; padding: 8px 18px 8px 14px; border-radius: 18px; font-weight: 700; font-size: 1.05rem; color: var(--text); background: rgba(42,22,64,.82); box-shadow: inset 0 0 0 2px var(--line), 0 6px 14px rgba(0,0,0,.25); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.hbtn svg { width: 26px; height: 26px; }
.hbtn:active { transform: translateY(2px); }
.hbtn[disabled] { opacity: .45; pointer-events: none; }
.hbtn .badge { position: absolute; top: -8px; right: -8px; padding: 1px 7px; border-radius: 99px; background: var(--mint); color: #06301a; font-style: normal; font-size: .7rem; font-weight: 700; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.hbtn .badge.ad { background: var(--accent); color: var(--accent-text); padding: 2px 5px; }
.hbtn .badge.ad svg { width: 16px; height: 16px; display: block; }
/* en horizontal: tarjetas a la izquierda y ayudas a la derecha */
#hud.land .hud-top { flex-direction: column; align-items: flex-start; width: auto; right: auto; bottom: 0; padding-bottom: calc(10px + var(--safe-b)); }
#hud.land .pcards { grid-template-columns: 1fr; width: clamp(150px, 22vw, 230px); flex: none; }
#hud.land .helpbar { left: auto; transform: none; right: calc(12px + var(--safe-r)); bottom: auto; top: 50%; translate: 0 -50%; flex-direction: column; }
#hud.land .hbtn { flex-direction: column; gap: 2px; padding: 10px 12px; font-size: .9rem; min-width: 92px; }

/* avisos */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: 6; overflow: hidden; }
.pop { position: absolute; transform: translate(-50%, -50%); font-weight: 700; font-size: 1.4rem; color: #fff; -webkit-text-stroke: 2px rgba(0,0,0,.5); paint-order: stroke fill; animation: popup 1.05s ease-out forwards; white-space: nowrap; }
.pop.gold { color: var(--accent); font-size: 1.9rem; }
.pop.crown { color: #ffe066; font-size: 2.1rem; }
@keyframes popup { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -190%) scale(1); } }
.banner { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); font-size: clamp(2rem, 9vw, 3.4rem); font-weight: 700; color: #fff; -webkit-text-stroke: 3px rgba(0,0,0,.45); paint-order: stroke fill; text-align: center; white-space: nowrap; animation: banner 1.7s ease-out forwards; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); } 12% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); } 22% { transform: translate(-50%, -50%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -70%); } }
#toasts { position: absolute; left: 0; right: 0; top: 50%; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 30; }
.toast { padding: 9px 16px; border-radius: 14px; background: rgba(42,22,64,.94); box-shadow: inset 0 0 0 2px var(--line), 0 6px 16px rgba(0,0,0,.3); font-weight: 600; animation: in .25s both; max-width: 90vw; text-align: center; }
.toast.gold { background: linear-gradient(180deg, #fff1a6, var(--accent)); color: var(--accent-text); }
.toast.out { animation: out .3s both; }

/* final y ayudas */
.end.win .card h2 { color: var(--accent); }
.end.lose .card h2 { color: #ffb0b0; }
.end-stats { display: flex; justify-content: center; gap: 10px; }
.end-stats span { display: flex; flex-direction: column; align-items: center; min-width: 76px; padding: 8px 6px; border-radius: 14px; background: rgba(255,255,255,.07); font-size: .85rem; color: var(--muted); }
.end-stats b { font-size: 1.6rem; color: #fff; }
.help-ic svg { width: 64px; height: 64px; color: var(--accent); }
.over .row .btn, .end .row .btn { flex: 1 1 0; min-width: 0; padding-left: .6em; padding-right: .6em; font-size: 1rem; }
.end .row { flex-wrap: nowrap; }
.stats-t { width: 100%; border-collapse: collapse; font-size: .95rem; }
.stats-t th, .stats-t td { padding: 7px 4px; text-align: center; }
.stats-t thead th { color: var(--muted); font-size: .78rem; font-weight: 600; }
.stats-t tbody th { text-align: left; white-space: nowrap; font-weight: 600; }
.stats-t tbody tr:nth-child(odd) { background: rgba(255,255,255,.05); }
.stats-t td.w { color: #8affa0; font-weight: 700; } .stats-t td.l { color: #ffb0b0; }

/* ajustes y cómo se juega */
.settings { display: flex; flex-direction: column; gap: 8px; text-align: left; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-radius: 14px; background: rgba(255,255,255,.06); font-weight: 600; }
.setting select, .setting input { font-family: inherit; font-size: 1rem; font-weight: 600; padding: 7px 10px; border-radius: 10px; border: 0; background: #22123a; color: var(--text); box-shadow: inset 0 0 0 2px var(--line); max-width: 58%; }
.tog { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 99px; background: rgba(0,0,0,.3); font-weight: 700; min-width: 74px; }
.tog i { width: 26px; height: 26px; border-radius: 50%; background: #6d5a85; transition: .2s; }
.tog.on i { background: var(--mint); transform: translateX(2px); }
.links { margin-top: 6px; }
.howto-body { text-align: left; }
.howto-body .t1 { font-size: 1.35rem; font-weight: 700; margin: 0 0 .4em; color: var(--accent); }
.howto-body h2 { font-size: 1.15rem; margin: 1em 0 .3em; }
.howto-body ul { padding-left: 1.2em; margin: .3em 0; }
.howto-body li { margin: .25em 0; line-height: 1.35; }
.howto-body p { line-height: 1.4; }

/* anuncio de prueba */
.dev-ad { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(0,0,0,.75); }
.dev-ad-box { width: min(340px, 90%); padding: 20px; border-radius: 20px; background: #111; color: #fff; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.dev-ad-tag { font-size: .8rem; color: #aaa; }
.dev-ad-art { width: 100%; aspect-ratio: 16/9; border-radius: 12px; display: grid; place-items: center; background: repeating-linear-gradient(45deg, #333 0 12px, #2a2a2a 12px 24px); font-size: 2rem; font-weight: 700; }

/* carga */
#loader { position: absolute; inset: 0; display: grid; place-items: center; z-index: 60; background: var(--bg); transition: opacity .4s; }
#loader.out { opacity: 0; pointer-events: none; }
.loader-chip { width: 64px; height: 64px; border-radius: 50%; border: 8px solid rgba(255,210,63,.25); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.noscript { position: absolute; inset: 0; display: grid; place-items: center; padding: 20px; text-align: center; }

/* pantallas bajas (móvil en horizontal) */
@media (max-height: 520px) {
  .logo .l1 { font-size: 3.4rem; } .logo p { font-size: .95rem; }
  .title-screen { flex-direction: column; align-items: flex-end; justify-content: center; gap: 10px; }
  .title-screen .logo, .title-screen .title-bottom { width: min(380px, 50%); margin: 0; }
  .logo .l1 { font-size: 3rem; }
  .btn.big { min-height: 50px; font-size: 1.15rem; }
  .title-bottom { gap: 8px; }
  .card { padding: 14px; gap: 9px; } .card h2 { font-size: 1.5rem; }
  .settings { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; } .setting { padding: 4px 8px; } .settings .links { grid-column: 1 / -1; }
  .card .b-close { position: sticky; bottom: 0; }
  .settings-p .card, .setup .card { width: min(720px, 100%); }
  .pcard .chip { width: 28px; height: 28px; } .pc-n { font-size: 1.15rem; }
}
@media (prefers-reduced-motion: reduce) { .pc-n.bump { animation: none; } }

/* texto rastreable bajo el juego: aquí oculto (lo usa la pantalla «Cómo se juega»; el portal lo muestra con su ficha) */
.howto-src { display: none; }
.howto .t1 { font-size: 1.25rem; font-weight: 700; margin: .67em 0; }
@media (max-height: 520px) {
  .lvl small, .rules-note { display: none; }
  .setup .btn.big { min-height: 46px; }
  .levels .lvl, .col-btn { padding-top: 6px; padding-bottom: 6px; }
}

/* fichas.py: ficha del juego bajo la pantalla de juego (visible al desplazarse; al jugar la página vuelve arriba y no se mueve) */
html, body { height: auto !important; min-height: 100%; overflow-x: hidden !important; overflow-y: auto !important; }
html:has(body.playing), body.playing { overflow: hidden !important; }
body:not(.playing) { touch-action: pan-y; }
body:not(.playing) #wrap, body:not(.playing) #app, body:not(.playing) #app canvas, body:not(.playing) #app .screen { touch-action: pan-y !important; }   /* fuera de la partida se puede bajar a la ficha deslizando sobre el juego */
#wrap, #app { position: relative !important; inset: auto !important; width: 100% !important; height: 100vh !important; height: 100dvh !important; }
.game-info { max-width: 860px; margin: 0 auto; padding: 26px 18px 40px; font-family: Fredoka, ui-rounded, system-ui, -apple-system, 'Segoe UI', sans-serif; color: #f4f0ff; line-height: 1.55; user-select: text; -webkit-user-select: text; }
.game-info .crumbs { font-size: .92rem; color: #b9b0d8; margin-bottom: 10px; } .game-info .crumbs a { color: #b9b0d8; } .game-info .crumbs span { margin: 0 6px; opacity: .6; }
.game-info .howto-src { display: block; } .game-info .howto { background: none; color: inherit; padding: 0; border-radius: 0; box-shadow: none; border: 0; }
.game-info h1 { font-size: clamp(1.6rem, 4.5vw, 2.2rem); line-height: 1.15; margin: 0 0 10px; color: #fff; }
.game-info h2 { font-size: 1.3rem; margin: 26px 0 8px; color: #ffd23f; }
.game-info p, .game-info li { color: #e8e2fa; } .game-info ul { padding-left: 1.2em; } .game-info a { color: #ffd23f; }
.game-info details { margin: 8px 0; padding: 12px 16px; border-radius: 14px; background: rgba(255,255,255,.06); box-shadow: inset 0 0 0 1.5px rgba(190,160,255,.22); }
.game-info summary { cursor: pointer; font-weight: 600; } .game-info details p { margin: 6px 0 0; }
.game-info .more { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; padding: 0; list-style: none; }
.game-info .more a { display: block; border-radius: 16px; overflow: hidden; background: rgba(255,255,255,.06); box-shadow: inset 0 0 0 1.5px rgba(190,160,255,.22); text-decoration: none; color: #fff; }
.game-info .more img { display: block; width: 100%; height: auto; aspect-ratio: 40 / 21; object-fit: cover; } .game-info .more b { display: block; padding: 8px 10px 0; } .game-info .more span { display: block; padding: 0 10px 10px; font-size: .88rem; color: #c9c0e6; }
.game-info .foot { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 34px; padding-top: 16px; border-top: 1px solid rgba(190,160,255,.22); font-size: .92rem; } .game-info .foot a { color: #b9b0d8; }
.howto .t1 { font-size: 1.25rem; font-weight: 700; margin: .67em 0; }
