:root {
  color-scheme: light;
  font-family: "STKaiti", "KaiTi", "Noto Serif SC", serif;
  background: #d6ead1;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  justify-content: center;
  color: #3f3625;
  background:
    radial-gradient(circle at 30% 10%, rgba(255,255,255,.8), transparent 26%),
    linear-gradient(135deg, #b9dfd3, #f4e7a9 50%, #cbe891);
  overscroll-behavior: none;
}

button { font: inherit; border: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid #fff4a9; outline-offset: 2px; }

.game-shell {
  position: relative;
  width: min(100vw, 430px);
  min-height: max(100svh, 760px);
  overflow: hidden;
  padding-top: max(184px, env(safe-area-inset-top));
  padding-bottom: max(22px, env(safe-area-inset-bottom));
  background-color: #f7edbd;
  background-image:
    linear-gradient(to bottom, transparent 56%, rgba(226, 246, 140, .43)),
    url('./assets/bg-main.png');
  background-repeat: no-repeat;
  background-position: center top;
  background-size: 100% auto;
  box-shadow: 0 0 46px rgba(44, 74, 54, .32);
  user-select: none;
  touch-action: manipulation;
}

.topbar {
  position: absolute;
  z-index: 5;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  display: flex;
  gap: 8px;
}

.round-action {
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.46);
  border-radius: 50%;
  color: #fff;
  background: rgba(74, 62, 44, .27);
  backdrop-filter: blur(5px);
}

.sound-on span { width: 15px; height: 12px; border: 3px solid #fff; border-top-color: transparent; border-bottom-color: transparent; border-radius: 50%; }
.sound-on.is-muted span { width: 17px; height: 3px; border: 0; border-radius: 2px; background: #fff; transform: rotate(-45deg); }
.pause-action span { width: 12px; height: 15px; border-left: 4px solid #fff; border-right: 4px solid #fff; }

.status-strip {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 36px;
  display: flex;
  align-items: center;
}

.heart-bar {
  width: 100px;
  height: 30px;
  margin-left: 8px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-radius: 17px;
  background: #16786b;
  box-shadow: 0 3px 0 rgba(53, 79, 58, .25);
}

.heart {
  position: relative;
  width: 21px;
  height: 19px;
  --heart-color: #ee5d60;
  filter: drop-shadow(1px 2px 1px rgba(84,45,37,.28));
  transition: opacity .2s, transform .2s;
}

.heart::before, .heart::after {
  content: "";
  position: absolute;
  top: 1px;
  width: 11px;
  height: 18px;
  border-radius: 11px 11px 0 0;
  background: var(--heart-color);
}
.heart::before { left: 10px; transform: rotate(-45deg); transform-origin: 0 100%; }
.heart::after { left: 0; transform: rotate(45deg); transform-origin: 100% 100%; }
.heart.is-empty { --heart-color: #083f3a; opacity: .36; filter: none; transform: scale(.82); }

.chapter-pill {
  width: 235px;
  height: 30px;
  margin-left: 7px;
  padding: 0 38px 0 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  color: #f9e9ab;
  background: rgba(79, 148, 119, .94);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(60, 67, 39, .42);
}

.streak-ribbon {
  position: absolute;
  right: -5px;
  width: 95px;
  height: 34px;
  padding-left: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 18px 0 0 18px;
  color: #fff0aa;
  background: linear-gradient(90deg, rgba(240,113,70,.78), #d94843 36%);
  box-shadow: 0 3px 6px rgba(120, 66, 41, .18);
  line-height: 15px;
}

.streak-ribbon strong { font-size: 14px; }
.streak-ribbon span { font: 11px Georgia, serif; }

.puzzle {
  position: relative;
  z-index: 2;
  width: 350px;
  height: 354px;
  margin: 5px auto 0;
}

.col-clues {
  position: absolute;
  left: 54px;
  top: 0;
  width: 280px;
  height: 68px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  align-items: end;
}

.col-clue {
  height: 68px;
  padding: 0 0 5px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  border-right: 2px solid #f2dda0;
  border-radius: 4px 4px 0 0;
  color: #222116;
  background: linear-gradient(90deg, #c6a750, #d8bd65 55%, #b99c49);
  font: 800 15px/14px Arial, sans-serif;
  text-shadow: 0 0 1px #fff16b;
  transition: opacity .2s;
}

.row-clues {
  position: absolute;
  left: 0;
  top: 68px;
  width: 54px;
  height: 280px;
  display: grid;
  grid-template-rows: repeat(10, 1fr);
}

.row-clue {
  padding-right: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  border-bottom: 2px solid #f2dda0;
  border-radius: 4px 0 0 4px;
  color: #222116;
  background: linear-gradient(#c8aa55, #d8bd67 58%, #b99b45);
  font: 800 17px/1 Arial, sans-serif;
  text-shadow: 0 0 1px #fff16b;
  transition: opacity .2s;
}

.clue-solved { opacity: .55; color: #665c36; text-shadow: none; }

.board {
  position: absolute;
  left: 54px;
  top: 68px;
  width: 286px;
  height: 286px;
  padding: 3px;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: 1px;
  border-radius: 6px;
  background: #756341;
  box-shadow: 5px 6px 3px rgba(81,77,45,.34), inset 0 0 0 2px rgba(95,76,43,.7);
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 3px;
  background: #f3f0df;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.85), 0 1px 1px rgba(64,54,35,.22);
  transition: transform .08s, background .15s;
}

.cell:hover { filter: brightness(1.04); }
.cell:active { transform: scale(.9); }
.cell.error { background: linear-gradient(#ed5651, #c92f36); animation: wrong .32s ease; }
.cell.marked { background: #f6f3e6; }
.cross { color: #b8bdf6; font: 800 27px/1 Arial, sans-serif; transform: translateY(-1px); }
.error .cross { color: #fff1cb; }

.sprite {
  background-image: url('./assets/ui-atlas.png');
  background-repeat: no-repeat;
  background-size: 200% 200%;
}

.sprite-panda { background-position: 0 0; }
.sprite-shovel { background-position: 100% 0; }
.sprite-rocket { background-position: 0 100%; }
.sprite-rake { background-position: 100% 100%; }
.cell-panda { position: absolute; inset: -16%; display: block; }

.tools {
  position: relative;
  z-index: 2;
  height: 80px;
  margin-top: 2px;
  display: flex;
  justify-content: center;
  gap: 15px;
}

.tool-button {
  position: relative;
  width: 72px;
  height: 72px;
  padding: 0;
  overflow: visible;
  border-radius: 50%;
  background: transparent;
  transition: transform .12s, filter .12s;
}

.tool-button:hover { filter: brightness(1.04); }
.tool-button:active { transform: translateY(2px) scale(.96); }
.tool-button.is-empty { filter: grayscale(.8); opacity: .58; }
.tool-art { display: block; width: 72px; height: 72px; border-radius: 50%; box-shadow: 0 4px 4px rgba(81,62,37,.3); }
.tool-count { position: absolute; right: -3px; bottom: 12px; color: #fff; font: 800 17px/1 Arial, sans-serif; -webkit-text-stroke: 1px #493426; text-shadow: 0 1px 2px #3d2c20; }
.tool-name { position: absolute; left: 0; right: 0; bottom: -16px; color: #725738; font-size: 12px; font-weight: 800; }

.mode-switch {
  position: relative;
  z-index: 2;
  width: 110px;
  height: 36px;
  margin: 44px auto 0;
  padding: 2px;
  display: flex;
  border-radius: 20px;
  background: #28796b;
  box-shadow: 0 3px 4px rgba(63,75,44,.31), inset 0 0 0 1px rgba(42,83,70,.5);
}

.mode-button {
  width: 53px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 17px;
  color: rgba(255,255,255,.75);
  background: transparent;
  font: 300 31px/1 Arial, sans-serif;
  transition: background .16s, transform .1s;
}

.mode-button:active { transform: scale(.92); }
.mode-mark.is-active { color: #fff; background: #4f9580; }
.mode-fill.is-active { background: linear-gradient(90deg, #f5d878, #edb84f); box-shadow: 0 2px 2px rgba(84,58,33,.32); }
.mode-fill span { width: 17px; height: 17px; border-radius: 4px; background: #fffdf0; }

.menu-button {
  position: absolute;
  z-index: 4;
  right: -7px;
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 54px;
  height: 54px;
  padding: 0 9px 0 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255,255,255,.88);
  border-radius: 50%;
  background: #0d716e;
  box-shadow: 0 3px 5px rgba(48,74,53,.32);
}

.menu-dots { width: 6px; height: 6px; border-radius: 50%; background: #f2c982; box-shadow: 0 12px 0 #f2c982, 0 -12px 0 #f2c982; }
.menu-lines { margin-left: 5px; display: flex; flex-direction: column; gap: 4px; }
.menu-lines i { width: 23px; height: 6px; border-radius: 5px; background: linear-gradient(#ffd99a, #d99a49); box-shadow: inset 0 0 0 1px rgba(115,71,31,.32); }

.toast {
  position: fixed;
  z-index: 8;
  left: 50%;
  bottom: 112px;
  max-width: min(330px, 82vw);
  padding: 10px 18px;
  border-radius: 22px;
  color: #fff9dc;
  background: rgba(48,68,57,.92);
  box-shadow: 0 5px 14px rgba(37,45,31,.24);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity .18s, transform .18s;
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 25px;
  background: rgba(38,61,48,.5);
  backdrop-filter: blur(4px);
}

.overlay[hidden] { display: none; }

.result-card {
  width: 320px;
  padding: 30px 24px 23px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 4px solid #d5a45c;
  border-radius: 20px;
  color: #594730;
  background: linear-gradient(#fff9de, #f6e4ad);
  box-shadow: 0 12px 30px rgba(55,48,34,.36), inset 0 0 0 2px #fff8d9;
  animation: card-in .28s cubic-bezier(.2,.9,.2,1.15);
}

.result-panda { width: 76px; height: 76px; margin-top: -66px; margin-bottom: 7px; border-radius: 16px; box-shadow: 0 5px 8px rgba(79,59,38,.24); }
.result-card h1 { margin: 0; color: #287969; font-size: 28px; letter-spacing: 2px; }
.result-card p { margin: 10px 0 0; font-size: 15px; line-height: 1.6; text-align: center; }
.result-actions { width: 100%; margin-top: 17px; display: grid; gap: 9px; }
.primary-button, .secondary-button { width: 100%; height: 46px; border-radius: 25px; font-size: 17px; font-weight: 800; }
.primary-button { color: #fff9d9; background: linear-gradient(#69aa8e, #31806e); box-shadow: 0 4px 0 #205f53; }
.secondary-button { color: #765538; background: #efd392; box-shadow: 0 3px 0 #bd914e; }

@keyframes wrong {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-3px); }
  65% { transform: translateX(3px); }
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(20px) scale(.92); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-height: 780px) {
  .game-shell { padding-top: 162px; min-height: 700px; }
  .puzzle { transform: scale(.92); transform-origin: top center; margin-bottom: -27px; }
  .tools { transform: scale(.9); }
  .mode-switch { margin-top: 27px; }
}

@media (min-width: 700px) {
  body { padding: 18px 0; }
  .game-shell { min-height: 844px; height: 844px; border-radius: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
