﻿/* Merge Drop — game styles (site-wide nav/footer/buttons come from ../css/site.css) */
.md {
  --bw: max(220px, min(92vw, 440px, calc((100dvh - 250px) * 5 / 7)));
  display: grid; justify-items: center; gap: 10px;
  grid-template-areas: "stats" "queue" "play" "controls";
  max-width: 1000px; margin: 0 auto; padding: 0 16px 8px;
}
.side { display: contents; }
.stats { grid-area: stats; } .queue { grid-area: queue; } .controls { grid-area: controls; } .play { grid-area: play; }
button.btn { font: inherit; font-weight: 600; cursor: pointer; touch-action: manipulation; }
button.btn:disabled { opacity: .4; cursor: default; }

/* ---------- score boxes ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: var(--bw); min-width: 260px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px; text-align: center; }
.stat span { display: block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.stat b { font-family: 'Space Grotesk', sans-serif; font-size: 20px; display: inline-block; }
.stat b.bump { animation: bump .25s; }

/* ---------- now / next / swap ---------- */
.queue { display: flex; align-items: center; justify-content: center; gap: 14px; }
.q-item { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.q-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.qtile { --cell: 46px; position: relative; width: var(--cell); height: var(--cell); }
.qtile.big { --cell: 64px; }
.qtile.flip .face { animation: flip .25s; }
.swap { padding: 10px 14px; }
.swap b { display: inline-grid; place-items: center; min-width: 22px; height: 22px; margin-left: 4px; border-radius: 11px; background: var(--accent); color: #1a1300; font-size: 13px; }
.swap.pulse { animation: pulse 1s ease-in-out 3; }

.controls { display: flex; gap: 8px; }
.btn.icon { padding: 10px 13px; }

/* ---------- board ---------- */
.play { position: relative; }
.board {
  position: relative; width: var(--bw); height: calc(var(--bw) * 7 / 5); padding: 6px;
  background: linear-gradient(180deg, #172233, #111a27); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.05);
  overflow: hidden; cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.board.shake { animation: shake .3s; }
.area { position: relative; width: 100%; height: 100%; }
.cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(7, 1fr); }
.cells i { margin: calc(var(--cell) * .05); border-radius: calc(var(--cell) * .2); background: rgba(255,255,255,.035); }
.aim { position: absolute; top: 0; bottom: 0; left: calc(var(--c, 2) * 20%); width: 20%; border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(255,255,255,.02)); transition: left .1s ease-out; }
.aim.no { background: linear-gradient(180deg, rgba(255,90,90,.22), rgba(255,90,90,.04)); }
.aim[hidden] { display: none; }

/* tiles: positioned by --r (row, 0 = top) and --c (column) */
.tile { position: absolute; left: 0; top: 0; width: 20%; height: calc(100% / 7);
  transform: translate(calc(var(--c, 0) * 100%), calc(var(--r, 0) * 100%));
  transition-property: transform; transition-timing-function: cubic-bezier(.45, 0, .8, .45); will-change: transform; }
.tile.absorb { transition-timing-function: ease-out; z-index: 0; }
.tile.absorb .face { transform: scale(.75); opacity: .8; transition: transform .11s, opacity .11s; }
.tile.vanish .face { transform: scale(0) rotate(20deg); opacity: 0; transition: transform .25s, opacity .25s; }
.tile.ghost { opacity: .28; pointer-events: none; transition: none; }
.tile.ghost.join .face { outline: 3px dashed #fff; outline-offset: -3px; }
.tile.land .face { animation: land .2s ease-out; }
.tile .face.pop { animation: pop .24s ease-out; }
.tiles { position: absolute; inset: 0; }
.tiles .tile { z-index: 1; }

.face {
  position: absolute; inset: calc(var(--cell) * .05); border-radius: calc(var(--cell) * .2);
  display: grid; place-items: center; background: var(--tc, #5ec2ff); color: var(--tx, #10161f);
  font-family: 'Space Grotesk', Inter, sans-serif; font-weight: 700; line-height: 1;
  box-shadow: inset 0 calc(var(--cell) * -.06) 0 rgba(0,0,0,.2), inset 0 calc(var(--cell) * .04) 0 rgba(255,255,255,.28);
  transform-origin: 50% 100%;
}
.face span { font-size: calc(var(--cell) * .42); letter-spacing: -.02em; }
[data-len="3"] .face span { font-size: calc(var(--cell) * .36); }
[data-len="4"] .face span { font-size: calc(var(--cell) * .29); }
[data-len="5"] .face span { font-size: calc(var(--cell) * .25); }

/* tile colors by exponent (2 = 2^1 ...) */
[data-e="1"]  { --tc: #5ec2ff; }
[data-e="2"]  { --tc: #3dd6b5; }
[data-e="3"]  { --tc: #86e05a; }
[data-e="4"]  { --tc: #ffd166; }
[data-e="5"]  { --tc: #ffa24c; }
[data-e="6"]  { --tc: #ff6b6b; --tx: #fff; }
[data-e="7"]  { --tc: #ff5fa2; --tx: #fff; }
[data-e="8"]  { --tc: #c77dff; --tx: #fff; }
[data-e="9"]  { --tc: #8a7dff; --tx: #fff; }
[data-e="10"] { --tc: #3f8cff; --tx: #fff; }
[data-e="11"] { --tc: linear-gradient(135deg, #ffe08a, #ffb400); }
[data-e="12"] { --tc: linear-gradient(135deg, #ff6bd6, #7c5cff); --tx: #fff; }
[data-e="13"] { --tc: linear-gradient(135deg, #00e0c6, #2f6bff); --tx: #fff; }
[data-e="x"]  { --tc: linear-gradient(135deg, #ff8a00, #e52e71, #7c3aed); --tx: #fff; }
[data-e="9"] .face, [data-e="10"] .face, [data-e="11"] .face, [data-e="12"] .face, [data-e="13"] .face, [data-e="x"] .face {
  box-shadow: inset 0 calc(var(--cell) * -.06) 0 rgba(0,0,0,.2), inset 0 calc(var(--cell) * .04) 0 rgba(255,255,255,.3), 0 0 calc(var(--cell) * .25) rgba(255,220,120,.35);
}

/* effects */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.float { position: absolute; transform: translate(-50%, -50%); font: 700 calc(var(--cell) * .3) 'Space Grotesk', sans-serif; color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,.6); animation: rise .8s ease-out forwards; white-space: nowrap; }
.combo { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); font: 700 calc(var(--cell) * .55) 'Space Grotesk', sans-serif;
  color: var(--accent); text-shadow: 0 3px 12px rgba(0,0,0,.7); animation: combo .9s ease-out forwards; white-space: nowrap; }
.hint { position: absolute; left: 6%; right: 6%; top: 22%; z-index: 4; text-align: center; background: rgba(13,19,28,.85); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 12px; font-size: 15px; line-height: 1.5; pointer-events: none; animation: bob 1.6s ease-in-out infinite; }
.toast { position: absolute; left: 50%; top: 14px; z-index: 5; transform: translateX(-50%); max-width: 90%; text-align: center;
  background: rgba(13,19,28,.92); border: 1px solid rgba(255,209,102,.5); color: var(--text); border-radius: 999px;
  padding: 8px 16px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; }
.toast.show { animation: toast 2.6s ease forwards; }

/* ---------- game over ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(5,8,14,.72); backdrop-filter: blur(3px); }
.modal-box { width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 20px; text-align: center; box-shadow: 0 24px 60px rgba(0,0,0,.5); animation: rise-in .3s ease-out; }
.modal-box h2 { font-size: 26px; }
.final { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0 10px; }
.final div { background: var(--panel-2); border-radius: 12px; padding: 8px 4px; }
.final span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.final b { font: 700 22px 'Space Grotesk', sans-serif; }
.new-best { color: var(--accent); font-weight: 700; margin: 4px 0 10px; }
#btn-again { font-size: 17px; padding: 12px 28px; margin-bottom: 12px; }
#ad-slot { margin-top: 6px; }

/* ---------- how to play (pop-up) ---------- */
.help-box { position: relative; width: min(540px, 100%); text-align: left; line-height: 1.55; }
.help-box h2 { margin-right: 40px; }
.help-box ul { padding-left: 20px; margin: 10px 0 16px; } .help-box li { margin: 7px 0; color: #cdd7e5; }
.help-box #help-ok { display: block; margin: 0 auto; padding: 11px 32px; }
.close { position: absolute; top: 12px; right: 12px; width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 16px; cursor: pointer; }
.close:hover { background: #24324a; }

/* ---------- landscape / desktop: info on the left, board on the right ---------- */
@media (min-aspect-ratio: 1/1) and (min-width: 600px) {
  .md {
    --bw: max(200px, min(440px, calc((100dvh - 84px) * 5 / 7)));
    grid-template-columns: minmax(240px, 300px) auto; grid-template-rows: auto auto 1fr;
    grid-template-areas: "stats play" "queue play" "controls play";
    justify-content: center; align-items: start; column-gap: 28px; row-gap: 14px;
  }
  .stats { width: 100%; min-width: 0; grid-template-columns: 1fr 1fr; }
  .stats .stat:first-child { grid-column: 1 / -1; }
  .stats .stat:first-child b { font-size: 30px; }
  .queue { justify-content: flex-start; width: 100%; flex-wrap: wrap; }
  .controls { width: 100%; }
}

@keyframes bump { 50% { transform: scale(1.18); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes land { 0% { transform: scale(1.08, .86); } 100% { transform: none; } }
@keyframes flip { 0% { transform: rotateY(90deg); } 100% { transform: none; } }
@keyframes rise { 0% { opacity: 0; margin-top: 0; } 15% { opacity: 1; } 100% { opacity: 0; margin-top: calc(var(--cell) * -.9); } }
@keyframes combo { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.5); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  70% { opacity: 1; transform: translate(-50%, -60%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -80%) scale(1); } }
@keyframes toast { 0% { opacity: 0; margin-top: -8px; } 10%, 85% { opacity: 1; margin-top: 0; } 100% { opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255,209,102,.35); } }
@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes rise-in { from { opacity: 0; transform: translateY(16px); } }
@media (prefers-reduced-motion: reduce) {
  .hint, .swap.pulse { animation: none; }
}
