/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --pokered:    #E3350D;
  --pokered-dk: #B02A0A;
  --pokewhite:  #F8F8F8;
  --pokeyellow: #FFCB05;
  --pokeblue:   #3D7DCA;
  --pokegray:   #AAB0B6;
  --pokedark:   #2B2B2B;
  --pokeborder: #1a1a1a;
  --radius:     16px;
  --shadow:     0 8px 40px rgba(0,0,0,0.35);
  --shadow-sm:  0 2px 12px rgba(0,0,0,0.20);
}

body {
  font-family: 'Nunito', sans-serif;
  background: linear-gradient(160deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  color: var(--pokedark);
}

/* ===== TYPOGRAPHY ===== */
.pixel    { font-family: 'Press Start 2P', monospace; -webkit-font-smoothing: none; }
.pixel-sm { font-family: 'Press Start 2P', monospace; font-size: 0.75rem; -webkit-font-smoothing: none; }
.pixel-xs { font-family: 'Press Start 2P', monospace; font-size: 0.65rem; -webkit-font-smoothing: none; }

/* ===== SCREENS ===== */
.screen { display: none; width: 88vw; max-width: 480px; animation: fadeIn 0.3s ease; }
.screen.active { display: flex; justify-content: center; }
@media (max-width: 480px) { .screen { width: 96vw; } body { padding: 8px; } }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== CARD ===== */
.card {
  background: var(--pokewhite);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  overflow: hidden;
  border: 3px solid var(--pokeborder);
}

.card-banner {
  background: linear-gradient(135deg, var(--pokered) 0%, var(--pokered-dk) 100%);
  padding: 28px 32px 24px;
  text-align: center;
  color: #fff;
}

.card-body {
  padding: 28px 32px;
}

/* ===== GENERIC ELEMENTS ===== */
.hidden { display: none !important; }

.title    { font-size: 1.6rem; color: #fff; margin-bottom: 4px; letter-spacing: 2px; }
.subtitle { font-size: 0.55rem; color: rgba(255,255,255,0.85); font-family: 'Press Start 2P', monospace; margin-top: 8px; }

/* ===== BUTTONS ===== */
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px 24px;
  background: var(--pokered);
  color: #fff;
  border: 3px solid var(--pokeborder);
  border-radius: 50px;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.65rem;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 4px 0 var(--pokeborder);
  margin-top: 16px;
  letter-spacing: 1px;
}
.btn-primary:hover  { transform: translateY(-2px); box-shadow: 0 6px 0 var(--pokeborder); }
.btn-primary:active { transform: translateY(2px);  box-shadow: 0 2px 0 var(--pokeborder); }

.btn-secondary {
  display: block;
  width: 100%;
  padding: 12px 24px;
  background: var(--pokewhite);
  color: var(--pokedark);
  border: 3px solid var(--pokeborder);
  border-radius: 50px;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  cursor: pointer;
  transition: transform 0.1s;
  box-shadow: 0 4px 0 var(--pokeborder);
  margin-top: 10px;
}
.btn-secondary:hover  { transform: translateY(-2px); }
.btn-secondary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--pokeborder); }

.btn-ghost {
  background: none;
  border: none;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.5rem;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 8px 12px;
}
.btn-ghost:hover { color: #fff; }

.btn-ghost-sm {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 20px;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.45rem;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 6px 10px;
}

.btn-large { font-size: 0.75rem; padding: 18px 24px; margin-top: 24px; }

/* ===== FORMS ===== */
.field       { margin-bottom: 16px; }
.field-label { display: block; font-family: 'Press Start 2P', monospace; font-size: 0.5rem; color: var(--pokedark); margin-bottom: 8px; }
.field-input {
  width: 100%;
  padding: 12px 16px;
  border: 3px solid var(--pokeborder);
  border-radius: 12px;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.6rem;
  background: #fff;
  outline: none;
  transition: border-color 0.2s;
}
.field-input:focus { border-color: var(--pokered); }

.auth-error {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.45rem;
  color: var(--pokered);
  margin-bottom: 12px;
  line-height: 1.6;
}

/* ===== LOGIN TABS ===== */
.login-tabs    { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 3px solid var(--pokeborder); }
.tab-btn       { flex: 1; padding: 10px; background: none; border: none; font-family: 'Press Start 2P', monospace; font-size: 0.5rem; cursor: pointer; color: var(--pokegray); border-bottom: 3px solid transparent; margin-bottom: -3px; }
.tab-btn.active { color: var(--pokered); border-bottom-color: var(--pokered); }
.tab-panel.hidden { display: none; }

/* Banner Pokeball decoration */
.banner-pokeball {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(180deg, #fff 0%, #fff 48%, var(--pokeborder) 48%, var(--pokeborder) 52%, var(--pokered) 52%, var(--pokered) 100%);
  border: 3px solid var(--pokeborder);
  margin: 0 auto 12px;
  position: relative;
}
.banner-pokeball::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--pokeborder);
}

/* ===== CONFIG SCREEN ===== */
.welcome-text { font-size: 0.5rem; color: rgba(255,255,255,0.8); margin-bottom: 4px; }
.username     { font-size: 1rem; color: #fff; letter-spacing: 1px; }

.section-label { font-size: 0.5rem; color: var(--pokegray); margin-bottom: 12px; margin-top: 20px; }
.section-label:first-child { margin-top: 0; }

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: #fff;
  border: 3px solid var(--pokeborder);
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.2s;
  box-shadow: 0 3px 0 var(--pokeborder);
}
.mode-btn:hover  { transform: translateY(-2px); }
.mode-btn:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--pokeborder); }
.mode-btn.active { border-color: var(--pokered); background: #fff5f4; box-shadow: 0 3px 0 var(--pokered); }

.mode-icon { font-size: 1.4rem; }
.mode-name { display: block; font-size: 0.42rem; color: var(--pokedark); }
.mode-desc { display: block; font-size: 0.5rem; color: var(--pokegray); font-family: 'Nunito', sans-serif; font-weight: 700; text-align: center; line-height: 1.3; }

.timer-toggle { display: flex; gap: 8px; }
.timer-btn {
  flex: 1;
  padding: 10px;
  background: #fff;
  border: 3px solid var(--pokeborder);
  border-radius: 50px;
  font-family: 'Press Start 2P', monospace;
  font-size: 0.55rem;
  cursor: pointer;
  transition: 0.15s;
  box-shadow: 0 3px 0 var(--pokeborder);
}
.timer-btn.active { background: var(--pokeyellow); border-color: var(--pokeborder); color: var(--pokedark); }

.config-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
}
.config-footer .btn-ghost { color: var(--pokegray); font-size: 0.45rem; }
.config-footer .btn-ghost:hover { color: var(--pokedark); }

/* ===== GAME SCREEN ===== */
.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 4px;
  color: #fff;
}
.game-header .pixel-sm { font-size: 0.55rem; }

/* ===== POKÉBALL FLIP CARD ===== */
.flip-card {
  width: 100%;
  max-width: 660px;
  height: clamp(500px, 72svh, 760px);
  perspective: 1200px;
  cursor: pointer;
  border-radius: var(--radius);
}

.flip-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius);
}

.flip-card.flipped .flip-card-inner {
  transform: rotateY(180deg);
}

.flip-card-front,
.flip-card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  overflow: hidden;
  border: 4px solid var(--pokeborder);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.flip-card-back { transform: rotateY(180deg); }

/* Front: red top, pokeball stripe, white bottom */
.card-banner-red {
  flex: 1;
  background: linear-gradient(160deg, var(--pokered) 0%, var(--pokered-dk) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.who-label {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.9);
  letter-spacing: 1px;
  margin-bottom: 8px;
  z-index: 2;
  position: relative;
}

.pokemon-silhouette {
  width: 240px;
  height: 240px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  filter: brightness(0);
  z-index: 2;
}

/* Back: white top, pokeball stripe, red bottom */
.card-banner-white {
  flex: 1;
  background: var(--pokewhite);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.pokemon-revealed {
  width: 240px;
  height: 240px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.pokemon-name {
  font-size: 0.75rem;
  color: var(--pokedark);
  margin-top: 8px;
  text-transform: uppercase;
}

/* Pokéball stripe (shared between front and back) */
.pokeball-stripe {
  height: 28px;
  background: var(--pokeborder);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.pokeball-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--pokeborder);
  z-index: 2;
}

/* Front bottom: white with question */
.card-body-white {
  height: 190px;
  background: var(--pokewhite);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Back bottom: red with answer */
.card-body-red {
  height: 190px;
  background: var(--pokered);
  display: flex;
  align-items: center;
  justify-content: center;
}

.question { font-size: 2.6rem; color: var(--pokedark); letter-spacing: 4px; }
.answer   { font-size: 2.6rem; color: #fff; letter-spacing: 4px; }

/* ===== TIMER BAR ===== */
.timer-track {
  width: 100%;
  max-width: 660px;
  height: 12px;
  background: rgba(255,255,255,0.15);
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.2);
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: var(--pokeyellow);
  border-radius: 4px;
  transform-origin: left center;
  transition: none;
}

.timer-bar.running {
  animation: timerShrink var(--timer-dur, 10s) linear forwards;
}

@keyframes timerShrink {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* Btn next below card */
#btn-next { max-width: 660px; margin-top: 0; }

/* ===== OVERLAY ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  animation: fadeIn 0.25s ease;
}
.overlay.hidden { display: none !important; }

.summary-card { max-width: 380px; width: 100%; }

.summary-pokemon-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.summary-pokemon-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.summary-sprite {
  width: 64px;
  height: 64px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}
.summary-sprite.missed { filter: brightness(0) opacity(0.5); }

.summary-catch-label {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.4rem;
  color: var(--pokered);
}
.summary-catch-label.caught { color: #22c55e; }

.summary-buttons { display: flex; flex-direction: column; gap: 4px; }

/* ===== HISTORY SCREEN ===== */
.history-card { max-width: 480px; }

.history-list { max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }

.history-item {
  border: 2px solid var(--pokeborder);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.history-mode {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.45rem;
  color: var(--pokered);
  text-transform: uppercase;
}

.history-date {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.4rem;
  color: var(--pokegray);
}

.history-score {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.5rem;
  color: var(--pokedark);
  margin-bottom: 8px;
}

.history-sprites {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.history-sprite {
  width: 32px;
  height: 32px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}
.history-sprite.missed { filter: brightness(0) opacity(0.4); }

.loading { font-size: 0.5rem; color: var(--pokegray); text-align: center; padding: 24px; }

/* ===== GAME SCREEN WIDER OVERRIDE ===== */
#screen-game { max-width: 760px; }
