:root {
  --background: #E4E8EF;
  --card: #EEF0F4;

  --surface: #DBE0E9;
  --surface-hover: #CCD3E0;

  --text: #111827;
  --text-dark: #1a1a1a;
  --text-light: #F8FAFC;
  --text-muted: #4B5563;

  --border: #C2C9D6;

  --shadow: 0 8px 20px rgba(0, 0, 0, .10);
  --glow: rgba(0, 0, 0, 0.05);

  --positive: #2F9E44;
  --negative: #C0392B;

  /* Pokemon Type Colors */
  --type-bug: #a8b820;
  --type-dark: #705848;
  --type-dragon: #7038f8;
  --type-electric: #f8d030;
  --type-fairy: #f0b6bc;
  --type-fighting: #c03028;
  --type-fire: #f08030;
  --type-flying: #a890f0;
  --type-ghost: #705898;
  --type-grass: #78c850;
  --type-ground: #e0c068;
  --type-ice: #98d8d8;
  --type-normal: #a8a878;
  --type-poison: #a040a0;
  --type-psychic: #f85888;
  --type-rock: #b8a038;
  --type-steel: #b8b8d0;
  --type-water: #6890f0;
}

body.darkmode {
  --background: #0B1220;
  --card: #172033;
  --surface: #202C43;
  --surface-hover: #2C3B5A;
  --text: #F8FAFC;
  --text-muted: #B8C4D6;
  --border: #34435F;
  --shadow: 0 8px 20px rgba(0, 0, 0, .25);
  --glow: rgba(255, 255, 255, 0.04);
  --positive: #57D957;
  --negative: #FF4D4D;
}

/* Reset */
*,
*::after,
*::before {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  font-family: "Inter", sans-serif;
}

/* MAIN APP */
body {
  display: flex;
  flex-direction: column;
  color: var(--text);
  min-height: 100vh;
  background-color: var(--background);
}

.header {
  margin: 10px auto 0 auto;
  padding: 0 1rem;
  width: 100%;
  max-width: 500px;
  font-size: 1.3rem;
  text-align: center;
}

.header p {
  font-size: 1rem;
}

#app {
  display: none;
  flex-direction: column;
  width: 100%;
  justify-content: center;
  max-width: 2000px;
  padding: 20px;
  margin: 0 auto;
  zoom: 80%;
}

#loading {
  margin-top: 30vh;
  display: block;
  text-align: center;
  font-size: 2rem;
}

.main {
  flex: 1;
  overflow: auto;
}

/* POKEMON TEAM GRID */
.pokemon-team-display {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1 1 auto;
  max-width: 820px;
}

.stats-table-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 100%;
  flex: 1;
  max-width: 820px;
}

/* POKEMON CARD */
.pokemon-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "name moves"
    "type moves"
    "image moves"
    "item ability";
  row-gap: 8px;
  column-gap: 12px;
  width: 100%;
  min-height: 280px;
  min-width: 0;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background-color: var(--card);
}

/* POKEMON CARD STYLES */
.pokemon-name {
  grid-area: name;
  width: 100%;
}

.pokemon-item {
  grid-area: item;
}

.pokemon-image {
  display: flex;
  justify-content: center;
  align-items: center;
  justify-self: center;
  min-width: 0;
  max-width: 130px;
  grid-area: image;
  min-height: 130px;
  overflow: hidden;
}

.pokemon-img {
  width: 96px;
  max-height: 130px;
  object-fit: contain;
  image-rendering: pixelated;
}

.moves {
  display: grid;
  grid-area: moves;
  gap: 10px;
  overflow: hidden;
}

.pokemon-ability {
  grid-area: ability;
}

/* INPUTS */
.item-select,
.move-select {
  max-width: none;
}

.pokemon-card select {
  width: 100%;
  min-width: 0px;
  height: 30px;
  border: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background-color: var(--surface);
  font-size: 1.2rem;
  font-weight: bold;
  font-family: inherit;
  cursor: pointer;
  color: inherit;
  transition: background 0.2s ease;
}

.pokemon-card select:hover {
  background-color: var(--surface-hover);
}

.pokemon-card select:disabled {
  color: var(--text);
  opacity: 0.9;
  cursor: not-allowed;
}

.pokemon-card select option {
  font-weight: bold;
}

.modal {
  margin: auto auto;
  max-width: 800px;
  padding: 16px;
  border: 1px solid black !important;
}

.modal p {
  margin: 8px 0 4px 0;
}

.modal table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 2rem;
}

.modal th,
.modal td {
  padding: 0.75rem 1rem;
  text-align: left;
}

.modal th {
  font-weight: 600;
  border-bottom: 2px solid var(--accent-color);
}

.modal td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal tbody tr:last-child td {
  border-bottom: none;
}

.modal tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

.modal th:last-child,
.modal td:last-child {
  width: 100px;
  text-align: right;
}

#close-manual {
  display: block;
  margin-left: auto;

  max-width: 120px;

  background-color: var(--surface-hover);
  color: var(--text);
  font-size: 1.3rem;
  border: none;
  padding: 8px;
  cursor: pointer;
}

.input-container {
  display: flex;
  width: 100%;
  margin-bottom: 14px;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  max-width: 820px;
}

.input-container>* {
  font-size: 1.2rem;
  border: 1px solid var(--border);
  background-color: var(--surface);
  color: var(--text);
  transition: background 0.2s ease;
  cursor: pointer;
  font-family: inherit;
}

.input-container>*:hover {
  background-color: var(--surface-hover);
}

.input-container select {
  max-width: 140px;
  padding: 8px;
}

.input-container button {
  max-width: 90px;
  padding: 8px;
  border-radius: 15px;
}

.field {
  position: relative;
}

/* Accessibility */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.field.pokemon-type {
  grid-area: type;
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  justify-content: center;
}

.type {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 0.8rem;
  letter-spacing: 1px;
  color: white;
  text-transform: uppercase;
  text-align: center;
  border: 2px solid rgba(0, 0, 0, 0.25);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 0 rgba(0, 0, 0, 0.15),
    0 2px 3px rgba(0, 0, 0, 0.25);
}

/* COLORS FOR MOVES AND TYPE BOXES */
.bug,
.move-select.bug {
  background: var(--type-bug);
  color: var(--text-dark);
}

.dark,
.move-select.dark {
  background: var(--type-dark);
  color: var(--text-light);
}

.dragon,
.move-select.dragon {
  background: var(--type-dragon);
  color: var(--text-light);
}

.electric,
.move-select.electric {
  background: var(--type-electric);
  color: var(--text-dark);
}

.fairy,
.move-select.fairy {
  background: var(--type-fairy);
  color: var(--text-dark);
}

.fighting,
.move-select.fighting {
  background: var(--type-fighting);
  color: var(--text-light);
}

.fire,
.move-select.fire {
  background: var(--type-fire);
  color: var(--text-dark);
}

.flying,
.move-select.flying {
  background: var(--type-flying);
  color: var(--text-dark);
}

.ghost,
.move-select.ghost {
  background: var(--type-ghost);
  color: var(--text-light);
}

.grass,
.move-select.grass {
  background: var(--type-grass);
  color: var(--text-dark);
}

.ground,
.move-select.ground {
  background: var(--type-ground);
  color: var(--text-dark);
}

.ice,
.move-select.ice {
  background: var(--type-ice);
  color: var(--text-dark);
}

.normal,
.move-select.normal {
  background: var(--type-normal);
  color: var(--text-dark);
}

.poison,
.move-select.poison {
  background: var(--type-poison);
  color: var(--text-light);
}

.psychic,
.move-select.psychic {
  background: var(--type-psychic);
  color: var(--text-light);
}

.rock,
.move-select.rock {
  background: var(--type-rock);
  color: var(--text-dark);
}

.steel,
.move-select.steel {
  background: var(--type-steel);
  color: var(--text-dark);
}

.water,
.move-select.water {
  background: var(--type-water);
  color: var(--text-dark);
}

.theme-switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
}

.theme-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 5px;
  flex-shrink: 0;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: 0.3s;
  border-radius: 999px;
}

.slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.theme-switch input:checked+.slider {
  background-color: #334155;
}

.theme-switch input:checked+.slider::before {
  transform: translateX(24px);
}

/* TEAM DEFENCE / ATTACK */
.team-defence-panel,
.team-attack-panel {
  align-self: start;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.team-defence-panel h2,
.team-attack-panel h2 {
  text-align: center;
  margin-bottom: 12px;
}

#team-defence-grid,
#team-attack-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 10px;
}

.defence-type,
.attack-type {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.defence-label,
.attack-label {
  width: 100%;
  text-align: center;
  padding: 4px;
  border-radius: 6px;
  font-size: 1.2rem;
  font-weight: 700;
}

.defence-value,
.attack-value {
  margin-top: 2px;
  font-size: 1rem;
  font-weight: 700;
}

.defence-positive,
.attack-label {
  color: var(--positive);
}

.defence-negative,
.attack-negative {
  color: var(--negative);
}

.defence-neutral,
.attack-neutral {
  color: var(--text);
}

.team-layout {
  display: flex;
  width: 100%;
  gap: 20px;
  align-items: stretch;
  justify-content: space-between;
}

.pokemon-stats-display {
  background-color: var(--card);
  border: 1px solid var(--border);
  padding: 14px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  justify-content: center;
  text-align: center;
}

/* TOOLTIP */
#type-tooltip {
  position: fixed;
  background-color: var(--card);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: none;
  pointer-events: none;
  z-index: 1000;
  max-width: 350px;
  font-size: 1.2rem;
  color: var(--text);
  transform: translateX(-50%);
}

.tooltip-pokemon-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  grid-auto-flow: row;
  gap: 12px;
}

.tooltip-pokemon-item {
  text-align: center;
  font-size: 1.2rem;
}

.tooltip-pokemon-item small {
  display: block;
}

.tooltip-pokemon-sprite {
  width: 80px;
  height: 80px;
  image-rendering: pixelated;
}

.tooltip-empty {
  margin-top: 6px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.page-footer {
  display: flex;
  justify-content: space-between;

  align-items: center;

  width: 100%;
  padding: 12px 24px;

  border-top: 1px solid rgba(255, 255, 255, 0.1);

  font-size: 0.9rem;
  color: #aaa;
}

.footer-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  justify-content: center;
}

.page-footer a {
  color: inherit;
  text-decoration: none;
}

.page-footer a:hover {
  color: white;
}


.mobile-team-nav {
  display: none;
}

@media (max-width: 750px) {


  .mobile-team-nav {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
  }

  .team-slot-btn {
    position: relative;
    max-width: 54px;
    height: 54px;
    border-radius: 12px;
    border: 1px solid #35528d;
    background: var(--card);
    color: var(--text);
    font-size: 18px;
    overflow: hidden;
    cursor: pointer;
    transition: 0.2s;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .team-slot-btn.active {
    border: 2px solid #5d5cff;
    box-shadow: 0 0 8px #5d5cff;
  }

  .team-slot-btn img,
  .slot-img {
    object-fit: contain;
    image-rendering: pixelated;
    padding-bottom: 5px;
  }

  .slot-img {
    display: none;
  }

  .team-slot-btn.has-pokemon .slot-img {
    display: block;
  }

  .team-slot-btn.has-pokemon span {
    display: none;
  }


  .pokemon-card-form {
    display: none;
  }


  .pokemon-card-form.active {
    display: block;
  }


  .pokemon-card {
    width: 100%;
    max-width: none;
  }

  .table-container,
  .defense-table,
  .attack-table {
    width: 100%;
  }
}

@media (max-width: 1080px) {
  .team-layout {
    flex-direction: column;
  }

  .team-defence-panel,
  .team-attack-panel {
    width: 100%;
    position: static;
  }

  .pokemon-team-display {
    grid-template-columns: repeat(2, 1fr);
    margin: 14px auto;
    max-width: 800px;
    width: 100%;
  }

  .pokemon-stats-display {
    width: 100%;
    max-width: 800px;
    margin: 14px auto 0 auto;
  }

  .stats-table-wrapper {
    margin: 0 auto;
    gap: 20px;
  }

  .input-container {
    max-width: 740px;
    margin: 0 auto;
  }

  #app {
    zoom: 100%;
  }
}

@media (max-width: 750px) {
  .pokemon-team-display {
    width: 100%;
    max-width: 440px;
    grid-template-columns: 1fr;
    margin: 0 auto;
    padding: 0;
    justify-content: center;
  }

  .pokemon-stats-display {
    max-width: 440px;
    margin: 0 auto;
  }

  .input-container {
    margin: 0 auto 14px auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    max-width: 450px;
    justify-items: center;
    align-items: center;
    grid-template-areas:
      "type   clear  region"
      "export import random"
      ".      manual .";
  }

  .input-container .button,
  .input-container select {
    font-size: 0.9rem !important;
    width: 100%;
    max-width: 140px;
  }

  #gen-selector {
    grid-area: region;
  }

  #open-manual {
    grid-area: manual;
  }

  .header {
    font-size: 1.5rem;
  }

  .button {
    min-height: 30px;
    padding: 5px;
  }

  .page-footer {
    flex-direction: column;
    gap: 1rem;

    text-align: center;
  }

  #manual-modal,
  #manual-modal .modal-content {
    max-height: 90vh;
    overflow-y: auto;
  }
}