* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --board-size: min(92vw, 440px);
  --gap: calc(var(--board-size) * 0.014);
  --cell: calc((var(--board-size) - 10 * var(--gap)) / 9);
  --row-h: calc(var(--cell) + var(--gap));
  --radius: calc(var(--board-size) * 0.03);
  --bg1: #0f0c1d;
  --bg2: #1b1035;
  --text: #f2eefc;
  --muted: #9b93b8;
  --board-bg: #241b3f;
  --tile-bg: #efe7db;
  --accent: #ffb347;
}

html, body { height: 100%; }

body {
  font-family: 'Outfit', system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 800px at 80% -10%, #3b1e6d 0%, transparent 55%),
              radial-gradient(900px 700px at -10% 100%, #16324f 0%, transparent 55%),
              linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
  display: flex;
  justify-content: center;
  overscroll-behavior: none;
}

.page {
  width: var(--board-size);
  padding: clamp(12px, 2.5vh, 32px) 0 24px;
  display: flex;
  flex-direction: column;
}

.title-row { display: flex; align-items: center; gap: 12px; }

.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 1.4rem;
  line-height: 1;
  padding: 6px 10px 8px;
  border-radius: 10px;
  transition: background 0.15s, color 0.15s;
}
.back:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }

h1 {
  font-size: clamp(1.3rem, 5.4vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, #ffb347, #ff5e8a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-right: auto;
  white-space: nowrap;
}

.scores { display: flex; gap: 8px; }

.score-box {
  position: relative;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 5px 12px;
  text-align: center;
  min-width: 64px;
}
.score-box .label {
  display: block;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.score-box .value { font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.score-bump {
  position: absolute;
  right: 6px;
  top: 2px;
  font-weight: 800;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
}
.score-bump.animate { animation: floatUp 0.6s ease-out; }
@keyframes floatUp {
  0%   { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-24px); }
}

.diff-row {
  display: flex;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 3px;
  margin: 12px 0;
}
.diff-row button {
  flex: 1;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 9px;
  padding: 7px 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.diff-row button.active {
  background: linear-gradient(135deg, #ffb347, #ff5e8a);
  color: #2b1230;
}

.board {
  position: relative;
  background: var(--board-bg);
  border-radius: var(--radius);
  padding: var(--gap);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  user-select: none;
  -webkit-user-select: none;
}

.board-scroll {
  max-height: min(58vh, calc(12 * var(--row-h)));
  min-height: calc(5 * var(--row-h));
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}

.row {
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  gap: var(--gap);
  max-height: var(--row-h);
  padding-bottom: var(--gap);
  transition: max-height 0.28s ease, opacity 0.28s ease, padding-bottom 0.28s ease;
  overflow: hidden;
}
.row.removing { max-height: 0; opacity: 0; padding-bottom: 0; }

.cell {
  height: var(--cell);
  border-radius: calc(var(--radius) * 0.5);
  background: var(--tile-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: calc(var(--cell) * 0.66);
  color: #3f3557;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s, background 0.2s, opacity 0.2s;
}
.cell:active { transform: scale(0.92); }

.cell.cleared {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(242, 238, 252, 0.22);
  text-decoration: line-through;
  cursor: default;
}
.cell.cleared:active { transform: none; }

.cell.sel {
  box-shadow: 0 0 0 3px var(--accent), 0 0 16px rgba(255, 179, 71, 0.5);
  transform: scale(1.06);
}

.cell.hinted { animation: hintPulse 0.9s ease infinite; }
@keyframes hintPulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(160, 107, 255, 0.9), 0 0 14px rgba(160, 107, 255, 0.5); }
  50%      { box-shadow: 0 0 0 2px rgba(160, 107, 255, 0.3), 0 0 4px rgba(160, 107, 255, 0.2); }
}

.cell.clearing { animation: zap 0.26s ease forwards; }
@keyframes zap {
  0%   { transform: scale(1.06); }
  55%  { transform: scale(1.2); box-shadow: 0 0 22px rgba(255, 179, 71, 0.9); }
  100% { transform: scale(1); box-shadow: none; }
}

.cell.spawn { animation: spawnIn 0.24s ease backwards; }
@keyframes spawnIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.cell.shake { animation: shake 0.3s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-3px); }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  border-radius: var(--radius);
  background: rgba(15, 12, 29, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s;
}
.overlay.show { opacity: 1; visibility: visible; }
.overlay.auto #overlay-restart { display: none; }

.combo {
  position: absolute;
  top: -12px;
  right: 12px;
  z-index: 5;
  background: linear-gradient(135deg, #ffb347, #ff5e8a);
  color: #2b1230;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 4px 12px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(255, 94, 138, 0.4);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.combo.show { opacity: 1; transform: scale(1); }
.overlay h2 { font-size: 1.7rem; font-weight: 800; text-align: center; padding: 0 16px; }
.overlay p { color: var(--muted); margin-bottom: 8px; }

.actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.actions button { flex: 1; }

button {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  padding: 10px 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  touch-action: manipulation;
  white-space: nowrap;
}
button:hover { background: rgba(255, 255, 255, 0.18); }
button:active { transform: scale(0.96); }
button:disabled { opacity: 0.35; cursor: default; }

#add.pulse { animation: addPulse 1s ease infinite; }
@keyframes addPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 179, 71, 0.7); }
  60%      { box-shadow: 0 0 0 8px rgba(255, 179, 71, 0); }
}

#new-game, #overlay-restart {
  background: linear-gradient(135deg, #ffb347, #ff5e8a);
  border: none;
  color: #2b1230;
}
#new-game:hover, #overlay-restart:hover { filter: brightness(1.1); }
#overlay-restart { padding: 10px 26px; flex: none; }

.hint-text {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
  text-align: center;
  margin-top: 14px;
}
