:root {
  --bg: #2b1f2e;
  --text: #fff3f8;
  --muted: #e6c6d8;
  --accent: #ff8fb3;
  --accent-dim: #c85f85;
  --panel: rgba(40, 22, 34, 0.94);
  --grid: #6b4458;
}

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

html, body {
  height: 100%;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
}

.wrap {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.wrap:fullscreen, .wrap:-webkit-full-screen { width: 100vw; height: 100vh; }

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  gap: 8px;
}
.bar h1 { font-size: 16px; font-weight: 800; letter-spacing: 0.2px; }
.scores { display: flex; align-items: center; gap: 10px; }
.score { font-size: 14px; color: var(--muted); }
.score strong { color: var(--text); margin-left: 2px; }

.icon {
  background: transparent;
  border: 1px solid var(--grid);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  width: 34px;
  height: 30px;
  cursor: pointer;
}
.icon:active { background: var(--grid); }
.icon.home { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

.board {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0 8px 6px;
  border-radius: 14px;
  overflow: hidden;
  border: 2px solid var(--grid);
  background: #3a2740;
}
#game { display: block; width: 100%; height: 100%; touch-action: none; }

/* Name tag floating above the player's cat ------------------------------- */
.nametag {
  position: absolute;
  transform: translate(-50%, -100%);
  background: rgba(255, 255, 255, 0.92);
  color: #4a2c3a;
  font-size: 12px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 10px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 4;
}
.nametag.hidden { display: none; }

/* Caption popup ("Enjoyed A Meal!" / "Meow-good!") ------------------------ */
.caption {
  position: absolute;
  top: 14%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  color: #7a3a56;
  font-size: clamp(16px, 3.4vmin, 22px);
  font-weight: 800;
  padding: 8px 20px;
  border-radius: 16px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.15);
  pointer-events: none;
  z-index: 7;
  animation: caption-pop 1.8s ease forwards;
}
.caption.hidden { display: none; }
@keyframes caption-pop {
  0% { opacity: 0; transform: translateX(-50%) translateY(6px) scale(0.9); }
  12% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* Overlays ----------------------------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 14px;
  padding: 18px;
  text-align: center;
  background: var(--panel);
  backdrop-filter: blur(3px);
  overflow-y: auto;
  z-index: 5;
}
.overlay.hidden { display: none; }
.title {
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
.sub { font-size: 14px; color: var(--muted); max-width: 380px; }

.mode-buttons { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.play {
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #3a1626;
  font-size: 16px;
  font-weight: 800;
  padding: 12px 28px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dim);
  transition: transform .08s;
}
.play:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dim); }
.play.alt { background: #ffd18f; box-shadow: 0 4px 0 #c99a5e; }

.cats { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.cat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid var(--grid);
  border-radius: 14px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text);
  transition: transform .08s, border-color .12s, background .12s;
}
.cat-card:hover, .cat-card:active { transform: translateY(-2px); border-color: var(--accent); background: rgba(255, 143, 179, 0.14); }
.cat-card canvas { image-rendering: pixelated; }
.cat-card .cat-name { font-size: 14px; font-weight: 800; }
.cat-card .cat-desc { font-size: 11px; color: var(--muted); }
.cat-card.crossed { opacity: 0.35; cursor: not-allowed; pointer-events: none; }
.cat-card.crossed .cat-name { text-decoration: line-through; }

.name-input {
  font-size: 16px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 2px solid var(--grid);
  background: rgba(255, 255, 255, 0.92);
  color: #3a1626;
  width: min(320px, 84vw);
  text-align: center;
}

/* Touch controls: 4-way D-pad bottom-left + jump bottom-right -------------- */
.touch { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.touch.hidden { display: none; }
.dpad {
  position: absolute;
  left: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vh, 28px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(4px, 1vw, 8px);
  width: clamp(150px, 38vmin, 220px);
  height: clamp(150px, 38vmin, 220px);
  pointer-events: none;
}
.tbtn {
  pointer-events: auto;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: rgba(40, 22, 34, 0.5);
  color: #fff;
  font-size: clamp(20px, 5vmin, 32px);
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  backdrop-filter: blur(2px);
}
.tbtn:active { background: rgba(255, 143, 179, 0.6); }
.tbtn.up { grid-column: 2; grid-row: 1; }
.tbtn.left { grid-column: 1; grid-row: 2; }
.tbtn.right { grid-column: 3; grid-row: 2; }
.tbtn.down { grid-column: 2; grid-row: 3; }

.jbtn {
  position: absolute;
  right: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vh, 28px);
  pointer-events: auto;
  width: clamp(70px, 18vmin, 96px);
  height: clamp(70px, 18vmin, 96px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 143, 179, 0.5);
  color: #fff;
  font-size: clamp(13px, 3vmin, 16px);
  font-weight: 800;
  backdrop-filter: blur(2px);
}
.jbtn:active { background: rgba(255, 143, 179, 0.85); }

/* Contextual action button (Eat / Climb / Play / Sleep / Out / Pat, ...) --- */
.action {
  position: absolute;
  left: 50%;
  bottom: clamp(90px, 20vmin, 130px);
  transform: translateX(-50%);
  pointer-events: auto;
  z-index: 6;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  color: #3a1626;
  font-size: clamp(15px, 3.4vmin, 19px);
  font-weight: 800;
  padding: 10px 26px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dim);
  animation: action-bounce 1s ease infinite;
}
.action.hidden { display: none; }
.action:active { transform: translateX(-50%) translateY(3px); box-shadow: 0 1px 0 var(--accent-dim); }
@keyframes action-bounce {
  0%, 100% { margin-bottom: 0; }
  50% { margin-bottom: 4px; }
}

/* Rotate hint (portrait, touch only) ---------------------------------------- */
.rotate {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  background: var(--panel);
}
.rotate.show { display: flex; }
.rotate-icon { font-size: clamp(48px, 16vmin, 96px); animation: spin 2.4s ease-in-out infinite; }
.rotate-title { font-size: clamp(18px, 6vw, 26px); font-weight: 800; color: var(--accent); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
.rotate-sub { font-size: clamp(13px, 4vw, 17px); color: var(--muted); }
.rotate-play {
  margin-top: 8px;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #3a1626;
  font-size: 16px;
  font-weight: 800;
  padding: 10px 30px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dim);
  touch-action: manipulation;
  transition: transform 0.08s ease;
}
.rotate-play:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dim); }
@keyframes spin {
  0%, 100% { transform: rotate(-12deg); }
  50% { transform: rotate(90deg); }
}

.hint { flex: 0 0 auto; text-align: center; font-size: 11px; color: var(--muted); padding: 2px 8px 4px; }
.foot { flex: 0 0 auto; text-align: center; font-size: 10px; color: var(--muted); padding-bottom: 4px; }
