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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #fff7ec;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #3a2a18;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#game {
  display: block;
  touch-action: none;
}

/* Overlay base */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.overlay > * { pointer-events: auto; }
.hidden { display: none !important; }

/* HUD */
#hud {
  align-items: flex-start;
  justify-content: stretch;
  flex-direction: column;
  pointer-events: none;
  padding-top: max(env(safe-area-inset-top), 12px);
}
#hud-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  gap: 12px;
}
#hud-score-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
#hud-score {
  font-size: 2.2rem;
  font-weight: 900;
  line-height: 1;
  color: #3a2a18;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}
#hud-best {
  font-size: 0.8rem;
  font-weight: 700;
  color: #8b6f4e;
  margin-top: 2px;
}
#hud-next {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid rgba(58, 42, 24, 0.1);
  border-radius: 14px;
  padding: 4px 10px 6px;
  pointer-events: none;
}
.hud-next-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #8b6f4e;
  text-transform: uppercase;
}
#hud-next-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e63946;
  border: 2px solid rgba(0,0,0,0.15);
  margin-top: 2px;
  transition: background 0.2s, border-color 0.2s;
  animation: pulse-next 1.6s ease-in-out infinite;
}
@keyframes pulse-next {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 2px solid rgba(58, 42, 24, 0.15);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.85);
  font-size: 1.1rem;
  cursor: pointer;
  pointer-events: auto;
  transition: transform 0.12s, background 0.12s;
}
.icon-btn:active { transform: scale(0.92); background: #fff; }

#hud-combo {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.8rem;
  font-weight: 900;
  color: #e94560;
  text-shadow: 0 2px 8px rgba(255, 255, 255, 0.6);
  pointer-events: none;
  animation: pop 0.5s ease-out;
}
@keyframes pop {
  0% { transform: translateX(-50%) scale(0.6); opacity: 0; }
  50% { transform: translateX(-50%) scale(1.2); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

#hud-mode-banner {
  position: absolute;
  top: 64px;
  right: 12px;
  background: rgba(233, 69, 96, 0.12);
  border: 1px solid rgba(233, 69, 96, 0.3);
  color: #c1335b;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
}

/* Title screen */
.title-content {
  text-align: center;
  background: rgba(255, 255, 255, 0.92);
  padding: 32px 28px;
  border-radius: 24px;
  box-shadow: 0 16px 50px rgba(58, 42, 24, 0.18);
  border: 2px solid rgba(58, 42, 24, 0.06);
  max-width: 360px;
  width: calc(100% - 32px);
}
.game-title {
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #e63946 0%, #2a9d8f 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}
.subtitle {
  font-size: 0.95rem;
  color: #8b6f4e;
  margin-bottom: 22px;
}
.primary-btn {
  display: block;
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #e63946, #f06292);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(230, 57, 70, 0.35);
  transition: transform 0.12s, box-shadow 0.12s;
  margin-bottom: 10px;
}
.primary-btn:active { transform: translateY(1px); box-shadow: 0 3px 10px rgba(230, 57, 70, 0.35); }
.secondary-btn {
  display: block;
  width: 100%;
  padding: 12px 18px;
  border: 2px solid rgba(58, 42, 24, 0.12);
  border-radius: 14px;
  background: #fff;
  color: #3a2a18;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s;
  margin-bottom: 10px;
}
.secondary-btn:active { transform: translateY(1px); background: #fdf2e3; }
.text-link {
  display: inline-block;
  margin-top: 4px;
  color: #8b6f4e;
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
}
.text-link:hover { color: #3a2a18; }

/* Game Over */
.gameover-content {
  text-align: center;
  background: rgba(255, 255, 255, 0.96);
  padding: 28px 24px;
  border-radius: 24px;
  box-shadow: 0 18px 50px rgba(58, 42, 24, 0.22);
  border: 2px solid rgba(58, 42, 24, 0.06);
  animation: slide-up 0.35s cubic-bezier(.2,.9,.2,1.15);
  max-width: 360px;
  width: calc(100% - 32px);
}
@keyframes slide-up {
  0% { transform: translateY(28px); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
#gameover-newbest {
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #d99e1f;
  margin-bottom: 4px;
}
#gameover-score {
  font-size: 3.4rem;
  font-weight: 900;
  line-height: 1;
  color: #3a2a18;
  margin-bottom: 6px;
}
#gameover-message {
  font-size: 1rem;
  color: #8b6f4e;
  margin-bottom: 4px;
}
#gameover-meta {
  font-size: 0.85rem;
  color: #b08e63;
  margin-bottom: 18px;
}

/* Toast */
#toast {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom), 24px);
  left: 50%;
  transform: translateX(-50%);
  background: rgba(58, 42, 24, 0.92);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 30;
  pointer-events: none;
  animation: fade-in-out 1.8s ease-out;
}
@keyframes fade-in-out {
  0%   { opacity: 0; transform: translate(-50%, 10px); }
  20%  { opacity: 1; transform: translate(-50%, 0); }
  80%  { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -6px); }
}

/* Bottom banner — persistent link back to PlayPuzzle */
#bottom-banner {
  position: absolute;
  bottom: max(env(safe-area-inset-bottom), 10px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(58, 42, 24, 0.12);
  border-radius: 999px;
  color: #3a2a18;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(58, 42, 24, 0.10);
  pointer-events: auto;
}
#bottom-banner:hover { background: #fff; }

/* Small screens */
@media (max-width: 380px) {
  .game-title { font-size: 2.2rem; }
  #hud-score { font-size: 1.8rem; }
  #gameover-score { font-size: 2.8rem; }
}
