:root {
  --bg: #10121c;
  --panel: #1c2033;
  --accent: #ffcc33;
  --accent-2: #4fd1c5;
  --pink: #ff5fa2;
  --danger: #ff5566;
  --text: #f2f2f2;
  --muted: #a7acc4;
  --font-display: "Baloo 2", "Trebuchet MS", "Segoe UI", sans-serif;
  --font-body: "Baloo 2", "Trebuchet MS", "Segoe UI", sans-serif;
  --radius-lg: 16px;
  --radius-md: 14px;
  --shadow-soft: 0 10px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 500;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 204, 51, 0.10), transparent 40%),
    radial-gradient(circle at 85% 80%, rgba(79, 209, 197, 0.12), transparent 40%),
    var(--bg);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 1000px;
  text-align: center;
}

.screen.active {
  display: flex;
}

.screen.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 11, 18, 0.92);
  justify-content: center;
  z-index: 50;
}

.screen.loading-cover {
  position: fixed;
  inset: 0;
  max-width: none;
  width: 100%;
  height: 100%;
  z-index: 10;
  background: #05060b;
  padding: 0;
  gap: 0;
  cursor: pointer;
  animation: fadeOutCover 0.6s ease 2.4s forwards;
}

.screen.loading-cover img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@keyframes fadeOutCover {
  to { opacity: 0; visibility: hidden; pointer-events: none; }
}

@media (prefers-reduced-motion: reduce) {
  .screen.loading-cover { animation-duration: 0.01s; animation-delay: 1.2s; }
}

.screen h2 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.375rem, 1.1rem + 1vw, 1.75rem);
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--accent-2);
  text-shadow: 0 3px 12px rgba(0, 0, 0, 0.5);
  margin: 0 0 4px;
}

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

.title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.5rem, 1.6rem + 4vw, 4.5rem);
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--accent);
  text-shadow: 0 3px 16px rgba(255, 95, 162, 0.35), 0 8px 28px rgba(0, 0, 0, 0.55);
  margin: 0;
  animation: float 3s ease-in-out infinite;
}

.subtitle {
  color: var(--muted);
  margin: 0;
  font-weight: 600;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 20px;
  font-weight: 600;
}

/* --- tela de título estilo "Carmen Sandiego": retrato dramático de um
   lado, texto do outro, sangrando até a borda da tela --- */
.screen.hero.active {
  position: fixed;
  inset: 0;
  max-width: none;
  width: 100%;
  height: 100%;
  flex-direction: row;
  align-items: stretch;
  justify-content: flex-start;
  text-align: left;
  gap: 0;
  z-index: 5;
  background:
    linear-gradient(100deg, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.15) 45%, transparent 60%),
    radial-gradient(ellipse at 30% 50%, #7a1224 0%, #3a0a12 45%, #14060b 78%);
  overflow: hidden;
}

.hero-portrait {
  position: relative;
  flex: 0 0 42%;
  min-width: 260px;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.hero-portrait::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(122,18,36,0.15), rgba(20,6,11,0.55) 85%);
  mix-blend-mode: multiply;
}

.hero-portrait img {
  width: 100%;
  height: 115%;
  object-fit: cover;
  object-position: center top;
  image-rendering: pixelated;
  filter: saturate(1.15) contrast(1.05);
}

.hero-text {
  position: relative;
  z-index: 2;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 16px;
  padding: 40px 48px 40px 24px;
  max-width: 640px;
}

.hero-text .title { text-align: left; }

.tagline {
  color: #f0e4e6;
  font-size: 1.05rem;
  line-height: 1.6;
  font-weight: 600;
  margin: 0;
  max-width: 58ch;
}

.tagline strong {
  color: #fff;
  font-weight: 800;
}

.btn-primary.btn-cta {
  background: linear-gradient(135deg, #35c05a, #1f9e46);
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 107, 40, 0.45);
  font-size: 1.05rem;
  padding: 18px 34px;
}
.btn-primary.btn-cta:hover:not(:disabled) { box-shadow: 0 14px 30px rgba(15, 107, 40, 0.55); }

.hero-text .hint { margin-top: 2px; }

@media (max-width: 760px) {
  .screen.hero.active {
    flex-direction: column;
    text-align: center;
  }
  .hero-portrait {
    flex: 0 0 38%;
    min-width: 0;
    width: 100%;
  }
  .hero-portrait img { object-position: center top; }
  .hero-text {
    align-items: center;
    text-align: center;
    padding: 20px 24px 32px;
    max-width: 100%;
  }
  .hero-text .title { text-align: center; }
  .tagline { max-width: 42ch; }
}

button {
  font-family: var(--font-body);
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 1rem;
  padding: 14px 30px;
  border-radius: var(--radius-lg);
  border: none;
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.15s ease;
}

button:hover:not(:disabled) { transform: translateY(-2px); }
button:active:not(:disabled) { transform: translateY(0) scale(0.98); }
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #ffb84f);
  color: #1a1a1a;
  box-shadow: 0 10px 22px rgba(163, 120, 26, 0.4);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 14px 28px rgba(163, 120, 26, 0.48); }

.btn-secondary {
  background: var(--panel);
  color: var(--text);
  border: 2px solid #333a55;
  box-shadow: var(--shadow-soft);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  width: 100%;
  max-height: 60vh;
  overflow-y: auto;
  padding: 8px;
}

.card {
  background: var(--panel);
  border: 3px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.card:hover:not(.locked) {
  transform: translateY(-4px);
  border-color: var(--accent-2);
  box-shadow: var(--shadow-soft);
}

.card img {
  width: 100%;
  height: 100px;
  object-fit: contain;
  image-rendering: pixelated;
  background: #fff;
  border-radius: 8px;
}

.card .name {
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--font-body);
  letter-spacing: -0.01em;
}

.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 204, 51, 0.3), var(--shadow-soft);
  transform: translateY(-3px);
}

.card.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.card .badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--pink);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
}

.card .missing {
  font-size: 0.65rem;
  color: var(--danger);
  font-weight: 700;
}

#hud {
  width: 960px;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
  font-family: var(--font-body);
}

#hud-score {
  font-weight: 800;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border: 1px solid #333a55;
  border-radius: 999px;
  padding: 6px 14px;
  white-space: nowrap;
}

#hud-phase {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#hud-meter {
  flex: 1;
  height: 12px;
  background: #000;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #333a55;
}

#hud-meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width 0.15s ease;
}

#game-canvas {
  background: #000;
  border-radius: var(--radius-lg);
  border: 2px solid #333a55;
  max-width: 100%;
  image-rendering: pixelated;
}

#touch-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 960px;
  max-width: 100%;
  margin-top: 4px;
}

.touch-btn {
  flex: 1 1 auto;
  min-width: 84px;
  padding: 16px 10px;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: var(--shadow-soft);
}

.touch-btn:active { transform: translateY(2px); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); }

.touch-run { background: linear-gradient(135deg, var(--accent-2), #2f9e94); }
.touch-crouch { background: linear-gradient(135deg, #7a8bff, #4f5fd6); }
.touch-jump { background: linear-gradient(135deg, var(--accent), #d99b1f); color: #1a1a1a; }
.touch-punch { background: linear-gradient(135deg, var(--pink), #c23f7d); }
.touch-kick { background: linear-gradient(135deg, var(--danger), #b83341); }

/* esconde os botões de toque só em quem tem mouse/trackpad de verdade —
   por largura de tela isso escondia errado em tablet no modo paisagem */
@media (hover: hover) and (pointer: fine) {
  #touch-controls { display: none; }
}

@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); }
  #hud { flex-wrap: wrap; gap: 8px; }
  #hud-phase { max-width: 100%; }
  button { font-size: 0.95rem; padding: 12px 24px; }
}

.item-img {
  width: 160px;
  height: 160px;
  object-fit: contain;
  background: #fff;
  border-radius: var(--radius-lg);
  image-rendering: pixelated;
}

@media (prefers-reduced-motion: reduce) {
  .title { animation: none; }
  button, .card { transition: none; }
  button:hover:not(:disabled), .card:hover:not(.locked) { transform: none; }
}

/* --- quantos jogadores --- */
.players-grid {
  max-width: 480px;
  grid-template-columns: repeat(3, 1fr);
}

.player-count-card {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 2.5rem;
}

.player-count-card .name {
  font-size: 0.85rem;
  font-weight: 700;
}

/* --- jogo precisa ser em paisagem: aviso cobre a tela toda quando o
   aparelho de toque está em retrato --- */
#rotate-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: #05060b;
  color: var(--text);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  padding: 24px;
}

.rotate-icon {
  width: 90px;
  height: 90px;
  color: var(--accent);
  animation: rotateHint 1.8s ease-in-out infinite;
}

@keyframes rotateHint {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-90deg); }
}

#rotate-overlay p {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  max-width: 30ch;
  margin: 0;
}

@media (pointer: coarse) and (orientation: portrait) {
  #rotate-overlay { display: flex; }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-icon { animation: none; }
}
