:root {
  --sky-top: #7ec8e3;
  --sky-mid: #b8e4c9;
  --sky-bottom: #f0d58a;
  --ink: #1f2a24;
  --ink-soft: #3d4f44;
  --panel: rgba(255, 252, 245, 0.92);
  --right: #2f9e6b;
  --right-dark: #217a52;
  --wrong: #d45b4a;
  --wrong-dark: #b04436;
  --primary: #e8a317;
  --primary-dark: #c4880f;
  --shadow: 0 12px 32px rgba(31, 42, 36, 0.18);
  --radius: 28px;
  --font: "Fredoka", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  min-height: 100dvh;
  overflow-x: hidden;
  overscroll-behavior: none;
}

.sky {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 255, 255, 0.45), transparent 28%),
    radial-gradient(circle at 82% 12%, rgba(255, 255, 255, 0.35), transparent 22%),
    linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 48%, var(--sky-bottom) 100%);
  z-index: -1;
}

.app {
  width: min(520px, 100%);
  margin: 0 auto;
  padding:
    max(1.25rem, env(safe-area-inset-top))
    max(1.25rem, env(safe-area-inset-right))
    max(2.5rem, env(safe-area-inset-bottom))
    max(1.25rem, env(safe-area-inset-left));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-wide {
  width: min(720px, 100%);
}

.top-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.brand {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.home-link {
  color: inherit;
  text-decoration: none;
}

.home-link:hover {
  text-decoration: underline;
}

.brand-sep {
  margin: 0 0.25rem;
  opacity: 0.55;
}

.score {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-soft);
  transition: transform 0.2s ease;
}

.score.bump {
  transform: scale(1.12);
  color: var(--right-dark);
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1rem;
  animation: fade-in 0.35s ease;
}

.screen[hidden] {
  display: none;
}

.title {
  margin: 0;
  font-size: clamp(2.2rem, 8vw, 3rem);
  line-height: 1.05;
  font-weight: 700;
}

.subtitle {
  margin: 0;
  max-width: 28ch;
  font-size: 1.1rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.card {
  width: 100%;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem 1.25rem 1.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.item-stage {
  width: min(260px, 70vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.9), rgba(232, 214, 160, 0.55));
  overflow: hidden;
}

.item-image {
  width: 88%;
  height: 88%;
  object-fit: contain;
  animation: pop-in 0.4s cubic-bezier(0.22, 1.4, 0.36, 1);
}

.item-image.refresh {
  animation: none;
}

.prompt {
  margin: 0.35rem 0 0;
  font-size: 1rem;
  color: var(--ink-soft);
}

.guess-name {
  margin: 0;
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  font-weight: 700;
  line-height: 1.1;
}

.feedback {
  min-height: 1.5rem;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.feedback.correct {
  color: var(--right-dark);
}

.feedback.incorrect {
  color: var(--wrong-dark);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  width: 100%;
  margin-top: 0.35rem;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1.2rem;
  font-weight: 700;
  padding: 0.95rem 1.25rem;
  cursor: pointer;
  color: #fff;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.btn-primary {
  background: linear-gradient(180deg, #f0b42c, var(--primary));
  color: #2a2208;
  min-width: 10rem;
  margin-top: 0.75rem;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-secondary {
  background: linear-gradient(180deg, #8aa0b0, #6d8294);
  color: #fff;
  min-width: 10rem;
  margin-top: 0.65rem;
}

.btn-secondary:active {
  background: #5a6f80;
}

.category-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-top: 0.5rem;
}

.category-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  appearance: none;
  border: none;
  text-align: left;
  font-family: inherit;
  color: inherit;
  cursor: pointer;
  background: var(--panel);
  border-radius: 24px;
  padding: 0.95rem 1.1rem;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.category-card:active {
  transform: translateY(3px);
  box-shadow: 0 6px 16px rgba(31, 42, 36, 0.14);
}

.category-card img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  flex: 0 0 auto;
}

.category-card-title {
  font-size: 1.35rem;
  font-weight: 700;
}

.btn-right {
  background: linear-gradient(180deg, #3cbc7f, var(--right));
}

.btn-right:active {
  background: var(--right-dark);
}

.btn-wrong {
  background: linear-gradient(180deg, #e97262, var(--wrong));
}

.btn-wrong:active {
  background: var(--wrong-dark);
}

.progress {
  margin: 0.5rem 0 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.final-score {
  margin: 0;
  font-size: clamp(2rem, 8vw, 2.8rem);
  font-weight: 700;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.board {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  padding: 0.25rem 0 1rem;
}

.memory-card {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  aspect-ratio: 1;
  perspective: 800px;
  cursor: pointer;
  font-family: inherit;
}

.memory-card:disabled {
  cursor: default;
}

.memory-card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
}

.memory-card.is-flipped .memory-card-inner,
.memory-card.is-matched .memory-card-inner {
  transform: rotateY(180deg);
}

.memory-card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 18px;
  backface-visibility: hidden;
  box-shadow: var(--shadow);
}

.memory-card-back {
  background: linear-gradient(160deg, #3cbc7f, #2f9e6b);
  color: #fff;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 700;
}

.memory-card-front {
  background: var(--panel);
  transform: rotateY(180deg);
}

.memory-card-front img {
  width: 78%;
  height: 78%;
  object-fit: contain;
}

.memory-card.is-matched .memory-card-front {
  box-shadow: 0 0 0 3px rgba(47, 158, 107, 0.55), var(--shadow);
}

.memory-card:active:not(:disabled) .memory-card-inner {
  transform: scale(0.97);
}

.memory-card.is-flipped:active:not(:disabled) .memory-card-inner,
.memory-card.is-matched:active:not(:disabled) .memory-card-inner {
  transform: rotateY(180deg) scale(0.97);
}

@media (max-width: 420px) {
  .app {
    padding:
      max(1rem, env(safe-area-inset-top))
      max(1rem, env(safe-area-inset-right))
      max(2rem, env(safe-area-inset-bottom))
      max(1rem, env(safe-area-inset-left));
  }

  .card {
    padding: 1.15rem 1rem 1.4rem;
  }

  .btn {
    font-size: 1.1rem;
    padding: 0.9rem 1rem;
  }

  .board {
    gap: 0.55rem;
  }

  .memory-card-face {
    border-radius: 14px;
  }
}
