*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #2a1f14;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

/* --- Game Container --- */
#game-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* --- Room --- */
#room {
  flex: 1;
  position: relative;
  overflow: hidden;
  /* Wall */
  background: linear-gradient(180deg, #e8d5b7 0%, #dcc8a6 60%, #dcc8a6 60%);
}

/* Floor */
#room .floor {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40%;
  background:
    repeating-linear-gradient(
      90deg,
      #c69c6d 0px,
      #c69c6d 48px,
      #b8894f 48px,
      #b8894f 50px
    ),
    linear-gradient(180deg, #c69c6d, #b07d42);
  background-blend-mode: overlay;
}

/* Baseboard */
#room .baseboard {
  position: absolute;
  bottom: 40%;
  left: 0;
  right: 0;
  height: 12px;
  background: #8b6914;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Window */
#room .window {
  position: absolute;
  top: 8%;
  left: 50%;
  transform: translateX(-50%);
  width: 120px;
  height: 100px;
  background: linear-gradient(180deg, #87ceeb 0%, #b8e4f9 70%, #d4f0ff 100%);
  border: 6px solid #8b6914;
  border-radius: 4px;
  box-shadow: inset 0 0 20px rgba(255,255,255,0.3);
}

#room .window::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 100%;
  background: #8b6914;
}

#room .window::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 100%;
  height: 4px;
  background: #8b6914;
}

/* Window sill */
#room .window-sill {
  position: absolute;
  top: calc(8% + 100px + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: 140px;
  height: 8px;
  background: #8b6914;
  border-radius: 0 0 2px 2px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

/* Rug */
#room .rug {
  position: absolute;
  bottom: 10%;
  left: 50%;
  transform: translateX(-50%);
  width: 60%;
  max-width: 280px;
  height: 80px;
  background: radial-gradient(ellipse, #c44d4d 0%, #a83232 60%, #8b2020 100%);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

#room .rug::before {
  content: '';
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: 8px;
  border: 2px solid rgba(255,200,100,0.4);
  border-radius: 50%;
}

/* Food & water bowls */
#room .bowl {
  position: absolute;
  bottom: 4%;
  width: 32px;
  height: 16px;
  border-radius: 0 0 50% 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
  cursor: pointer;
  z-index: 5;
}

#room .bowl-food {
  right: 12%;
  background: #e07040;
}

#room .bowl-food::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 4px;
  right: 4px;
  height: 8px;
  background: #8B5E3C;
  border-radius: 50%;
  transition: opacity 0.3s;
}

#room .bowl-water {
  right: calc(12% + 44px);
  background: #5ba3d9;
}

#room .bowl-water::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 4px;
  right: 4px;
  height: 8px;
  background: #7ec8f0;
  border-radius: 50%;
  transition: opacity 0.3s;
}

/* Bowl rims */
#room .bowl::before {
  content: '';
  position: absolute;
  top: -3px;
  left: -2px;
  right: -2px;
  height: 6px;
  background: inherit;
  border-radius: 4px;
  filter: brightness(0.85);
}

/* Empty bowl state */
#room .bowl-empty::after {
  opacity: 0.2;
}

/* Bowl refill bounce */
#room .bowl-refill {
  animation: bowl-bounce 0.4s ease-out;
}

@keyframes bowl-bounce {
  0% { transform: scale(1); }
  30% { transform: scale(1.2); }
  60% { transform: scale(0.9); }
  100% { transform: scale(1); }
}

/* --- Cat --- */
.cat {
  position: absolute;
  width: 80px;
  height: 80px;
  cursor: pointer;
  transition: none;
  z-index: 10;
  transform: translate(-50%, -50%);
}

.cat svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.cat.facing-left svg {
  transform: scaleX(-1);
}

/* Idle animation — gentle bob */
.cat.state-idle,
.cat.state-sitting {
  animation: cat-idle-bob 2s ease-in-out infinite;
}

@keyframes cat-idle-bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -3px; }
}

/* Walking animation — slight bounce */
.cat.state-walking {
  animation: cat-walk-bob 0.35s ease-in-out infinite;
}

@keyframes cat-walk-bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -4px; }
}

/* Eating/drinking animation — head bob down */
.cat.state-eating,
.cat.state-drinking {
  animation: cat-eat-bob 0.6s ease-in-out infinite;
}

@keyframes cat-eat-bob {
  0%, 100% { margin-top: 0; }
  50% { margin-top: 3px; }
}

/* Chasing animation — faster walk bob */
.cat.state-chasing {
  animation: cat-walk-bob 0.2s ease-in-out infinite;
}

/* Pet reaction — quick bounce */
.cat.petted {
  animation: cat-pet-bounce 0.4s ease-out;
}

@keyframes cat-pet-bounce {
  0% { transform: translate(-50%, -50%) scale(1); }
  30% { transform: translate(-50%, -50%) scale(1.15); }
  60% { transform: translate(-50%, -50%) scale(0.95); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* --- Hearts --- */
.heart {
  position: absolute;
  pointer-events: none;
  z-index: 20;
  animation: heart-float 1s ease-out forwards;
  font-size: 20px;
  line-height: 1;
}

@keyframes heart-float {
  0% {
    opacity: 1;
    transform: translate(-50%, 0) scale(0.5);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -20px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -100px) scale(0.8);
  }
}

/* --- Yarn Ball --- */
.yarn-ball {
  position: absolute;
  width: 32px;
  height: 32px;
  transform: translate(-50%, -50%);
  cursor: grab;
  touch-action: none;
  z-index: 15;
}

.yarn-ball:active {
  cursor: grabbing;
}

.yarn-ball svg {
  width: 100%;
  height: 100%;
}

/* --- Action Bar --- */
#action-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: #3d2b1a;
  border-top: 2px solid #5a3d20;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 52px;
  padding: 6px 16px;
  border: 2px solid #8b6914;
  border-radius: 12px;
  background: #5a3d20;
  color: #e8d5b7;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.action-btn:active {
  transform: scale(0.95);
  background: #4a3018;
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.action-btn:disabled:active {
  transform: none;
}

.action-btn.btn-active {
  background: #7a5a30;
  border-color: #c49a2a;
}

.btn-icon {
  font-size: 20px;
  line-height: 1;
}

.btn-label {
  margin-top: 2px;
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal.open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: #4a3525;
  border: 2px solid #8b6914;
  border-radius: 16px;
  padding: 20px;
  min-width: 260px;
  max-width: 90vw;
  z-index: 1;
}

.modal-title {
  color: #e8d5b7;
  font-size: 18px;
  text-align: center;
  margin-bottom: 16px;
}

.cat-options {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.cat-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: 2px solid #8b6914;
  border-radius: 12px;
  background: #5a3d20;
  color: #e8d5b7;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.cat-option:active {
  transform: scale(0.95);
  background: #4a3018;
}

.cat-option:hover {
  border-color: #c49a2a;
  background: #6a4a28;
}

.cat-option-preview {
  width: 64px;
  height: 64px;
}

.cat-option-preview svg {
  width: 100%;
  height: 100%;
}

.cat-option-name {
  white-space: nowrap;
}

/* --- Tail Swish (applied via JS to SVG tail element) --- */
.tail-swish {
  transform-origin: bottom center;
  animation: tail-swish 1.5s ease-in-out infinite;
}

@keyframes tail-swish {
  0%, 100% { transform: rotate(-10deg); }
  50% { transform: rotate(10deg); }
}

/* Walking tail — faster swish */
.cat.state-walking .tail-swish {
  animation-duration: 0.5s;
}

/* Chasing tail — fastest swish */
.cat.state-chasing .tail-swish {
  animation-duration: 0.3s;
}
