:root {
  --bg: #e8f2eb;
  --bg-glow: radial-gradient(120% 80% at 20% 0%, #dff0e6 0%, transparent 55%),
    radial-gradient(90% 70% at 100% 10%, #d7e8f4 0%, transparent 50%),
    linear-gradient(180deg, #e8f2eb 0%, #f3f7f1 100%);
  --ink: #2f4a3a;
  --ink-soft: #6a8574;
  --card: #ffffff;
  --line: #d5e4da;
  --shadow: 0 8px 24px rgba(40, 70, 55, 0.08);
  --chip: #eef7f1;
  --danger: #e85d5d;
  --ok: #2f9b6a;
  --accent: #3d8f6a;
  --accent-2: #5a9e7a;
  font-family:
    "Avenir Next",
    "PingFang SC",
    "Hiragino Sans GB",
    "Nunito",
    system-ui,
    sans-serif;
  -webkit-tap-highlight-color: transparent;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  background-image: var(--bg-glow);
  color: var(--ink);
}

body {
  display: flex;
  justify-content: center;
  padding: 12px 14px max(20px, env(safe-area-inset-bottom));
}

.app {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: rise-in 0.55s ease both;
}

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

/* —— Top —— */
.top-bar {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.94);
}

.brand-block {
  text-align: center;
}

.brand {
  display: block;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--accent);
  line-height: 1.1;
  margin-bottom: 2px;
}

.top-stats {
  display: flex;
  justify-content: center;
  gap: 28px;
}

.stat {
  text-align: center;
}

.stat-label {
  display: block;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.stat-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #3a5c4a;
}

/* —— Pills —— */
.pills {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  font-size: 0.92rem;
  color: #3a5c4a;
  box-shadow: var(--shadow);
  min-height: 36px;
}

.pill-milk {
  gap: 2px;
  padding: 4px 10px;
}

.milk {
  display: inline-flex;
  width: 22px;
  height: 26px;
  transition: opacity 0.2s, filter 0.2s, transform 0.2s;
}

.milk.is-lost {
  opacity: 0.25;
  filter: grayscale(1);
  transform: scale(0.92);
}

.milk-svg {
  width: 100%;
  height: 100%;
}

.pill-icon {
  font-size: 1rem;
  line-height: 1;
}

/* —— Rules —— */
.rules {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  background: var(--card);
  border-radius: 16px;
  padding: 8px;
  box-shadow: var(--shadow);
}

.rule {
  text-align: center;
  font-size: 0.72rem;
  color: var(--ink-soft);
  background: var(--chip);
  border-radius: 12px;
  padding: 10px 4px;
  line-height: 1.35;
  font-weight: 600;
}

.rule-sub {
  display: block;
  font-size: 0.62rem;
  font-weight: 500;
  opacity: 0.85;
  margin-top: 2px;
}

.status {
  margin: 0;
  min-height: 1.25em;
  text-align: center;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.status[data-kind="ok"] {
  color: var(--ok);
  font-weight: 700;
}

.status[data-kind="warn"] {
  color: #c4892a;
  font-weight: 700;
}

.status[data-kind="error"] {
  color: var(--danger);
  font-weight: 700;
}

/* —— Board —— */
.board-wrap {
  background: var(--card);
  border-radius: 22px;
  padding: 10px;
  box-shadow: var(--shadow);
  animation: board-pop 0.45s ease 0.08s both;
}

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

.board {
  --n: 6;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: 3px;
  aspect-ratio: 1;
  width: 100%;
  touch-action: none;
}

.board.is-painting {
  cursor: crosshair;
}

.cell {
  --cell: #ddd;
  position: relative;
  border: none;
  border-radius: 8px;
  background: var(--cell);
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  transition:
    transform 0.08s ease,
    filter 0.15s ease,
    box-shadow 0.15s ease;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  pointer-events: auto;
}

.board.is-painting .cell:active {
  transform: none;
}

.cell:active {
  transform: scale(0.94);
}

.cell.has-mark {
  filter: saturate(0.95) brightness(0.97);
}

.mark-svg {
  width: 52%;
  height: 52%;
  opacity: 0.95;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.08));
}

.cow-svg {
  width: 82%;
  height: 82%;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.12));
  pointer-events: none;
  animation: cow-land 0.28s ease;
}

@keyframes cow-land {
  from {
    transform: scale(0.7);
    opacity: 0.4;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.cell.flash-wrong {
  animation: shake 0.4s ease;
  box-shadow: inset 0 0 0 3px var(--danger);
}

.cell.flash-ok {
  box-shadow: inset 0 0 0 3px var(--ok);
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

/* —— Tools —— */
.tools {
  display: flex;
  justify-content: center;
  gap: 48px;
  padding: 8px 0 4px;
}

.tool {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.tool-face {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  font-size: 2rem;
  border: 3px solid #fff;
}

.tool-face.hay {
  font-size: 1.85rem;
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(232, 93, 93, 0.4);
}

.tool-label {
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.footer-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding-bottom: 4px;
}

.diff {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.diff select {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 8px 10px;
  font: inherit;
  color: var(--ink);
}

.btn-new {
  border: none;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  font: inherit;
  font-weight: 700;
  border-radius: 14px;
  padding: 10px 20px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(61, 143, 106, 0.35);
  transition: transform 0.12s ease;
}

.btn-new:active {
  transform: scale(0.97);
}

/* —— Overlay —— */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 50, 40, 0.35);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 20px;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  background: var(--card);
  border-radius: 24px;
  padding: 28px 24px;
  text-align: center;
  width: min(320px, 100%);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.15);
  animation: rise-in 0.35s ease;
}

.overlay-card h2 {
  margin: 0 0 8px;
  color: #3a5c4a;
}

.overlay-card p {
  margin: 0 0 18px;
  color: var(--ink-soft);
}

@media (min-width: 400px) {
  .rule {
    font-size: 0.78rem;
    padding: 12px 6px;
  }
}
