:root {
  color-scheme: dark;
  --ink: #101318;
  --ink-2: #171d24;
  --panel: #20252b;
  --panel-2: #2b312f;
  --paper: #f3ead8;
  --muted: #aeb5ad;
  --line: #45505a;
  --green: #9fcb6b;
  --red: #c75e4d;
  --blue: #6da7bf;
  --violet: #9a7bb9;
  --gold: #d7aa4f;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.36);
  font-family:
    ui-monospace, "SFMono-Regular", "Menlo", "Consolas", "Liberation Mono",
    monospace;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(55, 68, 60, 0.28), rgba(19, 22, 28, 0.94)),
    radial-gradient(circle at 18% 18%, rgba(159, 203, 107, 0.18), transparent 30%),
    #101318;
  color: var(--paper);
}

button,
a {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(1480px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 16px;
}

.topbar,
.pet-rail,
.pet-stage-panel,
.needs-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(36, 43, 49, 0.96), rgba(20, 25, 31, 0.96));
  box-shadow: var(--shadow);
}

.topbar {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 24px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 8px;
  color: var(--green);
  font-size: 1rem;
}

.credit-link,
.source-box a {
  color: var(--paper);
  text-decoration: none;
  border: 1px solid #77674c;
  border-radius: 6px;
  padding: 10px 12px;
  background: rgba(215, 170, 79, 0.12);
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(390px, 1fr) 340px;
  gap: 16px;
  min-height: 0;
}

.pet-rail,
.needs-panel {
  padding: 16px;
}

.pet-rail h2,
.needs-panel h2 {
  font-size: 1.1rem;
  margin-bottom: 14px;
}

.pet-list {
  display: grid;
  gap: 10px;
}

.pet-option {
  width: 100%;
  min-height: 84px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: rgba(10, 13, 16, 0.42);
  display: grid;
  grid-template-columns: 64px 1fr;
  align-items: center;
  gap: 14px;
  padding: 10px;
  text-align: left;
  cursor: pointer;
}

.pet-option[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 18%, rgba(10, 13, 16, 0.7));
  box-shadow: inset 4px 0 0 var(--accent);
}

.pet-option strong,
.pet-option small {
  display: block;
}

.pet-option strong {
  font-size: 1.02rem;
}

.pet-option small {
  margin-top: 5px;
  color: var(--muted);
  text-transform: capitalize;
}

.pet-mini {
  width: 58px;
  height: 58px;
  display: block;
  background-repeat: no-repeat;
  background-position: left center;
  background-size: auto 100%;
  image-rendering: pixelated;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.5));
}

.pet-stage-panel {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto auto;
  gap: 14px;
  padding: 16px;
  min-width: 0;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding-bottom: 14px;
}

.species-label {
  color: var(--green);
  text-transform: uppercase;
  font-size: 0.82rem;
}

#pet-name {
  margin-top: 4px;
  font-size: clamp(1.9rem, 5vw, 3.6rem);
  line-height: 0.96;
}

.temperament {
  max-width: 260px;
  color: var(--muted);
  text-align: right;
  line-height: 1.4;
}

.stage {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 2px solid #d8ccb5;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(170, 203, 205, 0.9), rgba(207, 216, 197, 0.86) 46%, rgba(98, 91, 70, 0.86) 47%),
    linear-gradient(90deg, rgba(44, 59, 43, 0.4), transparent 22%, transparent 78%, rgba(44, 59, 43, 0.42));
}

.stage::before,
.stage::after {
  content: "";
  position: absolute;
  bottom: 40%;
  width: 140px;
  height: 210px;
  background:
    linear-gradient(135deg, transparent 38%, #456348 39% 55%, transparent 56%),
    linear-gradient(45deg, transparent 38%, #324734 39% 55%, transparent 56%);
  opacity: 0.38;
}

.stage::before {
  left: 8%;
}

.stage::after {
  right: 8%;
  transform: scaleX(-1);
}

.pet-sprite {
  --frame-width: 160px;
  --frame-height: 160px;
  --strip-width: 800px;
  --frames: 5;
  --duration: 900ms;
  position: absolute;
  left: 50%;
  bottom: 82px;
  width: var(--frame-width);
  height: var(--frame-height);
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: auto 100%;
  transform: translateX(-50%);
  animation: sprite-cycle var(--duration) steps(var(--frames)) infinite;
  filter: drop-shadow(0 22px 18px rgba(0, 0, 0, 0.35));
  z-index: 2;
}

.pet-sprite.is-reacting {
  animation:
    sprite-cycle var(--duration) steps(var(--frames)) infinite,
    happy-hop 520ms ease-out 1;
}

.floor-shadow {
  position: absolute;
  left: 50%;
  bottom: 70px;
  width: min(260px, 44%);
  height: 34px;
  border-radius: 50%;
  background: rgba(27, 27, 20, 0.28);
  transform: translateX(-50%);
  filter: blur(2px);
}

.message {
  min-height: 52px;
  border: 1px solid rgba(159, 203, 107, 0.4);
  border-radius: 6px;
  padding: 14px;
  color: #d9ef9c;
  background: rgba(45, 62, 31, 0.4);
  line-height: 1.45;
}

.actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.actions button {
  min-height: 88px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  cursor: pointer;
  color: var(--paper);
  background: linear-gradient(180deg, #465b2d, #25331e);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.05);
}

.actions button:nth-child(2) {
  background: linear-gradient(180deg, #7c332b, #421f1b);
}

.actions button:nth-child(3) {
  background: linear-gradient(180deg, #33566d, #1b303d);
}

.actions button:nth-child(4) {
  background: linear-gradient(180deg, #59456d, #30243e);
}

.actions button span {
  display: block;
  font-size: 1.12rem;
}

.actions button:focus-visible,
.pet-option:focus-visible,
.credit-link:focus-visible,
.source-box a:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.actions button:active {
  transform: translateY(1px);
}

.stats {
  display: grid;
  gap: 18px;
}

.stat-copy {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.stat-copy span {
  color: var(--paper);
}

.stat-copy strong {
  color: var(--muted);
  font-weight: 700;
}

.meter {
  height: 16px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(0, 0, 0, 0.28);
  padding: 2px;
}

.meter span {
  display: block;
  height: 100%;
  background: var(--green);
}

.stat-hunger .meter span {
  background: var(--gold);
}

.stat-energy .meter span {
  background: var(--blue);
}

.stat-bond .meter span {
  background: var(--red);
}

.source-box {
  margin-top: 24px;
  border-radius: 8px;
  border: 1px solid #7b6d56;
  background: var(--paper);
  color: #211c16;
  padding: 14px;
}

.source-box h3 {
  font-size: 1.05rem;
  margin-bottom: 10px;
}

.source-box p {
  color: #382f25;
  line-height: 1.4;
}

.source-box a {
  display: inline-block;
  margin: 12px 0;
  color: #1c2831;
  background: rgba(109, 167, 191, 0.16);
  border-color: rgba(28, 40, 49, 0.25);
}

@keyframes sprite-cycle {
  to {
    background-position-x: calc(var(--strip-width) * -1);
  }
}

@keyframes happy-hop {
  0%,
  100% {
    transform: translateX(-50%) translateY(0) scale(1);
  }
  38% {
    transform: translateX(-50%) translateY(-24px) scale(1.04);
  }
  70% {
    transform: translateX(-50%) translateY(2px) scale(0.98);
  }
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 260px minmax(360px, 1fr);
  }

  .needs-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 16px, 720px);
    margin: 8px auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .pet-rail,
  .pet-stage-panel,
  .needs-panel {
    padding: 12px;
  }

  .pet-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pet-option {
    min-height: 72px;
    grid-template-columns: 48px 1fr;
    gap: 10px;
  }

  .pet-mini {
    width: 44px;
    height: 44px;
  }

  .stage {
    min-height: 330px;
  }

  .stage-header {
    align-items: start;
    flex-direction: column;
  }

  .temperament {
    text-align: left;
  }

  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .pet-sprite,
  .pet-sprite.is-reacting {
    animation: none;
  }
}
