:root {
  --bg: #eef3f8;
  --ink: #2c3340;
  --muted: #7a8494;
  --panel: #ffffff;
  --line: rgba(44, 51, 64, 0.1);
  --accent: #5b8def;
  --danger: #e85d5d;
  --font: "Outfit", system-ui, sans-serif;
  --display: "Nunito", "Outfit", sans-serif;
  --gap: 3px;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(700px 420px at 10% -10%, #dce9ff 0%, transparent 55%),
    radial-gradient(600px 380px at 100% 0%, #ffe8f0 0%, transparent 50%),
    linear-gradient(180deg, #f7fafc, var(--bg));
}
body {
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
}
.hidden { display: none !important; }
.home-user {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.92rem;
}

.screen {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.home-hero {
  text-align: center;
  padding: 48px 8px 12px;
}
.brand-mark {
  width: 88px;
  height: 88px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 12px 32px rgba(80, 100, 140, 0.18);
  display: grid;
  place-items: center;
}
.brand-mark img { width: 64px; height: 64px; }
.home-hero h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  font-size: 2.4rem;
  letter-spacing: 0.02em;
}
.tagline {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.4;
}
.home-progress {
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.btn {
  border: 0;
  border-radius: 16px;
  padding: 0.85rem 1.1rem;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  background: rgba(255,255,255,0.7);
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.primary {
  background: linear-gradient(160deg, #6ea0ff, var(--accent));
  color: #fff;
  border: 0;
  box-shadow: 0 10px 24px rgba(91, 141, 239, 0.35);
}
.btn.ghost { background: rgba(255,255,255,0.55); }
.btn.lg { font-size: 1.1rem; padding: 1rem 1.2rem; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.15rem;
  cursor: pointer;
  color: var(--ink);
}

.top-simple {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 8px;
}
.top-simple h2 {
  margin: 0;
  text-align: center;
  font-family: var(--display);
  font-weight: 900;
}
.levels-hint { margin: 0; color: var(--muted); font-size: 0.9rem; text-align: center; }
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  overflow: auto;
  padding-bottom: 12px;
}
.level-chip {
  aspect-ratio: 1;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--ink);
}
.level-chip.done { background: #e8f5e9; border-color: #a5d6a7; }
.level-chip.current { outline: 2px solid var(--accent); }
.level-chip.locked {
  opacity: 0.45;
  cursor: not-allowed;
  background: #f0f2f5;
}

.play-top {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  gap: 8px;
  align-items: start;
}
.play-title { text-align: center; }
.level-label {
  font-family: var(--display);
  font-weight: 900;
  font-size: 1.35rem;
}
.bones {
  display: inline-flex;
  gap: 6px;
  margin: 6px auto 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: #d9ecff;
}
.bone {
  width: 34px;
  height: 16px;
  transition: filter 0.2s, opacity 0.2s;
}
.bone.lost {
  filter: grayscale(1) brightness(0.75);
  opacity: 0.35;
}
.dog-progress {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-weight: 800;
  font-size: 0.92rem;
}
.dog-progress img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffe0b2;
}

.rules {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px 6px;
}
.rule {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.25;
  display: grid;
  gap: 4px;
  justify-items: center;
}
.rule-art {
  width: 54px;
  height: 40px;
  border-radius: 8px;
  background: #f3f6fa;
  position: relative;
  overflow: hidden;
}
.rule-art::before {
  content: "";
  position: absolute;
  inset: 4px;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  opacity: 0.95;
}
.rule-art[data-rule="color"]::before {
  background-image: linear-gradient(135deg, #b39ddb 40%, #fff 40%),
    radial-gradient(circle at 30% 40%, #8d6e63 4px, transparent 5px);
  background-color: #f3e5f5;
}
.rule-art[data-rule="rowcol"]::before {
  background:
    linear-gradient(#90caf9, #90caf9) center/8px 100% no-repeat,
    linear-gradient(#90caf9, #90caf9) center/100% 8px no-repeat;
}
.rule-art[data-rule="adj"]::before {
  background:
    radial-gradient(circle at 50% 50%, #8d6e63 5px, transparent 6px),
    radial-gradient(circle at 20% 20%, #bbb 2px, transparent 3px),
    radial-gradient(circle at 80% 20%, #bbb 2px, transparent 3px),
    radial-gradient(circle at 20% 80%, #bbb 2px, transparent 3px),
    radial-gradient(circle at 80% 80%, #bbb 2px, transparent 3px);
}

.board-wrap {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
}
.board {
  --n: 8;
  width: min(92vw, 420px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--gap);
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(60, 80, 120, 0.12);
  touch-action: none;
}
.cell {
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: var(--cell, #ccc);
  position: relative;
  padding: 0;
  cursor: pointer;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  transition: filter 0.12s, transform 0.12s;
}
.cell:active { transform: scale(0.96); }
.mark-x {
  font-size: clamp(1.35rem, 6.2vw, 2.35rem);
  font-weight: 900;
  color: rgba(255,255,255,0.96);
  text-shadow: 0 1px 3px rgba(0,0,0,0.35);
  line-height: 1;
  pointer-events: none;
  transform: scale(1.05);
}
.mark-x.bad {
  color: #ff2d2d;
  text-shadow: 0 1px 2px rgba(80,0,0,0.25);
  font-size: clamp(1.5rem, 7vw, 2.6rem);
}
.dog-icon {
  width: 72%;
  height: 72%;
  max-width: 42px;
  max-height: 42px;
  border-radius: 50%;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}
.cell.has-dog {
  outline: 2px solid rgba(255,255,255,0.65);
  outline-offset: -2px;
}

.hint-line {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(30, 40, 55, 0.45);
  display: grid;
  place-items: center;
  z-index: 40;
  padding: 20px;
}
.modal-card {
  width: min(360px, 100%);
  background: #fff;
  border-radius: 22px;
  padding: 1.4rem 1.2rem 1.2rem;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.25);
}
.modal-icon { font-size: 2.4rem; }
.modal-card h2 {
  margin: 0.35rem 0;
  font-family: var(--display);
  font-weight: 900;
}
.modal-card p { margin: 0 0 1rem; color: var(--muted); }
.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: rgba(30, 40, 55, 0.92);
  color: #fff;
  padding: 0.65rem 1rem;
  border-radius: 999px;
  z-index: 50;
  font-size: 0.9rem;
  font-weight: 700;
}

@media (min-width: 700px) {
  .screen.play { width: min(560px, 100%); }
  .board { width: min(92vw, 480px); }
}
