:root {
  color-scheme: light;
  --ink: #3f342f;
  --muted: #8c7c72;
  --cream: #fff8ec;
  --paper: #fffdf7;
  --line: #dfd2c2;
  --pink: #ef6685;
  --orange: #e6a136;
  --blue: #668bdd;
  --mint: #52b9a8;
}

* { box-sizing: border-box; }

html,
body { min-width: 320px; min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: #607b6b;
  font-family: "Trebuchet MS", Arial, sans-serif;
}

button,
canvas { -webkit-tap-highlight-color: transparent; }

button { font: inherit; }

.page-background {
  display: grid;
  min-height: 100svh;
  place-items: center;
  padding: 12px;
  background:
    radial-gradient(circle at 20% 15%, rgba(244, 213, 151, 0.38), transparent 28rem),
    radial-gradient(circle at 80% 86%, rgba(89, 130, 107, 0.65), transparent 30rem),
    linear-gradient(145deg, #385248, #8ca28c);
}

.phone-shell {
  position: relative;
  display: grid;
  width: min(430px, 100%);
  height: min(900px, calc(100svh - 24px));
  min-height: 650px;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  overflow: hidden;
  border: 6px solid rgba(255, 251, 239, 0.68);
  border-radius: 42px;
  background: var(--cream);
  box-shadow:
    0 38px 90px rgba(20, 38, 30, 0.42),
    inset 0 0 0 1px rgba(117, 90, 67, 0.12);
}

.pet-header {
  position: relative;
  z-index: 5;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 17px 9px;
  background: rgba(255, 250, 240, 0.97);
}

.pet-identity { display: flex; align-items: center; gap: 10px; }

.pet-avatar {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 2px solid #d8a819;
  border-radius: 15px 15px 19px 15px;
  color: #314638;
  background: #f9d63d;
  font-size: 18px;
  font-weight: 1000;
  letter-spacing: -0.08em;
  box-shadow: inset 0 2px rgba(255, 255, 255, 0.58), 0 5px 12px rgba(112, 75, 23, 0.13);
  transform: rotate(-3deg);
}

.eyebrow {
  margin: 0 0 2px;
  color: #a69588;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.13em;
}

.pet-header h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1;
  letter-spacing: -0.04em;
}

.level-badge {
  display: grid;
  min-width: 62px;
  gap: 2px;
  padding: 8px 11px;
  border: 1px solid #eadcc7;
  border-radius: 15px;
  background: #fffef9;
  text-align: center;
  box-shadow: 0 4px 10px rgba(77, 57, 40, 0.06);
}

.level-badge span { color: #d49722; font-size: 14px; font-weight: 1000; }
.level-badge small { color: #9c8c80; font-size: 12px; font-weight: 900; }

.status-hud {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 13px;
  padding: 9px 16px 12px;
  border-bottom: 1px solid #e8dccd;
  background: rgba(255, 250, 240, 0.97);
}

.hud-stat {
  display: grid;
  min-width: 0;
  grid-template-columns: 26px 1fr;
  align-items: center;
  gap: 6px;
}

.hud-icon {
  font-family: Arial, sans-serif;
  font-size: 23px;
  font-weight: 1000;
  line-height: 1;
  text-align: center;
  filter: drop-shadow(0 2px rgba(91, 64, 40, 0.12));
}

.hud-heart .hud-icon { color: var(--pink); }
.hud-food .hud-icon { color: var(--orange); }
.hud-energy .hud-icon { color: var(--blue); }
.hud-clean .hud-icon { color: var(--mint); }

.hud-value {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 900;
}

.hud-value span { overflow: hidden; color: #87776e; text-overflow: ellipsis; white-space: nowrap; }
.hud-value strong { color: #4b3b34; font-size: 13px; }

.hud-bar {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 2px solid #e6d9cc;
  border-radius: 999px;
  background: #f3ebe1;
  box-shadow: inset 0 1px 2px rgba(81, 55, 38, 0.12);
}

.hud-bar > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  transition: width 450ms cubic-bezier(0.22, 1, 0.36, 1);
}

.hud-heart .hud-bar > span { background: linear-gradient(90deg, #e64e72, #ff92aa); }
.hud-food .hud-bar > span { background: linear-gradient(90deg, #d88820, #f5bc4f); }
.hud-energy .hud-bar > span { background: linear-gradient(90deg, #5479d3, #81a6f4); }
.hud-clean .hud-bar > span { background: linear-gradient(90deg, #3ca895, #6bd3c3); }

.game-viewport {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #a4bea8;
  isolation: isolate;
}

.three-stage {
  position: absolute;
  z-index: 1;
  inset: 0;
  outline: none;
  cursor: grab;
}

.three-stage:active { cursor: grabbing; }

.three-stage canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.crt-overlay {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  background:
    repeating-linear-gradient(to bottom, transparent 0, transparent 3px, rgba(37, 31, 24, 0.12) 4px),
    radial-gradient(circle at center, transparent 54%, rgba(42, 31, 23, 0.18));
  mix-blend-mode: multiply;
}

.room-chip {
  position: absolute;
  z-index: 4;
  top: 12px;
  left: 13px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 9px;
  border: 1px solid rgba(86, 69, 53, 0.26);
  border-radius: 9px;
  color: #5b4d45;
  background: rgba(255, 248, 232, 0.83);
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: 0.06em;
  box-shadow: 2px 3px 0 rgba(74, 58, 45, 0.12);
  backdrop-filter: blur(4px);
}

.speech-bubble {
  position: absolute;
  z-index: 5;
  top: 16%;
  right: 7%;
  width: max-content;
  max-width: 160px;
  padding: 10px 13px;
  border: 2px solid #cdbba7;
  border-radius: 18px;
  color: #59473e;
  background: #fffdf5;
  box-shadow: 3px 5px 0 rgba(92, 68, 51, 0.17);
  font-size: 14px;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
  transform-origin: 70% 100%;
  transition: opacity 160ms ease, transform 160ms ease;
}

.speech-bubble::after {
  position: absolute;
  right: 23px;
  bottom: -10px;
  width: 16px;
  height: 16px;
  border-right: 2px solid #cdbba7;
  border-bottom: 2px solid #cdbba7;
  content: "";
  background: #fffdf5;
  transform: rotate(45deg);
}

.speech-bubble.changing { opacity: 0; transform: scale(0.88) translateY(5px); }

.sleep-bubble {
  position: absolute;
  z-index: 5;
  top: 31%;
  right: 22%;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  color: #5c70ac;
  font-family: Arial, sans-serif;
  font-weight: 1000;
  text-shadow: 2px 2px #e7ecff;
  pointer-events: none;
}

.sleep-bubble[hidden] { display: none; }
.sleep-bubble span:nth-child(1) { font-size: 28px; }
.sleep-bubble span:nth-child(2) { font-size: 20px; transform: translateY(-14px); }
.sleep-bubble span:nth-child(3) { font-size: 15px; transform: translateY(-25px); }

.touch-hint {
  position: absolute;
  z-index: 4;
  bottom: 10px;
  left: 50%;
  width: max-content;
  max-width: calc(100% - 24px);
  margin: 0;
  padding: 6px 10px;
  border-radius: 9px;
  color: rgba(255, 253, 244, 0.94);
  background: rgba(65, 54, 46, 0.62);
  font-size: 12px;
  font-weight: 800;
  transform: translateX(-50%);
  backdrop-filter: blur(5px);
}

.scene-fallback {
  display: grid;
  height: 100%;
  place-items: center;
  padding: 34px;
  color: #59473e;
  text-align: center;
}

.care-dock {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  padding: 11px 11px 9px;
  border-top: 1px solid #e5d6c5;
  background: #fff7ea;
}

.care-button {
  display: grid;
  min-width: 0;
  min-height: 82px;
  place-items: center;
  align-content: center;
  gap: 5px;
  padding: 7px 3px;
  border: 2px solid rgba(104, 76, 56, 0.12);
  border-radius: 18px;
  color: #5a4438;
  cursor: pointer;
  box-shadow: inset 0 2px rgba(255, 255, 255, 0.72), 0 4px 0 rgba(103, 74, 54, 0.12);
  transition: transform 120ms ease, filter 120ms ease;
}

.care-button:hover:not(:disabled) { filter: brightness(1.04); transform: translateY(-2px); }
.care-button:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 0 2px rgba(255, 255, 255, 0.7), 0 1px 0 rgba(103, 74, 54, 0.1); }
.care-button:focus-visible { outline: 3px solid rgba(80, 115, 173, 0.45); outline-offset: 2px; }
.care-button:disabled { filter: grayscale(0.55); opacity: 0.48; cursor: not-allowed; }
.care-icon { font-size: 28px; line-height: 1; filter: drop-shadow(0 2px rgba(83, 51, 35, 0.12)); }
.care-button strong { overflow: hidden; width: 100%; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.care-feed { background: #ffd8df; }
.care-play { background: #ffe6a9; }
.care-sleep { background: #dbe5ff; }
.care-bathe { background: #ccefe7; }

.pet-footer {
  position: relative;
  z-index: 5;
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 14px 10px;
  color: #89786d;
  background: #fff7ea;
  font-size: 12px;
  font-weight: 800;
}

.mood-status { display: flex; min-width: 0; align-items: center; gap: 6px; }
.mood-status i { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #55b68a; box-shadow: 0 0 0 3px rgba(85, 182, 138, 0.14); }
.mood-status span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.save-status { white-space: nowrap; }

.toast-region {
  position: absolute;
  z-index: 20;
  top: 120px;
  left: 50%;
  display: grid;
  width: min(340px, calc(100% - 28px));
  gap: 7px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 11px 14px;
  border: 2px solid #d9c7b1;
  border-radius: 14px;
  color: #59473e;
  background: rgba(255, 253, 245, 0.96);
  box-shadow: 3px 5px 0 rgba(92, 68, 51, 0.15);
  font-size: 14px;
  font-weight: 900;
  text-align: center;
  animation: toast-in 180ms ease both;
}

.toast.warning { border-color: #e1b44d; }
.toast.success { border-color: #6ab895; }
.toast.leaving { opacity: 0; transform: translateY(-6px); transition: 160ms ease; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-7px) scale(0.96); }
}

noscript {
  position: absolute;
  z-index: 30;
  right: 12px;
  bottom: 12px;
  left: 12px;
  padding: 12px;
  border-radius: 12px;
  color: #4b3b34;
  background: #ffe7a6;
  font-size: 14px;
  text-align: center;
}

@media (max-width: 520px) {
  .page-background { display: block; padding: 0; }
  .phone-shell {
    width: 100%;
    height: 100svh;
    min-height: 590px;
    border: 0;
    border-radius: 0;
  }
}

@media (max-height: 720px) {
  .phone-shell { min-height: 590px; }
  .pet-header { min-height: 60px; padding-block: 8px 6px; }
  .pet-avatar { width: 38px; height: 38px; }
  .status-hud { padding-block: 7px 9px; }
  .care-button { min-height: 68px; }
  .care-icon { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
