:root {
  --plastic: #7cb87a;
  --plastic-dark: #5a9a58;
  --plastic-light: #9fd09c;
  --bezel: #3d5c3c;
  --screen: #c8e8b8;
  --screen-deep: #a8d498;
  --ink: #1e2e1c;
  --ink-soft: #3a5238;
  --accent: #e8a838;
  --accent-dark: #c48420;
  --danger: #c44c3c;
  --bar-hunger: #e88840;
  --bar-happy: #e8c040;
  --bar-energy: #58a8e0;
  --bar-clean: #70c8b0;
  --shadow: rgba(30, 46, 28, 0.35);
  font-size: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
  overflow-x: hidden;
}

.backdrop {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 20%, #e8f4d8 0%, transparent 55%),
    linear-gradient(165deg, #8ecf7a 0%, #5a9e68 40%, #3d7a52 100%);
  z-index: -1;
}

.backdrop::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='40' height='40' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='4' cy='4' r='2' fill='%23ffffff22'/%3E%3C/svg%3E");
  opacity: 0.6;
  pointer-events: none;
}

.device {
  width: min(100%, 380px);
}

.device-bezel {
  background: linear-gradient(160deg, var(--plastic-light), var(--plastic) 45%, var(--plastic-dark));
  border-radius: 2.5rem;
  padding: 1.1rem 1.1rem 1.4rem;
  box-shadow:
    0 18px 40px var(--shadow),
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -3px 0 rgba(0, 0, 0, 0.12);
  border: 3px solid var(--bezel);
}

.device-speaker {
  width: 48%;
  height: 8px;
  margin: 0 auto 0.85rem;
  border-radius: 4px;
  background: repeating-linear-gradient(
    90deg,
    var(--bezel) 0 3px,
    transparent 3px 7px
  );
  opacity: 0.7;
}

.screen {
  position: relative;
  background: linear-gradient(180deg, var(--screen) 0%, var(--screen-deep) 100%);
  border-radius: 0.75rem;
  border: 4px solid var(--bezel);
  box-shadow: inset 0 0 24px rgba(30, 80, 40, 0.15);
  min-height: 480px;
  padding: 0.9rem;
  overflow: hidden;
}

.device-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1rem;
}

.d-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bezel);
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.15);
}

.d-btn.wide {
  width: 64px;
  border-radius: 18px;
}

/* Panels */
.panel {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  height: 100%;
  min-height: 450px;
  animation: fadeIn 0.25s ease;
}

.panel.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.logo {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.15rem;
  text-align: center;
  margin: 2.5rem 0 0.5rem;
  color: var(--ink);
  line-height: 1.5;
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.4);
}

.tagline {
  text-align: center;
  margin: 0 0 2rem;
  color: var(--ink-soft);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.panel-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  text-align: center;
  margin: 0.5rem 0;
  line-height: 1.6;
}

.fineprint {
  margin-top: auto;
  font-size: 0.65rem;
  text-align: center;
  color: var(--ink-soft);
  opacity: 0.75;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0 1rem;
}

.btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  border: 2px solid var(--bezel);
  border-radius: 0.65rem;
  padding: 0.55rem 0.9rem;
  background: #eef8e6;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--bezel);
  transition: transform 0.08s, box-shadow 0.08s;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--bezel);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  box-shadow: 0 3px 0 var(--accent-dark);
}

.btn.danger {
  background: #f0a898;
  border-color: var(--danger);
  box-shadow: 0 3px 0 var(--danger);
}

.btn.heal {
  background: #a8e0c8;
  border-color: #4a9a78;
  box-shadow: 0 3px 0 #4a9a78;
}

.btn.icon {
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border-radius: 0.5rem;
  font-size: 1rem;
}

.btn.action {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  padding: 0.5rem 0.35rem;
}

.btn-row {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Starter */
.starter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
}

.starter-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.5rem 0.25rem;
  border: 2px solid var(--bezel);
  border-radius: 0.65rem;
  background: #e4f4d8;
  cursor: pointer;
  font-family: inherit;
  color: inherit;
  transition: background 0.15s, transform 0.1s;
}

.starter-card:hover {
  background: #f0fae8;
}

.starter-card.selected {
  background: #fff6d0;
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.starter-card img {
  image-rendering: pixelated;
  width: 64px;
  height: 64px;
}

.starter-card span {
  font-size: 0.7rem;
  font-weight: 800;
}

.nick-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.nick-label input,
#rename-input {
  font: inherit;
  font-weight: 700;
  padding: 0.45rem 0.6rem;
  border: 2px solid var(--bezel);
  border-radius: 0.5rem;
  background: #f4faf0;
  color: var(--ink);
}

/* Care */
.care-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.pet-name {
  margin: 0;
  font-weight: 800;
  font-size: 1.15rem;
}

.pet-meta {
  margin: 0.1rem 0 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-weight: 700;
}

.stage {
  position: relative;
  height: 140px;
  display: grid;
  place-items: center;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 2px solid rgba(61, 92, 60, 0.25);
}

.stage-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, #b8e0f0 0%, #b8e0f0 55%, #78c060 55%, #68a850 100%);
}

.stage-bg::before {
  content: '';
  position: absolute;
  top: 18%;
  right: 12%;
  width: 36px;
  height: 20px;
  background: #fff8;
  border-radius: 20px;
}

.sprite {
  position: relative;
  z-index: 1;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.15));
  transition: transform 0.2s;
}

.stage.mood-happy .sprite {
  animation: bounce 0.8s ease infinite;
}

.stage.mood-hungry .sprite,
.stage.mood-sad .sprite {
  animation: wobble 1.2s ease infinite;
}

.stage.mood-sleepy .sprite {
  opacity: 0.85;
  transform: translateY(6px);
}

.stage.mood-dirty .sprite {
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.15)) saturate(0.7) brightness(0.9);
}

.stage.mood-fainted .sprite {
  transform: rotate(90deg) translateY(10px);
  opacity: 0.7;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes wobble {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}

.mood-bubble {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 2;
  margin: 0;
  font-size: 0.75rem;
  font-weight: 800;
  background: #fff9;
  padding: 0.2rem 0.45rem;
  border-radius: 0.4rem;
  color: var(--ink-soft);
}

.meters {
  display: grid;
  gap: 0.35rem;
}

.meter {
  display: grid;
  grid-template-columns: 3.4rem 1fr;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--ink-soft);
}

.bar {
  height: 10px;
  background: rgba(30, 46, 28, 0.15);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(61, 92, 60, 0.3);
}

.bar i {
  display: block;
  height: 100%;
  width: 50%;
  border-radius: 4px;
  transition: width 0.35s ease;
}

#bar-hunger { background: var(--bar-hunger); }
#bar-happiness { background: var(--bar-happy); }
#bar-energy { background: var(--bar-energy); }
#bar-clean { background: var(--bar-clean); }

.toast {
  min-height: 1.2rem;
  margin: 0;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
  color: var(--ink-soft);
}

.actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.actions.secondary {
  margin-top: 0.15rem;
}

.actions.secondary .btn {
  flex: 1;
}

/* Battle */
.battle-arena {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.fighter {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.25rem 0.5rem;
  align-items: center;
  padding: 0.4rem 0.5rem;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 0.6rem;
  border: 2px solid rgba(61, 92, 60, 0.2);
}

.fighter.enemy {
  grid-template-areas:
    'label sprite'
    'hp sprite';
}

.fighter.player {
  grid-template-areas:
    'sprite label'
    'sprite hp';
}

.fighter.enemy .fighter-label { grid-area: label; }
.fighter.enemy .hp-bar { grid-area: hp; }
.fighter.enemy .sprite { grid-area: sprite; justify-self: end; }

.fighter.player .fighter-label { grid-area: label; text-align: right; }
.fighter.player .hp-bar { grid-area: hp; }
.fighter.player .sprite { grid-area: sprite; justify-self: start; transform: scaleX(-1); }

.fighter-label {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 800;
}

.hp-bar {
  height: 10px;
  background: rgba(30, 46, 28, 0.15);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(61, 92, 60, 0.3);
}

.hp-bar i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #68c050, #90e070);
  transition: width 0.3s ease;
}

.hp-bar i.low {
  background: linear-gradient(90deg, #d05040, #e08060);
}

.battle-log {
  flex: 1;
  min-height: 90px;
  max-height: 110px;
  overflow-y: auto;
  background: rgba(30, 46, 28, 0.08);
  border-radius: 0.5rem;
  padding: 0.45rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--ink-soft);
}

.battle-log p {
  margin: 0 0 0.25rem;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(30, 46, 28, 0.45);
  display: grid;
  place-items: center;
  z-index: 10;
  padding: 1rem;
}

[hidden] {
  display: none !important;
}

.overlay-card {
  background: var(--screen);
  border: 3px solid var(--bezel);
  border-radius: 0.75rem;
  padding: 1rem;
  width: 100%;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  box-shadow: 0 10px 24px var(--shadow);
}

.overlay-card h3 {
  margin: 0;
  font-size: 1rem;
}

@media (max-width: 400px) {
  body { padding: 0.75rem; }
  .screen { min-height: 460px; }
  .logo { font-size: 1rem; }
}
