:root {
  --cream: #f6e6c8;
  --cream-dark: #e8c9a0;
  --coral: #e07a5f;
  --coral-deep: #c45c44;
  --teal: #2f6f66;
  --teal-deep: #1d4540;
  --mint: #7ec8b4;
  --gold: #f0c14b;
  --ink: #1a2e2b;
  --paper: #fff8ec;
  --wood: #8b5a2b;
  --wood-light: #c49258;
  --shadow: rgba(18, 32, 30, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 700px at 50% -10%, #3d7a6e 0%, transparent 55%),
    linear-gradient(180deg, #16332f 0%, #0d1f1d 100%);
  font-family: "Fredoka", "Nunito", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 12px 28px;
}

.device {
  width: min(880px, 96vw);
  background: linear-gradient(165deg, #f8edd4 0%, #e7c49a 70%, #d9b07e 100%);
  border-radius: 40px;
  padding: 14px 16px 18px;
  box-shadow:
    0 0 0 5px #245750,
    0 0 0 10px #3c8a7c,
    0 0 0 12px #1a3330,
    0 22px 48px var(--shadow);
}

.device-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 10px 10px;
  gap: 10px;
}

.led {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #7dffb0;
  box-shadow: 0 0 8px #5dff9a;
  border: 2px solid #1d4540;
  flex: 0 0 auto;
}

.led.sleepy {
  background: #f0c14b;
  box-shadow: 0 0 8px #e8b63a;
}

.led.sad {
  background: #e07a5f;
  box-shadow: 0 0 8px #c45c44;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: 12px;
  color: var(--teal-deep);
}

.dew-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff8ec;
  border-radius: 999px;
  padding: 3px 10px 3px 6px;
  box-shadow: 0 2px 0 #d7c4a2;
  color: var(--teal-deep);
  font-weight: 700;
  font-size: 14px;
  min-width: 92px;
}

.dew-badge.pop {
  animation: dewpop 0.35s ease;
}

.dew-drop {
  width: 12px;
  height: 16px;
  background: radial-gradient(circle at 35% 30%, #c8f3ea, #3c8a7c 70%);
  border-radius: 60% 60% 55% 55% / 40% 40% 70% 70%;
  transform: rotate(180deg);
  box-shadow: 0 0 0 1px #1d4540;
}

.dew-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
}

.screen-bezel {
  background: #142826;
  border-radius: 22px;
  padding: 8px;
  box-shadow: inset 0 0 0 3px #0b1816;
}

.screen {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  background: #0b1816;
  aspect-ratio: 960 / 540;
}

#game {
  width: 100%;
  height: 100%;
}

#game canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.screen-glass {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), transparent 18%);
  z-index: 2;
}

.shop {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: rgba(12, 24, 22, 0.55);
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 10px;
}

.shop.hidden { display: none; }

.shop-card {
  flex: 1;
  background: linear-gradient(180deg, #fff8ec, #f3e0c0);
  border-radius: 14px;
  border: 3px solid #5c3a1e;
  box-shadow: inset 0 0 0 2px #d4a574;
  padding: 10px 12px 12px;
  overflow: auto;
  color: var(--teal-deep);
}

.shop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.shop-head h2 {
  margin: 0;
  font-size: 20px;
}

.shop-close, .tool-btn, .buy-btn, .chip, .release-btn, .breed-btn, .park-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font: 600 13px/1 "Fredoka", system-ui, sans-serif;
  color: var(--teal-deep);
}

.shop-close {
  background: #fff8ec;
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: 0 2px 0 #d7c4a2;
}

.shop-blurb {
  margin: 6px 0 10px;
  font-size: 13px;
  color: #3c534e;
}

.shop-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shop-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.45);
  border-radius: 10px;
  padding: 8px 10px;
}

.shop-row .item-name { font-weight: 600; }
.shop-row .item-note { display: block; font-size: 11px; font-weight: 400; color: #5a6e69; }
.shop-row .cost { font-weight: 700; color: var(--teal); white-space: nowrap; }

.buy-btn {
  background: #7ec8b4;
  border-radius: 999px;
  padding: 6px 12px;
  box-shadow: 0 2px 0 #2f6f66;
}

.buy-btn:hover { transform: translateY(-1px); }
.buy-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #2f6f66; }

.buy-btn:disabled {
  background: #d7c4a2;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
  color: #6b5a44;
}

.hud { padding: 10px 8px 0; }

.status {
  margin: 0 0 8px;
  text-align: center;
  font-weight: 500;
  color: #3c534e;
  min-height: 1.3em;
}

.pet-panel {
  background: rgba(255, 248, 236, 0.55);
  border-radius: 16px;
  padding: 8px 10px 10px;
  margin-bottom: 10px;
  min-height: 72px;
}

.panel-empty {
  margin: 16px 0;
  text-align: center;
  color: #5a6e69;
  font-weight: 500;
}

.panel-body.hidden, .hidden { display: none; }

.name-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 8px;
}

#pet-name {
  width: 46%;
  min-width: 130px;
  text-align: left;
  font: 700 20px/1.2 "Fredoka", system-ui, sans-serif;
  color: var(--teal-deep);
  background: transparent;
  border: none;
  border-bottom: 2px dashed rgba(29, 69, 64, 0.28);
  padding: 2px 6px 4px;
}

#pet-name:focus {
  outline: none;
  border-bottom-color: var(--coral);
  background: rgba(255, 248, 236, 0.45);
  border-radius: 8px 8px 0 0;
}

.meta {
  font-size: 13px;
  font-weight: 600;
  color: #3c534e;
  letter-spacing: 0.02em;
}

.bars {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px 12px;
  max-width: 420px;
}

.bar-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--teal-deep);
  margin-bottom: 3px;
}

.bar-track {
  height: 12px;
  background: #fff8ec;
  border-radius: 99px;
  overflow: hidden;
  box-shadow: inset 0 0 0 2px rgba(29, 69, 64, 0.16);
}

.bar-fill {
  height: 100%;
  width: 70%;
  border-radius: 99px;
  transition: width 0.35s ease;
}

.bar-fill.coral { background: linear-gradient(90deg, #f0a07f, #e07a5f); }
.bar-fill.gold { background: linear-gradient(90deg, #f6d56b, #e8b63a); }
.bar-fill.mint { background: linear-gradient(90deg, #b6e3d4, #6fb8a4); }

.inv-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--teal-deep);
  margin: 0 2px 6px;
}

.inventory {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff8ec;
  border-radius: 999px;
  padding: 6px 10px;
  box-shadow: 0 2px 0 #d7c4a2;
}

.chip:hover { transform: translateY(-1px); }
.chip:active, .chip.pressed { transform: translateY(1px); box-shadow: 0 1px 0 #d7c4a2; }
.chip.empty { opacity: 0.45; }
.chip.selected {
  box-shadow: 0 0 0 2px var(--coral), 0 2px 0 #d7c4a2;
  background: #fff1d6;
}

.chip-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(26, 46, 43, 0.25);
}

.chip-swatch.rice { background: #f4e2b8; }
.chip-swatch.berry { background: #c45c7a; }
.chip-swatch.ember { background: #e07a5f; }
.chip-swatch.cave { background: #5b4a7a; }
.chip-swatch.jingle { background: #f0c14b; }
.chip-swatch.pillow { background: #7ec8b4; }
.chip-swatch.jerky { background: #a45a3a; }

.chip b { font-weight: 700; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  background: #fff8ec;
  border-radius: 14px;
  padding: 10px 16px;
  box-shadow: 0 3px 0 #d7c4a2;
}

.tool-btn:hover { transform: translateY(-1px); }
.tool-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #d7c4a2; }

.tool-btn.shop-btn {
  background: #7ec8b4;
  box-shadow: 0 3px 0 #2f6f66;
}

.tool-btn.map-btn {
  background: #e8d4a8;
  box-shadow: 0 3px 0 #8b5a2b;
}

.tool-btn.map-btn:active {
  box-shadow: 0 1px 0 #8b5a2b;
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.slot-meta {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.slots {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--teal-deep);
}

.habitat {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #3c534e;
  white-space: normal;
  text-align: right;
  max-width: 280px;
  line-height: 1.3;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #fff8ec;
  color: var(--teal-deep);
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: 0 8px 24px var(--shadow);
  z-index: 20;
}

.toast.hidden { display: none; }

@keyframes dewpop {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@media (max-width: 560px) {
  .brand { letter-spacing: 0.08em; font-size: 10px; }
  .bars { grid-template-columns: 1fr; }
  #pet-name { width: 55%; font-size: 18px; }
  .shop-row { grid-template-columns: 1fr auto; }
  .shop-row .cost { grid-column: 1; }
}

.release-btn {
  background: #f3d2c4;
  border-radius: 999px;
  padding: 5px 10px;
  box-shadow: 0 2px 0 #c45c44;
  color: #7a2e20;
  font: 600 12px/1 "Fredoka", system-ui, sans-serif;
  flex: 0 0 auto;
}
.release-btn:hover { transform: translateY(-1px); }
.release-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #c45c44; }

.breed-btn {
  background: #cfe8d8;
  border-radius: 999px;
  padding: 5px 10px;
  box-shadow: 0 2px 0 #2f6f66;
  color: #1d4540;
  font: 600 12px/1 "Fredoka", system-ui, sans-serif;
  flex: 0 0 auto;
  white-space: nowrap;
}
.breed-btn:hover { transform: translateY(-1px); }
.breed-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #2f6f66; }
.breed-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.park-btn {
  background: #cfe8d8;
  border-radius: 999px;
  padding: 5px 10px;
  box-shadow: 0 2px 0 #2f6f66;
  color: #1d4540;
  font: 600 12px/1 "Fredoka", system-ui, sans-serif;
  flex: 0 0 auto;
  white-space: nowrap;
}
.park-btn:hover { transform: translateY(-1px); }
.park-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 #2f6f66; }
.park-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.mate-card {
  flex: 0 1 auto;
  width: min(420px, 100%);
  max-height: 92%;
  margin: auto;
}
