:root {
  color-scheme: light;
  --ink: #263238;
  --muted: #607076;
  --paper: #fffdf7;
  --line: #d49b3e;
  --ground: #d9f4c8;
  --sky: #fff3cf;
  --blue: #4c9ed9;
  --green: #49bea0;
  --green-dark: #267565;
  --danger: #c44949;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", Arial, sans-serif;
  background: #f2f7fb;
}

button {
  font: inherit;
}

.game-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.stage {
  position: relative;
  width: min(100%, 980px);
  min-height: 720px;
  overflow: hidden;
  border: 4px solid #8ab7d5;
  border-radius: 8px;
  background: var(--sky);
  box-shadow: 0 18px 42px rgba(40, 63, 82, 0.18);
}

.utility-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px 0;
  font-size: 13px;
}

.utility-bar a {
  color: #176b63;
  font-weight: 700;
  text-decoration: none;
}

.utility-bar span {
  color: #68787d;
}

.utility-bar span[data-connected="true"] {
  color: #176b63;
}

.topbar {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}

.counter {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  border: 2px solid #efbb52;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
}

.counter span {
  color: #6a4a1c;
  font-size: 13px;
  white-space: nowrap;
}

.counter strong {
  font-size: 19px;
}

.counter--status strong {
  font-size: 16px;
}

.play-area {
  position: relative;
  min-height: 430px;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 22%, rgba(150, 222, 76, 0.62), transparent 22%),
    radial-gradient(circle at 80% 18%, rgba(255, 223, 79, 0.72), transparent 20%),
    linear-gradient(135deg, #dff8cc 0%, #83c66b 45%, #4e7d4b 100%);
}

.room {
  position: absolute;
  inset: 0;
  display: none;
}

.scene-3d {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #dff8cc;
  cursor: pointer;
}

.scene-3d canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.sun {
  position: absolute;
  right: 38px;
  top: 32px;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: #ffe17a;
}

.grass {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 116px;
  background: var(--ground);
}

.cage {
  position: absolute;
  left: 46px;
  top: 66px;
  width: 300px;
  height: 254px;
  border: 7px solid #82b8de;
  border-bottom-width: 0;
  border-radius: 42px 42px 0 0;
  background: rgba(255, 255, 255, 0.72);
}

.cage span {
  position: absolute;
  top: 14px;
  bottom: 18px;
  width: 4px;
  border-radius: 4px;
  background: #9cc7e4;
}

.cage span:nth-child(1) { left: 42px; }
.cage span:nth-child(2) { left: 88px; }
.cage span:nth-child(3) { left: 136px; }
.cage span:nth-child(4) { left: 184px; }
.cage span:nth-child(5) { left: 230px; }

.perch {
  position: absolute;
  left: 32px;
  right: 32px;
  bottom: 82px;
  height: 9px;
  border-radius: 9px;
  background: #8b6b4a;
}

.task-card {
  position: absolute;
  z-index: 2;
  right: 28px;
  top: 54px;
  width: min(36vw, 320px);
  min-width: 270px;
  min-height: 236px;
  padding: 22px 22px 18px;
  border: 5px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.task-card h1 {
  margin: 0 0 18px;
  color: #6a4a1c;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.task-card p {
  margin: 12px 0;
  font-size: 18px;
  line-height: 1.35;
}

.task-card small {
  display: block;
  margin-top: 16px;
  color: #9a6b1d;
  font-size: 14px;
  line-height: 1.4;
}

.task-card b {
  display: block;
  min-height: 22px;
  margin-top: 14px;
  color: var(--green-dark);
  font-size: 15px;
  line-height: 1.35;
}

.speech {
  position: absolute;
  z-index: 3;
  left: 150px;
  top: 86px;
  width: 300px;
  min-height: 54px;
  padding: 12px 14px;
  border: 3px solid #79a9c8;
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
  line-height: 1.35;
}

.speech::after {
  content: "";
  position: absolute;
  left: 114px;
  bottom: -14px;
  width: 22px;
  height: 22px;
  border-right: 3px solid #79a9c8;
  border-bottom: 3px solid #79a9c8;
  background: #fff;
  transform: rotate(45deg);
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  background: rgba(255, 253, 247, 0.78);
}

.reward-dock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-top: 1px solid #c6d9c0;
  background: #f7ffe9;
}

.reward-dock strong {
  color: #176b63;
}

.reward-dock p {
  margin: 3px 0 0;
  color: #61716d;
  font-size: 13px;
}

.reward-dock button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: #176b63;
  color: #fff;
  padding: 9px 16px;
  font-weight: 800;
  cursor: pointer;
}

.inventory {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px;
  background: #eff9e8;
}

.inventory-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 8px;
  border: 1px solid #cbdcc5;
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
}

.inventory-item span {
  font-size: 20px;
}

.inventory-item b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inventory-item strong {
  color: #176b63;
  font-size: 17px;
}

.phrasebook {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-top: 1px solid #d6e4c9;
  background: #fff8df;
}

.phrasebook strong {
  color: #6a4a1c;
}

.phrasebook p {
  margin: 3px 0 0;
  color: #52635f;
  font-size: 14px;
}

.phrasebook button {
  min-height: 42px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  background: #176b63;
  color: #fff;
  padding: 9px 16px;
  font-weight: 800;
  cursor: pointer;
}

.phrasebook button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.stat {
  min-width: 0;
  padding: 9px;
  border: 1px solid #d5e2e8;
  border-radius: 8px;
  background: #fff;
}

.stat__top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 13px;
}

.meter {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eef2;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4c9ed9, #49bea0);
}

.actions {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  padding: 10px 12px 18px;
  background: var(--ground);
}

.action-button {
  min-height: 58px;
  border: 2px solid #5f5f5f;
  border-radius: 8px;
  background: #fff;
  color: #2f2f2f;
  cursor: pointer;
}

.action-button {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  text-align: left;
  gap: 8px;
  font-weight: 700;
}

.action-button:hover,
.action-button:focus-visible {
  outline: 3px solid rgba(76, 158, 217, 0.24);
  transform: translateY(-1px);
}

.action-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.action-button__icon {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #fff8;
  font-size: 24px;
}

.action-button small {
  color: #52635f;
  font-size: 11px;
  font-weight: 500;
}

.action-button.is-unavailable:not(:disabled) {
  opacity: 0.62;
}

.action-button.is-expected {
  border-color: #1f8a67;
  box-shadow: inset 0 0 0 2px rgba(31, 138, 103, 0.28);
}

.action-button[data-care-action="feed"] { background: #ffd36b; }
.action-button[data-care-action="water"] { background: #8dd7ff; }
.action-button[data-care-action="play"] { background: #b6ef8f; }
.action-button[data-care-action="clean"] { background: #e9d2ff; }
.action-button[data-care-action="speak"] { background: #ffbdc8; }
.action-button[data-care-action="rest"] { background: #c7d3ff; }

@media (max-width: 760px) {
  .game-shell {
    padding: 0;
  }

  .stage {
    min-height: 100vh;
    border-width: 0;
    border-radius: 0;
  }

  .topbar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 10px;
    scrollbar-width: thin;
  }

  .counter {
    flex: 0 0 122px;
    min-height: 48px;
    padding: 7px 9px;
  }

  .play-area {
    min-height: 480px;
  }

  .cage {
    left: 20px;
    top: 214px;
    width: 220px;
    height: 214px;
  }

  .cage span:nth-child(1) { left: 30px; }
  .cage span:nth-child(2) { left: 66px; }
  .cage span:nth-child(3) { left: 102px; }
  .cage span:nth-child(4) { left: 138px; }
  .cage span:nth-child(5) { left: 174px; }

  .task-card {
    left: 12px;
    right: 12px;
    top: 12px;
    width: auto;
    min-width: 0;
    min-height: 0;
    padding: 14px 16px;
    border-width: 3px;
  }

  .task-card h1 {
    margin-bottom: 8px;
    font-size: 19px;
  }

  .task-card p,
  .task-card small {
    display: none;
  }

  .task-card b {
    margin-top: 0;
  }

  .speech {
    left: 28px;
    top: 108px;
    width: min(300px, calc(100% - 56px));
    font-size: 14px;
  }

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

  .reward-dock {
    align-items: stretch;
    flex-direction: column;
  }

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

  .actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 10px;
  }

  .action-button {
    min-height: 64px;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 2px;
    text-align: center;
  }

  .action-button__icon {
    grid-row: auto;
  }

  .phrasebook {
    align-items: stretch;
    flex-direction: column;
  }
}
