:root {
  /* Classic washed-out Bandai yellow shell */
  --shell: #efe47a;
  --shell-deep: #d4c45c;
  --shell-light: #f7f0b0;
  --shell-shadow: #b8a840;
  --button: #2f6f8a;
  --button-top: #4a94ad;
  --button-deep: #1a4558;
  --lcd-bg: #9aa882;
  --lcd-pixel: #2a3324;
  --lcd-pixel-dim: rgba(42, 51, 36, 0.22);
  --lcd-bezel: #4a5048;
  --bg-top: #2a2818;
  --bg-mid: #3a3620;
  --bg-bottom: #16140e;
  --text: #f5f0d8;
  --muted: rgba(245, 240, 216, 0.55);
  --font-pixel: "Press Start 2P", "IBM Plex Mono", monospace;
  --font-ui: "IBM Plex Mono", ui-monospace, monospace;
}

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

html,
body {
  min-height: 100%;
  min-height: 100dvh;
}

body {
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(ellipse 90% 55% at 50% 18%, #5a5230 0%, transparent 55%),
    radial-gradient(ellipse 70% 40% at 80% 90%, #2a3840 0%, transparent 50%),
    linear-gradient(165deg, var(--bg-top) 0%, var(--bg-mid) 45%, var(--bg-bottom) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  left: 1rem;
  top: 1rem;
  z-index: 10;
  background: #fff;
  color: #000;
  padding: 0.5rem 0.75rem;
}

.top {
  width: min(420px, 100%);
  padding: 1rem 1.25rem 0.25rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.top h1 {
  font-family: var(--font-pixel);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  font-weight: 400;
}

.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
}

.back:hover,
.back:focus-visible {
  color: var(--text);
}

.stage {
  width: min(420px, 100%);
  padding: 0.5rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}

/* ---- egg shell (classic Bandai silhouette) ---- */

.egg {
  position: relative;
  width: min(78vw, 280px);
  aspect-ratio: 0.72 / 1;
  margin-top: 0.5rem;
  border-radius: 50% 50% 46% 46% / 42% 42% 58% 58%;
  background:
    radial-gradient(ellipse 55% 35% at 32% 22%, var(--shell-light) 0%, transparent 55%),
    radial-gradient(ellipse 80% 70% at 50% 45%, var(--shell) 0%, var(--shell-deep) 70%, var(--shell-shadow) 100%);
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.4) inset,
    0 -18px 28px rgba(120, 100, 30, 0.28) inset,
    0 22px 40px rgba(0, 0, 0, 0.45),
    0 4px 0 rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 11% 12% 10%;
  transition: filter 280ms ease, transform 280ms ease;
}

.egg.is-attention {
  animation: wiggle 0.7s ease-in-out 2;
}

.egg.is-dead {
  filter: grayscale(0.35) brightness(0.92);
}

.egg.lights-off .lcd-glass {
  background: #6a7560;
}

.egg-shine {
  pointer-events: none;
  position: absolute;
  inset: 8% 18% auto;
  height: 18%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent);
  filter: blur(1px);
}

.egg-brand {
  font-family: var(--font-pixel);
  font-size: 0.42rem;
  letter-spacing: 0.12em;
  color: rgba(110, 90, 20, 0.55);
  margin-bottom: 0.55rem;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* ---- LCD ---- */

.lcd {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  background: linear-gradient(160deg, #5a6058, var(--lcd-bezel) 40%, #353a34);
  border-radius: 10px;
  padding: 7px;
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.12) inset,
    0 -3px 6px rgba(0, 0, 0, 0.35) inset,
    0 4px 10px rgba(0, 0, 0, 0.25);
}

.lcd-glass {
  height: 100%;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(40, 50, 30, 0.04) 2px,
      rgba(40, 50, 30, 0.04) 3px
    ),
    var(--lcd-bg);
  border-radius: 4px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.25) inset,
    0 2px 8px rgba(0, 0, 0, 0.15) inset;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 6px 5px 5px;
  gap: 4px;
  image-rendering: pixelated;
}

.lcd-icons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px 4px;
}

.tama-icon {
  appearance: none;
  border: none;
  background: transparent;
  padding: 3px;
  cursor: pointer;
  opacity: 0.35;
  display: grid;
  place-items: center;
  border-radius: 2px;
}

.tama-icon.active {
  opacity: 1;
  background: rgba(42, 51, 36, 0.12);
  box-shadow: 0 0 0 1px rgba(42, 51, 36, 0.35);
}

.tama-icon.blink {
  animation: blink 0.85s steps(1) infinite;
  opacity: 1;
}

.lcd-screen {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 110px;
  overflow: hidden;
}

.lcd-status {
  min-height: 14px;
  display: flex;
  justify-content: center;
}

.tama-scene {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
}

.tama-pet {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: opacity 200ms ease;
}

.tama-pet.dim {
  opacity: 0.45;
}

.tama-pet.bounce {
  animation: hop 0.4s ease;
}

.tama-poops {
  position: absolute;
  left: 8%;
  bottom: 8%;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 40%;
}

.tama-sick-mark {
  position: absolute;
  right: 14%;
  top: 18%;
  font-family: var(--font-pixel);
  font-size: 0.7rem;
  color: var(--lcd-pixel);
  animation: blink 1s steps(1) infinite;
}

.tama-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 4px 6px;
}

.tama-lcd-text {
  font-family: var(--font-pixel);
  font-size: 0.48rem;
  line-height: 1.55;
  color: var(--lcd-pixel);
  letter-spacing: 0.02em;
}

.tama-lcd-text.sel {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tama-meters {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 4px;
}

.tama-meter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-pixel);
  font-size: 0.4rem;
  color: var(--lcd-pixel);
}

.tama-hearts {
  display: inline-flex;
  gap: 2px;
  align-items: center;
}

.status-hearts {
  opacity: 0.9;
}

.px,
.pet-sprite {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.egg-message {
  margin-top: 0.55rem;
  min-height: 1.1em;
  font-family: var(--font-pixel);
  font-size: 0.42rem;
  text-align: center;
  color: rgba(90, 75, 15, 0.75);
  line-height: 1.4;
  max-width: 90%;
}

/* ---- buttons ---- */

.buttons {
  margin-top: 0.65rem;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 1.15rem;
  width: 100%;
}

.btn-key {
  appearance: none;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, var(--button-top), var(--button) 52%, var(--button-deep) 100%);
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.18) inset,
    0 -3px 4px rgba(0, 0, 0, 0.4) inset,
    0 4px 0 #123040,
    0 6px 10px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  color: rgba(200, 235, 245, 0.55);
  font-family: var(--font-pixel);
  font-size: 0.4rem;
  display: grid;
  place-items: center;
  transition: transform 80ms ease, box-shadow 80ms ease;
}

.btn-key-main {
  width: 44px;
  height: 44px;
  margin-top: 10px;
}

.btn-key:active,
.btn-key:focus-visible {
  transform: translateY(3px);
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.12) inset,
    0 -2px 3px rgba(0, 0, 0, 0.35) inset,
    0 1px 0 #123040,
    0 2px 6px rgba(0, 0, 0, 0.25);
  outline: none;
}

.egg-feet {
  position: absolute;
  bottom: 4%;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 28%;
  pointer-events: none;
}

.egg-feet span {
  width: 22px;
  height: 10px;
  border-radius: 40% 40% 30% 30%;
  background: linear-gradient(180deg, var(--shell-deep), var(--shell-shadow));
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

.forecast {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
  max-width: 28rem;
  min-height: 1.45em;
}

.catchup {
  width: 100%;
  max-width: 28rem;
  text-align: center;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #f5efc8;
  background: rgba(180, 150, 40, 0.22);
  border: 1px solid rgba(230, 210, 100, 0.28);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
}

.meters {
  width: 100%;
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: center;
}

.live-meters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 1.25rem;
  width: 100%;
}

.live-meters > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--muted);
}

.live-meters .tama-hearts canvas {
  /* hearts reuse LCD pixel color; lighten for dark bg */
  filter: invert(1) brightness(1.35) contrast(0.85);
}

.live-meta {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.restart {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
}

.restart:hover,
.restart:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

.help {
  margin-top: 0.25rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.5;
  max-width: 26rem;
}

.help kbd {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.25);
}

.help-note {
  margin-top: 0.45rem;
  opacity: 0.85;
}

@keyframes hop {
  0%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-6px);
  }
}

@keyframes blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0.2;
  }
}

@keyframes wiggle {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-2.5deg);
  }
  75% {
    transform: rotate(2.5deg);
  }
}

@media (max-width: 380px) {
  .egg {
    width: min(86vw, 260px);
  }

  .btn-key {
    width: 34px;
    height: 34px;
  }

  .btn-key-main {
    width: 40px;
    height: 40px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .top {
    padding-top: 0.5rem;
  }

  .egg {
    width: min(42vh, 220px);
    margin-top: 0;
  }

  .help-note {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .egg.is-attention,
  .tama-pet.bounce,
  .tama-icon.blink,
  .tama-sick-mark {
    animation: none;
  }
}
