@font-face { font-family: "Audiowide"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/audiowide-400.woff2") format("woff2"); }
@font-face { font-family: "Orbitron"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/orbitron-500.woff2") format("woff2"); }
@font-face { font-family: "Orbitron"; font-style: normal; font-weight: 700 900; font-display: swap; src: url("fonts/orbitron-700.woff2") format("woff2"); }

:root {
  --bg0: #050208;
  --panel: rgba(16, 6, 30, 0.78);
  --cell-bg: rgba(22, 10, 42, 0.95);
  --cell-border: rgba(186, 90, 255, 0.3);
  --cyan: #00f3ff;
  --magenta: #ff2bd6;
  --lime: #c8ff00;
  --yellow: #ffe500;
  --orange: #ff8a1a;
  --text: #f4fbff;
  --muted: #cdb8ee;
  --danger: #ff3b8b;
  --green: #39ff14;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* Board fits the narrower of width and the height left after HUD, power-ups and tray. */
  /* The tray grows with the board (~0.27x), hence the divide. */
  --board: min(calc(100vw - 20px), calc((100dvh - 262px - var(--safe-top) - var(--safe-bottom)) / 1.27), 600px);
  --bpad: clamp(5px, 1.4vw, 10px);
  --gap: clamp(3px, 0.8vw, 6px);
  --cell: calc((var(--board) - 2 * var(--bpad) - 7 * var(--gap)) / 8);
  --pc: calc(var(--cell) * 0.72);
  --radius: clamp(6px, 1.5vw, 11px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  background: var(--bg0); color: var(--text);
  font-family: Orbitron, "Trebuchet MS", "Segoe UI", sans-serif;
  overflow: hidden; overscroll-behavior: none; touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(160, 30, 255, 0.3), transparent 55%),
    radial-gradient(ellipse 60% 40% at 85% 100%, rgba(0, 180, 255, 0.14), transparent 50%),
    radial-gradient(ellipse 50% 40% at 10% 90%, rgba(255, 43, 214, 0.12), transparent 50%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #140820 0%, #07040f 45%, #050208 100%);
}

button { font-family: inherit; color: inherit; }
.hidden { display: none !important; }

#app {
  height: 100dvh; max-height: 100dvh;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(8px + var(--safe-top)) 10px calc(8px + var(--safe-bottom));
  max-width: 640px; margin: 0 auto;
  transition: filter 0.25s;
}
#app.under-overlay .top, #app.under-overlay .stage { filter: blur(3px) brightness(0.55); }

/* ---------- HUD ---------- */
.top { width: 100%; flex: 0 0 auto; }
.hud { display: flex; align-items: stretch; gap: 8px; width: min(100%, var(--board)); margin: 0 auto 8px; }
.stat {
  flex: 1 1 0; min-width: 0; text-align: center;
  background: var(--panel); border: 1px solid rgba(0, 243, 255, 0.4); border-radius: 12px;
  padding: 5px 8px 6px;
  box-shadow: 0 0 12px rgba(0, 243, 255, 0.2), inset 0 0 12px rgba(0, 243, 255, 0.06);
}
.stat-best { border-color: rgba(255, 43, 214, 0.45); box-shadow: 0 0 12px rgba(255, 43, 214, 0.2); }
.stat-label { display: block; font-size: 10px; letter-spacing: 0.18em; color: var(--cyan); font-weight: 700; }
.stat-best .stat-label { color: #ff7ae6; }
.stat-value {
  display: block; font-size: clamp(22px, 6vw, 30px); font-weight: 800; line-height: 1.15;
  font-variant-numeric: tabular-nums; color: #fff; text-shadow: 0 0 8px var(--cyan);
}
.stat-value.bump { animation: bump 0.35s ease-out; }
@keyframes bump { 40% { transform: scale(1.25); color: var(--lime); } }

.icon-btn {
  flex: 0 0 auto; width: 52px; min-height: 52px; border-radius: 12px; cursor: pointer;
  background: var(--panel); border: 1px solid rgba(200, 255, 0, 0.45);
  box-shadow: 0 0 10px rgba(200, 255, 0, 0.2); display: grid; place-items: center; padding: 0;
}
.icon-btn svg { width: 26px; height: 26px; fill: var(--lime); stroke: var(--lime); filter: drop-shadow(0 0 4px var(--lime)); }
.icon-btn svg rect, .icon-btn svg path:not(.wave) { stroke: none; }
.icon-btn .ico-off { display: none; }
.icon-btn.muted .ico-on { display: none; }
.icon-btn.muted .ico-off { display: block; fill: var(--danger); stroke: var(--danger); filter: drop-shadow(0 0 4px var(--danger)); }
.icon-btn:active { transform: scale(0.94); }

/* ---------- Board ---------- */
.stage { flex: 1 1 auto; width: 100%; display: flex; flex-direction: column; align-items: center; min-height: 0; gap: 8px; }
.board-wrap { position: relative; width: var(--board); height: var(--board); flex: 0 0 auto; }
.board-wrap.quake { animation: quake 0.4s; }
@keyframes quake { 20% { transform: translate(-5px, 3px); } 40% { transform: translate(5px, -3px); } 60% { transform: translate(-3px, 2px); } 80% { transform: translate(2px, -1px); } }
.board {
  width: 100%; height: 100%;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  gap: var(--gap); padding: var(--bpad);
  background: linear-gradient(160deg, rgba(40, 12, 70, 0.85), rgba(10, 4, 22, 0.92));
  border: 2px solid var(--green); border-radius: calc(var(--radius) + 6px);
  box-shadow: 0 0 10px rgba(57, 255, 20, 0.7), 0 0 28px rgba(57, 255, 20, 0.45), 0 0 56px rgba(57, 255, 20, 0.2), inset 0 0 26px rgba(57, 255, 20, 0.14);
  animation: greenGlow 3.6s ease-in-out infinite;
  touch-action: none;
}
@keyframes greenGlow {
  50% { box-shadow: 0 0 14px rgba(57, 255, 20, 0.85), 0 0 36px rgba(57, 255, 20, 0.55), 0 0 70px rgba(57, 255, 20, 0.25), inset 0 0 30px rgba(57, 255, 20, 0.18); }
}
.cell { border-color: rgba(57, 255, 20, 0.16) !important; }
.cell.ghost-valid, .cell.ghost-invalid, .cell.bomb-target, .cell.zap-target, .cell.will-clear.ghost-valid { border-color: currentColor !important; }
.cell.ghost-valid { color: var(--cyan); }
.cell.ghost-invalid { color: var(--danger); }
.cell.bomb-target { color: var(--orange); }
.cell.will-clear.ghost-valid { color: var(--lime); }
.cell.zap-target { color: var(--yellow); background: rgba(255, 229, 0, 0.25); box-shadow: 0 0 12px rgba(255, 229, 0, 0.8); }
.cell.zap-target > .tile { filter: brightness(1.4) saturate(0.6); }
#app.zap-mode .board { border-color: var(--yellow); box-shadow: 0 0 22px rgba(255, 229, 0, 0.6); animation: none; cursor: pointer; }
.tile.zapped { animation: zapped 0.42s ease-in forwards; }
@keyframes zapped { 30% { transform: scaleY(0.3) scaleX(1.15); filter: brightness(3); } 100% { transform: scale(0, 0); opacity: 0; } }
.zap-beam {
  position: absolute; left: -4%; width: 108%; height: 10px; margin-top: -5px; border-radius: 6px; pointer-events: none;
  background: linear-gradient(90deg, transparent, #fff 12%, var(--yellow) 50%, #fff 88%, transparent);
  box-shadow: 0 0 18px var(--yellow), 0 0 40px #fff; animation: beam 0.55s ease-out forwards;
}
@keyframes beam { 0% { transform: scaleX(0); opacity: 1; } 40% { transform: scaleX(1); opacity: 1; } 100% { transform: scaleX(1) scaleY(3); opacity: 0; } }
.board-wrap.rewind { animation: rewind 0.45s ease-out; }
@keyframes rewind { 0% { filter: hue-rotate(0) brightness(1.6); transform: rotate(-1.5deg) scale(0.98); } 100% { filter: none; transform: none; } }
.tray.raining .piece { animation: rainDrop 0.55s cubic-bezier(.3,1.5,.5,1); }
@keyframes rainDrop { from { transform: translateY(-40px); opacity: 0; filter: brightness(2) hue-rotate(60deg); } }
#app.bomb-mode .board { animation: none; border-color: var(--orange); box-shadow: 0 0 22px rgba(255, 138, 26, 0.6), inset 0 0 24px rgba(255, 138, 26, 0.15); cursor: crosshair; }
#app.stuck .board { animation: stuckGlow 1.2s ease-in-out infinite; }
@keyframes stuckGlow { 50% { border-color: var(--danger); box-shadow: 0 0 26px rgba(255, 59, 139, 0.6); } }
#app.ended .board { filter: grayscale(0.6) brightness(0.7); transition: filter 0.6s; }

.cell {
  position: relative; border-radius: var(--radius);
  background: var(--cell-bg); border: 1px solid var(--cell-border);
  box-shadow: inset 0 0 8px rgba(120, 40, 200, 0.25);
  display: flex; align-items: stretch; justify-content: stretch; min-width: 0; min-height: 0;
}
.cell.ghost-valid { background: rgba(0, 243, 255, 0.2); border-color: var(--cyan); box-shadow: 0 0 10px rgba(0, 243, 255, 0.55), inset 0 0 12px rgba(0, 243, 255, 0.35); }
.cell.ghost-invalid { background: rgba(255, 59, 139, 0.2); border-color: var(--danger); }
.cell.will-clear > .tile { animation: willClear 0.6s ease-in-out infinite alternate; }
.cell.will-clear.ghost-valid { background: rgba(200, 255, 0, 0.3); border-color: var(--lime); box-shadow: 0 0 14px rgba(200, 255, 0, 0.8); }
.cell.will-clear.ghost-valid .ghost-letter { color: var(--lime); }
@keyframes willClear { to { filter: brightness(1.6); box-shadow: 0 0 14px #fff, 0 0 26px var(--lime); } }
.cell.bomb-target { background: rgba(255, 138, 26, 0.3); border-color: var(--orange); box-shadow: 0 0 12px rgba(255, 138, 26, 0.8); }
.cell.bomb-target > .tile { filter: brightness(1.4) saturate(0.6); }
.ghost-letter {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none;
  font-weight: 800; font-size: calc(var(--cell) * 0.5); color: rgba(220, 255, 255, 0.85); text-shadow: 0 0 8px var(--cyan);
}

/* ---------- Tiles ---------- */
.tile {
  width: var(--pc); height: var(--pc); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; position: relative;
  font-family: Orbitron, "Trebuchet MS", sans-serif; font-weight: 800;
  font-size: calc(var(--pc) * 0.56); line-height: 1; color: #fff;
  -webkit-text-stroke: 1.2px #120018; paint-order: stroke fill;
  text-shadow: 0 0 4px #fff, 0 0 10px var(--tile-glow, #00f3ff);
  box-shadow: 0 0 8px var(--tile-glow, #00f3ff), inset 0 2px 0 rgba(255, 255, 255, 0.55), inset 0 -3px 0 rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.4);
}
.cell > .tile { width: 100%; height: 100%; font-size: calc(var(--cell) * 0.56); }
.tile.cyan { --tile-glow: var(--cyan); background: linear-gradient(165deg, #b8ffff 0%, #00e1ff 42%, #008ab8 100%); }
.tile.magenta { --tile-glow: var(--magenta); background: linear-gradient(165deg, #ffc6f5 0%, #ff2bd6 44%, #b00080 100%); }
.tile.lime { --tile-glow: var(--lime); background: linear-gradient(165deg, #f2ffb0 0%, #c8ff00 44%, #6ea000 100%); }
.tile.yellow { --tile-glow: var(--yellow); background: linear-gradient(165deg, #fff7b0 0%, #ffe500 44%, #e09a00 100%); }
.tile.orange { --tile-glow: var(--orange); background: linear-gradient(165deg, #ffd9b0 0%, #ff8a1a 44%, #d04500 100%); }
.tile.wild {
  --tile-glow: #fff;
  background: linear-gradient(135deg, #00f3ff, #ff2bd6, #ffe500, #c8ff00, #00f3ff);
  background-size: 300% 300%; animation: wildShift 3s linear infinite;
}
@keyframes wildShift { to { background-position: 300% 0; } }
.tile.drop { animation: drop 0.22s cubic-bezier(.2,1.6,.4,1); }
@keyframes drop { from { transform: scale(1.18); filter: brightness(1.6); } }
.tile.clearing { animation: tilePop 0.55s ease-out forwards; z-index: 6; pointer-events: none; }
@keyframes tilePop {
  0% { transform: scale(1); filter: brightness(1); }
  20% { transform: scale(1.3); filter: brightness(2.4); box-shadow: 0 0 16px #fff, 0 0 36px var(--tile-glow), 0 0 70px #fff; }
  55% { transform: scale(1.05); filter: brightness(1.8); opacity: 1; }
  100% { transform: scale(0.2) rotate(18deg); opacity: 0; }
}
.tile.bombed { animation: bombed 0.42s ease-in forwards; }
@keyframes bombed { 30% { transform: scale(1.2); filter: brightness(2) hue-rotate(40deg); } 100% { transform: scale(0) rotate(-40deg); opacity: 0; } }

/* ---------- FX ---------- */
.fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 10; }
.burst { position: absolute; width: 0; height: 0; }
.burst-core {
  position: absolute; left: -30px; top: -30px; width: 60px; height: 60px; border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, rgba(0, 243, 255, 0.7) 35%, transparent 70%);
  animation: burstFlash 0.5s ease-out forwards;
}
@keyframes burstFlash { 0% { transform: scale(0.3); opacity: 1; } 100% { transform: scale(2.4); opacity: 0; } }
.spark {
  position: absolute; left: -3px; top: -3px; width: 7px; height: 7px; border-radius: 2px;
  box-shadow: 0 0 8px currentColor; animation: sparkFly 0.7s ease-out forwards;
}
@keyframes sparkFly { to { transform: translate(var(--dx), var(--dy)) rotate(200deg) scale(0.2); opacity: 0; } }
.float-word {
  position: absolute; transform: translate(-50%, -50%); white-space: nowrap;
  font-family: Audiowide, Orbitron, sans-serif; font-size: clamp(18px, 5vw, 28px); color: #fff;
  -webkit-text-stroke: 1px #200030; paint-order: stroke fill;
  text-shadow: 0 0 6px #fff, 0 0 14px var(--lime), 0 0 26px var(--lime);
  animation: floatWord 1.4s ease-out both;
}
@keyframes floatWord {
  0% { transform: translate(-50%, -30%) scale(0.5); opacity: 0; }
  15% { transform: translate(-50%, -60%) scale(1.15); opacity: 1; }
  70% { opacity: 1; }
  100% { transform: translate(-50%, -190%) scale(1); opacity: 0; }
}
.callout {
  position: absolute; left: 50%; z-index: 12; pointer-events: none;
  transform: translate(-50%, -50%) scale(0.6); opacity: 0;
  font-family: Audiowide, Orbitron, sans-serif; text-align: center; white-space: nowrap; line-height: 1.2;
  font-size: clamp(28px, 8.5vw, 50px); top: 16%;
  padding: 6px 18px 8px; border-radius: 18px; background: rgba(8, 2, 18, 0.62); box-shadow: 0 0 24px rgba(8, 2, 18, 0.6); color: #fff; -webkit-text-stroke: 1.5px #2a0040; paint-order: stroke fill;
  text-shadow: 0 0 8px #fff, 0 0 18px var(--magenta), 0 0 36px var(--magenta);
}
.callout.show { animation: calloutPop 1.2s ease-out forwards; }
.callout.combo { color: var(--yellow); text-shadow: 0 0 8px #fff, 0 0 18px var(--orange), 0 0 40px var(--magenta); }
.callout.power, .callout.stuck { font-size: clamp(18px, 5.4vw, 30px); top: 50%; text-shadow: 0 0 8px #fff, 0 0 18px var(--cyan); }
.callout.stuck { color: #ffd0e6; text-shadow: 0 0 8px #fff, 0 0 18px var(--danger); }
.callout-sub {
  display: block; margin-top: 6px; font-family: Orbitron, sans-serif; font-weight: 800; font-size: 0.42em; letter-spacing: 0.08em;
  color: #fff; -webkit-text-stroke: 0; text-shadow: 0 0 6px var(--cyan), 0 0 14px var(--cyan);
}
.callout:empty { display: none; }
@keyframes calloutPop {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
  14% { transform: translate(-50%, -50%) scale(1.12); opacity: 1; }
  24% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { transform: translate(-50%, -62%) scale(1); opacity: 0; }
}

/* ---------- Power-ups (one row of 6: icon over a short label; each button 50px+ wide) ---------- */
.powers { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; width: min(100%, max(var(--board), 370px)); flex: 0 0 auto; margin-top: 4px; }
.power {
  --pc-color: var(--yellow);
  position: relative; min-height: 52px; border-radius: 12px; cursor: pointer; padding: 4px 1px 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0;
  background: var(--panel); border: 1.5px solid var(--pc-color); color: #fff;
  font-weight: 700; font-size: 9px; letter-spacing: 0.01em;
  box-shadow: 0 0 10px color-mix(in srgb, var(--pc-color) 35%, transparent), inset 0 0 10px color-mix(in srgb, var(--pc-color) 10%, transparent);
}
.power[data-power="bomb"] { --pc-color: var(--orange); }
.power[data-power="wild"] { --pc-color: var(--magenta); }
.power[data-power="undo"] { --pc-color: var(--cyan); }
.power[data-power="zap"] { --pc-color: #fff36b; }
.power[data-power="rain"] { --pc-color: #7db8ff; }
.power-ico { width: 22px; height: 22px; flex: 0 0 22px; color: var(--pc-color); filter: drop-shadow(0 0 4px var(--pc-color)); }
.power-name { white-space: nowrap; line-height: 1; }
.power-count {
  position: absolute; top: -7px; right: -4px; min-width: 20px; height: 20px; padding: 0 4px;
  border-radius: 10px; display: grid; place-items: center; font-size: 12px; font-weight: 900;
  background: var(--lime); color: #170020; box-shadow: 0 0 8px var(--lime);
}
.power:disabled { opacity: 0.38; cursor: default; filter: grayscale(0.6); }
.power:not(:disabled):active { transform: scale(0.95); }
.power.armed { background: color-mix(in srgb, var(--pc-color) 30%, transparent); animation: armed 0.7s ease-in-out infinite alternate; }
@keyframes armed { to { box-shadow: 0 0 22px var(--pc-color); } }
.power.earned { animation: earned 0.8s ease-out; }
@keyframes earned { 30% { transform: scale(1.15); box-shadow: 0 0 26px #fff; } }
#app.stuck .power:not(:disabled) { animation: armed 0.6s ease-in-out infinite alternate; }

/* ---------- Mode bar & timer ---------- */
.mode-bar { display: flex; align-items: center; gap: 10px; width: min(100%, var(--board)); margin: 0 auto 6px; min-height: 22px; }
.mode-badge {
  flex: 0 0 auto; font-size: 11px; font-weight: 800; letter-spacing: 0.14em; color: var(--green);
  padding: 3px 10px; border: 1px solid rgba(57, 255, 20, 0.6); border-radius: 999px; text-shadow: 0 0 6px var(--green);
  background: rgba(57, 255, 20, 0.08);
}
#app[data-game="daily"] .mode-badge { color: var(--yellow); border-color: rgba(255, 229, 0, 0.6); text-shadow: 0 0 6px var(--yellow); background: rgba(255, 229, 0, 0.08); }
#app[data-game="timer"] .mode-badge { color: var(--cyan); border-color: rgba(0, 243, 255, 0.6); text-shadow: 0 0 6px var(--cyan); background: rgba(0, 243, 255, 0.08); }
.timer { flex: 1 1 auto; display: flex; align-items: center; gap: 8px; position: relative; }
.timer-track { flex: 1 1 auto; height: 12px; border-radius: 6px; background: rgba(0, 243, 255, 0.12); border: 1px solid rgba(0, 243, 255, 0.45); overflow: hidden; }
.timer-fill { height: 100%; width: 100%; transform-origin: left; background: linear-gradient(90deg, var(--cyan), var(--green)); box-shadow: 0 0 10px var(--cyan); transition: transform 0.1s linear; }
.timer-text { font-family: "Avenir Next", "Exo 2", "Segoe UI", "Noto Sans", Arial, sans-serif; font-weight: 800; font-size: 18px; min-width: 46px; text-align: right; font-variant-numeric: tabular-nums; text-shadow: 0 0 8px var(--cyan); }
.timer.low .timer-fill { background: linear-gradient(90deg, var(--danger), var(--orange)); }
.timer.low .timer-text { color: #ffd0e6; text-shadow: 0 0 8px var(--danger); animation: bump 1s infinite; }
.time-bonus {
  position: absolute; right: 56px; top: -4px; font-family: Audiowide, sans-serif; font-size: 18px; color: var(--green);
  text-shadow: 0 0 8px var(--green); pointer-events: none; animation: timeBonus 1.2s ease-out forwards;
}
@keyframes timeBonus { 0% { transform: translateY(6px) scale(0.6); opacity: 0; } 20% { transform: translateY(-6px) scale(1.15); opacity: 1; } 100% { transform: translateY(-26px); opacity: 0; } }

/* ---------- Tray ---------- */
.tray-wrap { width: var(--board); flex: 0 0 auto; }
.tray {
  display: grid; grid-template-columns: repeat(3, 1fr); align-items: center;
  min-height: calc(var(--cell) * 0.72 * 3 + var(--gap) * 2 + 20px);
  background: var(--panel); border: 1px solid rgba(255, 43, 214, 0.4); border-radius: 16px;
  box-shadow: 0 0 14px rgba(255, 43, 214, 0.2), inset 0 0 18px rgba(255, 43, 214, 0.06);
  touch-action: none;
}
.tray.has-bonus { grid-template-columns: repeat(3, 1fr) 0.7fr; }
.tray.shuffling .piece { animation: shuffleIn 0.4s ease-out; }
@keyframes shuffleIn { from { transform: rotateY(90deg) scale(0.6); opacity: 0; } }
.tray-slot {
  align-self: stretch; display: grid; place-items: center; min-height: 0; padding: 6px 4px;
  border-radius: 14px; cursor: grab; touch-action: none; outline: none;
}
.tray-slot.bonus-slot { border-left: 1px dashed rgba(255, 43, 214, 0.5); border-radius: 0 14px 14px 0; }
.tray-slot.selected { background: rgba(0, 243, 255, 0.14); box-shadow: inset 0 0 0 2px var(--cyan), 0 0 14px rgba(0, 243, 255, 0.4); }
.tray-slot:focus-visible { box-shadow: inset 0 0 0 3px var(--yellow); }
.piece { display: grid; gap: var(--gap); pointer-events: none; transition: transform 0.15s, opacity 0.15s; }
.piece > i { display: block; }
.piece.long { --pc: calc(var(--cell) * 0.54); }
.tray.has-bonus .piece { --pc: calc(var(--cell) * 0.6); }
.tray.has-bonus .piece.long { --pc: calc(var(--cell) * 0.44); }
.piece.unplaceable { opacity: 0.32; filter: grayscale(0.8); }
.tray-slot.lifting .piece { opacity: 0.15; transform: scale(0.9); }
.tray-slot.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.drag-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.drag-float {
  position: absolute; left: 0; top: 0; display: grid; will-change: transform;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.55)) drop-shadow(0 0 12px rgba(0, 243, 255, 0.5));
}
.drag-float > i { display: block; }
.drag-float .tile { font-size: calc(var(--pc) * 0.56); }

/* ---------- Words found ---------- */
.words-bar { width: var(--board); display: flex; align-items: center; gap: 8px; flex: 0 0 auto; min-height: 36px; }
.words-label { font-size: 10px; letter-spacing: 0.16em; color: var(--muted); font-weight: 700; }
.words-list { flex: 1 1 auto; display: flex; gap: 6px; overflow: hidden; white-space: nowrap; mask-image: linear-gradient(90deg, #000 85%, transparent); -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); }
.words-empty { font-size: 12px; color: var(--muted); font-family: "Trebuchet MS", sans-serif; letter-spacing: 0.02em; }
.word-chip {
  flex: 0 0 auto; padding: 5px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; letter-spacing: 0.06em;
  border: 1px solid var(--cyan); color: #e8ffff; background: rgba(0, 243, 255, 0.1); box-shadow: 0 0 8px rgba(0, 243, 255, 0.3);
}
.word-chip.c1 { border-color: var(--magenta); background: rgba(255, 43, 214, 0.12); }
.word-chip.c2 { border-color: var(--lime); background: rgba(200, 255, 0, 0.1); }
.word-chip.c3 { border-color: var(--yellow); background: rgba(255, 229, 0, 0.1); }
.word-chip.c4 { border-color: var(--orange); background: rgba(255, 138, 26, 0.12); }
.word-chip.fresh { animation: chipIn 0.5s ease-out; }
@keyframes chipIn { from { transform: scale(0.3); opacity: 0; } 60% { transform: scale(1.15); } }

/* ---------- Overlay screens ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 80; display: none; align-items: flex-start; justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: radial-gradient(ellipse at 50% 30%, rgba(60, 10, 100, 0.55), rgba(5, 2, 8, 0.82));
  overflow-y: auto;
}
.overlay.open { display: flex; }
.screen { display: none; width: min(100%, 440px); margin: auto 0; text-align: center; animation: screenIn 0.28s ease-out; }
.screen.active { display: block; }
@keyframes screenIn { from { transform: translateY(14px) scale(0.97); opacity: 0; } }
.title {
  margin: 0; font-family: Audiowide, Orbitron, Impact, sans-serif; font-weight: 400; color: #fff;
  letter-spacing: 0.06em; line-height: 1.02;
  text-shadow: 0 0 4px #fff, 0 0 10px var(--cyan), 0 0 20px var(--cyan), 0 0 36px var(--magenta), 0 0 64px var(--magenta);
  animation: titlePulse 3.2s ease-in-out infinite;
}
.title.big { font-size: clamp(50px, 16vw, 88px); display: flex; flex-direction: column; }
.title.big span:last-child { color: #fff6fe; }
@keyframes titlePulse {
  50% { text-shadow: 0 0 6px #fff, 0 0 14px var(--magenta), 0 0 26px var(--magenta), 0 0 44px var(--cyan), 0 0 72px var(--cyan); }
}
.demo-tiles { display: flex; justify-content: center; gap: 8px; margin: 14px 0 4px; --pc: 46px; }
.demo-tiles .tile { animation: bob 1.8s ease-in-out infinite; }
.demo-tiles .tile:nth-child(2) { animation-delay: 0.2s; }
.demo-tiles .tile:nth-child(3) { animation-delay: 0.4s; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.start-best { font-size: 15px; letter-spacing: 0.16em; color: var(--muted); margin: 8px 0 14px; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mode-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 64px; padding: 6px 10px; }
.mode-name { font-size: 19px; letter-spacing: 0.12em; }
.mode-sub { font-family: "Trebuchet MS", "Segoe UI", sans-serif; font-weight: 700; font-size: 13px; letter-spacing: 0.02em; color: var(--muted); }
.mode-classic { border-color: var(--green); box-shadow: 0 0 14px rgba(57, 255, 20, 0.45), inset 0 0 12px rgba(57, 255, 20, 0.12); }
.mode-classic .mode-name { color: #eaffdf; text-shadow: 0 0 8px var(--green); }
.mode-daily { border-color: var(--yellow); box-shadow: 0 0 14px rgba(255, 229, 0, 0.4), inset 0 0 12px rgba(255, 229, 0, 0.1); }
.mode-daily .mode-name { color: #fff8c2; text-shadow: 0 0 8px var(--yellow); }
.mode-daily.done .mode-sub { color: #fff36b; }
.mode-timer { border-color: var(--cyan); }
.mode-timer .mode-name { text-shadow: 0 0 8px var(--cyan); }
.start-best span { color: #fff; font-weight: 800; text-shadow: 0 0 8px var(--magenta); font-size: 20px; }
.version { color: rgba(205, 184, 238, 0.6); font-size: 11px; letter-spacing: 0.2em; margin-top: 18px; }
.menu { display: flex; flex-direction: column; gap: 12px; align-items: stretch; width: min(100%, 320px); margin: 0 auto; }
.btn {
  min-height: 56px; border-radius: 14px; cursor: pointer; font-weight: 800; font-size: 17px; letter-spacing: 0.12em;
  background: rgba(16, 6, 30, 0.9); color: #fff; border: 2px solid var(--cyan);
  box-shadow: 0 0 12px rgba(0, 243, 255, 0.35), inset 0 0 12px rgba(0, 243, 255, 0.1);
}
.btn-primary {
  color: #180020; border: 0; font-size: 20px;
  background: linear-gradient(180deg, #f6ffb8, var(--lime) 45%, #82c400);
  box-shadow: 0 0 18px rgba(200, 255, 0, 0.6), 0 4px 0 #4d7a00;
}
.btn:active { transform: translateY(2px) scale(0.98); }
.btn:focus-visible, .power:focus-visible, .icon-btn:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.screen-title {
  font-family: Audiowide, Orbitron, sans-serif; font-weight: 400; font-size: clamp(34px, 10vw, 52px); margin: 0 0 18px;
  color: #fff; text-shadow: 0 0 6px #fff, 0 0 16px var(--cyan), 0 0 32px var(--magenta);
}
.over-title { text-shadow: 0 0 6px #fff, 0 0 16px var(--danger), 0 0 32px var(--magenta); }
.how-list { list-style: none; padding: 0; margin: 0 0 14px; text-align: left; display: grid; gap: 10px; }
.how-list li {
  display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: 12px;
  background: rgba(16, 6, 30, 0.85); border: 1px solid rgba(0, 243, 255, 0.3);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif; font-size: 16px; line-height: 1.35; color: #f4f0ff;
}
.how-list b { color: var(--lime); }
.how-num {
  flex: 0 0 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--magenta); color: #fff; font-family: Orbitron, sans-serif; font-weight: 800; font-size: 14px; box-shadow: 0 0 10px var(--magenta);
}
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 0 22px; }
.stats-grid .stats-head { grid-column: 1 / -1; background: none; border: 0; padding: 6px 0 0; text-align: left; font-size: 12px; font-weight: 800; letter-spacing: 0.16em; color: var(--green); text-shadow: 0 0 6px var(--green); }
.over-note { font-family: "Trebuchet MS", "Segoe UI", sans-serif; font-size: 15px; color: var(--muted); margin: -8px 0 18px; line-height: 1.35; }
.how-sub { font-family: Orbitron, sans-serif; font-size: 13px; letter-spacing: 0.16em; color: var(--green); text-shadow: 0 0 6px var(--green); margin: 4px 0 8px; text-align: left; }
.how-powers { list-style: none; padding: 0; margin: 0 0 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; text-align: left; }
.how-powers li, .how-modes li { font-family: "Trebuchet MS", "Segoe UI", sans-serif; font-size: 14px; line-height: 1.3; color: #f4f0ff; background: rgba(16, 6, 30, 0.85); border: 1px solid rgba(186, 90, 255, 0.3); border-radius: 10px; padding: 7px 9px; }
.how-powers b, .how-modes b { display: block; font-family: Orbitron, sans-serif; font-size: 12px; letter-spacing: 0.08em; }
.c-shuffle { color: var(--yellow); } .c-bomb { color: var(--orange); } .c-wild { color: var(--magenta); }
.c-undo { color: var(--cyan); } .c-zap { color: #fff36b; } .c-rain { color: #7db8ff; }
.how-modes { list-style: none; padding: 0; margin: 0 0 18px; display: grid; gap: 6px; text-align: left; }
.how-modes b { color: var(--lime); }
.stats-grid div { background: rgba(16, 6, 30, 0.85); border: 1px solid rgba(255, 43, 214, 0.35); border-radius: 12px; padding: 10px 6px; }
.stats-grid dt { font-size: 10px; letter-spacing: 0.14em; color: var(--muted); font-weight: 700; }
.stats-grid dd { margin: 4px 0 0; font-size: 18px; font-weight: 800; color: #fff; text-shadow: 0 0 8px var(--cyan); word-break: break-word; }
.stats-grid.small dd { font-size: 16px; }
.over-score { font-size: clamp(56px, 16vw, 84px); font-weight: 900; margin: 0 0 18px; line-height: 1; color: #fff; text-shadow: 0 0 10px var(--lime), 0 0 30px var(--lime); font-variant-numeric: tabular-nums; }
.new-best { margin: -8px 0 8px; font-family: Audiowide, sans-serif; font-size: 24px; color: var(--yellow); text-shadow: 0 0 10px var(--orange), 0 0 24px var(--magenta); animation: titlePulse 1.4s infinite, bob 1.4s ease-in-out infinite; }

/* ---------- Larger screens ---------- */
@media (min-width: 700px) {
  :root { --board: min(calc(100vw - 40px), calc((100dvh - 300px) / 1.27), 660px); }
  #app { justify-content: center; max-width: 720px; }
  .stage { flex: 0 0 auto; }
  .power { font-size: 12px; min-height: 64px; letter-spacing: 0.06em; }
  .power-ico { width: 24px; height: 24px; flex-basis: 24px; }
  .mode-badge { font-size: 13px; }
  .icon-btn { width: 60px; min-height: 60px; }
  .stat-label { font-size: 12px; }
  .words-label { font-size: 12px; }
  .word-chip { font-size: 15px; }
}
@media (max-height: 700px) {
  .power { min-height: 48px; }
  .mode-bar { margin-bottom: 4px; }
  .icon-btn { min-height: 44px; width: 46px; }
  .stage { gap: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .tile.clearing, .tile.bombed { animation-duration: 0.3s !important; }
}

/* Orbitron's zero is slashed; use a rounder face for numbers so kids read scores easily. */
.stat-value, .over-score, .start-best span, .power-count, .stats-grid dd {
  font-family: "Avenir Next", "Exo 2", "Segoe UI", "Noto Sans", "Liberation Sans", Arial, sans-serif;
  font-weight: 800;
}

/* Phones turned sideways: the game is portrait-only, so ask to rotate. */
@media (orientation: landscape) and (max-height: 500px) {
  #app, .overlay { visibility: hidden; }
  body::before {
    content: "\21BB  Turn your device upright to play";
    position: fixed; inset: 0; display: grid; place-items: center; z-index: 200; padding: 20px; text-align: center;
    font-family: Audiowide, Orbitron, sans-serif; font-size: 24px; color: #fff;
    text-shadow: 0 0 8px var(--cyan), 0 0 20px var(--magenta);
  }
}
