*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  background: #141816;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: #e8efe8;
}

input,
select,
button {
  font: inherit;
}

#app {
  position: fixed;
  inset: 0;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow: auto;
}

.screen.active {
  display: block;
}

.screen#screen-game.active {
  overflow: hidden;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at 50% 30%, #1f2a22 0%, #141816 55%, #0d100e 100%);
  cursor: crosshair;
}

@media (hover: none) and (pointer: coarse) {
  #game {
    cursor: none;
  }
}

.panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 10, 9, 0.72);
  backdrop-filter: blur(6px);
  z-index: 3;
}

.panel.hidden,
.hidden {
  display: none !important;
}

.panel-inner,
.hero,
.wizard,
.status-card,
.home-layout {
  width: min(460px, 100%);
  margin: 0 auto;
  padding: 28px 24px;
}

.panel-inner,
.hero,
.wizard,
.status-card {
  border-radius: 20px;
  background: rgba(24, 32, 27, 0.95);
  border: 1px solid rgba(120, 170, 255, 0.25);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.home-layout {
  width: min(560px, 100%);
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: 40px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8eb8ff;
}

h1,
h2,
h3 {
  margin: 0 0 10px;
  line-height: 1.1;
}

h1 {
  font-size: clamp(1.8rem, 5vw, 2.4rem);
}

h2 {
  font-size: clamp(1.4rem, 4vw, 1.9rem);
}

.lead {
  margin: 0 0 22px;
  color: #b8c4b8;
  line-height: 1.5;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 0.95rem;
}

.field span {
  color: #d4ddd4;
}

.field input,
.field select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(142, 184, 255, 0.35);
  background: #101512;
  color: #eef4ee;
}

.btn-primary,
.btn-secondary,
.btn-link,
.file-btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-top: 10px;
  padding: 16px 18px;
  border-radius: 14px;
  border: 0;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, #5b9cff 0%, #ffd54a 100%);
  color: #101512;
  font-weight: 700;
}

.btn-secondary,
.file-btn {
  background: rgba(255, 255, 255, 0.06);
  color: #eef4ee;
  border: 1px solid rgba(142, 184, 255, 0.25);
}

.btn-link {
  width: auto;
  margin-top: 16px;
  padding: 0;
  background: transparent;
  color: #8eb8ff;
}

.hint {
  margin: 16px 0 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: #8a968a;
}

#screen-welcome.active,
#screen-profile.active,
#screen-processing.active,
#screen-login.active,
#screen-register.active,
#screen-cats.active {
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 20%, #1f2a22 0%, #141816 60%, #0d100e 100%);
}

#screen-cats.active {
  display: block;
  overflow: auto;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.cat-grid-card {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(120, 170, 255, 0.25);
  background: rgba(24, 32, 27, 0.95);
  color: inherit;
  text-align: center;
  cursor: pointer;
}

.cat-grid-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  border: 2px solid rgba(255, 213, 74, 0.35);
}

.cat-grid-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 2rem;
}

.cat-grid-card strong {
  font-size: 0.95rem;
}

.cat-grid-card span {
  color: #b8c4b8;
  font-size: 0.82rem;
}

.cat-grid-status {
  color: #8eb8ff !important;
}

.camera-wrap {
  position: relative;
  overflow: hidden;
  aspect-ratio: 4 / 5;
  border-radius: 18px;
  background: #0d100e;
  border: 1px solid rgba(142, 184, 255, 0.2);
}

#camera-preview,
#photo-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.loader {
  width: 56px;
  height: 56px;
  margin: 0 auto 18px;
  border-radius: 50%;
  border: 4px solid rgba(142, 184, 255, 0.18);
  border-top-color: #ffd54a;
  animation: spin 1s linear infinite;
}

.processing-preview {
  width: 180px;
  height: 180px;
  object-fit: cover;
  border-radius: 999px;
  margin: 18px auto 0;
  display: block;
  border: 3px solid rgba(255, 213, 74, 0.45);
}

.home-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 24px;
}

.profile-card,
.guest-card,
.game-card {
  border-radius: 20px;
  background: rgba(24, 32, 27, 0.95);
  border: 1px solid rgba(120, 170, 255, 0.25);
}

.profile-card,
.guest-card {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 16px;
  padding: 18px;
  margin-bottom: 24px;
  align-items: center;
}

.avatar-button {
  position: relative;
  width: 120px;
  height: 120px;
  padding: 0;
  overflow: hidden;
  border-radius: 999px;
  border: 3px solid rgba(255, 213, 74, 0.45);
  background: #101512;
  cursor: pointer;
}

.avatar-button img,
.avatar-button video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-button video,
.avatar-button #avatar-gif {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.avatar-button.is-live video,
.avatar-button.is-live #avatar-gif {
  opacity: 1;
}

.avatar-button.is-live #avatar-still {
  opacity: 0;
}

.avatar-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  font-size: 0.65rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

.profile-meta h2 {
  margin-bottom: 4px;
}

.profile-meta p {
  margin: 0;
  color: #b8c4b8;
}

.game-list h3 {
  margin-bottom: 12px;
}

.game-card {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 18px;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.game-card strong {
  font-size: 1.05rem;
}

.game-card span {
  color: #b8c4b8;
}

#hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 2;
  pointer-events: none;
}

#hud.hidden {
  display: none;
}

#score {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(10, 14, 12, 0.55);
  color: #dbe8db;
  font-size: 0.9rem;
}

.hud-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.hud-actions button {
  padding: 8px 14px;
  border: 0;
  border-radius: 999px;
  background: rgba(10, 14, 12, 0.55);
  color: #dbe8db;
}

#catch-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle, rgba(255, 213, 74, 0.35) 0%, transparent 65%);
  z-index: 1;
  transition: opacity 0.08s ease-out;
}

#catch-flash.show {
  opacity: 1;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  #catch-flash,
  .avatar-button video,
  .avatar-button #avatar-gif {
    transition: none;
  }

  .loader {
    animation: none;
  }
}

@media (max-width: 520px) {
  .profile-card {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
}

.leaderboard-section,
.history-section {
  margin-bottom: 24px;
}

.section-head h3,
.game-list h3,
.history-section h3 {
  margin-bottom: 6px;
}

.leaderboard-list {
  display: grid;
  gap: 10px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 42px 56px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(120, 170, 255, 0.22);
  border-radius: 16px;
  background: rgba(24, 32, 27, 0.92);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.leaderboard-row:active {
  transform: scale(0.99);
}

.leaderboard-rank {
  font-weight: 700;
  color: #ffd54a;
}

.leaderboard-portrait {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  object-fit: cover;
  border: 2px solid rgba(255, 213, 74, 0.35);
}

.leaderboard-meta {
  display: grid;
  gap: 4px;
}

.leaderboard-meta span {
  color: #b8c4b8;
  font-size: 0.88rem;
}

.cat-profile-layout {
  padding-top: max(16px, env(safe-area-inset-top));
}

.back-link {
  margin-bottom: 12px;
}

.cat-profile-hero {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 16px;
  align-items: center;
  padding: 18px;
  margin-bottom: 20px;
  border-radius: 20px;
  background: rgba(24, 32, 27, 0.95);
  border: 1px solid rgba(120, 170, 255, 0.25);
}

#cat-profile-portrait {
  width: 120px;
  height: 120px;
  border-radius: 999px;
  object-fit: cover;
  border: 3px solid rgba(255, 213, 74, 0.45);
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(24, 32, 27, 0.95);
  border: 1px solid rgba(120, 170, 255, 0.18);
}

.history-row time {
  grid-column: 1 / -1;
  color: #8a968a;
  font-size: 0.84rem;
}

.inline-link {
  width: auto;
  margin-top: 8px;
  padding: 0;
}

@media (max-width: 520px) {
  .cat-profile-hero {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
}

.wait-banner {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  display: grid;
  gap: 2px;
  width: min(420px, calc(100% - 24px));
  padding: 12px 16px;
  border-radius: 14px;
  text-align: center;
  background: rgba(10, 14, 12, 0.82);
  border: 1px solid rgba(255, 213, 74, 0.35);
  pointer-events: none;
}

.wait-banner strong {
  color: #ffd54a;
}

.wait-banner span {
  color: #dbe8db;
  font-size: 0.9rem;
}

.welcome-banner {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 6;
  padding: 14px 18px;
  border-radius: 14px;
  background: rgba(24, 32, 27, 0.96);
  border: 1px solid rgba(90, 150, 255, 0.4);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  animation: banner-in 0.35s ease-out;
}

.avatar-button.avatar-surprise {
  animation: avatar-pop 2.4s ease-out;
}

@keyframes banner-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes avatar-pop {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 213, 74, 0.65);
  }
  40% {
    box-shadow: 0 0 0 12px rgba(255, 213, 74, 0.15);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 213, 74, 0);
  }
}
