:root {
  --paper: #fff8e6;
  --paper-deep: #ead19c;
  --ink: #4c2b19;
  --muted: #8a674f;
  --green: #89b84a;
  --coral: #ec766e;
  --blue: #61b5dc;
  --purple: #9d86c9;
  --line: rgba(132, 82, 37, .28);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: #d5bb85;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100svh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 25% 8%, rgba(255,255,255,.48), transparent 30%),
    repeating-linear-gradient(90deg, transparent 0 46px, rgba(84,52,25,.025) 47px 49px),
    #d8bf8b;
}

@media (display-mode: standalone) {
  html, body {
    min-height: 100dvh;
    background: #b9dff0;
  }

  .game-shell {
    height: 100dvh;
    max-height: none;
  }
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.game-shell {
  width: min(100%, 540px);
  height: 100svh;
  min-height: 560px;
  max-height: 980px;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: #d7b371;
  box-shadow: 0 0 60px rgba(53, 33, 15, .24);
}

.home-screen { position: absolute; inset: 0; overflow: hidden; }

.room-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  transition: opacity .8s ease, transform .55s cubic-bezier(.2,.9,.25,1), filter .8s;
}

.room-art-sleep { opacity: 0; }

.room-shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(62,35,11,.08), transparent 23%, transparent 72%, rgba(61,34,13,.19));
  transition: background .7s;
}

.game-shell.sheet-open .room-art { transform: scale(1.018); }
.game-shell.is-reacting .room-art { animation: happyBounce .58s ease; }
.game-shell.cat-responding .room-art-awake { transform-origin: 50% 66%; animation: catHello .72s cubic-bezier(.2,.8,.25,1); }
.game-shell.is-sleeping .room-art-awake { opacity: 0; }
.game-shell.is-sleeping .room-art-sleep { opacity: 1; filter: brightness(.88) saturate(.84); transform: scale(1.025); }
.game-shell.is-sleeping .room-shade { background: rgba(21, 29, 55, .1); }

.identity-corner {
  position: absolute;
  z-index: 5;
  top: max(14px, calc(env(safe-area-inset-top) + 8px));
  left: 14px;
  min-width: 112px;
  height: 49px;
  padding: 5px 12px 5px 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1.5px solid rgba(111,68,31,.5);
  border-radius: 999px;
  background: rgba(255, 249, 229, .86);
  box-shadow: 0 4px 16px rgba(62,36,14,.17), inset 0 1px rgba(255,255,255,.78);
  backdrop-filter: blur(9px);
}

.cat-avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid #d9a45d;
  border-radius: 50%;
  background: #fff3cd;
  font-size: 23px;
}

.identity-copy { display: flex; flex-direction: column; line-height: 1.1; }
.identity-copy strong { font: 700 18px "STKaiti", "KaiTi", serif; letter-spacing: .05em; }
.identity-copy small { margin-top: 2px; color: var(--muted); font-size: 10px; font-weight: 700; }

.cat-touch-zone {
  position: absolute;
  z-index: 6;
  left: 17%;
  top: 25%;
  width: 66%;
  height: 58%;
  border: 0;
  border-radius: 48% 48% 42% 42%;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.cat-touch-zone::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 48%;
  width: 76px;
  height: 76px;
  border: 2px solid rgba(255,248,221,.86);
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%,-50%) scale(.55);
  pointer-events: none;
}

.cat-touch-zone.pressed::after { animation: touchRipple .65s ease-out; }
.cat-touch-zone:focus-visible { outline: 3px solid rgba(255,248,221,.95); outline-offset: 4px; }
.sheet-open .cat-touch-zone, .is-sleeping .cat-touch-zone { pointer-events: none; }

.interact-button {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  translate: -50% 0;
  min-width: 130px;
  min-height: 57px;
  padding: 8px 25px 9px 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 2px solid #8a5528;
  border-radius: 999px;
  background: linear-gradient(180deg, #f8d98b, #e9b558);
  box-shadow: inset 0 2px rgba(255,255,255,.6), 0 5px 0 #a86a30, 0 11px 28px rgba(59,34,13,.3);
  font: 700 24px "STKaiti", "KaiTi", serif;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .15s, opacity .2s, box-shadow .15s;
}

.interact-paw {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255,249,225,.7);
  font-family: sans-serif;
  font-size: 17px;
}

.interact-button:active { transform: translateY(4px); box-shadow: inset 0 2px rgba(255,255,255,.5), 0 1px 0 #a86a30, 0 6px 18px rgba(59,34,13,.24); }
.interact-button:disabled { opacity: .58; filter: grayscale(.3); cursor: wait; }
.sheet-open .interact-button { opacity: 0; pointer-events: none; transform: translateY(20px); }

.interaction-sheet {
  position: absolute;
  z-index: 25;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: transparent;
  transform: translateX(105%);
  visibility: hidden;
  transition: transform .42s cubic-bezier(.2,.82,.2,1), visibility .42s;
}

.sheet-open .interaction-sheet { transform: translateX(0); visibility: visible; }

.interaction-top {
  padding: max(12px, calc(env(safe-area-inset-top) + 7px)) 13px 11px;
  border-bottom: 1.5px solid rgba(165,111,54,.42);
  background:
    radial-gradient(circle at 8% 8%, rgba(255,255,255,.86), transparent 30%),
    rgba(255, 248, 226, .95);
  box-shadow: 0 5px 22px rgba(63,36,14,.16);
  backdrop-filter: blur(9px);
}

.sheet-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.sheet-profile { display: flex; align-items: center; gap: 9px; }
.sheet-kicker { display: block; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .06em; }
.sheet-heading h1 { margin: 0 0 2px; font: 700 23px "STKaiti", "KaiTi", serif; }

.close-sheet {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255,255,255,.55);
  cursor: pointer;
}
.close-sheet svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; }

.stats { margin-top: 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.stat { min-width: 0; }
.stat-label { display: flex; align-items: center; justify-content: space-between; gap: 4px; font-size: 12px; font-weight: 800; }
.stat-label strong { color: var(--muted); font-size: 11px; }
.meter { margin-top: 6px; height: 10px; overflow: hidden; border-radius: 99px; background: #6c4932; box-shadow: inset 0 1px 2px rgba(38,20,9,.26); }
.meter span { display: block; height: 100%; border-radius: inherit; transition: width .45s cubic-bezier(.2,.9,.2,1); }
.stat-hunger .meter span { background: linear-gradient(90deg, #b5db67, var(--green)); }
.stat-mood .meter span { background: linear-gradient(90deg, #f7a097, var(--coral)); }
.stat-energy .meter span { background: linear-gradient(90deg, #88d2eb, var(--blue)); }

.small-things { margin-top: 11px; min-height: 38px; display: grid; grid-template-columns: auto 1fr; gap: 9px; }
.coins, .daily-task {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(137,91,45,.2);
  border-radius: 13px;
  background: rgba(234, 210, 159, .28);
  font-size: 11px;
  font-weight: 800;
}
.coins { padding: 5px 10px; }
.coins > span { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 50%; background: #f7c84f; border: 1px solid #d88b1c; font-size: 11px; }
.daily-task { padding: 5px 9px; justify-content: space-between; }
.task-item { color: var(--muted); font-size: 10px; }
.task-item.done { color: #6c963a; text-decoration: line-through; }
.daily-task strong { color: #9a632d; }

.interaction-stage { min-height: 0; pointer-events: none; }
.interaction-bottom {
  padding: 10px 11px max(12px, env(safe-area-inset-bottom));
  border-top: 1.5px solid rgba(165,111,54,.42);
  background: rgba(255, 247, 221, .96);
  box-shadow: 0 -5px 22px rgba(63,36,14,.16);
  backdrop-filter: blur(9px);
}
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.action {
  --action-color: #d7b46d;
  min-height: 68px;
  padding: 7px 10px;
  display: grid;
  grid-template-columns: 43px 1fr;
  align-items: center;
  gap: 7px;
  border: 1.5px solid color-mix(in srgb, var(--action-color), #70401d 29%);
  border-radius: 17px;
  background: color-mix(in srgb, var(--action-color), white 62%);
  box-shadow: inset 0 1px rgba(255,255,255,.7), 0 3px 0 color-mix(in srgb, var(--action-color), #76502c 45%);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .1s, box-shadow .1s, opacity .2s;
}
.action-feed { --action-color: #9fc552; }
.action-pet { --action-color: #ee8a7b; }
.action-play { --action-color: #72bbda; }
.action-sleep { --action-color: #a58dce; }
.action:active { transform: translateY(3px); box-shadow: inset 0 1px rgba(255,255,255,.6), 0 0 0 color-mix(in srgb, var(--action-color), #76502c 45%); }
.action:disabled { opacity: .46; filter: grayscale(.35); cursor: not-allowed; }
.action-icon, .action-icon svg { width: 40px; height: 40px; }
.action-icon { display: grid; place-items: center; }
.action-icon svg { overflow: visible; fill: rgba(255,253,233,.8); stroke: color-mix(in srgb, var(--action-color), #56301d 62%); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.action > span:last-child { min-width: 0; display: flex; flex-direction: column; text-align: left; line-height: 1.08; }
.action strong { font: 700 22px "STKaiti", "KaiTi", serif; }
.action small { margin-top: 4px; overflow: hidden; color: rgba(73,41,23,.68); font-size: 9px; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; }
.time-rule { margin: 9px 0 0; color: var(--muted); text-align: center; font-size: 10px; font-weight: 600; }

.speech {
  position: absolute;
  z-index: 7;
  top: 18%;
  left: 50%;
  width: max-content;
  max-width: 74%;
  translate: -50% 0;
  padding: 10px 15px;
  border: 1.5px solid #a56a39;
  border-radius: 22px;
  background: rgba(255,253,239,.93);
  box-shadow: 0 5px 17px rgba(61,36,16,.16);
  text-align: center;
  font: 700 17px "STKaiti", "KaiTi", serif;
}
.speech::after { content: ""; position: absolute; left: 50%; bottom: -9px; width: 15px; height: 15px; background: #fffdef; border-right: 1.5px solid #a56a39; border-bottom: 1.5px solid #a56a39; transform: translateX(-50%) rotate(45deg); }
.speech.pop { animation: speechPop .32s ease; }

.sleep-scene {
  position: absolute;
  z-index: 9;
  left: 50%;
  top: 24%;
  translate: -50% 0;
  width: min(270px, 76%);
  padding: 17px 20px;
  display: grid;
  justify-items: center;
  border: 1px solid rgba(222,212,183,.38);
  border-radius: 22px;
  background: rgba(27,35,61,.72);
  color: #fff8df;
  box-shadow: 0 12px 35px rgba(11,17,34,.32);
  backdrop-filter: blur(9px);
}
.sleep-moon { margin-bottom: 2px; color: #ffe49a; font-size: 34px; }
.sleep-scene strong { font: 700 20px "STKaiti", "KaiTi", serif; }
.sleep-scene > span:not(.sleep-moon) { margin-top: 3px; font-size: 17px; font-variant-numeric: tabular-nums; }
.sleep-scene small { margin-top: 8px; color: rgba(255,248,223,.68); font-size: 10px; }
.sleep-progress { width: 100%; height: 7px; margin-top: 10px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.15); }
.sleep-progress span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #8eb9df, #ffe39a); transition: width 1s linear; }

.reaction-layer { position: absolute; inset: 0; z-index: 8; pointer-events: none; overflow: hidden; }
.reaction { position: absolute; left: var(--x); top: var(--y); font-size: var(--size); animation: floatUp 1.25s ease-out forwards; filter: drop-shadow(0 2px 2px rgba(78,42,16,.25)); }
.toast { position: absolute; z-index: 40; left: 50%; bottom: 105px; translate: -50% 12px; opacity: 0; padding: 8px 14px; border-radius: 99px; background: rgba(62,39,25,.9); color: #fff9e8; font-size: 11px; font-weight: 700; white-space: nowrap; pointer-events: none; transition: opacity .2s, translate .2s; }
.toast.show { opacity: 1; translate: -50% 0; }

@keyframes happyBounce { 0%,100% { transform: scale(1); } 45% { transform: scale(1.035) translateY(-4px); } }
@keyframes catHello {
  0%,100% { transform: scale(1) translateY(0); }
  28% { transform: scale(1.018) translateY(-7px) rotate(-.3deg); }
  58% { transform: scale(1.012) translateY(1px) rotate(.25deg); }
}
@keyframes touchRipple { 0% { opacity: .9; transform: translate(-50%,-50%) scale(.45); } 100% { opacity: 0; transform: translate(-50%,-50%) scale(1.5); } }
@keyframes speechPop { 0% { transform: scale(.85); } 65% { transform: scale(1.05); } 100% { transform: scale(1); } }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%,12px) scale(.5) rotate(-8deg); } 20% { opacity: 1; } 100% { opacity: 0; transform: translate(calc(-50% + var(--drift)),-95px) scale(1.2) rotate(10deg); } }

@media (min-width: 700px) {
  .game-shell { height: min(94svh, 940px); border: 7px solid rgba(255,247,218,.76); border-radius: 32px; }
}

@media (max-height: 700px) {
  .interaction-top { padding-top: max(8px, calc(env(safe-area-inset-top) + 4px)); }
  .stats, .small-things { margin-top: 8px; }
  .action { min-height: 60px; }
  .time-rule { margin-top: 7px; }
}

@media (max-width: 350px) {
  .interaction-top { padding-inline: 10px; }
  .interaction-bottom { padding-inline: 8px; }
  .action { grid-template-columns: 36px 1fr; padding-inline: 7px; }
  .action-icon, .action-icon svg { width: 34px; height: 34px; }
  .daily-task > span:first-child { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
