:root {
  --board: #26232d;
  --board-edge: #15131a;
  --hole: #34303d;
  --boardW: min(calc(100vw - 32px), 460px, calc(100dvh - 290px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
}
body {
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}

.app {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: calc(env(safe-area-inset-top) + 14px) 16px calc(env(safe-area-inset-bottom) + 16px);
}

/* Header */
.top { width: var(--boardW); display: flex; align-items: center; gap: 8px; }
.brand { font-weight: 800; font-size: 24px; letter-spacing: -0.03em; margin-right: auto; white-space: nowrap; }
.brand span { font-weight: 500; font-size: 14px; color: var(--muted); letter-spacing: 0; }
.brand a { color: inherit; text-decoration: none; }
.mode { font-size: 13px; font-weight: 700; color: var(--muted); text-align: center; white-space: nowrap; }

.scores { margin-top: auto; width: var(--boardW); display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; }
.score label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.score output { display: block; font-size: 44px; font-weight: 800; line-height: 1; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.score.best { text-align: right; }
.score.best output { font-size: 26px; color: var(--muted); }
.combo { font-weight: 800; font-size: 18px; color: var(--c1); padding-bottom: 4px; }

/* Board */
.board-wrap { position: relative; width: var(--boardW); aspect-ratio: 1; flex: none; }
.board {
  position: absolute; inset: 0; padding: 2.2%;
  background: var(--board); border-radius: 18px;
  box-shadow: 0 6px 0 var(--board-edge), 0 18px 30px rgba(31, 29, 36, 0.18);
}
.grid { display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); gap: 3px; width: 100%; height: 100%; }
.cell { position: relative; border-radius: 6px; background: var(--hole); }
.cell.nxt::after {
  content: ''; position: absolute; inset: 26%; border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.5);
}

/* Buddy */
.buddy { position: absolute; left: 0; top: 0; z-index: 5; pointer-events: none; transition: transform 0.3s cubic-bezier(0.3, 1.4, 0.5, 1); }
.buddy .face {
  position: absolute; inset: 7%; border-radius: 50%; overflow: hidden;
  background: #fff; box-shadow: 0 0 0 3px #fff, 0 4px 0 3px rgba(0, 0, 0, 0.35);
  display: grid; place-items: center;
}
.buddy img { display: none; width: 100%; height: 100%; object-fit: cover; }
.buddy.has-photo img { display: block; }
.buddy.has-photo .eyes { display: none; }
.buddy .eyes { display: flex; gap: 22%; width: 60%; justify-content: center; }
.buddy .eyes i { width: 18%; aspect-ratio: 1; border-radius: 50%; background: var(--ink); }
.buddy.hot .face { box-shadow: 0 0 0 3px var(--c2), 0 0 14px 4px rgba(255, 190, 46, 0.8); }
.buddy.hop .face { animation: hop 0.34s ease-out; }
@keyframes hop { 0% { transform: scale(1); } 45% { transform: scale(1.2) translateY(-14%); } 100% { transform: scale(1); } }
.buddy-tip {
  position: absolute; left: 4%; right: 4%; bottom: 4%; z-index: 6; pointer-events: none;
  background: rgba(244, 239, 230, 0.94); color: var(--ink); border-radius: 12px;
  padding: 8px 12px; font-size: 14px; font-weight: 600; line-height: 1.3; text-align: center;
}
body:has(.piece.drag) .buddy-tip { display: none; }

.c1 { --cc: var(--c1); } .c2 { --cc: var(--c2); } .c3 { --cc: var(--c3); } .c4 { --cc: var(--c4); }
.c5 { --cc: var(--c5); } .c6 { --cc: var(--c6); } .c7 { --cc: var(--c7); }

.cell.f, .piece i {
  background: var(--cc);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.2), inset 0 3px 0 rgba(255, 255, 255, 0.3);
}
.cell.ghost { background: var(--cc); opacity: 0.42; }
.cell.hot { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.85); filter: brightness(1.12); }
.cell.ghost.hot { opacity: 0.75; }
.cell.pop { animation: pop 0.2s ease-out; }
.cell.clearing { animation: clear 0.32s ease-in forwards; }
@keyframes pop { 0% { transform: scale(0.82); } 70% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes clear { 0% { transform: scale(1); filter: brightness(1.6); } 100% { transform: scale(0.15) rotate(20deg); opacity: 0; } }

/* Tray */
.tray {
  width: var(--boardW); flex: none;
  height: calc(var(--boardW) * 0.38);
  margin-bottom: auto;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.slot { position: relative; display: grid; place-items: center; touch-action: none; cursor: grab; border-radius: 14px; }
.slot.empty { cursor: default; }
.slot.nofit .piece { opacity: 0.25; filter: grayscale(0.6); }
.slot.lifted .piece { visibility: hidden; }
.piece { position: relative; pointer-events: none; }
.piece i { position: absolute; border-radius: 4px; }
.piece.drag { position: fixed; left: 0; top: 0; z-index: 50; filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.3)); }
.piece.drag i { border-radius: 6px; }

.float-pts {
  position: fixed; z-index: 40; pointer-events: none; transform: translate(-50%, -50%);
  font-weight: 800; font-size: 26px; color: #fff;
  text-shadow: 0 2px 0 var(--ink), 0 0 10px rgba(0, 0, 0, 0.4);
  animation: rise 0.9s ease-out forwards;
}
@keyframes rise { 0% { opacity: 0; margin-top: 8px; } 20% { opacity: 1; } 100% { opacity: 0; margin-top: -40px; } }

/* Cheer */
.cheer { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; pointer-events: none; }
.cheer-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 78%; }
.cheer.show .cheer-inner { animation: cheer var(--cheer-ms, 2000ms) ease-out both; }
@keyframes cheer {
  0% { transform: scale(0.5) rotate(-6deg); opacity: 0; }
  10% { transform: scale(1.06) rotate(1deg); opacity: 1; }
  16% { transform: scale(1) rotate(0); }
  84% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.96) translateY(-14px); opacity: 0; }
}
.cheer-title {
  font-weight: 800; font-size: clamp(30px, 9vw, 48px); letter-spacing: -0.03em; line-height: 1;
  color: #fff; text-align: center;
  text-shadow: 0 3px 0 var(--ink), 0 0 18px rgba(0, 0, 0, 0.45);
}
.cheer-card {
  margin: 0; background: #fff; padding: 8px 8px 10px; border-radius: 12px; transform: rotate(-2.5deg);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.4);
  max-width: 100%;
}
.cheer-card img { display: block; width: 100%; max-height: calc(var(--boardW) * 0.55); object-fit: cover; border-radius: 6px; }
.cheer-card figcaption { margin-top: 8px; text-align: center; font-weight: 700; font-size: 17px; color: var(--ink); }

#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 60; }

.over-photo { margin: 14px auto 0; background: #fff; padding: 8px 8px 10px; border-radius: 12px; transform: rotate(-2deg); max-width: 78%; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2); }
.over-photo img { display: block; width: 100%; max-height: 40dvh; object-fit: cover; border-radius: 6px; }
.over-photo figcaption { margin-top: 8px; font-weight: 700; }
.over-scores { display: grid; grid-template-columns: 1fr 1fr; margin: 18px 0; }
.over-scores label { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.over-scores b { font-size: 36px; font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  .cell.pop, .cell.clearing, .float-pts { animation-duration: 0.01ms; }
}

.mid { display: flex; flex-direction: column; align-items: center; gap: 2px; padding-bottom: 4px; }
.brand span a { color: var(--muted); }
.buddy.nap .face { filter: saturate(0.5) brightness(0.85); }
.buddy.nap::after {
  content: 'z'; position: absolute; right: -4%; top: -10%;
  font-weight: 800; font-size: 16px; color: #fff; text-shadow: 0 1px 0 var(--ink);
}

/* Treats */
.cell.treat::after {
  content: ''; position: absolute; inset: 22%; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #7a4a26 0 9%, transparent 10%),
              radial-gradient(circle at 65% 45%, #7a4a26 0 9%, transparent 10%),
              radial-gradient(circle at 45% 70%, #7a4a26 0 9%, transparent 10%),
              #e0a85c;
  box-shadow: 0 0 0 2px #fff6, 0 0 12px 2px rgba(255, 190, 46, 0.55);
  animation: treat-in 0.35s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.cell.treat.low::after { animation: treat-blink 0.8s ease-in-out infinite; }
@keyframes treat-in { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes treat-blink { 50% { opacity: 0.35; } }
.buddy.charged .face { box-shadow: 0 0 0 3px var(--c2), 0 0 16px 6px rgba(255, 190, 46, 0.9); animation: charged 1.2s ease-in-out infinite; }
@keyframes charged { 50% { box-shadow: 0 0 0 3px var(--c2), 0 0 6px 2px rgba(255, 190, 46, 0.5); } }
.float-note { font-size: 20px; white-space: nowrap; animation-duration: 1.4s; }

/* Daily + share */
.daily-box { margin-top: 16px; padding-top: 14px; border-top: 2px solid var(--paper-2); }
.daily-box .hint { margin-bottom: 0; }
.over-share { margin-top: 10px; }
.share-text { width: 100%; margin-top: 10px; font: inherit; font-size: 15px; padding: 8px; border-radius: 8px; border: 2px solid var(--paper-2); -webkit-user-select: text; user-select: text; resize: none; }
