* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: "Nunito", "Avenir Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #fefae0 0%, #cdeefd 100%);
  color: #264653;
  touch-action: manipulation;
}

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: calc(64px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

header button {
  width: 48px;
  height: 48px;
  border: none;
  background: transparent;
  font-size: 28px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
header button:active {
  background: rgba(0, 0, 0, 0.08);
  transform: scale(0.9);
}

#total {
  font-weight: 900;
  font-size: 22px;
  letter-spacing: 0.5px;
  color: #2a9d8f;
}

#playfield {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top, 0px));
  left: 0;
  right: 0;
  bottom: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.group {
  position: absolute;
  top: 0;
  left: 0;
  transform: translate(var(--x, 0px), var(--y, 0px));
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  touch-action: none;
  will-change: transform;
}

.group.dragging {
  transition: none;
  z-index: 1000;
  cursor: grabbing;
}

.group-inner {
  position: relative;
  display: inline-block;
  transform-origin: top left;
}

.group.bounce .group-inner {
  animation: bounce 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bounce {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.08); }
}

.group.appear .group-inner {
  animation: appear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes appear {
  0% { transform: scale(0.3); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.blocks {
  display: grid;
  gap: 0;
  position: relative;
}

.block {
  width: var(--block, 48px);
  height: var(--block, 48px);
  background: var(--color);
  border: 3px solid rgba(0, 0, 0, 0.18);
  border-radius: 7px;
  position: relative;
  box-shadow:
    inset 0 -6px 0 rgba(0, 0, 0, 0.15),
    inset 0 4px 0 rgba(255, 255, 255, 0.25),
    0 2px 4px rgba(0, 0, 0, 0.12);
}

.block .face {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}
.block.head .face { display: block; }

.block.head::after {
  content: attr(data-count);
  position: absolute;
  top: -14px;
  right: -14px;
  background: white;
  color: var(--color);
  border: 3px solid var(--color);
  border-radius: 999px;
  min-width: 36px;
  height: 36px;
  font-size: 20px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  z-index: 6;
  pointer-events: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  font-family: "Comic Sans MS", "Marker Felt", system-ui;
}

.markers {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 4;
}

.marker {
  position: absolute;
  left: 0;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
}
.marker::before {
  content: "";
  position: absolute;
  left: -6px;
  right: -6px;
  top: 50%;
  height: 0;
  border-top: 3px dashed rgba(0, 0, 0, 0.45);
  opacity: 0.7;
}
.marker span {
  position: relative;
  background: white;
  border: 2px solid rgba(0, 0, 0, 0.45);
  border-radius: 999px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s;
  z-index: 1;
}
.marker:active span { transform: scale(1.3); background: #fff3a0; }

.shape-btn {
  position: absolute;
  top: -22px;
  left: -22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--color, #2a9d8f);
  background: white;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18);
  z-index: 7;
  touch-action: none;
}
.shape-btn:active {
  transform: scale(0.9);
  background: #fff3a0;
}

/* tooltip-style hint */
.hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(38, 70, 83, 0.92);
  color: white;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
  z-index: 20;
}
.hint.show { opacity: 1; }
