:root {
  --bg0: #0b1020;
  --bg1: #131a33;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.1);
  --ink: #f2f4ff;
  --ink-dim: #aab2d5;
  --accent: #6c7bff;
  --accent2: #2dd4bf;
  --board-bg: rgba(9, 13, 30, 0.85);
  --cell: rgba(255, 255, 255, 0.07);
  --gap: 5px;
  --board-pad: 10px;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}

:root[data-theme="dawn"] {
  --bg0: #2b1445;
  --bg1: #57255a;
  --accent: #ff8a5c;
  --accent2: #ffd166;
  --board-bg: rgba(30, 12, 40, 0.88);
}

:root[data-theme="mint"] {
  --bg0: #06231f;
  --bg1: #0b3d3a;
  --accent: #34d399;
  --accent2: #a7f3d0;
  --board-bg: rgba(4, 26, 24, 0.9);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: "Nunito", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: radial-gradient(1200px 800px at 20% -10%, #2a3570 0%, transparent 60%),
    radial-gradient(1000px 700px at 90% 10%, #123f45 0%, transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  min-height: 100dvh;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body.dragging { touch-action: none; }
body.dragging * { touch-action: none !important; }

.app { max-width: 560px; margin: 0 auto; padding: 10px 14px calc(20px + env(safe-area-inset-bottom)); position: relative; }

.bg-orbs span { position: fixed; border-radius: 50%; filter: blur(70px); opacity: 0.35; pointer-events: none; z-index: 0; }
.bg-orbs span:nth-child(1) { width: 340px; height: 340px; background: #5b6cff; left: -120px; top: -80px; }
.bg-orbs span:nth-child(2) { width: 300px; height: 300px; background: #0ea5a5; right: -100px; top: 30%; }
.bg-orbs span:nth-child(3) { width: 260px; height: 260px; background: #ff5d8f; left: 10%; bottom: -120px; opacity: 0.22; }

.topbar { display: flex; align-items: center; justify-content: space-between; position: relative; z-index: 2; padding: 6px 2px 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 900; font-size: 20px; letter-spacing: 0.3px; }
.brand-logo { width: 30px; height: 30px; border-radius: 9px; background: conic-gradient(from 45deg, #6c7bff, #2dd4bf, #ffb020, #ff5d8f, #6c7bff); box-shadow: 0 6px 18px rgba(108, 123, 255, 0.5); }
.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--panel-border);
  background: var(--panel); color: var(--ink); font-size: 18px; font-weight: 800; cursor: pointer;
  backdrop-filter: blur(8px);
}
.icon-btn:active { transform: scale(0.93); }

.layout { display: flex; flex-direction: column; gap: 12px; position: relative; z-index: 1; }

.hud .score-card {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  padding: 12px 14px; backdrop-filter: blur(10px); box-shadow: var(--shadow);
}
.score-row { display: flex; justify-content: space-between; align-items: flex-end; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink-dim); font-weight: 800; }
.score-value { font-size: 38px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.score-value.bump { animation: bump 0.18s ease; }
@keyframes bump { 50% { transform: scale(1.12); } }
.best-value { font-size: 24px; font-weight: 900; color: #ffd166; font-variant-numeric: tabular-nums; }
.score-block.right { text-align: right; }
.progress-row { display: flex; align-items: center; gap: 10px; margin-top: 8px; min-height: 26px; }
.combo-pill {
  background: linear-gradient(90deg, #ff7a18, #ff2d78); font-weight: 900; font-size: 14px;
  padding: 3px 12px; border-radius: 999px; box-shadow: 0 6px 18px rgba(255, 45, 120, 0.45);
}
.combo-pill.hidden { display: none; }
.combo-pill.pop-in { animation: popin 0.3s cubic-bezier(0.2, 1.6, 0.4, 1); }
@keyframes popin { 0% { transform: scale(0.5); } 100% { transform: scale(1); } }
.streak-note { color: var(--ink-dim); font-size: 13px; font-weight: 700; }
.hidden { display: none !important; }

.board-wrap { display: flex; justify-content: center; }
.board-frame {
  position: relative; width: min(92vw, 440px); aspect-ratio: 1;
  background: var(--board-bg); border: 1px solid var(--panel-border);
  border-radius: 22px; padding: var(--board-pad); box-shadow: var(--shadow);
}
.board-frame.shake { animation: shake 0.28s ease; }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }

.board {
  position: relative; display: grid; width: 100%; height: 100%;
  grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  gap: var(--gap);
}
.cell {
  background: var(--cell); border-radius: 7px; transition: background 0.12s, transform 0.12s;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.cell.filled { animation: none; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4), inset 0 2px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.25); }
.cell.pop { animation: pop 0.2s ease; }
@keyframes pop { 0% { transform: scale(0.4); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
.cell.clearing { animation: clearpulse 0.26s ease infinite alternate; filter: brightness(1.7) saturate(1.4); z-index: 2; }
@keyframes clearpulse { from { transform: scale(1); } to { transform: scale(1.12); } }
.cell.preview-ok { outline: 2px solid rgba(255, 255, 255, 0.55); outline-offset: -2px; filter: brightness(1.25); }
.cell.preview-bad { filter: brightness(0.7); }

.ghost { position: absolute; left: 0; top: 0; display: grid; gap: var(--gap); pointer-events: none; z-index: 3; opacity: 0.75; }
.gblock { border-radius: 7px; }
.gblock.blank { visibility: hidden; }
.gblock.bad { background: rgba(255, 80, 100, 0.5) !important; outline: 2px dashed rgba(255, 120, 140, 0.8); outline-offset: -2px; }

/* Tile palette — original gradient set */
.tile-blue { background: linear-gradient(145deg, #7d8bff, #4a5cf5) !important; }
.tile-teal { background: linear-gradient(145deg, #4fe3c1, #0ea5a5) !important; }
.tile-amber { background: linear-gradient(145deg, #ffcf5c, #f59e0b) !important; }
.tile-pink { background: linear-gradient(145deg, #ff8fb3, #f43f7f) !important; }
.tile-violet { background: linear-gradient(145deg, #c4a4ff, #8b5cf6) !important; }
.tile-green { background: linear-gradient(145deg, #7ee2a0, #22a06b) !important; }
.tile-orange { background: linear-gradient(145deg, #ffab6b, #f97316) !important; }
.tile-cyan { background: linear-gradient(145deg, #7dd8ff, #0284c7) !important; }
.cell.filled, .pblock:not(.blank), .gblock:not(.blank):not(.bad) { border-radius: 7px; box-shadow: 0 3px 8px rgba(0,0,0,0.4), inset 0 2px 0 rgba(255,255,255,0.35), inset 0 -3px 0 rgba(0,0,0,0.25); }

.fx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }
.board-flash { position: absolute; inset: 0; border-radius: 22px; background: radial-gradient(circle, #fff, transparent 70%); opacity: 0; pointer-events: none; z-index: 4; }
.board-flash.go { animation: flash 0.32s ease-out; }
@keyframes flash { 0% { opacity: var(--fo, 0.3); } 100% { opacity: 0; } }
.float-layer { position: absolute; inset: 0; pointer-events: none; z-index: 6; overflow: visible; }
.float-score {
  position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 22px;
  color: #ffd166; text-shadow: 0 2px 12px rgba(0,0,0,0.6); transition: all 1s ease-out; white-space: nowrap;
}
.float-score.big { font-size: 30px; color: #ff9d5c; }
.float-score.rise { transform: translate(-50%, -160%); opacity: 0; }

.drag-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.drag-ghost { position: absolute; left: 0; top: 0; will-change: transform; filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.55)); }

.tray-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.tray {
  display: flex; justify-content: space-around; align-items: center; gap: 8px; width: 100%;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: var(--radius);
  padding: 12px 8px; min-height: 118px; backdrop-filter: blur(10px); touch-action: none;
}
.slot { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 92px; touch-action: none; cursor: grab; }
.slot.empty { visibility: hidden; }
.slot.unplaceable { filter: saturate(0.4); }
.piece { display: grid; grid-template-columns: repeat(var(--pc), calc(26px * var(--ps, 1))); grid-auto-rows: calc(26px * var(--ps, 1)); gap: 3px; pointer-events: none; }
.pblock { border-radius: 6px; }
.pblock.blank { visibility: hidden; }
.tray-hint { color: var(--ink-dim); font-size: 13px; font-weight: 700; }

.controls { display: flex; gap: 10px; justify-content: center; }

.btn {
  border: 1px solid var(--panel-border); border-radius: 14px; padding: 12px 20px;
  font-family: inherit; font-weight: 900; font-size: 16px; color: var(--ink);
  background: var(--panel); cursor: pointer; backdrop-filter: blur(8px);
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #9d4edd); border: none; box-shadow: 0 10px 26px rgba(108, 123, 255, 0.45); }
.btn.big { width: 100%; font-size: 19px; padding: 15px; }
.btn.soft { background: rgba(255, 255, 255, 0.1); flex: 1; }
.btn.ghost { background: transparent; }

.overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(5, 8, 20, 0.7); backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.card {
  width: min(92vw, 420px); max-height: 88dvh; overflow-y: auto; background: linear-gradient(180deg, #1c2447, #121836);
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 24px; padding: 26px 22px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); text-align: center;
  transform: translateY(14px) scale(0.97); transition: transform 0.25s;
}
.overlay.show .card { transform: none; }
.card h1 { margin: 0; font-size: 38px; font-weight: 900; }
.card h2 { margin: 0; font-size: 24px; }
.tagline { color: var(--ink-dim); margin: 4px 0 0; font-weight: 700; }
.logo-row { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.big-logo { display: grid; grid-template-columns: 30px 30px; gap: 5px; }
.big-logo i { width: 30px; height: 30px; border-radius: 9px; display: block; }
.big-logo i:nth-child(1) { background: linear-gradient(145deg, #7d8bff, #4a5cf5); }
.big-logo i:nth-child(2) { background: linear-gradient(145deg, #4fe3c1, #0ea5a5); }
.big-logo i:nth-child(3) { background: linear-gradient(145deg, #ffcf5c, #f59e0b); }
.big-logo i:nth-child(4) { background: linear-gradient(145deg, #ff8fb3, #f43f7f); }
.menu-best { display: flex; justify-content: space-between; background: rgba(255,255,255,0.07); border-radius: 14px; padding: 10px 16px; font-weight: 800; }
.menu-best strong { color: #ffd166; font-size: 20px; }
.menu-grid { display: flex; gap: 10px; }
.mini-settings, .card .switch-row { display: flex; flex-direction: column; gap: 10px; }
.switch-row { flex-direction: row !important; justify-content: space-between; align-items: center; font-weight: 800; }
.switch { width: 52px; height: 30px; border-radius: 999px; border: none; background: rgba(255,255,255,0.18); position: relative; cursor: pointer; }
.switch span { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: left 0.18s; }
.switch.on { background: linear-gradient(90deg, var(--accent2), var(--accent)); }
.switch.on span { left: 25px; }

.help-list { text-align: left; margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 14.5px; line-height: 1.45; }
.help-demo { background: rgba(255,255,255,0.06); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 5px; }
.demo-row { display: flex; gap: 5px; justify-content: center; }
.demo-row span { width: 30px; height: 30px; border-radius: 7px; background: rgba(255,255,255,0.1); }
.demo-row span.lit { background: linear-gradient(145deg, #ffcf5c, #f59e0b); box-shadow: 0 0 12px rgba(255, 200, 80, 0.7); }
.demo-note { font-size: 13px; color: var(--ink-dim); font-weight: 700; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stats-grid > div { background: rgba(255,255,255,0.07); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.stats-grid span { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; font-weight: 800; }
.stats-grid strong { font-size: 24px; }
.row-btns { display: flex; gap: 10px; }
.row-btns .btn { flex: 1; }

.gameover-emoji { font-size: 52px; }
.final-row { display: flex; gap: 10px; }
.final-row > div { flex: 1; background: rgba(255,255,255,0.07); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; }
.final-row span { font-size: 12px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 1px; font-weight: 800; }
.final-row strong { font-size: 30px; }
.new-best { background: linear-gradient(90deg, #ffd166, #ff7a18); color: #3a1c00; font-weight: 900; border-radius: 12px; padding: 8px; animation: popin 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }

.theme-row { display: flex; gap: 10px; }
.theme-dot { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.theme-dot.on { border-color: #fff; }
.theme-night { background: linear-gradient(135deg, #131a33, #6c7bff); }
.theme-dawn { background: linear-gradient(135deg, #57255a, #ff8a5c); }
.theme-mint { background: linear-gradient(135deg, #0b3d3a, #34d399); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: rgba(10, 14, 30, 0.92); border: 1px solid var(--panel-border); color: var(--ink);
  padding: 10px 18px; border-radius: 999px; font-weight: 800; font-size: 14px;
  opacity: 0; transition: all 0.25s; z-index: 200; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .score-value { font-size: 30px; }
  .piece { grid-template-columns: repeat(var(--pc), calc(22px * var(--ps, 1))); grid-auto-rows: calc(22px * var(--ps, 1)); }
  .tray { min-height: 104px; }
}

@media (min-width: 700px) {
  .app { max-width: 600px; }
  .board-frame { width: min(60vh, 480px); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
