:root {
  color-scheme: light;
  --cream: #fff1ba;
  --paper: #fffefb;
  --paper-blue: #eef5ff;
  --cocoa: #724721;
  --cocoa-soft: #9b754f;
  --gold: #ffc84f;
  --gold-deep: #e7a813;
  --gold-light: #ffe28d;
  --blue: #3977e8;
  --green: #55a933;
  --coral: #f06458;
  --orange: #ff8b2d;
  --shadow: rgba(127, 82, 17, 0.17);
  --tile-gap: 4px;
  --radius-card: 28px;
  --ease-pop: cubic-bezier(0.2, 1.4, 0.35, 1);
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  background: #e7c979;
  color: var(--cocoa);
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  position: relative;
  display: flex;
  width: min(100%, 560px);
  min-height: 100svh;
  margin: 0 auto;
  flex-direction: column;
  overflow: hidden;
  isolation: isolate;
  background-color: var(--cream);
  background-image: url("assets/garden-bg.webp");
  background-position: center;
  background-size: cover;
  box-shadow: 0 0 48px rgba(89, 54, 8, 0.22);
}

.game-header {
  position: relative;
  z-index: 2;
  padding: max(18px, env(safe-area-inset-top)) 20px 12px;
}

.top-bar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 12px;
}

.top-bar h1 {
  margin: 0;
  color: var(--cocoa);
  font-size: clamp(25px, 7vw, 34px);
  font-weight: 900;
  letter-spacing: -0.04em;
  text-align: center;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.62);
}

.round-button,
.modal-close {
  display: grid;
  width: 46px;
  height: 46px;
  padding: 0;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.76);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 5px 10px var(--shadow), inset 0 -2px 0 rgba(221, 173, 75, 0.18);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.round-button svg,
.modal-close svg {
  width: 25px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
}

.round-button:active,
.modal-close:active,
.mode-button:active,
.hint-button:active,
.primary-button:active,
.secondary-button:active {
  transform: translateY(2px) scale(0.97);
}

.round-button:disabled {
  opacity: 0.32;
  cursor: default;
}

.round-button:focus-visible,
.modal-close:focus-visible,
.mode-button:focus-visible,
.hint-button:focus-visible,
.cell:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.text-button:focus-visible {
  outline: 4px solid rgba(57, 119, 232, 0.3);
  outline-offset: 3px;
}

.status-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-top: 7px;
}

.hearts {
  display: flex;
  grid-column: 2;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.heart {
  width: 25px;
  height: 23px;
  filter: drop-shadow(0 2px 1px rgba(164, 57, 43, 0.2));
  transition: filter 220ms ease, opacity 220ms ease, transform 220ms var(--ease-pop);
}

.heart path {
  fill: var(--coral);
  stroke: #e34f48;
  stroke-width: 1;
}

.heart.is-empty {
  opacity: 0.25;
  filter: grayscale(1);
  transform: scale(0.82);
}

.mole-counter {
  display: flex;
  grid-column: 2;
  align-items: center;
  justify-content: center;
  min-width: 132px;
  height: 42px;
  margin-top: 2px;
  padding: 4px 16px 4px 8px;
  border: 2px solid rgba(235, 178, 62, 0.35);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 4px 8px var(--shadow), inset 0 -2px 0 rgba(230, 180, 83, 0.14);
  font-size: 18px;
  font-weight: 900;
  white-space: nowrap;
}

.mole-counter img {
  width: 36px;
  height: 31px;
  margin-right: 7px;
  object-fit: contain;
}

.game-main {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 0;
  padding: 0 18px 38px;
  flex: 1 1 auto;
}

.board-card {
  position: relative;
  display: flex;
  width: 100%;
  min-height: 410px;
  padding: 20px 14px;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-card);
  background: rgba(255, 254, 251, 0.97);
  box-shadow: 0 10px 22px var(--shadow), inset 0 -5px 0 rgba(230, 186, 98, 0.11);
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--columns, 6), var(--cell-size, 46px));
  grid-auto-rows: var(--cell-size, 46px);
  gap: var(--tile-gap);
  touch-action: manipulation;
  user-select: none;
}

.cell,
.cell-space {
  width: var(--cell-size, 46px);
  height: var(--cell-size, 46px);
}

.cell {
  position: relative;
  display: grid;
  padding: 0;
  place-items: center;
  overflow: visible;
  border: 0;
  border-radius: clamp(8px, calc(var(--cell-size) * 0.24), 14px);
  background: linear-gradient(145deg, var(--gold-light), var(--gold));
  box-shadow:
    0 calc(var(--cell-size) * 0.08) calc(var(--cell-size) * 0.09) rgba(190, 125, 5, 0.28),
    inset 0 -3px 0 rgba(213, 144, 9, 0.34),
    inset 0 2px 0 rgba(255, 245, 184, 0.7);
  color: var(--cocoa);
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, box-shadow 180ms ease, background 180ms ease;
}

.cell:not(.is-revealed):hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.cell:not(.is-revealed):active {
  transform: translateY(2px) scale(0.96);
}

.cell.is-revealed {
  animation: reveal-cell 260ms var(--ease-pop) both;
  background: linear-gradient(145deg, #fbfdff, #e8f1ff);
  box-shadow:
    0 2px 3px rgba(61, 102, 168, 0.18),
    inset 0 -2px 0 rgba(121, 160, 218, 0.22),
    inset 0 1px 0 white;
  cursor: default;
}

.cell.is-zero {
  background: #f1f5fb;
  box-shadow: inset 0 0 0 1px rgba(121, 150, 193, 0.12);
}

.cell.is-hit {
  z-index: 3;
  animation: mole-hit 440ms var(--ease-pop) both;
  background: #ffe8cf;
  box-shadow: 0 0 0 3px rgba(240, 100, 88, 0.22);
}

.cell.is-hint {
  animation: hint-glow 900ms ease both;
}

.cell-number {
  font-size: clamp(17px, calc(var(--cell-size) * 0.55), 30px);
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 2px 0 white;
}

.number-1 { color: var(--blue); }
.number-2 { color: var(--green); }
.number-3 { color: var(--coral); }
.number-4 { color: #8b5bd3; }
.number-5,
.number-6,
.number-7,
.number-8 { color: var(--cocoa); }

.cell-flag {
  width: 66%;
  height: 66%;
  overflow: visible;
  animation: flag-pop 240ms var(--ease-pop) both;
  fill: none;
  stroke: #9a5c25;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.4;
  filter: drop-shadow(0 2px 1px rgba(120, 70, 15, 0.22));
}

.cell-flag .flag-fill {
  fill: var(--orange);
  stroke: #df6512;
}

.cell-mole {
  position: absolute;
  z-index: 2;
  width: 122%;
  max-width: none;
  height: 110%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 4px 3px rgba(95, 52, 14, 0.2));
}

.cell-space {
  pointer-events: none;
}

.toast {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 17px;
  max-width: calc(100% - 36px);
  padding: 8px 14px;
  border-radius: 13px;
  background: rgba(114, 71, 33, 0.9);
  color: white;
  font-size: 14px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 180ms ease, transform 180ms ease;
  white-space: nowrap;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.game-controls {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 13px;
  align-items: center;
  padding: 14px 22px max(42px, env(safe-area-inset-bottom));
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 0;
  padding: 4px;
  border: 2px solid rgba(232, 175, 65, 0.37);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 6px 12px var(--shadow), inset 0 -2px 0 rgba(222, 167, 50, 0.13);
}

.mode-button {
  display: flex;
  min-width: 0;
  min-height: 58px;
  padding: 7px 11px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 0;
  border-radius: 17px;
  background: transparent;
  color: var(--cocoa-soft);
  font-size: 17px;
  font-weight: 950;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 180ms ease, box-shadow 180ms ease, color 180ms ease, transform 140ms ease;
}

.mode-button svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: #714522;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.mode-button svg .shovel-grip {
  fill: #9b6b42;
}

.mode-button svg .shovel-blade {
  fill: #9b6b42;
}

.mode-button svg .shovel-shaft {
  fill: none;
  stroke-width: 3;
}

.mode-button svg .flag-fill {
  fill: var(--orange);
}

.mode-button.is-active {
  background: linear-gradient(145deg, #ffe58f, var(--gold));
  color: var(--cocoa);
  box-shadow: 0 4px 7px rgba(190, 125, 5, 0.25), inset 0 -3px 0 rgba(209, 138, 6, 0.24), inset 0 2px 0 rgba(255, 250, 200, 0.78);
}

.hint-button {
  display: flex;
  min-width: 78px;
  padding: 0;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: var(--cocoa);
  font-size: 13px;
  font-weight: 950;
  cursor: pointer;
  transition: transform 140ms ease, opacity 180ms ease;
}

.hint-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.hint-icon {
  position: relative;
  display: grid;
  width: 61px;
  height: 61px;
  place-items: center;
  border: 4px solid white;
  border-radius: 50%;
  background: linear-gradient(145deg, #80adff, #3977e8);
  box-shadow: 0 6px 10px rgba(33, 82, 167, 0.24), inset 0 -3px 0 rgba(19, 70, 167, 0.24);
}

.hint-icon svg {
  width: 32px;
  fill: #ffe379;
  stroke: white;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  filter: drop-shadow(0 2px 1px rgba(55, 87, 150, 0.3));
}

.hint-icon b {
  position: absolute;
  right: -8px;
  bottom: -5px;
  min-width: 31px;
  padding: 3px 5px;
  border: 3px solid white;
  border-radius: 11px;
  background: var(--blue);
  color: white;
  font-size: 13px;
  line-height: 1.1;
  box-shadow: 0 2px 5px rgba(29, 65, 131, 0.3);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  padding: 24px;
  place-items: center;
  background: rgba(88, 54, 20, 0.32);
  backdrop-filter: blur(5px);
  animation: fade-in 180ms ease both;
}

.modal-card {
  position: relative;
  width: min(100%, 360px);
  padding: 30px 28px 24px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 28px;
  background: #fffdf6;
  box-shadow: 0 24px 54px rgba(82, 48, 10, 0.28), inset 0 -5px 0 rgba(235, 187, 87, 0.12);
  text-align: center;
  animation: modal-pop 320ms var(--ease-pop) both;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 39px;
  height: 39px;
  border-radius: 13px;
  box-shadow: 0 3px 7px var(--shadow);
}

.modal-close svg {
  width: 20px;
}

.modal-mole {
  width: 108px;
  height: 92px;
  object-fit: contain;
}

.modal-card h2 {
  margin: 5px 0 20px;
  font-size: 28px;
  letter-spacing: -0.03em;
}

.setting-row {
  display: grid;
  grid-template-columns: 1fr 50px;
  align-items: center;
  min-height: 56px;
  border-bottom: 1px solid rgba(114, 71, 33, 0.11);
  font-size: 17px;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.setting-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 99px;
  background: #d9d4ca;
  box-shadow: inset 0 2px 3px rgba(91, 70, 48, 0.18);
  transition: background 180ms ease;
}

.toggle::after {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 5px rgba(84, 62, 38, 0.24);
  content: "";
  transition: transform 180ms var(--ease-pop);
}

.setting-row input:checked + .toggle {
  background: var(--green);
}

.setting-row input:checked + .toggle::after {
  transform: translateX(20px);
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 52px;
  border-radius: 17px;
  font-size: 17px;
  font-weight: 950;
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease;
}

.primary-button {
  border: 0;
  background: linear-gradient(145deg, #ffe28a, var(--gold));
  box-shadow: 0 6px 9px rgba(185, 119, 4, 0.26), inset 0 -3px 0 rgba(210, 139, 6, 0.28), inset 0 2px 0 rgba(255, 251, 206, 0.75);
  color: var(--cocoa);
}

.secondary-button {
  margin-top: 18px;
  border: 2px solid rgba(232, 175, 65, 0.43);
  background: #fff6d9;
  box-shadow: 0 4px 8px rgba(138, 93, 22, 0.1);
  color: var(--cocoa);
}

.text-button {
  padding: 12px 18px;
  border: 0;
  background: transparent;
  color: var(--cocoa-soft);
  font-size: 15px;
  font-weight: 850;
  cursor: pointer;
}

.text-button.danger {
  margin-top: 4px;
  color: var(--coral);
}

.result-card {
  overflow: hidden;
  padding-top: 22px;
}

.result-mole {
  position: relative;
  z-index: 1;
  width: 168px;
  height: 144px;
  object-fit: contain;
  animation: mascot-bounce 900ms var(--ease-pop) both;
}

.result-burst {
  position: absolute;
  top: -70px;
  left: 50%;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, rgba(255, 207, 76, 0.28) 0 9deg, transparent 9deg 18deg);
  transform: translateX(-50%);
  animation: slow-spin 14s linear infinite;
}

.result-kicker {
  position: relative;
  margin: 2px 0 4px;
  color: var(--green);
  font-size: 13px;
  font-weight: 950;
  letter-spacing: 0.12em;
}

.result-card h2 {
  position: relative;
  margin: 0;
  font-size: 30px;
}

.result-card > p:not(.result-kicker) {
  position: relative;
  margin: 8px 0 22px;
  color: var(--cocoa-soft);
  font-size: 15px;
  line-height: 1.45;
}

.result-card .text-button {
  margin-top: 5px;
}

.confetti-layer {
  position: absolute;
  z-index: 30;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 16px;
  border-radius: 4px;
  animation: confetti-fall var(--fall-time) cubic-bezier(0.2, 0.55, 0.45, 0.98) forwards;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes reveal-cell {
  0% { opacity: 0.45; transform: scale(0.72) rotate(-2deg); }
  100% { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes mole-hit {
  0% { transform: scale(0.78); }
  48% { transform: scale(1.12) rotate(-3deg); }
  72% { transform: scale(0.97) rotate(2deg); }
  100% { transform: scale(1); }
}

@keyframes flag-pop {
  0% { transform: translateY(8px) scale(0.5) rotate(-12deg); }
  100% { transform: translateY(0) scale(1) rotate(0); }
}

@keyframes hint-glow {
  0%, 100% { box-shadow: 0 2px 3px rgba(61, 102, 168, 0.18); }
  40% { box-shadow: 0 0 0 6px rgba(57, 119, 232, 0.28), 0 0 25px rgba(57, 119, 232, 0.38); }
}

@keyframes modal-pop {
  0% { opacity: 0; transform: translateY(18px) scale(0.9); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes mascot-bounce {
  0% { opacity: 0; transform: translateY(40px) scale(0.7); }
  55% { opacity: 1; transform: translateY(-7px) scale(1.05); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes slow-spin {
  to { transform: translateX(-50%) rotate(360deg); }
}

@keyframes confetti-fall {
  0% { opacity: 1; transform: translate3d(0, -5vh, 0) rotate(0); }
  100% { opacity: 0.9; transform: translate3d(var(--drift), 105vh, 0) rotate(var(--spin)); }
}

@media (min-width: 561px) {
  .app-shell {
    min-height: min(100svh, 980px);
  }
}

@media (max-width: 390px) {
  .game-header { padding-inline: 16px; }
  .game-main { padding-inline: 12px; padding-bottom: 30px; }
  .board-card { min-height: 390px; padding-inline: 10px; border-radius: 24px; }
  .game-controls { grid-template-columns: minmax(0, 1fr) 72px; padding-inline: 16px; }
  .mode-button { gap: 4px; padding-inline: 7px; font-size: 15px; }
  .mode-button svg { width: 25px; }
  .hint-icon { width: 56px; height: 56px; }
}

@media (max-height: 720px) and (orientation: portrait) {
  .game-header { padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: 7px; }
  .top-bar { grid-template-columns: 42px 1fr 42px; }
  .round-button { width: 41px; height: 41px; }
  .status-row { margin-top: 1px; }
  .hearts { min-height: 28px; }
  .heart { width: 21px; height: 20px; }
  .mole-counter { height: 36px; font-size: 16px; }
  .board-card { min-height: 340px; padding-block: 12px; }
  .game-main { padding-bottom: 22px; }
  .game-controls { padding-top: 9px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  .mode-button { min-height: 50px; }
  .hint-icon { width: 52px; height: 52px; }
}

@media (orientation: landscape) and (max-height: 620px) {
  body { overflow: auto; }
  .app-shell { min-height: 680px; }
}

@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;
  }
}
