:root {
  --ink: #3a322a;
  --ink-soft: #7a6f62;
  --paper: #f3e7d4;
  --paper-deep: #e6d4b8;
  --paper-wash: #faf3e8;
  --chrome: #fffaf3;
  --chrome-border: rgba(90, 70, 50, 0.14);
  --accent: #e09a86;
  --accent-soft: #ecc4ba;
  --line: rgba(58, 50, 42, 0.16);
  --shadow: rgba(58, 50, 42, 0.1);
  --win: #8fc49a;
  --win-ink: #4a7a5c;
  --danger: #e09aaa;
  --hint: #efe0b0;
  --hint-ink: #6b5a38;
  --heart: #e8b0b6;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Nunito", system-ui, sans-serif;
  /* Region colours: 10 distinct pastels (10×10); avoid near-duplicates */
  --region-0: #ecc4ba; /* peach */
  --region-1: #a8d49a; /* leaf */
  --region-2: #9bc4de; /* sky */
  --region-3: #e6d49a; /* butter */
  --region-4: #d8b4dc; /* lilac */
  --region-5: #7ec9c8; /* teal */
  --region-6: #e6c49a; /* apricot */
  --region-7: #b4b6e0; /* periwinkle */
  --region-8: #e8a8b8; /* rose */
  --region-9: #c4c090; /* olive sand — not another leaf green */
}

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

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 120% 80% at 10% -10%, #fff8ee 0%, transparent 55%),
    radial-gradient(ellipse 90% 70% at 100% 0%, #e8d9c0 0%, transparent 50%),
    linear-gradient(165deg, var(--paper-wash) 0%, var(--paper) 45%, var(--paper-deep) 100%);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.45'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.85rem 1rem 1.75rem;
}

.app-shell {
  width: min(100%, 34rem);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.brand {
  text-align: center;
}

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 5.5vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--ink);
}

.brand .tagline {
  margin: 0.25rem 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
  line-height: 1.3;
}

.rule-tips {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 0.45rem;
  width: 100%;
  padding: 0.15rem 0 0.2rem;
}

.rule-tip {
  flex: 1 1 0;
  margin: 0;
  max-width: 6.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.rule-tip-board {
  position: relative;
  display: grid;
  gap: 0;
  width: 5.25rem;
  height: 5.25rem;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 0.4rem;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 2px 6px var(--shadow);
  flex-shrink: 0;
}

.rule-tip-cell {
  display: grid;
  place-items: center;
  min-height: 0;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1.5px #fff;
}

.rule-tip-cat {
  width: 88%;
  height: 88%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.rule-tip-ban {
  position: absolute;
  inset: 8%;
  border: 2.5px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0.85;
}

.rule-tip-ban::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 118%;
  height: 2.5px;
  background: var(--accent);
  border-radius: 2px;
  transform: translate(-50%, -50%) rotate(-45deg);
}

.rule-tip figcaption {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--ink-soft);
  text-align: center;
}

.picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.picker button {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  border: 1.5px solid var(--chrome-border);
  background: var(--chrome);
  color: var(--ink);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.picker button:hover {
  background: #fff;
  border-color: rgba(90, 70, 50, 0.24);
}

.picker button:active {
  transform: scale(0.97);
}

.picker button.is-active {
  background: var(--accent-soft);
  color: var(--ink);
  border-color: rgba(212, 138, 114, 0.4);
}

.board-wrap {
  display: flex;
  justify-content: center;
  padding: 0.25rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.board-placeholder {
  width: min(100%, 30rem);
  aspect-ratio: 1;
  margin-inline: auto;
  border: 2.5px dashed rgba(42, 36, 28, 0.22);
  border-radius: 0.65rem;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 2rem;
  color: var(--ink-soft);
  background: rgba(255, 252, 246, 0.35);
}

.board {
  display: grid;
  gap: 0;
  width: min(100%, 30rem);
  aspect-ratio: 1;
  border: 2.5px solid #fff;
  border-radius: 0.65rem;
  overflow: hidden;
  box-shadow: 0 12px 28px var(--shadow);
  background: #fff;
  touch-action: none;
}

.cell {
  position: relative;
  border: none;
  margin: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  display: grid;
  place-items: center;
  outline: none;
  border-radius: 5px;
  box-shadow: inset 0 0 0 1.5px #fff;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

.cell:focus-visible {
  z-index: 1;
  box-shadow: inset 0 0 0 2.5px var(--ink);
}

.cell.is-invalid {
  animation: shake 0.35s ease;
}

.cell.is-hint {
  animation: hint-pulse 1.1s ease;
  z-index: 1;
  box-shadow: inset 0 0 0 2.5px var(--hint-ink);
}

.cell-mark {
  width: 82%;
  height: 82%;
  display: block;
  pointer-events: none;
  user-select: none;
  overflow: visible;
}

.cell-mark--neutral .cell-mark-stroke {
  stroke: #7a7268;
  stroke-width: 8.5;
  opacity: 0.78;
}

.cell-mark--neutral .cell-mark-dot {
  fill: #8a8278;
  opacity: 0.8;
}

.cell-mark--miss .cell-mark-stroke {
  stroke: var(--danger);
  stroke-width: 8.5;
  opacity: 0.95;
}

.cell-mark--miss .cell-mark-dot {
  fill: #e07a88;
  opacity: 0.95;
}

.cell-cat {
  width: 80%;
  height: 80%;
  display: block;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 1px 1px rgba(255, 255, 255, 0.35))
    drop-shadow(0 2px 3px rgba(42, 36, 28, 0.22));
}

.cell-cat.is-celebrate {
  animation: cat-cheer 0.7s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

.generate-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.generate-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-right: 0.25rem;
}

.generate-btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  border: 1.5px solid rgba(212, 138, 114, 0.45);
  background: rgba(236, 196, 186, 0.45);
  color: var(--ink);
  padding: 0.4rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
}

.generate-btn:hover:not(:disabled) {
  background: rgba(236, 196, 186, 0.7);
}

.generate-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.generate-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.generate-error {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--danger);
}

.level-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.level-nav-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 9.5rem;
  padding: 0 0.35rem;
}

.level-nav-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ink);
}

.level-nav-btn,
.level-nav-jump {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  border: 1.5px solid var(--chrome-border);
  background: var(--chrome);
  color: var(--ink);
  border-radius: 0.55rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.12s ease;
}

.level-nav-btn {
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
}

.level-nav-jump {
  font-size: 0.8rem;
  padding: 0.4rem 0.7rem;
}

.level-nav-btn:hover:not(:disabled),
.level-nav-jump:hover:not(:disabled) {
  background: #fff;
  border-color: rgba(90, 70, 50, 0.24);
}

.level-nav-btn:active:not(:disabled),
.level-nav-jump:active:not(:disabled) {
  transform: scale(0.97);
}

.level-nav-btn:disabled,
.level-nav-jump:disabled {
  opacity: 0.45;
  cursor: default;
}

.toolbar {
  display: flex;
  justify-content: center;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.toolbar button {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.9rem;
  border: 1.5px solid transparent;
  background: var(--accent-soft);
  color: var(--ink);
  padding: 0.55rem 1.15rem;
  border-radius: 0.55rem;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.toolbar button:hover {
  background: #e2b4a8;
}

.toolbar button:active {
  transform: scale(0.97);
}

.toolbar button.secondary {
  background: var(--chrome);
  color: var(--ink);
  border-color: var(--chrome-border);
}

.toolbar button.secondary:hover {
  background: #fff;
  border-color: rgba(90, 70, 50, 0.24);
}

.toolbar .hint-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--hint);
  color: var(--hint-ink);
  border-color: rgba(107, 90, 56, 0.1);
}

.toolbar .hint-btn:hover {
  background: #e6d49a;
}

.toolbar .hint-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.bulb-icon {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
}

.hint,
.meta {
  text-align: center;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0;
}

.hint-reason {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--hint-ink);
  margin: 0;
  line-height: 1.35;
  padding: 0 0.5rem;
}

.hearts {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  min-height: 1.6rem;
}

.heart {
  font-size: 1.45rem;
  line-height: 1;
  color: var(--heart);
  text-shadow: 0 1px 0 rgba(58, 50, 42, 0.08);
  transition: transform 0.2s ease, opacity 0.2s ease, color 0.2s ease;
}

.heart.is-lost {
  color: rgba(58, 50, 42, 0.18);
  transform: scale(0.88);
  opacity: 0.7;
}

.result-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem 0.75rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 2px solid var(--win);
  border-radius: 0.65rem;
  background: rgba(168, 212, 154, 0.28);
  animation: pop-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.result-banner.is-lose {
  border-color: var(--danger);
  background: rgba(236, 196, 186, 0.45);
}

.result-banner-text {
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.35;
  flex: 1 1 10rem;
}

.result-banner-text strong {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--win-ink);
  font-weight: 700;
  margin-right: 0.25rem;
}

.result-banner.is-lose .result-banner-text strong {
  color: #a85a62;
}

.result-banner-actions {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.result-banner-actions button {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.85rem;
  border: 1.5px solid transparent;
  background: var(--win);
  color: #f4faf6;
  padding: 0.4rem 0.85rem;
  border-radius: 0.5rem;
  cursor: pointer;
}

.result-banner.is-lose .result-banner-actions button:not(.secondary) {
  background: var(--accent);
  color: #fff8f4;
}

.result-banner-actions button.secondary {
  background: var(--chrome);
  color: var(--ink);
  border-color: var(--chrome-border);
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(2px);
  }
}

@keyframes hint-pulse {
  0% {
    filter: brightness(1);
  }
  40% {
    filter: brightness(1.12);
  }
  100% {
    filter: brightness(1);
  }
}

@keyframes cat-cheer {
  0% {
    transform: scale(1) rotate(0deg);
  }
  28% {
    transform: scale(1.22) rotate(-8deg);
  }
  55% {
    transform: scale(1.12) rotate(7deg);
  }
  78% {
    transform: scale(1.06) rotate(-3deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

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

@media (max-width: 420px) {
  #app {
    padding: 0.65rem 0.75rem 1.5rem;
  }

  .brand h1 {
    font-size: 1.65rem;
  }
}
