/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #2a1f18;
  color: #f5e6d3;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: linear-gradient(180deg, #4a3728 0%, #3d2b1f 40%, #2e2118 100%);
  position: relative;
}

/* ===== Overlay ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 20, 15, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.4s;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-content {
  text-align: center;
}

.overlay-content p {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

#btn-enable-sound,
#btn-test-sound-overlay {
  padding: 1rem 2rem;
  font-size: 1.1rem;
  border: none;
  border-radius: 2rem;
  cursor: pointer;
  font-weight: 600;
  display: block;
  width: 100%;
  max-width: 260px;
  margin: 0 auto;
}

#btn-enable-sound {
  background: #c4956a;
  color: #2a1f18;
  margin-bottom: 0.75rem;
}

#btn-test-sound-overlay {
  background: transparent;
  color: #c4956a;
  border: 2px solid #c4956a;
}

/* ===== Header ===== */
.header {
  padding: 0.5rem 0.75rem 0.4rem;
  background: rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.header-top h1 {
  font-size: 1.15rem;
  font-weight: 600;
  flex: 1;
}

.sound-toggle {
  background: rgba(196, 149, 106, 0.2);
  border: 1px solid rgba(196, 149, 106, 0.35);
  border-radius: 50%;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1rem;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
}

.sound-toggle:active {
  background: rgba(196, 149, 106, 0.45);
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
  font-size: 0.65rem;
  opacity: 0.9;
}

.volume-control label {
  flex-shrink: 0;
  width: 1.6rem;
}

.volume-control input[type="range"] {
  flex: 1;
  height: 4px;
  accent-color: #c4956a;
  cursor: pointer;
}

.stats-compact {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.mood-badge {
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.8rem;
  text-transform: capitalize;
  background: rgba(196, 149, 106, 0.3);
  border: 1px solid rgba(196, 149, 106, 0.5);
}

.mood-badge.happy { background: rgba(120, 200, 120, 0.3); border-color: #78c878; }
.mood-badge.relaxed { background: rgba(150, 180, 220, 0.3); border-color: #96b4dc; }
.mood-badge.sleepy { background: rgba(180, 160, 200, 0.3); border-color: #b4a0c8; }
.mood-badge.annoyed { background: rgba(220, 180, 80, 0.3); border-color: #dcb450; }
.mood-badge.angry { background: rgba(220, 80, 80, 0.3); border-color: #dc5050; }

/* ===== Stats ===== */
.stat-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-row label {
  font-size: 0.65rem;
  width: 4.2rem;
  flex-shrink: 0;
  opacity: 0.85;
}

.stat-bar {
  flex: 1;
  height: 5px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 3px;
  overflow: hidden;
}

.stat-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 50%;
}

.stat-fill.happiness { background: linear-gradient(90deg, #e8a838, #f5d060); }
.stat-fill.trust { background: linear-gradient(90deg, #6a9fd4, #96c4f0); }

/* ===== Game Area ===== */
.game-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  min-height: 0;
  padding: 0.25rem 0 0.5rem;
}

.reaction-bubble {
  position: absolute;
  top: 4%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.97);
  color: #2a1f18;
  padding: 0.65rem 1.1rem;
  border-radius: 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  animation: bubble-pop 0.3s ease;
  white-space: normal;
  text-align: center;
  max-width: 90%;
  line-height: 1.35;
  pointer-events: none;
}

.reaction-bubble.hidden {
  display: none;
}

.sound-cue {
  position: absolute;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #f5e6d3;
  padding: 0.35rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  z-index: 11;
  pointer-events: none;
  animation: sound-cue-fade 1.8s ease forwards;
}

.sound-cue.hidden {
  display: none;
}

@keyframes sound-cue-fade {
  0% { opacity: 0; transform: translateX(-50%) translateY(6px); }
  15% { opacity: 1; transform: translateX(-50%) translateY(0); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes bubble-pop {
  0% { transform: translateX(-50%) scale(0.5); opacity: 0; }
  70% { transform: translateX(-50%) scale(1.05); }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* ===== Cat Container ===== */
.cat-container {
  width: 96%;
  max-width: 440px;
  height: 100%;
  max-height: 100%;
  aspect-ratio: 3 / 4;
  position: relative;
  touch-action: none;
  filter: drop-shadow(0 10px 28px rgba(0, 0, 0, 0.35));
}

.cat-flash {
  position: absolute;
  inset: 0;
  border-radius: 1.25rem;
  background: rgba(220, 60, 60, 0.45);
  z-index: 15;
  pointer-events: none;
  animation: red-flash 0.35s ease forwards;
}

.cat-flash.hidden {
  display: none;
}

@keyframes red-flash {
  0%   { opacity: 0.85; }
  100% { opacity: 0; }
}

.heart-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 12;
  overflow: visible;
}

.heart-particle {
  position: absolute;
  font-size: 1rem;
  animation: heart-float 1.2s ease forwards;
  opacity: 0;
}

@keyframes heart-float {
  0%   { opacity: 1; transform: translateY(0) scale(0.6); }
  100% { opacity: 0; transform: translateY(-50px) scale(1.1); }
}

.cat-body {
  width: 100%;
  height: 100%;
  position: relative;
  transform-origin: center center;
}

.cat-visual {
  width: 100%;
  height: 100%;
  position: relative;
  border-radius: 1.25rem;
  overflow: hidden;
  background: #2e2118;
  cursor: pointer;
  touch-action: none;
}

/* Real cat photo — belly-up ginger cat on deck */
.cat-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 15%;
  display: block;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.cat-photo[hidden],
.cat-placeholder[hidden] {
  display: none !important;
}

/* CSS placeholder fallback */
.cat-placeholder {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, #c4956a 0%, #a07850 50%, #8a6840 100%);
  box-shadow: inset 0 -20px 40px rgba(0, 0, 0, 0.15);
}

/* Touch zones — positioned from ZONES in script.js */
.cat-zones {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.zone-overlay {
  position: absolute;
  box-sizing: border-box;
  border-radius: 8%;
  outline: 2px solid rgba(255, 255, 255, 0.9);
  outline-offset: -1px;
  pointer-events: none;
}

.zone-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(0.55rem, 2.8vw, 0.75rem);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95), 0 0 8px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  white-space: nowrap;
  z-index: 6;
}

.zone-debug-banner {
  display: none;
  position: absolute;
  top: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: #ffd43b;
  font-family: monospace;
  font-size: 0.65rem;
  padding: 0.3rem 0.65rem;
  border-radius: 0.35rem;
  z-index: 26;
  pointer-events: none;
  white-space: nowrap;
  max-width: 95%;
  text-align: center;
}

body.debug-zones .zone-debug-banner {
  display: block;
}

.zone-debug {
  display: none;
  position: absolute;
  bottom: 2%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: #7CFC00;
  font-family: monospace;
  font-size: 0.75rem;
  padding: 0.35rem 0.75rem;
  border-radius: 0.5rem;
  z-index: 25;
  pointer-events: none;
  white-space: nowrap;
}

body.debug-zones .zone-debug {
  display: block;
}

.touch-debug-panel {
  display: none;
  position: absolute;
  top: 2.5rem;
  right: 0.5rem;
  background: rgba(0, 0, 0, 0.85);
  color: #e9ecef;
  font-family: monospace;
  font-size: 0.7rem;
  padding: 0.45rem 0.65rem;
  border-radius: 0.45rem;
  z-index: 27;
  pointer-events: none;
  line-height: 1.5;
  min-width: 7.5rem;
  border: 1px solid rgba(255, 212, 59, 0.35);
}

body.debug-zones .touch-debug-panel {
  display: block;
}

.touch-debug-title {
  color: #ffd43b;
  font-weight: 700;
  margin-bottom: 0.15rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#touch-zone {
  color: #7CFC00;
  font-weight: 700;
}

/* Eyes */
.cat-eyes {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  gap: clamp(1.5rem, 12vw, 2.8rem);
  z-index: 4;
  pointer-events: none;
  width: 55%;
}

.cat-visual.has-photo .cat-eyes {
  top: 10%;
  bottom: auto;
  left: 52%;
  right: auto;
  transform: none;
  width: 18%;
  gap: 28%;
  display: flex;
}

.eye {
  width: clamp(10px, 3.5vw, 16px);
  height: clamp(12px, 4.5vw, 20px);
  background: rgba(20, 15, 10, 0.75);
  border-radius: 50%;
  position: relative;
  transition: height 0.12s ease, border-radius 0.12s ease, transform 0.12s ease;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.cat-visual.has-photo .eye {
  width: 28%;
  height: 0.55rem;
  max-height: 10px;
  background: rgba(15, 10, 8, 0.85);
  border-radius: 50%;
}

.eye::after {
  content: '';
  position: absolute;
  top: 15%;
  left: 25%;
  width: 35%;
  height: 35%;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
}

.cat-visual.has-photo .eye::after {
  display: none;
}

.eye.closed {
  height: 2px !important;
  max-height: 2px;
  border-radius: 2px;
  transform: scaleY(0.3);
}

.eye.half-closed {
  height: clamp(5px, 2vw, 8px) !important;
  max-height: 8px;
}

/* Tail overlay */
.cat-tail {
  position: absolute;
  top: 38%;
  right: -4%;
  width: 16%;
  height: 32%;
  background: #a07850;
  border-radius: 40% 60% 50% 50%;
  transform-origin: 15% 15%;
  transform: rotate(12deg);
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s;
}

.cat-visual:not(.has-photo) .cat-tail {
  opacity: 1;
  width: 18px;
  height: 80px;
  right: -8%;
  border-radius: 9px;
}

.cat-visual.has-photo .cat-tail {
  bottom: 22%;
  top: auto;
  left: 4%;
  right: auto;
  width: 16%;
  height: 18%;
  transform-origin: 50% 80%;
  transform: rotate(15deg);
}

.cat-visual.has-photo .cat-tail.wagging {
  opacity: 0.55;
  animation: tail-wag-photo 0.35s infinite alternate ease-in-out;
}

.cat-visual.has-photo .cat-tail.angry {
  opacity: 0.55;
  animation: tail-flick-photo 0.18s infinite alternate;
}

@keyframes tail-wag-photo {
  0%   { transform: rotate(-12deg); }
  100% { transform: rotate(10deg); }
}

@keyframes tail-flick-photo {
  0%   { transform: rotate(-8deg); }
  100% { transform: rotate(-28deg); }
}

/* ===== Cat Animations ===== */
.cat-body.ear-twitch {
  animation: ear-twitch 0.55s ease;
  transform-origin: 48% 22%;
}

@keyframes ear-twitch {
  0%, 100% { transform: rotate(0deg) scale(1); }
  14%      { transform: rotate(-2.2deg) scale(1.008); }
  32%      { transform: rotate(1.6deg) scale(1.005); }
  50%      { transform: rotate(-1.4deg) scale(1.006); }
  68%      { transform: rotate(0.9deg) scale(1.003); }
}

.cat-body.purr-pulse {
  animation: purr-pulse 0.5s ease-in-out infinite alternate;
}

@keyframes purr-pulse {
  0%   { transform: scale(1) translateY(0); }
  100% { transform: scale(1.028) translateY(-2px); }
}

.cat-body.relaxed {
  animation: relaxed-sway 1.4s ease-in-out;
  transform-origin: center 55%;
}

@keyframes relaxed-sway {
  0%, 100% { transform: translateY(0) rotate(0deg) scale(1); }
  30%      { transform: translateY(2px) rotate(0.5deg) scale(1.012); }
  60%      { transform: translateY(1px) rotate(-0.35deg) scale(1.014); }
}

.cat-body.purring {
  animation: purr-breathe 0.7s ease-in-out infinite alternate;
}

@keyframes purr-breathe {
  0%   { transform: scale(1) translateX(0); }
  100% { transform: scale(1.018) translateX(0.5px); }
}

.cat-body.dodge {
  animation: dodge-away 0.45s ease;
}

@keyframes dodge-away {
  0%   { transform: translateX(0) scale(1); }
  35%  { transform: translateX(-18px) rotate(-2deg) scale(0.98); }
  100% { transform: translateX(0) scale(1); }
}

.cat-body.angry-shake {
  animation: angry-shake 0.45s ease;
}

@keyframes angry-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px) rotate(-1deg); }
  40% { transform: translateX(7px) rotate(1deg); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.cat-body.rub {
  animation: rub-against 0.65s ease;
}

@keyframes rub-against {
  0%   { transform: translateX(0); }
  25%  { transform: translateX(10px) rotate(1.5deg); }
  50%  { transform: translateX(-7px) rotate(-0.8deg); }
  75%  { transform: translateX(8px) rotate(1deg); }
  100% { transform: translateX(0); }
}

.cat-body.roll-over {
  animation: roll-over 0.85s ease;
}

@keyframes roll-over {
  0%   { transform: rotate(0) scale(1); }
  40%  { transform: rotate(8deg) translateY(6px) scale(1.02); }
  70%  { transform: rotate(8deg) translateY(6px) scale(1.02); }
  100% { transform: rotate(0) scale(1); }
}

.cat-body.bite-flinch {
  animation: bite-flinch 0.3s ease;
}

.cat-body.happy-bounce {
  animation: happy-bounce 0.55s ease;
}

@keyframes happy-bounce {
  0%, 100% { transform: scale(1) translateY(0); }
  35%      { transform: scale(1.03) translateY(-5px); }
  65%      { transform: scale(1.01) translateY(-2px); }
}

@keyframes bite-flinch {
  0%   { transform: scale(1); }
  45%  { transform: scale(0.96); }
  100% { transform: scale(1); }
}

.cat-body.idle-shift {
  animation: idle-shift 5s ease-in-out infinite;
}

@keyframes idle-shift {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}

.cat-tail.wagging {
  opacity: 1;
  animation: tail-wag 0.35s infinite alternate ease-in-out;
}

@keyframes tail-wag {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(22deg); }
}

.cat-tail.angry {
  opacity: 1;
  animation: tail-flick 0.18s infinite alternate;
}

@keyframes tail-flick {
  0%   { transform: rotate(5deg); }
  100% { transform: rotate(-18deg); }
}

/* Touch indicator */
.touch-indicator {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.6);
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 20;
  animation: touch-pulse 0.6s ease forwards;
}

.touch-indicator.hidden {
  display: none;
}

@keyframes touch-pulse {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

/* ===== Desktop adjustments ===== */
@media (min-width: 481px) {
  #app {
    border-left: 1px solid rgba(255, 255, 255, 0.05);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
  }

  .cat-container {
    cursor: pointer;
  }
}
