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

:root {
  --bg: #f5f5f5;
  --text: #1a1a1a;
  --text-dim: #777;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 8px;
  flex-shrink: 0;
}

.level-pill {
  background: #ffffff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  transition: transform 0.15s;
  font-family: var(--font);
}

.level-pill::after {
  content: ' ▾';
  color: var(--text-dim);
  font-size: 12px;
}

.level-pill:active { transform: scale(0.95); }

.hearts {
  display: flex;
  gap: 6px;
}

.heart {
  width: 28px;
  height: 28px;
  transition: transform 0.25s, opacity 0.25s;
}

.heart::before {
  content: '♥';
  font-size: 26px;
  color: #e53935;
}

.heart.lost { opacity: 0.2; transform: scale(0.85); }
.heart.lost::before { color: #ccc; }
.heart.pop { animation: heartPop 0.35s ease; }

@keyframes heartPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(0.85); opacity: 0.2; }
}

.game-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  min-height: 0;
}

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

.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 12px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 50;
  background: linear-gradient(to top, var(--bg) 62%, rgba(245, 245, 245, 0));
}

.btn-circle {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: #ffffff;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-circle:active { transform: scale(0.92); }

.hint-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #ff9800;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.btn-circle.depleted { opacity: 0.55; }
.btn-circle.depleted .hint-badge { background: #bbb; }

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #1a0f33 center / contain no-repeat;
  background-image: url('../assets/loading.png');
  transition: opacity 0.5s ease;
}

.loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(245, 245, 245, 0.94);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  padding: 20px;
}

.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: #ffffff;
  border-radius: 24px;
  padding: 36px 28px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.logo {
  font-size: 30px;
  font-weight: 800;
  margin-bottom: 12px;
  color: #1a1a1a;
}

.modal p {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.btn-play {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 16px;
  background: #1a1a1a;
  color: white;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s;
}

.btn-play:active { transform: scale(0.97); }

/* Branded start screen */
.overlay-start {
  background: #170a2e;
  backdrop-filter: none;
  padding: 0;
}

.start-art {
  position: relative;
  width: 100%;
  height: 100%;
  line-height: 0;
}

.start-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.start-play {
  position: absolute;
  left: 50%;
  top: 86.7%;
  transform: translate(-50%, -50%);
  width: 24%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: playPulse 1.6s ease-in-out infinite;
}

.start-play:active { transform: translate(-50%, -50%) scale(0.94); }

@keyframes playPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 200, 60, 0.0); }
  50% { box-shadow: 0 0 26px 6px rgba(255, 200, 60, 0.45); }
}

.win-title { font-size: 26px; color: #2e7d32; margin-bottom: 8px; }
.fail-title { font-size: 26px; color: #e53935; margin-bottom: 8px; }

.overlay-levels {
  background: rgba(245, 245, 245, 0.97);
}

.modal-levels {
  max-width: 400px;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  max-height: 82vh;
}

.levels-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.levels-title {
  font-size: 20px;
  font-weight: 800;
}

.btn-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #f0f0f0;
  font-size: 15px;
  cursor: pointer;
  color: var(--text-dim);
  transition: transform 0.15s;
}

.btn-close:active { transform: scale(0.9); }

.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  overflow-y: auto;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
}

.level-cell {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s;
}

.level-cell:active { transform: scale(0.92); }

.level-cell.current {
  background: #1a1a1a;
  color: #fff;
}

.level-cell.cleared {
  background: #e8f5e9;
  color: #2e7d32;
}

.level-cell.locked {
  background: #f0f0f0;
  color: #ccc;
  cursor: default;
  box-shadow: none;
}

@media (min-width: 481px) {
  #app {
    border-left: 1px solid rgba(0, 0, 0, 0.06);
    border-right: 1px solid rgba(0, 0, 0, 0.06);
  }
}
