:root {
  --red: #c8102e;
  --red-dark: #8e0a20;
  --red-light: #e23a4f;
  --ink: #1f2429;
  --ink-soft: #5a636c;
  --panel: #f3f5f6;
  --line: #d9dee2;
  --screen: #183a36;
  --screen-glow: #2a5a52;
  --bezel: #e4e2dd;
  --lens: #2f9ee0;
  --yellow: #f2c230;

  --font-display: "Oxanium", system-ui, sans-serif;
  --font-body: "Atkinson Hyperlegible", system-ui, sans-serif;
}

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, #fbe9ec 0, transparent 45%),
    #eceef0;
  min-height: 100vh;
  line-height: 1.5;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}

/* ---------- Aparelho ---------- */

.dex {
  max-width: 1120px;
  margin: 32px auto 16px;
  padding: 0 16px;
  display: grid;
  grid-template-columns: minmax(320px, 410px) 18px 1fr;
  align-items: start;
}

.dex__left,
.dex__right {
  background: var(--red);
  border: 3px solid var(--red-dark);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .14), 0 18px 40px -24px rgba(90, 0, 15, .55);
}

.dex__left {
  min-width: 0;
  position: sticky;
  top: 16px;
  border-radius: 22px 8px 8px 22px;
  padding: 20px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hinge {
  align-self: stretch;
  margin: 40px 0;
  background: linear-gradient(90deg, var(--red-dark), var(--red-light) 50%, var(--red-dark));
  border-radius: 4px;
}

.dex__top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lens {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #bfe6ff 0 12%, var(--lens) 32%, #155f8f 100%);
  border: 5px solid #f4f4f4;
  box-shadow: 0 0 0 3px var(--red-dark);
  margin-right: 8px;
}

.led {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--red-dark);
}
.led--red { background: #ff5161; }
.led--yellow { background: var(--yellow); }
.led--green { background: #5fd068; }

.dex.is-loading .led--yellow { animation: blink .6s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }

.screen-frame {
  background: var(--bezel);
  border-radius: 10px 10px 10px 34px;
  padding: 18px 18px 12px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .12);
}

.screen {
  position: relative;
  aspect-ratio: 4 / 3.3;
  border-radius: 6px;
  border: 3px solid #3c3f42;
  background:
    radial-gradient(circle at 50% 60%, var(--screen-glow) 0, var(--screen) 70%);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.screen::after { /* linhas de varredura discretas */
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.035) 0 1px, transparent 1px 3px);
  pointer-events: none;
}

.screen__number {
  position: absolute;
  top: 8px;
  left: 12px;
  font-family: var(--font-display);
  font-weight: 700;
  color: #9fe3c8;
  letter-spacing: .04em;
  font-size: .95rem;
}

.screen__sprite {
  max-width: 78%;
  max-height: 78%;
  image-rendering: auto;
  filter: drop-shadow(0 6px 4px rgba(0, 0, 0, .35));
  transition: opacity .2s;
}
.screen__sprite.is-pixel { image-rendering: pixelated; min-height: 45%; object-fit: contain; }
.dex.is-loading .screen__sprite { opacity: .25; }

.screen__status {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-display);
  color: #9fe3c8;
  font-size: .9rem;
}
.screen__status:empty { display: none; }

.screen-frame__bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
}

.cry {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #8b1020;
  background: var(--red);
  display: grid;
  place-items: center;
}
.cry svg { width: 20px; fill: #fff; }
.cry:disabled { opacity: .4; cursor: not-allowed; }
.cry.is-playing { background: var(--yellow); }
.cry.is-playing svg { fill: var(--ink); }

.speaker { display: grid; gap: 4px; }
.speaker i {
  display: block;
  width: 44px;
  height: 3px;
  border-radius: 2px;
  background: #6b6b6b;
}

/* controles */

.controls {
  display: flex;
  gap: 8px;
}

.segmented {
  flex: 1;
  display: flex;
  background: var(--red-dark);
  border-radius: 8px;
  padding: 3px;
}
.segmented button,
.toggle {
  border: 0;
  background: transparent;
  color: #ffdfe3;
  padding: 7px 8px;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 700;
  flex: 1;
}
.segmented button[aria-pressed="true"] {
  background: #fff;
  color: var(--ink);
}
.toggle {
  flex: 0 0 auto;
  background: var(--red-dark);
  padding: 7px 14px;
  border-radius: 8px;
}
.toggle[aria-pressed="true"] {
  background: var(--yellow);
  color: var(--ink);
}

.search__label {
  display: block;
  color: #fff;
  font-weight: 700;
  font-size: .9rem;
  margin-bottom: 6px;
}
.search__row { display: flex; gap: 8px; }
.search input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 2px solid #3c3f42;
  background: #fff;
  font-weight: 700;
}

.btn {
  border: 2px solid #111;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 700;
  white-space: nowrap;
}
.btn--dark {
  background: #34383c;
  color: #fff;
  box-shadow: 0 3px 0 #111;
}
.btn--dark:active { transform: translateY(2px); box-shadow: 0 1px 0 #111; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
}

.hint {
  color: #ffd5da;
  font-size: .8rem;
  text-align: center;
  margin-top: -8px;
}

/* ---------- Ficha ---------- */

.dex__right {
  border-radius: 8px 22px 22px 8px;
  padding: 18px;
}

.sheet {
  background: var(--panel);
  border-radius: 12px;
  overflow: clip;              /* arredonda sem quebrar o position: sticky das abas */
}

/* abas: só aparecem no celular */
.tabs { display: none; }
.hint__touch { display: none; }

.sheet-head {
  padding: 22px 24px 18px;
  border-bottom: 1px solid var(--line);
}

.sheet-head__name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  line-height: 1.05;
}
.sheet-head__genus {
  color: var(--ink-soft);
  margin-top: 4px;
}

.types, .tags {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.type {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
  text-shadow: 0 1px 1px rgba(0, 0, 0, .25);
}
.type--sm { padding: 1px 9px; font-size: .78rem; }

.tag {
  font-size: .8rem;
  padding: 2px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
}
.tag--strong { border-color: var(--yellow); background: #fff6d6; color: #6a5200; }

.block {
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
}
.block:last-child { border-bottom: 0; }
.block h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 10px;
  color: var(--red-dark);
}
.block__title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.flavor { max-width: 62ch; font-size: 1.05rem; }
.flavor-source, .note { color: var(--ink-soft); font-size: .82rem; margin-top: 6px; }

.link-btn {
  border: 0;
  background: none;
  color: var(--red-dark);
  font-weight: 700;
  font-size: .85rem;
  text-decoration: underline;
}
.link-btn:disabled { color: var(--ink-soft); text-decoration: none; cursor: default; }

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px 18px;
}
.facts dt { color: var(--ink-soft); font-size: .82rem; }
.facts dd { font-weight: 700; }

/* atributos */
.stats { width: 100%; border-collapse: collapse; }
.stats th {
  text-align: left;
  font-weight: 400;
  color: var(--ink-soft);
  width: 92px;
  padding: 3px 0;
  font-size: .9rem;
}
.stats td.value {
  width: 42px;
  text-align: right;
  font-family: var(--font-display);
  font-weight: 700;
  padding-right: 10px;
}
.bar {
  height: 10px;
  border-radius: 5px;
  background: #e1e5e8;
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  border-radius: 5px;
  transform-origin: left;
  animation: grow .5s ease-out;
}
@keyframes grow { from { transform: scaleX(0); } }
.stats caption { caption-side: top; text-align: left; font-size: .8rem; color: var(--ink-soft); margin-bottom: 6px; }
.stats td.diff { width: 44px; text-align: right; font-family: var(--font-display); font-weight: 700; font-size: .85rem; }
.diff--up { color: #1d7a3a; }
.diff--down { color: #b3261e; }
.stats tr.total th, .stats tr.total td { padding-top: 8px; border-top: 1px solid var(--line); font-weight: 700; color: var(--ink); }

/* fraquezas */
.matchups { display: grid; gap: 8px; }
.matchup { display: flex; gap: 10px; align-items: baseline; }
.matchup__mult {
  flex: 0 0 44px;
  font-family: var(--font-display);
  font-weight: 800;
}
.matchup__list { display: flex; flex-wrap: wrap; gap: 5px; }

/* formas */
.forms-summary { color: var(--ink-soft); margin: -4px 0 12px; }
.forms-summary:empty { display: none; }

.form-info {
  border-left: 4px solid var(--yellow);
  background: #fffbea;
  border-radius: 0 10px 10px 0;
  padding: 12px 16px;
  margin-bottom: 14px;
  max-width: 68ch;
}
.form-info h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin-bottom: 4px;
}
.form-info p + p { margin-top: 6px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
}
.form-card {
  display: flex;
  gap: 10px;
  align-items: center;
  text-align: left;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px 8px 6px;
}
.form-card:hover { border-color: #b9c0c6; }
.form-card[aria-current="true"] { border-color: var(--red); }
.form-card img, .form-card__noimg { width: 64px; height: 64px; flex: 0 0 64px; object-fit: contain; }
.form-card__body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.form-card__name { font-weight: 700; }
.form-card__kind { font-size: .78rem; color: var(--ink-soft); }
.form-card__kind--mega, .form-card__kind--primal { color: #7a3fc4; font-weight: 700; }
.form-card__kind--regional { color: #1d7a52; font-weight: 700; }
.form-card__kind--gmax { color: var(--red-dark); font-weight: 700; }
.form-card__types { display: flex; flex-wrap: wrap; gap: 4px; }
.form-card__debut { font-size: .74rem; color: var(--ink-soft); }

/* evolução */
.evo {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.evo__stage { display: flex; flex-direction: column; gap: 6px; }
.evo__arrow { color: var(--ink-soft); font-size: 1.2rem; padding: 0 2px; }
.evo__item {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid transparent;
  background: #fff;
  border-radius: 10px;
  padding: 4px 10px 4px 4px;
  text-align: left;
}
.evo__item:hover { border-color: var(--line); }
.evo__item[aria-current="true"] { border-color: var(--red); }
.evo__item img { width: 48px; height: 48px; }
.evo__name { display: block; font-weight: 700; font-size: .9rem; }
.evo__how { display: block; font-size: .76rem; color: var(--ink-soft); }
.evo__single { color: var(--ink-soft); }

/* fontes */
.sources {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.sources a {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  text-decoration: none;
  font-weight: 700;
  font-size: .88rem;
}
.sources a:hover { border-color: var(--red); }
.sources small { font-weight: 400; color: var(--ink-soft); }

.foot {
  max-width: 1120px;
  margin: 0 auto 28px;
  padding: 0 16px;
  font-size: .8rem;
  color: var(--ink-soft);
  text-align: center;
}


/* ---------- Música ---------- */
.music-btn {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  background: var(--red-dark);
  color: #ffdfe3;
  font-weight: 700;
  font-size: .8rem;
  padding: 6px 12px;
}
.music-btn[aria-pressed="true"] { background: var(--yellow); color: var(--ink); }
.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 12px; }
.eq i { display: block; width: 3px; height: 4px; background: currentColor; border-radius: 1px; }
.music-btn[aria-pressed="true"] .eq i { animation: eq .5s ease-in-out infinite alternate; }
.music-btn[aria-pressed="true"] .eq i:nth-child(2) { animation-delay: -.25s; }
.music-btn[aria-pressed="true"] .eq i:nth-child(3) { animation-delay: -.4s; }
@keyframes eq { from { height: 3px; } to { height: 12px; } }

/* ---------- Animações ---------- */

/* 1. Liga a tela como um monitor antigo, só na primeira abertura */
.screen::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 35%;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(180deg, transparent, rgba(159, 227, 200, .22), transparent);
}
.dex.is-loading .screen::before { animation: sweep .9s linear infinite; }
@keyframes sweep {
  from { opacity: 1; transform: translateY(-100%); }
  to { opacity: 1; transform: translateY(300%); }
}

.dex.is-booting .screen::before {
  top: 0;
  height: 100%;
  background: #e9fff6;
  animation: crt-on .9s ease-out forwards;
}
@keyframes crt-on {
  0%   { opacity: 1; transform: scale(0, .006); }
  35%  { opacity: 1; transform: scale(1, .006); }
  60%  { opacity: .9; transform: scale(1, 1); }
  100% { opacity: 0; transform: scale(1, 1); }
}
.dex.is-booting .led { animation: led-on .9s steps(3) both; }
.dex.is-booting .led--yellow { animation-delay: .15s; }
.dex.is-booting .led--green { animation-delay: .3s; }
@keyframes led-on { from { opacity: .2; } }

/* 2. Lente pulsa enquanto busca */
.dex.is-loading .lens { animation: lens-pulse .9s ease-in-out infinite; }
@keyframes lens-pulse {
  50% { box-shadow: 0 0 0 3px var(--red-dark), 0 0 18px 6px rgba(120, 205, 255, .75); }
}

/* 3. Pokémon aparece como silhueta e ganha cor */
.screen__sprite.is-entering { animation: reveal .6s cubic-bezier(.2, .9, .3, 1.15) both; }
@keyframes reveal {
  0%   { opacity: 0; transform: translateX(var(--dx, 0)) scale(.7); filter: brightness(0) drop-shadow(0 6px 4px rgba(0,0,0,.35)); }
  45%  { opacity: 1; filter: brightness(0) drop-shadow(0 6px 4px rgba(0,0,0,.35)); }
  100% { opacity: 1; transform: none; filter: brightness(1) drop-shadow(0 6px 4px rgba(0,0,0,.35)); }
}
.screen__sprite.is-swapping { animation: swap .3s ease-out both; }
@keyframes swap { from { opacity: 0; transform: scale(.92); } }

/* 4. Ficha troca suavemente */
.dex__right.is-swapping .sheet > :not(.tabs) { animation: sheet-in .32s ease-out both; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(6px); } }

.stats tr:nth-child(2) .bar span { animation-delay: .04s; }
.stats tr:nth-child(3) .bar span { animation-delay: .08s; }
.stats tr:nth-child(4) .bar span { animation-delay: .12s; }
.stats tr:nth-child(5) .bar span { animation-delay: .16s; }
.stats tr:nth-child(6) .bar span { animation-delay: .2s; }
.stats tr:nth-child(7) .bar span { animation-delay: .24s; }
.bar span { animation-fill-mode: both; }

/* 5. Brilho ao ativar shiny */
.sparkle {
  position: absolute;
  z-index: 3;
  width: 18px;
  height: 18px;
  background: #fff6c2;
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
  pointer-events: none;
  animation: sparkle .8s ease-out both;
}
@keyframes sparkle {
  0%   { opacity: 0; transform: scale(0) rotate(0); }
  40%  { opacity: 1; transform: scale(1.2) rotate(45deg); }
  100% { opacity: 0; transform: scale(.2) rotate(120deg) translateY(-12px); }
}

/* 6. Alto-falante vibra durante o grito */
.speaker.is-playing i { animation: speak .18s ease-in-out infinite alternate; transform-origin: right; }
.speaker.is-playing i:nth-child(2) { animation-delay: -.06s; }
.speaker.is-playing i:nth-child(3) { animation-delay: -.12s; }
@keyframes speak { to { transform: scaleX(.55); background: var(--red); } }

/* 7. Resposta ao toque */
.form-card, .evo__item, .sources a {
  transition: transform .15s ease, border-color .15s ease;
}
.form-card:hover, .evo__item:hover, .sources a:hover { transform: translateY(-2px); }
.form-card:active, .evo__item:active { transform: translateY(0); }
.segmented button, .toggle, .music-btn { transition: background-color .2s, color .2s; }

/* ---------- Cores dos tipos ---------- */
.t-normal { background: #9fa19f; }
.t-fire { background: #e62829; }
.t-water { background: #2980ef; }
.t-electric { background: #d9a800; }
.t-grass { background: #3fa129; }
.t-ice { background: #3dcef3; }
.t-fighting { background: #ff8000; }
.t-poison { background: #9141cb; }
.t-ground { background: #915121; }
.t-flying { background: #81b9ef; }
.t-psychic { background: #ef4179; }
.t-bug { background: #91a119; }
.t-rock { background: #afa981; }
.t-ghost { background: #704170; }
.t-dragon { background: #5060e1; }
.t-dark { background: #624d4e; }
.t-steel { background: #60a1b8; }
.t-fairy { background: #ef70ef; }
.t-stellar { background: #40b5a5; }
.t-unknown { background: #68a090; }


/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  .dex {
    grid-template-columns: minmax(0, 1fr);
    max-width: 560px;
    margin-top: 16px;
  }
  .dex__left {
    position: static;
    border-radius: 22px 22px 8px 8px;
  }
  .hinge { height: 14px; margin: 0 30px; }
  .dex__right { border-radius: 8px 8px 22px 22px; padding: 12px; }
  .block, .sheet-head { padding-left: 16px; padding-right: 16px; }
}


/* ---------- Celular ---------- */
@media (hover: none), (pointer: coarse) {
  .hint__keys { display: none; }
  .hint__touch { display: inline; }
}

@media (max-width: 600px) {
  body {
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
    background: #eceef0;
  }

  .dex {
    margin: 0 auto;
    padding: 8px 8px 0;
    gap: 0;
  }

  /* aparelho mais compacto */
  .dex__left {
    padding: 12px 14px 16px;
    gap: 12px;
    border-radius: 20px 20px 8px 8px;
  }
  .lens { width: 42px; height: 42px; border-width: 4px; margin-right: 4px; }
  .led { width: 11px; height: 11px; }
  .music-btn { padding: 8px 12px; min-height: 36px; }
  .music-btn #music-label { display: none; }
  .music-btn::after { content: "Música"; }

  .screen-frame { padding: 12px 12px 8px; border-radius: 8px 8px 8px 26px; }
  .screen { aspect-ratio: 4 / 3; max-height: 32vh; width: 100%; touch-action: pan-y; }
  .search__label {          /* some visualmente, mas continua para leitores de tela */
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%);
  }
  .screen-frame__bottom { margin-top: 8px; }
  .cry { width: 44px; height: 44px; }

  .segmented button, .toggle { min-height: 40px; }
  .search input, .search .btn { min-height: 46px; font-size: 16px; } /* 16px evita zoom no iPhone */
  .hint { margin-top: -6px; font-size: .75rem; }

  /* navegação fixa embaixo, ao alcance do polegar */
  .nav {
    position: fixed;
    z-index: 30;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--red);
    border-top: 3px solid var(--red-dark);
    box-shadow: 0 -8px 20px -12px rgba(90, 0, 15, .6);
    grid-template-columns: 1fr auto 1fr;
  }
  .nav .btn { min-height: 48px; }
  .nav #btn-random { grid-column: auto; grid-row: auto; }

  .hinge { height: 12px; margin: 0 28px; }

  .dex__right { padding: 8px; border-radius: 8px 8px 20px 20px; }

  .sheet-head { padding: 16px 16px 12px; }
  .sheet-head__name { font-size: 1.8rem; }

  /* abas da ficha, grudadas no topo ao rolar */
  .tabs {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 10;
    overflow-x: auto;
    scrollbar-width: none;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 0 4px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button {
    flex: 1 0 auto;
    border: 0;
    background: none;
    padding: 13px 7px 11px;
    font-weight: 700;
    font-size: .88rem;
    color: var(--ink-soft);
    border-bottom: 3px solid transparent;
  }
  .tabs button[aria-pressed="true"] { color: var(--red-dark); border-bottom-color: var(--red); }
  .tabs button[hidden] { display: none; }

  .block.tab-off { display: none; }
  .block { padding: 16px; }
  .block.tab-in { animation: sheet-in .25s ease-out both; }

  .facts { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .stats th { width: 80px; }

  .evo { flex-direction: column; align-items: stretch; }
  .evo__arrow { transform: rotate(90deg); align-self: center; }
  .evo__stage { flex-direction: row; flex-wrap: wrap; }
  .evo__item { flex: 1 1 140px; }

  .foot { padding: 12px 16px 0; }
}


@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
