:root {
  --bg-1: #fff8cc;
  --bg-2: #d9f7ff;
  --ink: #1f2a44;
  --card: #ffffff;
  --start: #22c55e;
  --reset: #ef4444;
  --good: #16a34a;
  --bad: #dc2626;
  --animal-size: clamp(88px, 12vw, 150px);
  --animal-font-size: clamp(2.6rem, 6vw, 5rem);
  --vv-top: 0px;
  --vv-bottom: 0px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: "Nunito", "Trebuchet MS", "Comic Sans MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, var(--bg-1), var(--bg-2));
}

body {
  overflow-x: hidden;
  overflow-y: auto;
}

.game-shell {
  width: 100vw;
  min-height: 100svh;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(1rem, env(safe-area-inset-top), var(--vv-top))
    max(0.8rem, env(safe-area-inset-right))
    max(0.8rem, env(safe-area-inset-bottom), var(--vv-bottom))
    max(0.8rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--card) 88%, transparent);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.top-bar {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  letter-spacing: 0.4px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-left: auto;
}

.actions-group {
  display: flex;
  gap: 0.55rem;
  align-items: center;
}

.btn {
  border: 0;
  color: white;
  padding: 0.9rem 1.35rem;
  font-family: "Nunito", "Trebuchet MS", "Comic Sans MS", sans-serif;
  font-size: clamp(1rem, 2.2vw, 1.3rem);
  font-weight: 800;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .25);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
  min-height: 56px;
  box-shadow: 0 4px var(--btn-shadow, #334155), 0 0 0 0.5em #fff;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px) scale(1.01);
  filter: brightness(1.05);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 2px var(--btn-shadow, #334155), 0 0 0 0.5em #fff;
}

.btn-start {
  background: var(--start);
  --btn-shadow: #2d8f39;
}

.btn-reset {
  background: var(--reset);
  --btn-shadow: #b4232d;
}

.parent-btn {
  border: 0;
  background: #f59e0b;
  color: #fff;
  border-radius: 14px;
  padding: 0.9rem 1.35rem;
  font-family: "Nunito", "Trebuchet MS", "Comic Sans MS", sans-serif;
  font-weight: 800;
  font-size: clamp(1rem, 2.2vw, 1.3rem);
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .25);
  min-height: 56px;
  cursor: pointer;
  box-shadow: 0 4px #b45309, 0 0 0 0.5em #fff;
  white-space: nowrap;
}

.parent-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px #b45309, 0 0 0 0.5em #fff;
}

.parent-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.settings-panel {
  background: #fff;
  border: 2px solid #dbeafe;
  border-radius: 16px;
  padding: 0.55rem 0.7rem 0.75rem;
  box-shadow: 0 8px 18px rgb(0 0 0 / 0.1);
}

.settings-panel[hidden] {
  display: none;
}

.settings-title {
  margin: 0;
  font-weight: 900;
  color: #1e3a8a;
}

.settings-note {
  margin: 0.1rem 0 0.45rem;
  font-size: 0.9rem;
  color: #334155;
  font-weight: 700;
}

.settings-step {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
  color: #0f172a;
  font-weight: 900;
}

.settings-modes {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.diff-btn {
  border: 2px solid #cbd5e1;
  background: #fff;
  color: #0f172a;
  border-radius: 14px;
  padding: 0.9rem 1.35rem;
  font-family: "Nunito", "Trebuchet MS", "Comic Sans MS", sans-serif;
  font-weight: 800;
  font-size: clamp(1rem, 2.2vw, 1.3rem);
  text-shadow: 1px 1px 1px rgba(0, 0, 0, .25);
  cursor: pointer;
  min-height: 56px;
  box-shadow: 0 4px #8da1b8, 0 0 0 0.5em #fff;
  white-space: nowrap;
}

.diff-btn.is-active {
  border-color: #1d4ed8;
  background: #dbeafe;
  box-shadow: 0 4px #1e40af, 0 0 0 0.5em #fff;
}

.diff-btn[data-mode="toddler"] {
  border-color: #86efac;
  background: #dcfce7;
  color: #14532d;
  box-shadow: 0 4px #15803d, 0 0 0 0.5em #fff;
}

.diff-btn[data-mode="easy"] {
  border-color: #fde047;
  background: #fef9c3;
  color: #713f12;
  box-shadow: 0 4px #ca8a04, 0 0 0 0.5em #fff;
}

.diff-btn[data-mode="fast"] {
  border-color: #fca5a5;
  background: #fee2e2;
  color: #7f1d1d;
  box-shadow: 0 4px #dc2626, 0 0 0 0.5em #fff;
}

.diff-btn[data-mode="toddler"].is-active {
  border-color: #22c55e;
  background: #bbf7d0;
  box-shadow: 0 4px #166534, 0 0 0 0.5em #fff;
}

.diff-btn[data-mode="easy"].is-active {
  border-color: #eab308;
  background: #fde68a;
  box-shadow: 0 4px #a16207, 0 0 0 0.5em #fff;
}

.diff-btn[data-mode="fast"].is-active {
  border-color: #ef4444;
  background: #fecaca;
  box-shadow: 0 4px #991b1b, 0 0 0 0.5em #fff;
}

.diff-btn:hover {
  transform: translateY(-1px) scale(1.01);
}

.diff-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px #8da1b8, 0 0 0 0.5em #fff;
}

.diff-btn.is-active:active {
  box-shadow: 0 2px #1e40af, 0 0 0 0.5em #fff;
}

.mode-hint {
  margin: 0.55rem 0 0;
  padding: 0.45rem 0.6rem;
  border-radius: 12px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 0.92rem;
  font-weight: 800;
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin: 0.5rem 0;
}

.stat-card {
  margin: 0;
  background: #f3f4f6;
  border-radius: 16px;
  padding: 0.65rem 0.75rem;
  text-align: center;
  /*border: 2px solid #e5e7eb;*/
  box-shadow: 0 4px #b6c3d1, 0 0 0 0.5em #fff;
}

.stat-icon {
  display: block;
  font-size: clamp(1.5rem, 2.9vw, 2.2rem);
  line-height: 1.1;
}

.stat-title {
  margin: 0.2rem 0 0;
  font-size: clamp(0.85rem, 1.8vw, 1.05rem);
  color: #334155;
  font-weight: 800;
}

.stat-value {
  margin: 0.2rem 0 0;
  font-size: clamp(1.65rem, 4vw, 2.6rem);
  line-height: 1;
  font-weight: 900;
}

.target-card {
  background: linear-gradient(180deg, #fff9db, #ffe9a8);
  box-shadow: 0 4px #b8860b, 0 0 0 0.5em #fff;
}

.target-label {
  margin: 0.2rem 0 0;
  font-size: clamp(0.95rem, 2vw, 1.15rem);
  font-weight: 900;
  color: #7c2d12;
}

.target-emoji {
  margin: 0.15rem 0 0;
  font-size: clamp(1.65rem, 4vw, 2.6rem);
  line-height: 1.1;
  font-weight: 900;
}

.play-area {
  position: relative;
  flex: 1 1 auto;
  border-radius: 16px;
  overflow: hidden;
  border: 3px dashed #67c8ff;
  background: linear-gradient(180deg, #c8efff, #e8ffd1);
  min-height: 220px;
  height: 100%;
  touch-action: manipulation;
}

.animal {
  position: absolute;
  width: var(--animal-size);
  height: var(--animal-size);
  display: grid;
  place-items: center;
  font-size: var(--animal-font-size);
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: rgb(255 255 255 / 0.95);
  box-shadow: 0 8px 14px rgb(0 0 0 / 0.12);
  animation: pop-in 170ms ease-out, floaty 1.9s ease-in-out infinite alternate;
  user-select: none;
}

.animal.newborn {
  box-shadow: 0 0 0 5px rgb(59 130 246 / 0.2), 0 8px 14px rgb(0 0 0 / 0.12);
}

.animal.fade-out {
  animation: fade-away 210ms ease-in forwards;
}

.message {
  margin: 0;
  text-align: center;
  font-weight: 700;
  font-size: clamp(1.05rem, 2.2vw, 1.35rem);
}

.message.good {
  color: var(--good);
}

.message.bad {
  color: var(--bad);
}

.shake {
  animation: shake 220ms linear;
}

@keyframes pop-in {
  from {
    transform: scale(0.2);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes fade-away {
  from {
    transform: scale(1);
    opacity: 1;
  }
  to {
    transform: scale(0.1);
    opacity: 0;
  }
}

@keyframes floaty {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-4px);
  }
}

@keyframes shake {
  0% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(7px);
  }
  50% {
    transform: translateX(-7px);
  }
  75% {
    transform: translateX(5px);
  }
  100% {
    transform: translateX(0);
  }
}

@media (max-width: 900px) {
  .top-bar {
    align-items: flex-start;
  }

  .controls {
    width: auto;
    margin-left: auto;
  }

  .settings-modes .diff-btn {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 640px) {
  :root {
    --animal-size: clamp(96px, 24vw, 140px);
    --animal-font-size: clamp(3rem, 11vw, 4.5rem);
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .play-area {
    min-height: 180px;
  }

  .top-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.6rem;
  }

  .controls {
    margin-left: 0;
    justify-content: space-between;
  }

  .actions-group {
    flex: 1;
  }

  .actions-group .btn {
    flex: 1;
    min-width: 0;
  }

  .parent-btn {
    min-width: 110px;
  }
}
