/* Popcat — Purr-suit of Prey Styles */

:root {
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-surface: #0f3460;
  --accent: #e94560;
  --accent-glow: #ff6b81;
  --text: #eee;
  --text-muted: #aaa;
  --green: #2ecc71;
  --yellow: #f1c40f;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 800px;
  padding: 16px;
  touch-action: manipulation;
}

/* Views */
.view { display: none; }
.view.active { display: block; }

.hidden { display: none !important; }

/* Typography */
.title {
  font-size: 3rem;
  text-align: center;
  margin-top: 48px;
  background: linear-gradient(135deg, var(--accent), var(--yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.screen-title {
  text-align: center;
  margin: 32px 0 24px;
  font-size: 1.4rem;
  color: var(--text);
}

/* === START PAGE === */
.start-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: var(--shadow);
  margin-top: 8px;
}

.instructions h2 {
  margin-bottom: 20px;
  font-size: 1.3rem;
}

.step-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 1rem;
  line-height: 1.4;
}

.step-row:last-child { border-bottom: none; }

.step-num {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.start-preview {
  margin: 24px 0;
  text-align: center;
}

.prey-showcase {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 2.2rem;
}

.prey-divider {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 700;
  padding: 0 8px;
}

.cat-big {
  font-size: 3rem;
  animation: cat-bounce 2s ease-in-out infinite;
}

@keyframes cat-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.btn-play {
  width: 100%;
  padding: 16px;
  margin-top: 8px;
  background: linear-gradient(135deg, var(--accent), #ff8a5c);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 20px rgba(233,69,96,0.3);
}

.btn-play:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(233,69,96,0.5);
}

.btn-play:active {
  transform: translateY(0);
}

/* === END START PAGE === */

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}

.card h2 { margin-bottom: 16px; font-size: 1.2rem; }

/* Inputs */
input, select {
  width: 100%;
  padding: 12px 16px;
  margin: 8px 0;
  background: var(--bg);
  border: 2px solid var(--bg-surface);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
input:focus, select:focus {
  border-color: var(--accent);
}

/* Buttons */
button {
  width: 100%;
  padding: 14px;
  margin: 8px 0;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
button:hover:not(:disabled) {
  background: var(--accent-glow);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(233,69,96,0.4);
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
button.btn-ghost {
  background: transparent;
  border: 2px solid var(--bg-surface);
  color: var(--text-muted);
}
button.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* Create / Join layout */
#create-join {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
#create-join .card { flex: 1; }
.divider {
  display: flex;
  align-items: center;
  padding: 24px 8px;
  color: var(--text-muted);
}

/* Active lobbies */
#active-lobbies { margin-top: 24px; }
#active-lobbies h2 { margin-bottom: 8px; }
#lobby-list {
  list-style: none;
}
#lobby-list li {
  background: var(--bg-card);
  padding: 12px 16px;
  margin: 4px 0;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  transition: background 0.2s;
}
#lobby-list li:hover {
  background: var(--bg-surface);
}

/* Cat Grid */
#cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 16px 0;
}

.cat-card {
  cursor: pointer !important;
  pointer-events: auto !important;
  background: var(--bg-card);
  border: 3px solid transparent;
  border-radius: var(--radius);
  padding: 16px 8px;
  text-align: center;
  transition: all 0.2s;
  position: relative;
  z-index: 10;
}
.cat-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.cat-card.selected {
  border-color: var(--green);
  box-shadow: 0 0 16px rgba(46,204,113,0.3);
}
.cat-card.taken {
  opacity: 0.4;
  cursor: not-allowed !important;
  pointer-events: none !important;
}
.cat-card .cat-avatar {
  width: 72px;
  height: 72px;
  margin: 0 auto 8px;
  background: var(--bg-surface);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
}
.cat-card .cat-name {
  font-weight: 600;
  font-size: 0.95rem;
}
.cat-card .cat-personality {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Lobby bar */
.lobby-bar {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  box-shadow: var(--shadow);
}
#player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.player-chip {
  background: var(--bg-surface);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.player-chip .ready-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
}
.player-chip .ready-dot.ready {
  background: var(--green);
}
.player-chip .host-badge {
  font-size: 0.7rem;
  background: var(--yellow);
  color: #111;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 600;
}
.lobby-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}
.lobby-controls select { flex: 1; }
.lobby-controls button { flex: 1; }

/* Game View */
#game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 16px 0;
}
#prey-display {
  font-size: 1.5rem;
  font-weight: 600;
}
#target-display {
  font-size: 1.2rem;
  color: var(--yellow);
}

/* Game area fills the full screen during gameplay — tap anywhere */
#game-area {
  min-height: calc(100vh - 100px);
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* When in tap-mode, #game-view becomes the full viewport — no wasted space */
body.tap-mode #game-view {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  height: 100dvh;
  z-index: 50;
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  touch-action: none !important;
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
  overscroll-behavior: none !important;
}

body.tap-mode #game-header {
  flex-shrink: 0;
  margin: 0;
  padding: 4px 8px;
  padding-top: max(4px, env(safe-area-inset-top, 4px));
  pointer-events: none;
}

body.tap-mode #game-area {
  /* KEY: flex:1 fills remaining vertical space between header and scoreboard.
     This is the actual tap target — every pixel from header bottom to
     scoreboard top. */
  flex: 1;
  min-height: 0;
  width: 100%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none !important;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* Ensure horizontal edge-to-edge — no gaps */
  margin: 0;
  padding: 0;
}

/* Cat stage — just the visual cat area, centered in #game-area.
   This is NOT the tap zone — #game-area itself is the tap zone. */
#cat-stage {
  width: 200px;
  height: 200px;
  max-width: 200px;
  max-height: 30vh;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
  flex-shrink: 0;
  position: relative;
}

#cat-area {
  font-size: 4rem;
  transition: transform 0.15s;
  pointer-events: none;
}
#cat-area.tap-idle { transform: translateY(0); }
#cat-area.tap-crouch { transform: translateY(4px) scale(0.95); }
#cat-area.tap-coil { transform: translateY(8px) scale(0.9) rotate(-3deg); }
#cat-area.tap-spring { transform: translateY(-12px) scale(1.1); }
#cat-area.tap-pounce { transform: translate(-20px, -8px) scale(1.2); }
#cat-area.tap-catch { transform: translate(-30px, 0) scale(1.1); }
#cat-area.tap-win { animation: victory-bounce 0.4s ease-in-out 3; }
@keyframes victory-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}



#game-scoreboard {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.score-card {
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  flex: 1;
  min-width: 100px;
}
.score-card .taps-bar {
  height: 4px;
  flex: 1;
  background: var(--bg-surface);
  border-radius: 2px;
  overflow: hidden;
}
.score-card .taps-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.1s;
}

/* Game Over */
#gameover-view {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  height: 100dvh;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top, 16px));
  padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
  box-sizing: border-box;
  overflow-y: auto;
}
#gameover-view.active {
  display: flex;
}
#winner-text {
  font-size: 2.5rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
}
#final-scoreboard {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 8px 20px;
  margin-bottom: 16px;
  width: 100%;
  max-width: 360px;
  flex-shrink: 0;
  box-sizing: border-box;
}
.final-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--bg-surface);
  text-align: left;
  width: 100%;
}
.final-row:last-child { border-bottom: none; }
.final-row .final-rank {
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
  width: 28px;
  flex: none;
}
.final-row .final-emoji {
  font-size: 1.6rem;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  flex: none;
}
.final-row .final-name {
  font-weight: 500;
  font-size: 1.1rem;
  flex: 1;
  min-width: 0;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.final-row .final-taps {
  text-align: right;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  flex: none;
  min-width: 100px;
}
.final-row.winner .final-rank {
  color: var(--yellow);
}
.final-row.winner .final-name,
.final-row.winner .final-taps {
  color: var(--yellow);
  font-weight: 700;
  text-shadow: 0 0 12px rgba(241,196,15,0.3);
}
.gameover-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 360px;
  flex-shrink: 0;
}
.gameover-actions button {
  flex: 1;
  padding: 14px 0;
  font-size: 1.05rem;
}

/* Countdown overlay */
#countdown-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  align-items: center;
  justify-content: center;
  z-index: 100;
  font-size: 6rem;
  font-weight: 800;
  color: var(--accent);
}
#countdown-overlay.active { display: flex; }

/* Loading / connecting state */
.connecting {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
}

/* Footer — powered by Smart Charlie (in-flow, before the version badge) */
.footer {
  text-align: center;
  padding: 16px 0 8px;
  font-size: 0.75rem;
  color: #888;
  letter-spacing: 0.5px;
}

/* Version badge — bottom right, fixed */
.version-badge {
  position: fixed;
  bottom: 6px;
  right: 10px;
  font-size: 0.65rem;
  color: #888;
  background: rgba(26,26,46,0.85);
  padding: 2px 8px;
  border-radius: 8px;
  font-family: monospace;
  letter-spacing: 0.3px;
  z-index: 100;
}

/* Responsive */
@media (max-width: 600px) {
  #create-join { flex-direction: column; }
  #cat-grid { grid-template-columns: repeat(2, 1fr); }
}
