:root {
  color-scheme: light;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  color: #493b3a;
  background: #fff8f3;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --pink: #df8ba4;
  --dark-pink: #bd607d;
  --cream: #fff8f3;
  --ink: #493b3a;
  --soft-shadow: 0 18px 48px rgb(108 72 64 / 12%);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(ellipse at 10% 10%, rgb(250 221 227 / 70%), transparent 34%),
    radial-gradient(ellipse at 92% 85%, rgb(255 233 195 / 65%), transparent 32%),
    var(--cream);
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid #684663;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.title-screen,
.game-screen {
  width: min(100%, 660px);
}

.title-screen {
  display: grid;
  min-height: min(680px, calc(100dvh - 40px));
  place-items: center;
}

.title-content {
  display: grid;
  justify-items: center;
  gap: 28px;
  width: min(100%, 440px);
  padding: 64px 28px;
  border: 1px solid rgb(255 255 255 / 85%);
  border-radius: 38px;
  background: rgb(255 255 255 / 66%);
  box-shadow: var(--soft-shadow);
  text-align: center;
}

.title-content h1,
.game-header h1 {
  margin: 0;
  color: var(--dark-pink);
  font-size: clamp(2.8rem, 12vw, 4.6rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-shadow: 0 4px 0 #f9dfe5;
}

.primary-button,
.secondary-button {
  min-height: 54px;
  padding: 12px 24px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
  -webkit-tap-highlight-color: transparent;
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, #e5a0b4, #cf7591);
  box-shadow: 0 7px 0 #b95d7c, 0 12px 20px rgb(185 93 124 / 18%);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-2px);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(2px);
}

.title-content .primary-button {
  min-width: min(100%, 260px);
  font-size: 1.1rem;
}

.error-message {
  margin: 0;
  color: #9d2948;
}

.game-screen {
  display: grid;
  justify-items: center;
  gap: 18px;
}

.game-header {
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
}

.game-header h1 {
  font-size: clamp(1.8rem, 7vw, 2.5rem);
}

.board-size,
.cat-count {
  margin: 0;
  font-weight: 700;
}

.board-size {
  color: #846e6c;
  font-size: 0.9rem;
}

.cat-count {
  color: #a14866;
  font-size: 1.15rem;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--board-size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--board-size), minmax(0, 1fr));
  gap: clamp(3px, 1vw, 6px);
  width: min(92vw, 58dvh, 560px);
  aspect-ratio: 1;
  padding: clamp(6px, 1.5vw, 10px);
  border: 2px solid rgb(255 255 255 / 90%);
  border-radius: 24px;
  background: rgb(255 255 255 / 78%);
  box-shadow: var(--soft-shadow);
}

.cell {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: visible;
  padding: 0;
  border: 1px solid rgb(103 77 73 / 12%);
  border-radius: clamp(7px, 2vw, 14px);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: filter 130ms ease, transform 130ms ease;
}

.cell:not(:disabled):hover {
  z-index: 1;
  filter: saturate(1.08);
  transform: scale(1.04);
}

.cell:disabled {
  cursor: default;
}

.cell-marked {
  box-shadow: inset 0 0 0 3px rgb(117 67 83 / 42%);
}

.cross-mark {
  color: #694651;
  font-size: clamp(1.3rem, 7vw, 3rem);
  font-weight: 700;
  line-height: 1;
}

.cat-illustration {
  position: absolute;
  z-index: 2;
  width: 125%;
  height: 125%;
  overflow: visible;
  filter: drop-shadow(0 4px 3px rgb(94 55 56 / 24%));
  animation: cat-pop 520ms cubic-bezier(0.2, 1.5, 0.45, 1) both;
}

.cat-face,
.cat-ear {
  fill: #8e594f;
  stroke: #67413d;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.cat-inner-ear {
  fill: #e8a0a7;
}

.cat-eye {
  fill: none;
  stroke: #fff8e9;
  stroke-linecap: round;
  stroke-width: 6;
}

.cat-nose {
  fill: #e78a98;
  stroke: #7a4a4b;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.cat-mouth,
.cat-whiskers {
  fill: none;
  stroke: #67413d;
  stroke-linecap: round;
  stroke-width: 2;
}

.cat-cheek {
  fill: #f6aeb4;
  opacity: 0.88;
}

.result-overlay {
  position: fixed;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgb(61 42 44 / 42%);
  backdrop-filter: blur(5px);
}

.result-card {
  width: min(100%, 430px);
  padding: clamp(28px, 8vw, 42px);
  border: 2px solid white;
  border-radius: 30px;
  background: #fffaf7;
  box-shadow: 0 24px 80px rgb(50 30 30 / 25%);
  text-align: center;
  animation: card-appear 240ms ease-out both;
}

.result-eyebrow {
  margin: 0 0 8px;
  color: var(--dark-pink);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.result-card h2 {
  margin: 0;
  color: #9d5067;
  font-size: clamp(1.7rem, 8vw, 2.25rem);
}

.result-message {
  margin: 12px 0 24px;
  line-height: 1.7;
}

.result-actions {
  display: grid;
  gap: 12px;
}

.secondary-button {
  border: 2px solid #e8c4ce;
  color: #844c60;
  background: #fff;
}

@keyframes cat-pop {
  0% {
    opacity: 0;
    transform: translateY(35%) scale(0.15) rotate(-24deg);
  }
  65% {
    opacity: 1;
    transform: translateY(-16%) scale(1.28) rotate(7deg);
  }
  100% {
    opacity: 1;
    transform: translateY(-5%) scale(1) rotate(0);
  }
}

@keyframes card-appear {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-height: 650px) {
  .game-screen {
    gap: 10px;
  }

  .board {
    width: min(88vw, 72dvh, 560px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
