/* Palette: off-white, sage, clay, oat, soft charcoal, fog */
:root {
  --bg: #F4F1EA;
  --board: #E9E4DA;
  --empty: #DFD9CD;
  --ink: #4A4744;
  --muted: #9C968D;
  --c1: #A3B09A; /* sage */
  --c2: #C99A82; /* clay */
  --c3: #D8C49C; /* oat */
  --c4: #7E7A75; /* soft charcoal */
  --c5: #A8B4B8; /* fog */

  /* Sizes are recalculated by game.js to fit the screen */
  --cell: 40px;
  --gap: 5px;
  --pad: 8px;
  --mini: 20px;
  --mgap: 3px;
  --bw: 360px;
  --r: calc(var(--cell) * 0.26);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", system-ui, sans-serif;
  font-weight: 300;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: calc(env(safe-area-inset-top) + 28px) 10px calc(env(safe-area-inset-bottom) + 10px);
}

header {
  width: var(--bw);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 0.06em;
}
.brand { letter-spacing: 0.32em; }
.best b { font-weight: 400; color: var(--ink); font-variant-numeric: tabular-nums; }

.scoreline { margin: 4.5vh 0 3.5vh; text-align: center; }
#score {
  font-size: 58px;
  font-weight: 200;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
#note {
  height: 18px;
  margin-top: 10px;
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--c2);
  opacity: 0;
  transition: opacity 0.5s ease;
}
#note.on { opacity: 1; }

/* ---------- Board ---------- */
#boardwrap { position: relative; }

#board {
  display: grid;
  grid-template-columns: repeat(var(--n), var(--cell));
  gap: var(--gap);
  padding: var(--pad);
  background: var(--board);
  border-radius: calc(var(--r) + var(--pad));
}

.cell, .b, .fxcell {
  width: var(--cell);
  height: var(--cell);
  border-radius: var(--r);
}
.cell { background: var(--empty); transition: background-color 0.18s ease, opacity 0.18s ease; }

.k1 { background: var(--c1) !important; }
.k2 { background: var(--c2) !important; }
.k3 { background: var(--c3) !important; }
.k4 { background: var(--c4) !important; }
.k5 { background: var(--c5) !important; }

.k1, .k2, .k3, .k4, .k5 { box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.06); }

.cell.ghost { opacity: 0.45; }
.cell.hint { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45); }

.cell.pop { animation: pop 0.34s cubic-bezier(0.3, 1.5, 0.5, 1); }
@keyframes pop {
  from { transform: scale(0.7); }
  to   { transform: scale(1); }
}

/* Cleared blocks float away on a separate layer */
#fx { position: absolute; inset: 0; pointer-events: none; }
.fxcell {
  position: absolute;
  animation: vanish 0.5s ease-in forwards;
}
@keyframes vanish {
  0%   { transform: scale(1); opacity: 1; }
  35%  { transform: scale(1.08); opacity: 1; filter: brightness(1.08); }
  100% { transform: scale(0.15); opacity: 0; }
}
.float {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 22px;
  font-weight: 300;
  color: var(--ink);
  animation: rise 1s ease-out forwards;
  white-space: nowrap;
}
@keyframes rise {
  0%   { opacity: 0; transform: translate(-50%, -20%); }
  20%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -150%); }
}

/* ---------- Game over ---------- */
#over {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: calc(var(--r) + var(--pad));
  background: rgba(244, 241, 234, 0.82);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fadein 0.6s ease;
}
#over[hidden] { display: none; }
.over-title { font-size: 15px; letter-spacing: 0.14em; color: var(--muted); }
#final { font-size: 52px; font-weight: 200; line-height: 1.1; }
#overbest { font-size: 13px; letter-spacing: 0.1em; color: var(--c2); min-height: 16px; }
#again {
  margin-top: 14px;
  padding: 12px 28px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 15px;
  letter-spacing: 0.06em;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Tray ---------- */
#tray {
  width: var(--bw);
  display: flex;
  margin-top: 4.5vh;
}
.slot {
  flex: 1;
  height: calc(var(--mini) * 5 + var(--mgap) * 4 + 16px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.mini {
  display: grid;
  gap: var(--mgap);
  transition: opacity 0.3s ease, transform 0.3s ease;
  animation: arrive 0.4s cubic-bezier(0.3, 1.3, 0.5, 1) backwards;
}
.mini .b { width: var(--mini); height: var(--mini); border-radius: calc(var(--mini) * 0.26); }
.slot.nofit .mini { opacity: 0.3; }
.slot.lifted .mini { visibility: hidden; }
@keyframes arrive {
  from { opacity: 0; transform: translateY(10px) scale(0.9); }
  to   { opacity: 1; transform: none; }
}

/* The piece following your finger */
.drag {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 10;
  pointer-events: none;
  will-change: transform;
}
.drag-inner {
  display: grid;
  gap: var(--gap);
  animation: grow 0.16s ease-out;
  filter: drop-shadow(0 6px 10px rgba(74, 71, 68, 0.14));
}
.drag.back { transition: transform 0.22s ease; }
@keyframes grow { from { transform: scale(0.6); } to { transform: scale(1); } }

#restart {
  margin-top: auto;
  padding: 10px 16px;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--muted);
}

/* ---------- Landscape fallback ---------- */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--muted);
  letter-spacing: 0.1em;
  z-index: 20;
}
@media (orientation: landscape) and (max-height: 520px) {
  #rotate { display: flex; }
}
