.trio {
  --bsize: min(94vw, 470px, calc(100vh - 215px));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 6px 12px 16px;
  min-height: calc(100vh - 80px);
}
@supports (height: 100dvh) {
  .trio { --bsize: min(94vw, 470px, calc(100dvh - 215px)); min-height: calc(100dvh - 80px); }
}
@supports not (height: 100dvh) {
  .trio { --bsize: min(94vw, 470px, calc(var(--vh) * 100 - 215px)); }
}

/* ---------- marcador ---------- */
.hud { width: var(--bsize); display: flex; gap: 10px; }
.moves, .progress { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
.moves { min-width: 92px; padding: 8px 12px; text-align: center; }
.moves b { display: block; font-size: 32px; font-weight: 900; line-height: 1.05; font-variant-numeric: tabular-nums; }
.moves span { font-size: 12px; color: var(--muted); font-weight: 600; }
.moves.low b { color: var(--danger); animation: pulse-low 1s ease-in-out infinite; }
.moves.bump b { animation: bump .25s; }
@keyframes pulse-low { 50% { transform: scale(1.12); } }
@keyframes bump { 50% { transform: scale(.85); } }
.progress { flex: 1; padding: 10px 14px; display: flex; flex-direction: column; justify-content: center; gap: 9px; }
.progress-top { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); font-weight: 600; }
.progress-top b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 850; }
.bar { position: relative; height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar i {
  display: block; height: 100%; width: 0; border-radius: 99px;
  background: linear-gradient(90deg, #ff6a3d, #ffb02e, #ffe14d);
  box-shadow: inset 0 2px 0 rgb(255 255 255 / .45);
  transition: width .5s cubic-bezier(.2, 1.2, .4, 1);
}
.bar.full i { animation: bar-glow 1s ease-in-out infinite alternate; }
@keyframes bar-glow { to { filter: brightness(1.25); } }
.tip { margin: 0; color: var(--muted); font-size: 14px; text-align: center; max-width: var(--bsize); }

/* ---------- tablero ---------- */
.board-wrap {
  padding: 7px;
  border-radius: 24px;
  background: linear-gradient(160deg, #5a4bd1, #2f2a8a 45%, #1f1d5c);
  box-shadow: 0 10px 30px rgb(40 30 120 / .35), inset 0 2px 0 rgb(255 255 255 / .25);
}
.tboard {
  position: relative;
  width: calc(var(--bsize) - 14px);
  aspect-ratio: 1;
  border-radius: 18px;
  overflow: hidden;
  touch-action: none;
  background-color: #1b1d4a;
  background-image:
    radial-gradient(circle at 50% 0%, rgb(140 120 255 / .35), transparent 60%),
    conic-gradient(rgb(255 255 255 / .06) 25%, transparent 0 50%, rgb(255 255 255 / .06) 0 75%, transparent 0);
  background-size: 100% 100%, 25% 25%;
  box-shadow: inset 0 3px 12px rgb(0 0 0 / .45);
}

.gem {
  position: absolute;
  left: 0; top: 0;
  width: 12.5%; height: 12.5%;
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%));
  transition: transform calc(150ms + var(--fall, 0) * 45ms) cubic-bezier(.45, .05, .55, 1.15);
  cursor: pointer;
}
.gem .gi {
  position: absolute;
  left: 5%; top: 5%; width: 90%; height: 90%;
  transition: transform .15s;
  overflow: visible;
}

/* Piezas especiales */
.gem .ov { position: absolute; pointer-events: none; display: none; }
.gem[data-special="h"] .ov, .gem[data-special="v"] .ov {
  display: block;
  border-radius: 99px;
  background: linear-gradient(90deg, rgb(255 255 255 / 0), #fff 22% 78%, rgb(255 255 255 / 0));
  box-shadow: 0 0 10px 3px rgb(255 255 255 / .75), 0 0 18px 6px var(--glow);
  animation: stripe .8s ease-in-out infinite alternate;
}
.gem[data-special="h"] .ov { left: 2%; right: 2%; top: 44%; height: 12%; }
.gem[data-special="v"] .ov {
  top: 2%; bottom: 2%; left: 44%; width: 12%;
  background: linear-gradient(180deg, rgb(255 255 255 / 0), #fff 22% 78%, rgb(255 255 255 / 0));
}
.gem[data-special="bomb"] .ov {
  display: block;
  inset: 3%;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgb(255 255 255 / .9), 0 0 14px 5px var(--glow), inset 0 0 12px 3px var(--glow);
  animation: throb 1s ease-in-out infinite;
}
.gem[data-special="bomb"] .gi { animation: throb 1s ease-in-out infinite; }
.gem[data-special="star"] .gi { display: none; }
.gem[data-special="star"] .ov {
  display: block;
  inset: 9%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #fff 0 10%, rgb(255 255 255 / .2) 30%, transparent 45%),
    conic-gradient(#ff4d6d, #ff9f1c, #ffe14d, #3fe07c, #3ac6ff, #5b6cff, #c45bff, #ff4d6d);
  box-shadow: 0 0 14px 4px rgb(255 255 255 / .6), 0 0 26px 8px rgb(200 120 255 / .55);
  animation: spin 2.4s linear infinite;
}

/* Estados */
.gem.sel::before, .gem.hint::before {
  content: ""; position: absolute; inset: 3%;
  border-radius: 24%;
  background: radial-gradient(circle, rgb(255 255 255 / .35), rgb(255 255 255 / .08) 70%);
  box-shadow: 0 0 0 2px rgb(255 255 255 / .85), 0 0 14px rgb(255 255 255 / .5);
}
.gem.hint::before { animation: hint-glow 1s ease-in-out infinite; }
.gem.sel .gi { transform: scale(1.12); }
.gem.hint .gi { animation: wiggle .9s ease-in-out infinite; }
.gem.nope .gi { animation: shake .3s; }
.gem.pop .gi, .gem.pop .ov { animation: pop .26s ease-in forwards; }
.gem.born .gi, .gem.born .ov { animation: born .45s cubic-bezier(.2, 1.6, .4, 1); }
.gem.land .gi { animation: land .25s ease-out; }

/* Destello ocasional sobre una gema */
.gem.twinkle::after {
  content: ""; position: absolute; left: 14%; top: 10%; width: 34%; height: 34%;
  background: #fff;
  clip-path: polygon(50% 0, 60% 40%, 100% 50%, 60% 60%, 50% 100%, 40% 60%, 0 50%, 40% 40%);
  animation: twinkle .9s ease-in-out forwards;
}

@keyframes pop { 30% { transform: scale(1.3); filter: brightness(1.8); } to { transform: scale(0); opacity: 0; } }
@keyframes born { from { transform: scale(1.9); opacity: .2; } }
@keyframes land { 40% { transform: scaleY(.86) scaleX(1.08) translateY(4%); } }
@keyframes throb { 50% { transform: scale(1.08); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes stripe { to { opacity: .55; } }
@keyframes wiggle { 0%, 100% { transform: scale(1) rotate(0); } 25% { transform: scale(1.12) rotate(-6deg); } 75% { transform: scale(1.12) rotate(6deg); } }
@keyframes hint-glow { 50% { opacity: .35; } }
@keyframes shake { 25% { transform: translateX(-12%); } 75% { transform: translateX(12%); } }
@keyframes twinkle { 0% { transform: scale(0) rotate(0); } 50% { transform: scale(1) rotate(45deg); } 100% { transform: scale(0) rotate(90deg); } }

/* Rayos de las piezas especiales */
.fx { position: absolute; pointer-events: none; z-index: 5; }
.fx.beam-h {
  left: 0; right: 0; height: 12.5%; top: calc(var(--r) * 12.5%);
  background: linear-gradient(rgb(255 255 255 / 0), rgb(255 255 255 / .95) 40% 60%, rgb(255 255 255 / 0));
  box-shadow: 0 0 30px 10px rgb(255 255 255 / .4);
  animation: beam-h .45s ease-out forwards;
}
.fx.beam-v {
  top: 0; bottom: 0; width: 12.5%; left: calc(var(--c) * 12.5%);
  background: linear-gradient(90deg, rgb(255 255 255 / 0), rgb(255 255 255 / .95) 40% 60%, rgb(255 255 255 / 0));
  box-shadow: 0 0 30px 10px rgb(255 255 255 / .4);
  animation: beam-v .45s ease-out forwards;
}
.fx.flash { inset: 0; background: radial-gradient(circle, rgb(255 255 255 / .8), rgb(255 255 255 / .3)); animation: fade .5s ease-out forwards; }
@keyframes beam-h { from { transform: scaleX(.1); opacity: 1; } 40% { transform: scaleX(1); opacity: 1; } to { transform: scaleX(1) scaleY(.3); opacity: 0; } }
@keyframes beam-v { from { transform: scaleY(.1); opacity: 1; } 40% { transform: scaleY(1); opacity: 1; } to { transform: scaleY(1) scaleX(.3); opacity: 0; } }
@keyframes fade { from { opacity: 1; } to { opacity: 0; } }

.float-text {
  position: absolute; z-index: 6; pointer-events: none;
  font-weight: 900; font-size: clamp(18px, calc(var(--bsize) * .06), 28px);
  color: #fff;
  text-shadow: 0 2px 0 rgb(0 0 0 / .4), 0 0 12px rgb(0 0 0 / .35);
  white-space: nowrap;
  animation: rise .9s ease-out forwards;
}
@keyframes rise {
  from { transform: translate(-50%, -30%) scale(.6); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
  to { transform: translate(-50%, -180%) scale(1); opacity: 0; }
}

.toast {
  position: absolute; z-index: 7; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  padding: 10px 16px; border-radius: 12px;
  background: rgb(0 0 0 / .72); color: #fff; font-weight: 700;
  animation: fade 1.4s ease-in .6s forwards;
}

/* Diálogos */
.stars { display: flex; justify-content: center; gap: 6px; height: 54px; }
.stars span {
  font-size: 46px; line-height: 1; color: var(--line);
  transform: scale(0);
  animation: star-in .5s cubic-bezier(.2, 1.8, .4, 1) forwards;
}
.stars span:nth-child(2) { font-size: 54px; margin-top: -8px; }
.stars span.on { color: var(--gold); text-shadow: 0 3px 0 #c98a00, 0 0 18px rgb(255 200 50 / .7); }
@keyframes star-in { to { transform: scale(1); } }
.level-badge {
  display: inline-block; margin-bottom: 4px;
  padding: 4px 12px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  .gem, .gem .gi { transition-duration: 1ms !important; }
  .gem[data-special] .gi, .gem[data-special] .ov, .gem.hint .gi, .moves.low b { animation: none; }
}
