:root {
  /* Pokédex red & black palette */
  --red: #d3242b;          /* chassis red */
  --red-deep: #8a1218;     /* shadow red */
  --red-bright: #ff5b4a;   /* highlight red */
  --ink: #140c0d;          /* near-black outlines */
  --ink-soft: #2a1c1d;
  --screen: #1c1315;       /* dark LCD */
  --screen-2: #271a1c;
  --lcd: #f4e7cd;          /* cream LCD text */
  --lcd-dim: #b89a86;      /* muted LCD text */
  --good: #46d07a;         /* used sparingly for "correct" tick */
  --font-pixel: "Press Start 2P", "Courier New", monospace;
  --font-lcd: "VT323", "Courier New", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-lcd);
  color: var(--lcd);
  min-height: 100vh;
  background:
    radial-gradient(900px 500px at 80% -10%, var(--red-bright) 0%, transparent 55%),
    repeating-linear-gradient(135deg, #c41f26 0 14px, #cf2228 14px 28px),
    var(--red);
}

/* Global CRT scanlines */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 90;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.16) 0 1px,
    transparent 1px 3px
  );
  mix-blend-mode: multiply;
  opacity: 0.5;
}

/* ============ Top bar / Pokédex hinge ============ */
.topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 20px 26px;
  max-width: 1100px;
  margin: 18px auto 0;
  background: var(--red);
  border: 5px solid var(--ink);
  border-radius: 14px 14px 0 0;
  box-shadow: inset 0 4px 0 rgba(255, 255, 255, 0.18),
    inset 0 -8px 0 rgba(0, 0, 0, 0.22), 8px 8px 0 rgba(0, 0, 0, 0.35);
}

/* Big round lens + indicator lights */
.dex-lights { display: flex; align-items: center; gap: 12px; }
.lens {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 30%, #ffd2cd 0 6%, transparent 18%),
    radial-gradient(circle at 60% 65%, #e23a30, #7c0d12 75%);
  border: 4px solid var(--ink);
  box-shadow: 0 0 0 3px #f3d7d3, inset -2px -2px 6px rgba(0, 0, 0, 0.5);
  flex: none;
}
.light {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: #6a0c10;
  box-shadow: inset 1px 1px 2px rgba(255, 255, 255, 0.25);
  flex: none;
}
.light.on {
  background: radial-gradient(circle at 35% 30%, #fff3a0, #ffb000 70%);
  box-shadow: 0 0 8px #ffb000, inset 1px 1px 2px rgba(255, 255, 255, 0.6);
}

.topbar h1 {
  margin: 0;
  flex: 1;
  font-family: var(--font-pixel);
  font-size: clamp(13px, 2.4vw, 22px);
  line-height: 1.4;
  color: var(--lcd);
  text-shadow: 3px 3px 0 var(--ink), -1px -1px 0 var(--red-deep);
  letter-spacing: 1px;
}

.streaks { display: flex; gap: 12px; }
.streak-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--screen);
  border: 4px solid var(--ink);
  border-radius: 6px;
  padding: 6px 14px 8px;
  min-width: 74px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.7);
}
.streak-num {
  font-family: var(--font-lcd);
  font-size: 34px;
  line-height: 0.9;
  color: var(--red-bright);
  text-shadow: 0 0 8px rgba(255, 91, 74, 0.6);
}
.streak-box.best .streak-num { color: #ffcf3f; text-shadow: 0 0 8px rgba(255, 207, 63, 0.6); }
.streak-label {
  font-family: var(--font-pixel);
  font-size: 7px;
  letter-spacing: 1px;
  color: var(--lcd-dim);
  margin-top: 7px;
}

/* ============ Layout ============ */
.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 26px;
  display: grid;
  grid-template-columns: 1fr 330px;
  gap: 22px;
  align-items: start;
}

/* Shared "screen panel" bezel: black border + red ring + black ring */
.game, .sidebar {
  background:
    radial-gradient(120% 120% at 50% 0%, var(--screen-2) 0%, var(--screen) 70%);
  border: 5px solid var(--ink);
  border-radius: 10px;
  box-shadow:
    0 0 0 6px var(--red),
    0 0 0 10px var(--ink),
    inset 0 0 26px rgba(0, 0, 0, 0.85);
  position: relative;
}
/* faint inner scanlines on screens */
.game::before, .sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,0.025) 0 1px, transparent 1px 4px);
}

.layout { margin-top: 16px; margin-bottom: 40px; }
.game { padding: 30px 28px; text-align: center; }

/* ============ Generation filter ============ */
.gen-filter {
  margin: 0 0 22px;
  padding-bottom: 16px;
  border-bottom: 3px dashed rgba(244, 231, 205, 0.18);
}
.gen-filter-label {
  display: block;
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--lcd-dim);
  margin-bottom: 10px;
}
.gen-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.gen-chip {
  font-family: var(--font-pixel);
  font-size: 9px;
  padding: 8px 9px;
  color: var(--lcd-dim);
  background: var(--ink-soft);
  border: 3px solid var(--ink);
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.05s ease;
}
.gen-chip:hover { color: var(--lcd); }
.gen-chip:active { transform: translateY(1px); }
.gen-chip.on {
  color: #fff;
  background: var(--red);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.22);
}
.gen-chip.all.on {
  background: var(--good);
  color: var(--ink);
}

.prompt {
  font-size: 24px;
  color: var(--lcd);
  margin: 0 0 22px;
  line-height: 1.1;
}
.prompt strong { color: var(--red-bright); }

/* ============ Type badges ============ */
.types {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.type-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  min-width: 138px;
  border: 4px solid var(--ink);
  border-radius: 6px;
  box-shadow: 4px 4px 0 var(--ink), inset 0 0 20px rgba(0, 0, 0, 0.35);
  image-rendering: pixelated;
}
.type-card img {
  width: 60px; height: 60px; object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.6));
}
.type-card .type-name {
  font-family: var(--font-pixel);
  font-size: 11px;
  letter-spacing: 1px;
  color: #fff;
  text-transform: capitalize;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
}
.type-plus {
  font-family: var(--font-pixel);
  font-size: 20px;
  color: var(--lcd);
  text-shadow: 2px 2px 0 var(--ink);
}

/* ============ Input + autocomplete ============ */
.input-wrap { position: relative; max-width: 440px; margin: 0 auto; }

#guess {
  width: 100%;
  padding: 13px 14px;
  font-family: var(--font-lcd);
  font-size: 22px;
  color: var(--lcd);
  background: #120c0d;
  border: 4px solid var(--ink);
  border-radius: 4px;
  outline: none;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.9);
  caret-color: var(--red-bright);
}
#guess::placeholder { color: var(--lcd-dim); }
#guess:focus { box-shadow: inset 0 0 12px rgba(0,0,0,.9), 0 0 0 3px var(--red); }
#guess:disabled { opacity: 0.55; }

.suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  margin: 0; padding: 5px;
  list-style: none;
  background: #160f10;
  border: 4px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 0 0 3px var(--red), 0 0 0 6px var(--ink), 10px 14px 0 rgba(0, 0, 0, 0.5);
  z-index: 95; /* float above page UI + CRT overlay */
  max-height: 320px;
  overflow-y: auto;
  text-align: left;
}
.suggestions li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 2px solid transparent;
  cursor: pointer;
}
.suggestions li.active,
.suggestions li:hover {
  background: var(--red-deep);
  border-color: var(--red-bright);
}
.suggestions li img { width: 42px; height: 42px; image-rendering: pixelated; flex: none; }
.suggestions li .s-name { font-size: 20px; color: var(--lcd); }

/* Pixel scrollbar */
.suggestions::-webkit-scrollbar, .wrong-list::-webkit-scrollbar { width: 12px; }
.suggestions::-webkit-scrollbar-track, .wrong-list::-webkit-scrollbar-track { background: #0e0809; }
.suggestions::-webkit-scrollbar-thumb, .wrong-list::-webkit-scrollbar-thumb {
  background: var(--red); border: 2px solid var(--ink);
}

/* ============ Buttons ============ */
.buttons {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}
.btn {
  font-family: var(--font-pixel);
  font-size: 11px;
  letter-spacing: 1px;
  padding: 13px 18px;
  border: 4px solid var(--ink);
  border-radius: 4px;
  cursor: pointer;
  color: #fff;
  background: var(--red);
  box-shadow: 4px 4px 0 var(--ink), inset 0 3px 0 rgba(255, 255, 255, 0.25),
    inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  transition: transform 0.05s;
}
.btn:hover { background: var(--red-bright); }
.btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink), inset 0 0 0 rgba(0,0,0,.3); }
.btn.ghost { background: var(--ink-soft); color: var(--lcd-dim); }
.btn.ghost:hover { background: #3a2728; color: var(--lcd); }
.btn.next { background: #1f7a45; }
.btn.next:hover { background: var(--good); }

/* ============ Feedback (inline messages) ============ */
.feedback { margin-top: 24px; min-height: 40px; }

/* ============ Result pop-up overlay (Rotom-Dex) ============ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 98; /* over all page UI + CRT overlay, under loader */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 3, 4, 0.7);
  backdrop-filter: blur(1px);
  animation: fade 0.15s ease-out;
}
.overlay[hidden] { display: none; }

.result-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 22px 30px 24px;
  max-width: min(440px, 90vw);
  border: 5px solid var(--ink);
  border-radius: 18px;
  background: var(--screen-2);
  box-shadow: 8px 8px 0 var(--ink), 0 0 0 6px var(--red), inset 0 0 18px rgba(0, 0, 0, 0.6);
  animation: popin 0.2s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.result-card.correct { box-shadow: 8px 8px 0 var(--ink), 0 0 0 6px var(--good), inset 0 0 18px rgba(0,0,0,.6); }
.result-card.reveal  { box-shadow: 8px 8px 0 var(--ink), 0 0 0 6px var(--red-bright), inset 0 0 18px rgba(0,0,0,.6); }
.result-card .big {
  font-family: var(--font-pixel);
  font-size: 16px;
  letter-spacing: 1px;
  text-shadow: 2px 2px 0 var(--ink);
}
.result-card.correct .big { color: var(--good); }
.result-card.reveal .big { color: var(--red-bright); }
.result-card img { width: 92px; height: 92px; image-rendering: pixelated; }
.result-card .sub { font-size: 22px; color: var(--lcd); }
.result-card .answers { font-size: 20px; color: var(--lcd-dim); max-width: 360px; line-height: 1.15; }
.result-card .next { margin-top: 6px; }

.inline-msg {
  font-size: 22px;
  color: var(--red-bright);
  animation: shake 0.3s steps(4, end);
}

@keyframes pop { from { transform: scale(0.8); } to { transform: scale(1); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes popin {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ============ Sidebar / wrong-guess popups ============ */
.sidebar { padding: 18px; position: sticky; top: 16px; }
.sidebar h2 {
  margin: 0 0 8px;
  font-family: var(--font-pixel);
  font-size: 12px;
  color: var(--red-bright);
  text-shadow: 2px 2px 0 var(--ink);
}
.sidebar-hint { color: var(--lcd-dim); font-size: 18px; margin: 0 0 14px; line-height: 1.1; }

.wrong-list { display: flex; flex-direction: column; gap: 12px; max-height: 70vh; overflow-y: auto; padding: 2px; }

.wrong-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--screen-2);
  border: 4px solid var(--ink);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 4px 4px 0 var(--ink), 0 0 0 3px var(--red-deep);
  animation: pop 0.15s steps(3, end);
}
.wrong-card img { width: 58px; height: 58px; image-rendering: pixelated; flex: none; }
.wc-name { font-size: 21px; color: var(--lcd); line-height: 1; padding-right: 18px; }
.wc-types { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.mini-type {
  font-family: var(--font-pixel);
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
  padding: 4px 7px;
  border: 2px solid var(--ink);
  border-radius: 3px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
}

/* Retro pixel close X */
.wrong-close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 26px;
  height: 26px;
  padding: 0;
  font-family: var(--font-pixel);
  font-size: 10px;
  color: #fff;
  background: var(--red);
  border: 3px solid var(--ink);
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  line-height: 1;
}
.wrong-close:hover { background: var(--red-bright); }
.wrong-close:active { transform: translate(2px, 2px); box-shadow: none; }

/* ============ Footer / loader ============ */
.credit {
  text-align: center;
  color: rgba(0, 0, 0, 0.55);
  font-size: 18px;
  padding: 8px 0 26px;
}
.credit a { color: var(--ink); text-decoration: underline; }

.loader {
  position: fixed; inset: 0;
  background:
    repeating-linear-gradient(135deg, #c41f26 0 14px, #cf2228 14px 28px), var(--red);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 20px; z-index: 100;
  transition: opacity 0.4s;
}
.loader.hide { opacity: 0; pointer-events: none; }
.loader p {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--lcd);
  text-shadow: 2px 2px 0 var(--ink);
}
.pokeball {
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(var(--red-bright) 0 50%, #fff 50% 100%);
  border: 5px solid var(--ink);
  position: relative;
  animation: spin 1s steps(8) infinite;
}
.pokeball::after {
  content: ""; position: absolute;
  top: 50%; left: 0; right: 0; height: 6px;
  background: var(--ink); transform: translateY(-50%);
}
.pokeball::before {
  content: ""; position: absolute;
  top: 50%; left: 50%;
  width: 18px; height: 18px;
  background: #fff; border: 5px solid var(--ink); border-radius: 50%;
  transform: translate(-50%, -50%); z-index: 1;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Responsive ============ */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .topbar { flex-wrap: wrap; }
}

/* =====================================================================
   Type Duel (multiplayer) screens
   ===================================================================== */
[hidden] { display: none !important; }

#main { width: 100%; }

/* Non-solo screens center a single panel */
.screen:not(.layout) {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 26px 40px;
  display: flex;
  justify-content: center;
}
.game.panel {
  width: 100%;
  max-width: 560px;
  position: relative;
}

.dexbtn { font-size: 9px; }

.screen-title {
  margin: 0 0 6px;
  font-family: var(--font-pixel);
  font-size: 16px;
  color: var(--accent, var(--red-bright));
  color: var(--red-bright);
  text-shadow: 2px 2px 0 var(--ink);
}
.screen-sub { color: var(--lcd-dim); font-size: 18px; margin: 0 0 18px; line-height: 1.15; }
.screen-msg { color: var(--red-bright); font-size: 18px; min-height: 22px; margin: 14px 0 6px; }

/* form fields */
.field { text-align: left; margin: 0 auto 16px; max-width: 360px; }
.field > label {
  display: block;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--lcd-dim);
  margin-bottom: 8px;
  letter-spacing: 1px;
}
.field input[type="text"],
.field input[type="number"] {
  width: 100%;
  padding: 11px 12px;
  font-family: var(--font-lcd);
  font-size: 20px;
  color: var(--lcd);
  background: #120c0d;
  border: 4px solid var(--ink);
  border-radius: 4px;
  outline: none;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.9);
}
.field input:focus { box-shadow: inset 0 0 12px rgba(0,0,0,.9), 0 0 0 3px var(--red); }

/* segmented mode control */
.seg { display: flex; gap: 8px; }
.seg-btn {
  flex: 1;
  font-family: var(--font-pixel);
  font-size: 10px;
  padding: 12px 8px;
  color: var(--lcd-dim);
  background: var(--ink-soft);
  border: 4px solid var(--ink);
  border-radius: 4px;
  cursor: pointer;
}
.seg-btn.active { color: #fff; background: var(--red); box-shadow: inset 0 3px 0 rgba(255,255,255,.2); }

.setup-actions { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 8px; }
.or { color: var(--lcd-dim); font-size: 16px; }
.join-row { display: flex; gap: 8px; justify-content: center; }
.join-row input {
  width: 130px;
  padding: 11px 12px;
  font-family: var(--font-pixel);
  font-size: 14px;
  letter-spacing: 3px;
  text-align: center;
  text-transform: uppercase;
  color: var(--lcd);
  background: #120c0d;
  border: 4px solid var(--ink);
  border-radius: 4px;
  outline: none;
}
.btn.small { font-size: 9px; padding: 9px 14px; }

/* lobby */
.code-display {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: #120c0d;
  border: 4px solid var(--ink);
  border-radius: 8px;
  padding: 14px;
  margin: 6px auto 18px;
  max-width: 320px;
  box-shadow: inset 0 0 14px rgba(0,0,0,.8);
}
.code-label { font-family: var(--font-pixel); font-size: 8px; color: var(--lcd-dim); letter-spacing: 1px; }
.code-value {
  font-family: var(--font-pixel);
  font-size: 30px;
  letter-spacing: 8px;
  color: var(--red-bright);
  text-shadow: 0 0 10px rgba(255,91,74,.5);
  padding-left: 8px;
}
.lobby-players {
  display: flex; align-items: center; justify-content: center; gap: 16px; margin: 10px 0 6px;
}
.lobby-player {
  display: flex; flex-direction: column; gap: 4px; min-width: 110px;
  background: var(--screen-2); border: 3px solid var(--ink); border-radius: 8px; padding: 10px;
}
.lp-role { font-family: var(--font-pixel); font-size: 8px; color: var(--lcd-dim); }
.lp-name { font-size: 20px; color: var(--lcd); }
.lobby-vs { font-family: var(--font-pixel); font-size: 14px; color: var(--red-bright); }
.lobby-mode { color: var(--lcd-dim); font-size: 17px; margin: 6px 0; }

/* type pick grid */
.type-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 14px 0 6px;
}
.type-pick {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
}
.type-pick img { width: 32px; height: 32px; object-fit: contain; filter: drop-shadow(1px 1px 0 rgba(0,0,0,.6)); }
.type-pick span {
  font-family: var(--font-pixel); font-size: 7px; color: #fff;
  text-transform: capitalize; text-shadow: 1px 1px 0 rgba(0,0,0,.6);
}
.type-pick.sel { outline: 4px solid var(--lcd); outline-offset: 1px; transform: translate(1px, 1px); }
.type-pick.locked { opacity: 0.5; cursor: default; }

/* scorebar */
.scorebar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
  font-family: var(--font-lcd); font-size: 20px; color: var(--lcd);
}
.scorebar .sb-side b { color: var(--red-bright); }
.scorebar .sb-mode {
  font-family: var(--font-pixel); font-size: 8px; color: var(--lcd-dim);
  letter-spacing: 1px;
}

/* countdown */
.duel-arena { position: relative; }
.countdown {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-pixel);
  font-size: 64px;
  color: var(--red-bright);
  text-shadow: 4px 4px 0 var(--ink);
  background: rgba(8, 3, 4, 0.78);
  border-radius: 6px;
  z-index: 5;
  animation: pop 0.2s steps(3, end);
}
.countdown.go { color: var(--good); }
.result-card .answers.waiting { color: var(--lcd-dim); }

@media (max-width: 560px) {
  .type-grid { grid-template-columns: repeat(3, 1fr); }
}
