:root {
  --bg: #edf2f7;
  --card: #ffffff;
  --accent: #598cb8;
  --accent-soft: #b8d1e6;
  --text: #2e3847;
  --muted: #73808c;
  --danger: #d95959;
  --success: #4da680;
  --daily: #738cc7;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(46, 56, 71, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
}

body {
  overscroll-behavior: none;
}

#app {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(24px + var(--safe-bottom));
  position: relative;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.hero {
  text-align: center;
  padding: 24px 8px 8px;
}

.logo-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), var(--daily));
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

h1 {
  margin: 0;
  font-size: 1.85rem;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0;
  font-size: 1.25rem;
}

h3 {
  margin: 0 0 6px;
}

.tagline,
.muted,
.hint,
.daily-meta {
  color: var(--muted);
  margin: 0;
}

.hint,
.daily-meta,
.small {
  font-size: 0.85rem;
  text-align: center;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent-soft);
  color: var(--text);
  transition: transform 0.08s ease, opacity 0.15s ease;
  min-height: 48px;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.secondary {
  background: #fff;
  box-shadow: var(--shadow);
}

.btn.ghost {
  background: transparent;
  color: var(--accent);
}

.btn.danger {
  background: #f8e0e0;
  color: var(--danger);
}

.btn.icon {
  width: 44px;
  min-width: 44px;
  padding: 0;
  background: #fff;
  box-shadow: var(--shadow);
  font-size: 1.2rem;
}

.nav-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.badge.ok {
  text-align: center;
  color: var(--success);
  font-weight: 600;
  margin: 0;
}

.play-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.scores {
  flex: 1;
  display: flex;
  gap: 8px;
}

.score-chip {
  background: #fff;
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.score-chip span {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
}

.score-chip strong {
  font-size: 1.1rem;
}

.mode-pill {
  background: var(--daily);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 6px 10px;
  border-radius: 999px;
  text-transform: uppercase;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  background: #dfe7f0;
  padding: 10px;
  border-radius: 20px;
  aspect-ratio: 1 / 1;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
  touch-action: manipulation;
  user-select: none;
}

.tile {
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.35);
  font-weight: 800;
  font-size: clamp(0.95rem, 4.2vw, 1.35rem);
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 0 rgba(46, 56, 71, 0.08);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  padding: 0;
  cursor: pointer;
}

.tile.empty {
  background: rgba(255, 255, 255, 0.35);
  box-shadow: none;
}

.tile.selected {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  transform: scale(1.04);
  z-index: 1;
}

.tile.merged {
  animation: pop 0.22s ease;
}

.tile.spawned {
  animation: spawn 0.25s ease;
}

@keyframes pop {
  0% {
    transform: scale(0.85);
  }
  60% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes spawn {
  from {
    opacity: 0;
    transform: scale(0.5);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.game-over {
  text-align: center;
  padding-top: 40px;
}

.big-score {
  font-size: 3rem;
  font-weight: 800;
  margin: 8px 0;
  letter-spacing: -0.03em;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.price {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.shop-msg {
  color: var(--success);
  margin: 0;
  font-weight: 600;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  padding: 14px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.toggle-row input {
  width: 22px;
  height: 22px;
}

.ad-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 40, 0.55);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 24px;
}

.ad-card {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  width: min(320px, 100%);
  box-shadow: var(--shadow);
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 12px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.ad-debug {
  font-size: 0.75rem;
}

@media (min-width: 480px) {
  .board {
    gap: 10px;
    padding: 12px;
  }
}
