:root { color-scheme: dark; --accent:#ffd166; --text:#eaeaf0; --muted:#9a9aaa; --border:#ffffff18; --board:#1b1030; --empty:#ffffff08; --empty-line:#ffffff0c; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; color: var(--text); font-family: ui-sans-serif, system-ui, sans-serif;
  background:
    radial-gradient(1200px 700px at 10% -10%, #3a1c6e 0%, transparent 55%),
    radial-gradient(900px 500px at 110% 10%, #0a3a4a 0%, transparent 55%),
    radial-gradient(700px 400px at 50% 110%, #2a0a3a 0%, transparent 50%),
    #0a0714;
  display: flex; flex-direction: column; }
header { display: flex; align-items: baseline; gap: 1rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); }
header h1 { margin: 0; font-size: 1.3rem; letter-spacing: -.01em; }
a.home { color: var(--muted); text-decoration: none; font-size: .9rem; }
a.home:hover { color: #fff; }
main { flex: 1; padding: 1rem; max-width: 560px; margin: 0 auto; width: 100%; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.scores { display: flex; gap: .5rem; }
.box {
  background: linear-gradient(180deg, #ffffff10, #ffffff04);
  border: 1px solid var(--border);
  padding: .5rem .9rem; border-radius: 12px; min-width: 84px; text-align: center;
  box-shadow: inset 0 1px 0 #ffffff18;
}
.box span { display: block; font-size: .62rem; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 700; margin-bottom: .15rem; }
.box b { font-variant-numeric: tabular-nums; font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.box.combo { background: linear-gradient(135deg, #ffd16633, #ef476f33); border-color: var(--accent); animation: comboGlow 1.2s ease-in-out infinite; }
.box.combo b { color: var(--accent); }
@keyframes comboGlow { 50% { box-shadow: 0 0 20px #ffd16666, inset 0 1px 0 #ffffff30; } }
#newGame, #again { font: inherit; padding: .65rem 1.1rem; background: linear-gradient(135deg, #ffd166, #f08a3b); color: #1a0a00; border: none; border-radius: 12px; cursor: pointer; font-weight: 800; letter-spacing: .02em; box-shadow: 0 6px 16px -6px #ffd16666, inset 0 1px 0 #fff5; transition: transform .1s, filter .1s; }
#newGame:hover, #again:hover { filter: brightness(1.08); transform: translateY(-1px); }
.hint { margin: 0 0 1rem; color: var(--muted); font-size: .82rem; }

/* ---- Board ---- */
#boardWrap { position: relative; width: 100%; aspect-ratio: 1/1; }
#board {
  width: 100%; height: 100%;
  background:
    linear-gradient(135deg, #221444 0%, #2b1a52 100%);
  border: 1px solid #ffffff15;
  border-radius: 18px; padding: 8px;
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  gap: 5px; touch-action: none;
  box-shadow:
    0 30px 80px -30px #000,
    inset 0 2px 0 #ffffff14,
    inset 0 -2px 0 #0006;
  position: relative;
}
.cell {
  background: var(--empty);
  border-radius: 6px;
  position: relative;
  box-shadow: inset 0 1px 0 #ffffff06, inset 0 -1px 0 #00000033;
  transition: background .15s;
}
/* Alternating subtle pattern like a checkerboard */
.cell:nth-child(16n+1), .cell:nth-child(16n+3), .cell:nth-child(16n+5), .cell:nth-child(16n+7),
.cell:nth-child(16n+10), .cell:nth-child(16n+12), .cell:nth-child(16n+14), .cell:nth-child(16n+16) {
  background: var(--empty-line);
}

.cell.filled {
  box-shadow:
    inset 0 2px 0 #ffffff55,
    inset 0 -3px 0 #00000055,
    inset 2px 0 0 #ffffff22,
    inset -2px 0 0 #00000033;
}
.cell.filled::after {
  content: ''; position: absolute; inset: 0; border-radius: 6px;
  background: radial-gradient(circle at 30% 20%, #ffffff40, transparent 55%);
  pointer-events: none;
}
.cell.ghost { box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 14px #ffd16655; background: #ffd16620 !important; }
.cell.ghost-bad { box-shadow: inset 0 0 0 3px #ef476f; background: #ef476f20 !important; }
.cell.clear-anim {
  animation: clearFlash .5s ease-out forwards;
}
@keyframes clearFlash {
  0% { filter: brightness(1.6) saturate(1.5); transform: scale(1); }
  60% { filter: brightness(2.4) saturate(1.8); transform: scale(1.15); }
  100% { filter: brightness(1); transform: scale(0); opacity: 0; }
}

/* ---- Tray ---- */
#tray {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: .75rem; margin-top: 1.25rem;
  background: #ffffff04; border: 1px solid var(--border); border-radius: 14px;
  padding: .75rem;
  box-shadow: inset 0 1px 0 #ffffff08;
}
.slot {
  background: transparent; border-radius: 10px; display: grid; place-items: center;
  padding: .75rem; aspect-ratio: 1/1; touch-action: none; min-height: 110px;
}
.slot.empty { opacity: .2; }
.piece { display: grid; cursor: grab; touch-action: none; }
.piece:active { cursor: grabbing; }
.piece.dragging { opacity: .15; filter: grayscale(1); }
.pcell {
  border-radius: 4px;
  box-shadow:
    inset 0 2px 0 #ffffff55,
    inset 0 -2px 0 #00000055,
    inset 1px 0 0 #ffffff22,
    inset -1px 0 0 #00000033;
  position: relative;
}
.pcell::after {
  content: ''; position: absolute; inset: 0; border-radius: 4px;
  background: radial-gradient(circle at 30% 20%, #ffffff55, transparent 60%);
  pointer-events: none;
}

#ghost { position: fixed; pointer-events: none; z-index: 5; display: grid; }
#ghost .pcell {
  filter: drop-shadow(0 8px 20px #000a);
}

/* ---- Game over ---- */
#overlay { position: fixed; inset: 0; background: #000c; backdrop-filter: blur(10px); display: grid; place-items: center; z-index: 10; }
#msgBox {
  background: linear-gradient(180deg, #2a1244, #1a0a2e);
  border: 1px solid var(--border);
  padding: 1.75rem 2rem; border-radius: 18px;
  text-align: center; min-width: 280px;
  box-shadow: 0 30px 80px -20px #000;
}
#msgBox h2 { margin: 0 0 1rem; font-size: 1.6rem; background: linear-gradient(90deg, #ffd166, #ef476f); -webkit-background-clip: text; background-clip: text; color: transparent; }
#msgBox .scoreRow { display: flex; justify-content: space-between; gap: 2rem; background: #ffffff08; padding: .5rem 1rem; border-radius: 10px; margin-bottom: .5rem; font-size: 1rem; }
#msgBox .scoreRow b { font-variant-numeric: tabular-nums; font-size: 1.15rem; }
#msgBox #again { margin-top: .9rem; width: 100%; padding: .8rem; font-size: 1rem; }
