:root {
  --grass: #7CBD4B;
  --grass-dark: #5DAE3B;
  --grass-light: #8FCF5F;
  --dirt: #8B5A2B;
  --dirt-dark: #6B4A2B;
  --dirt-light: #A06A3B;
  --stone: #8C8C8C;
  --stone-light: #C9C9C9;
  --stone-dark: #555;
  --gold: #F8C471;
  --gold-dark: #DAA520;
  --red: #C0392B;
  --pink: #F48FB1;
  --cream: #FDF3E3;
  --ink: #1B1B1B;
  --night: #0B1026;
  --pixel-font: 'Press Start 2P', 'PingFang SC', 'Microsoft YaHei', monospace, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  font-family: var(--pixel-font);
  background: var(--ink);
  overflow: hidden;
  color: #fff;
}

.view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transition: opacity .4s ease;
}

.view.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.mc-btn {
  font-family: var(--pixel-font);
  font-size: 14px;
  color: #fff;
  background: var(--stone);
  border: none;
  padding: 14px 22px;
  cursor: pointer;
  position: relative;
  image-rendering: pixelated;
  box-shadow:
    inset 3px 3px 0 var(--stone-light),
    inset -3px -3px 0 var(--stone-dark),
    4px 4px 0 rgba(0, 0, 0, .55);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .6);
  user-select: none;
  transition: filter .1s;
}

.mc-btn:hover {
  filter: brightness(1.12);
}

.mc-btn:active {
  box-shadow:
    inset 3px 3px 0 var(--stone-dark),
    inset -3px -3px 0 var(--stone-light),
    1px 1px 0 rgba(0, 0, 0, .55);
  transform: translateY(2px);
}

.mc-btn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.mc-btn.gold {
  background: var(--gold-dark);
  box-shadow:
    inset 3px 3px 0 var(--gold),
    inset -3px -3px 0 #9A7B1A,
    4px 4px 0 rgba(0, 0, 0, .55);
}

.mc-btn.gold:active {
  box-shadow:
    inset 3px 3px 0 #9A7B1A,
    inset -3px -3px 0 var(--gold),
    1px 1px 0 rgba(0, 0, 0, .55);
}

#view-start {
  background:
    radial-gradient(circle at 50% 30%, rgba(255, 255, 255, .12), transparent 55%),
    linear-gradient(#6FC3F0 0%, #AEE4FF 55%, #CFF2FF 62%, var(--grass) 62%, var(--grass) 66%, var(--dirt) 66%, var(--dirt) 100%);
  text-align: center;
  padding: 24px;
}

#view-start .pixel-sun {
  position: absolute;
  top: 7%;
  right: 12%;
  width: 64px;
  height: 64px;
  background: #FFE082;
  box-shadow: 0 0 0 8px #FFE08233, 0 0 40px #FFD54F88;
  border: 4px solid #FFC107;
}

#view-start .cloud {
  position: absolute;
  width: 120px;
  height: 36px;
  background: #fff;
  border: 3px solid #E3F2FD;
  opacity: .92;
}

#view-start .cloud::before,
#view-start .cloud::after {
  content: '';
  position: absolute;
  background: #fff;
  border: 3px solid #E3F2FD;
}

#view-start .cloud::before {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  left: 12px;
  top: -30px;
}

#view-start .cloud::after {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  right: 14px;
  top: -22px;
}

.title-pixel {
  font-family: var(--pixel-font);
  font-size: clamp(20px, 5.2vw, 44px);
  line-height: 1.35;
  color: #fff;
  text-shadow: 4px 4px 0 #1B1B1B, 8px 8px 0 rgba(0, 0, 0, .25);
  margin-bottom: 6px;
}

.title-heart {
  display: inline-block;
  color: var(--red);
  text-shadow: 4px 4px 0 #1B1B1B;
}

.sub-pixel {
  font-family: var(--pixel-font);
  font-size: clamp(11px, 2.2vw, 17px);
  color: #FFF9E6;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, .65);
  margin: 18px 0 6px;
  letter-spacing: 1px;
}

.start-desc {
  font-size: 11px;
  line-height: 2;
  color: #E8F6FF;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .5);
  margin-bottom: 26px;
  opacity: .95;
}

.start-desc .kbd {
  background: rgba(0, 0, 0, .35);
  border: 2px solid rgba(255, 255, 255, .6);
  padding: 2px 8px;
  margin: 0 2px;
  display: inline-block;
}

#start-btn {
  margin-top: 8px;
  animation: pulse 1.6s infinite;
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.05);
  }
}

.start-foot {
  position: absolute;
  bottom: 16px;
  width: 100%;
  text-align: center;
  font-size: 10px;
  color: rgba(255, 255, 255, .75);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, .5);
}

#view-game {
  background: #000;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
}

#task-bar {
  background: rgba(0, 0, 0, .5);
  border: 3px solid #000;
  outline: 2px solid rgba(255, 255, 255, .55);
  padding: 8px 12px;
  font-size: 11px;
  line-height: 1.8;
  color: #FFF;
  text-shadow: 1px 1px 0 #000;
  max-width: 72vw;
}

#task-bar .task-goal {
  color: var(--gold);
}

#hotbar {
  background: rgba(0, 0, 0, .45);
  border: 3px solid #000;
  outline: 2px solid rgba(255, 255, 255, .4);
  padding: 5px;
  display: flex;
  gap: 5px;
}

.slot {
  width: 34px;
  height: 34px;
  background: rgba(0, 0, 0, .35);
  border: 2px solid rgba(255, 255, 255, .35);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.slot.got {
  background: rgba(255, 255, 255, .12);
  border-color: var(--gold);
}

.slot .slot-ico {
  width: 20px;
  height: 20px;
  image-rendering: pixelated;
}

.coin-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  margin-left: 10px;
  background: rgba(0, 0, 0, .35);
  border: 2px solid #000;
  outline: 1px solid rgba(255, 193, 7, .55);
  color: #FFD54F;
  text-shadow: 1px 1px 0 #000;
  font-size: 10px;
  letter-spacing: 1px;
}

.coin-count.ready {
  background: rgba(255, 193, 7, .18);
  outline-color: #FFD54F;
  color: #FFF;
  animation: coinPulse 1.4s infinite;
}

@keyframes coinPulse {

  0%,
  100% {
    outline-color: #FFD54F;
  }

  50% {
    outline-color: #FFF;
  }
}

.coin-icon {
  display: inline-block;
  width: 14px;
  height: 14px;
  background: #F8C471;
  border: 1px solid #8D5A2B;
  border-radius: 2px;
  position: relative;
  box-shadow: inset -2px -2px 0 rgba(0, 0, 0, .28), inset 2px 2px 0 rgba(255, 255, 255, .28);
}

.coin-icon::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 4px;
  width: 2px;
  height: 10px;
  background: #B8860B;
}

.coin-num {
  font-weight: bold;
  color: #FFE082;
}

.hp-count {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  margin-left: 10px;
  background: rgba(0, 0, 0, .35);
  border: 2px solid #000;
  outline: 1px solid rgba(244, 67, 54, .55);
  color: #EF5350;
  text-shadow: 1px 1px 0 #000;
  font-size: 10px;
  letter-spacing: 1px;
}

.hp-hearts {
  display: inline-block;
  width: 14px;
  height: 14px;
  background:
    radial-gradient(circle at 30% 30%, #FFCDD2 2px, #E53935 3px),
    #E53935;
  clip-path: polygon(50% 100%, 0% 35%, 0% 15%, 15% 0%, 35% 0%, 50% 15%, 65% 0%, 85% 0%, 100% 15%, 100% 35%);
}

#mute-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, .5);
  border: 3px solid #000;
  outline: 2px solid rgba(255, 255, 255, .4);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  font-family: "Noto Sans Symbols 2", "Segoe UI Symbol", "Apple Symbols", sans-serif;
}

#mute-btn:active {
  filter: brightness(1.3);
}

#hint {
  position: fixed;
  left: 50%;
  bottom: 16%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, .72);
  border: 3px solid #000;
  outline: 2px solid rgba(255, 255, 255, .5);
  color: var(--gold);
  font-size: 12px;
  padding: 10px 16px;
  text-shadow: 1px 1px 0 #000;
  z-index: 6;
  display: none;
  text-align: center;
  line-height: 1.9;
}

#dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, 90vw);
  background: rgba(10, 10, 14, .92);
  border: 4px solid #000;
  outline: 3px solid rgba(255, 255, 255, .6);
  padding: 18px 20px 16px;
  z-index: 8;
  box-shadow: 8px 8px 0 rgba(0, 0, 0, .5);
}

#dialog.hidden {
  display: none;
}

#dialog .dlg-title {
  font-size: 10px;
  color: var(--gold);
  margin-bottom: 10px;
  letter-spacing: 1px;
}

#dialog .dlg-text {
  font-size: clamp(12px, 2.6vw, 15px);
  line-height: 2.1;
  color: #FFF;
  text-shadow: 1px 1px 0 #000;
  min-height: 60px;
  word-break: break-word;
}

#dialog .dlg-photo-wrap {
  float: left;
  width: 120px;
  height: 120px;
  margin: 2px 14px 8px 0;
  background: #111;
  border: 4px solid #000;
  outline: 3px solid rgba(255, 255, 255, .55);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#dialog .dlg-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: auto;
  display: block;
}

#dialog .dlg-photo[src=""],
#dialog .dlg-photo:not([src]) {
  display: none;
}

#dialog .dlg-actions {
  margin-top: 12px;
  text-align: right;
}

#dialog .mc-btn {
  padding: 10px 18px;
  font-size: 12px;
}

#touch-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 7;
  display: none;
  padding: 14px;
  pointer-events: none;
}

#touch-controls .pad {
  pointer-events: auto;
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(3, 58px);
  gap: 4px;
  width: 182px;
}

#touch-controls .tbtn {
  background: rgba(0, 0, 0, .4);
  border: 3px solid rgba(255, 255, 255, .5);
  color: #fff;
  font-size: 20px;
  font-family: var(--pixel-font);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

#touch-controls .tbtn:active {
  background: rgba(255, 255, 255, .35);
}

#touch-controls .tbtn.empty {
  visibility: hidden;
}

#touch-controls .act {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: rgba(248, 196, 113, .35);
  border: 3px solid var(--gold);
  color: var(--gold);
  font-size: 12px;
  pointer-events: auto;
}

#view-done {
  background: transparent;
  text-align: center;
  padding: 24px;
  overflow: hidden;
}

#view-done::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(11, 16, 38, 0.55) 0%, rgba(26, 35, 64, 0.50) 30%, rgba(46, 27, 79, 0.48) 55%, rgba(74, 35, 90, 0.45) 75%, rgba(27, 27, 27, 0.55) 100%),
    radial-gradient(2px 2px at 10% 15%, #fff, transparent),
    radial-gradient(2px 2px at 22% 8%, #FFE082, transparent),
    radial-gradient(2px 2px at 35% 22%, #fff, transparent),
    radial-gradient(3px 3px at 48% 12%, #fff, transparent),
    radial-gradient(2px 2px at 60% 25%, #FFF9C4, transparent),
    radial-gradient(2px 2px at 72% 10%, #fff, transparent),
    radial-gradient(2px 2px at 85% 18%, #FFCCBC, transparent),
    radial-gradient(2px 2px at 92% 8%, #fff, transparent),
    radial-gradient(2px 2px at 5% 35%, #fff, transparent),
    radial-gradient(2px 2px at 18% 42%, #B3E5FC, transparent),
    radial-gradient(3px 3px at 30% 38%, #fff, transparent),
    radial-gradient(2px 2px at 55% 42%, #fff, transparent),
    radial-gradient(2px 2px at 68% 36%, #F8BBD9, transparent),
    radial-gradient(2px 2px at 80% 44%, #fff, transparent),
    radial-gradient(2px 2px at 95% 38%, #fff, transparent);
  background-size: 100% 100%;
  animation: twinkle 3s ease-in-out infinite alternate;
  z-index: 1;
}

#view-done::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 80px;
  pointer-events: none;
  background:
    linear-gradient(#7CB342 #7CB342 50%, #558B2F 50% #558B2F 80%, transparent 80%);
  background-size: 16px 16px;
  image-rendering: pixelated;
  opacity: 0.4;
  z-index: 2;
}

@keyframes twinkle {
  0% {
    opacity: 0.85;
  }

  100% {
    opacity: 1;
  }
}

.done-moon {
  position: absolute;
  top: 8%;
  right: 10%;
  width: 72px;
  height: 72px;
  background: #E8ECFF;
  box-shadow:
    0 0 0 6px rgba(232, 236, 255, 0.2),
    0 0 60px rgba(232, 236, 255, 0.5);
  image-rendering: pixelated;
  z-index: 3;
}

.done-moon::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 60%;
  width: 20px;
  height: 20px;
  background: #0B1026;
  transform: translate(-50%, -50%);
}

.done-decor {
  position: absolute;
  bottom: 40px;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 4;
}

.done-heart-decor {
  position: absolute;
  bottom: 65px;
  left: 6%;
  color: #FF4081;
  font-size: 28px;
  text-shadow: 2px 2px 0 #000;
  animation: floatHeart 2s ease-in-out infinite;
}

.done-heart-decor:nth-child(2) {
  left: 14%;
  color: #FF80AB;
  font-size: 20px;
  animation-delay: 0.5s;
  bottom: 55px;
}

@keyframes floatHeart {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

.done-content {
  position: relative;
  z-index: 10;
}

#view-game.play-ended .hud,
#view-game.play-ended .hint,
#view-game.play-ended .dialog-box,
#view-game.play-ended .touch-controls {
  opacity: 0;
  pointer-events: none;
  transition: opacity .35s;
}

#view-done .done-title {
  font-family: var(--pixel-font);
  font-size: clamp(18px, 4.6vw, 38px);
  line-height: 1.5;
  color: #fff;
  text-shadow: 4px 4px 0 #000, 0 0 30px rgba(248, 196, 113, .6);
  margin-bottom: 14px;
}

#view-done .done-love {
  font-size: clamp(13px, 2.8vw, 19px);
  color: var(--gold);
  text-shadow: 2px 2px 0 #000;
  margin-bottom: 30px;
  line-height: 2;
}

#view-done .mc-btn {
  margin: 6px 8px;
}

@media (max-width:640px) {
  #touch-controls {
    display: block;
  }

  #task-bar {
    font-size: 12px;
  }

  .start-desc {
    font-size: 13px;
  }

  .start-foot {
    font-size: 12px;
  }

  .sub-pixel {
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #start-btn {
    animation: none;
  }
}