@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&family=Fira+Code:wght@400;500&display=swap');

:root {
  --bg: #14151a;
  --surface: #1c1e26;
  --surface-raised: #24262f;
  --line: #33353f;
  --text: #edeef2;
  --muted: #8b8f9c;
  --accent: #f4c945;
  --accent-dim: #7a6320;
  --danger: #e6584f;

  --type-normal:#a4a290;   --type-fire:#ee8130;    --type-water:#6390f0;
  --type-electric:#f7d02c; --type-grass:#7ac74c;   --type-ice:#96d9d6;
  --type-fighting:#c22e28; --type-poison:#a33ea1;  --type-ground:#e2bf65;
  --type-flying:#a98ff3;   --type-psychic:#f95587; --type-bug:#a6b91a;
  --type-rock:#b6a136;     --type-ghost:#735797;   --type-dragon:#6f35fc;
  --type-dark:#705746;     --type-steel:#b7b7ce;   --type-fairy:#d685ad;

  --font-display: 'Poppins', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'Fira Code', monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
}

a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--line);
}

.brand { font-family: var(--font-display); font-weight: 700; font-size: 1.4rem; letter-spacing: 0.02em; }
.brand-mark { color: var(--accent); margin-right: 0.35rem; }

.reg-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
}

main { max-width: 880px; margin: 0 auto; padding: 2.5rem 1.5rem 4rem; }

.hero h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.1rem, 5vw, 3.1rem);
  line-height: 1.08;
  margin: 0 0 0.9rem;
}

.hero-sub { color: var(--muted); max-width: 46ch; margin: 0 0 2.5rem; }

.search-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

.search-widget {
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
  padding: 0.6rem;
}
.search-widget.hidden { display: none; }

.search-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* La X di annullamento sta sempre in fondo a destra della casella di
   ricerca, mai dentro la riga input/Aggiungi: così resta nello stesso punto
   qualunque cosa venga mostrata sopra (feedback, conferma nome). */
.search-widget-footer { display: flex; justify-content: flex-end; margin-top: 0.5rem; }

#search-input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
}
#search-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

#search-btn, #search-cancel-btn {
  border-radius: 6px;
  padding: 0 0.6rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
#search-btn {
  background: var(--accent);
  color: #1a1500;
  border: none;
}
#search-btn:hover { background: #ffd85c; }
#search-btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
#search-cancel-btn {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--line);
}
#search-cancel-btn:hover { color: var(--danger); border-color: var(--danger); }

.search-feedback { min-height: 1.2em; font-size: 0.85rem; margin: 0.6rem 0 0; color: var(--muted); }
.search-feedback.error { color: var(--danger); }

.confirm-box {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-top: 0.8rem;
  padding: 0.7rem 1rem;
  background: var(--surface-raised);
  border: 1px solid var(--accent-dim);
  border-radius: 10px;
}
.confirm-box.hidden { display: none; }
.confirm-box img { width: 48px; height: 48px; image-rendering: pixelated; }
.confirm-text { flex: 1; }
.confirm-text span { font-family: var(--font-display); font-weight: 600; font-size: 1rem; text-transform: capitalize; }
.confirm-text p { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--muted); }
.confirm-actions { display: flex; gap: 0.5rem; }
.confirm-actions button {
  font-family: var(--font-display);
  font-size: 0.85rem;
  border-radius: 6px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
#confirm-yes { background: var(--accent); color: #1a1500; border: none; font-weight: 600; }
#confirm-yes:hover { background: #ffd85c; }
#confirm-no:hover { border-color: var(--danger); color: var(--danger); }

/* Box del prompt per AI esterna: stessa "carta" del confirm-box, ma in
   colonna (sprite+testo+azioni in riga non serve qui) per fare spazio alla
   textarea a piena larghezza. */
.external-prompt-box { flex-direction: column; align-items: stretch; }
.external-prompt-text { width: 100%; }
#external-prompt-textarea {
  width: 100%;
  margin-top: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.4;
  resize: vertical;
}
.external-prompt-box .confirm-actions { justify-content: flex-end; }

.team-tabs { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1.2rem; }
.team-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}
.team-tab.active { border-color: var(--accent); color: var(--text); }
.team-tab-remove { color: var(--muted); font-size: 0.75rem; line-height: 1; }
.team-tab-remove:hover { color: var(--danger); }
.team-tab-add {
  background: var(--surface-raised);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
}
.team-tab-add:disabled { opacity: 0.4; cursor: not-allowed; }

.screenshot-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.3rem;
  margin-bottom: 1.5rem;
}
.screenshot-help { margin-bottom: 0.8rem; font-size: 0.82rem; }
.screenshot-help summary {
  cursor: pointer;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  text-decoration: underline;
  text-underline-offset: 2px;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  list-style: none; /* niente triangolo di default del browser: usiamo la nostra freccina qui sotto */
}
.screenshot-help summary::-webkit-details-marker { display: none; }
/* Freccina che ruota all'apertura: rende evidente che la scritta è cliccabile
   (non solo un titolo) e comunica lo stato aperto/chiuso senza altro testo. */
.screenshot-help summary::after {
  content: '▸';
  font-size: 0.7em;
  transition: transform 0.15s ease;
}
.screenshot-help[open] summary::after { transform: rotate(90deg); }
.screenshot-help summary:hover { color: #ffd85c; }
.screenshot-help[open] summary { color: var(--text); margin-bottom: 0.5rem; }
.screenshot-help-case { margin: 0.7rem 0 0.3rem; color: var(--text); font-weight: 600; }
.screenshot-help ol { margin: 0 0 0 1.1rem; padding: 0; color: var(--muted); }
.screenshot-help li { margin-bottom: 0.2rem; }

/* Carosello dei due casi ("mai condiviso" / "già condiviso"): CSS scroll-snap
   nativo, scroll orizzontale con swipe libero su mobile, niente libreria. */
.screenshot-carousel {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.screenshot-carousel::-webkit-scrollbar { display: none; }
.screenshot-slide {
  flex: 0 0 100%;
  min-width: 0;
  scroll-snap-align: start;
}
.screenshot-carousel-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  margin-top: 0.6rem;
}
.carousel-arrow {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.carousel-arrow:hover { border-color: var(--accent); color: var(--accent); }
.carousel-dots { display: flex; gap: 6px; }
.carousel-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line);
  cursor: pointer;
  transition: background-color 0.2s ease;
}
.carousel-dots span.active { background: var(--accent); }

.screenshot-inputs { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.screenshot-file {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  flex: 1;
  min-width: 180px;
}
.screenshot-file input {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.8rem;
}
#screenshot-build-btn {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 1.1rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}
#screenshot-build-btn:hover { border-color: var(--accent); color: var(--accent); }
#screenshot-build-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.roster-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1rem; }
.roster-header h2 { font-family: var(--font-display); font-size: 1.3rem; margin: 0; }
.roster-header-actions { display: flex; align-items: baseline; gap: 0.9rem; }
.roster-count { font-family: var(--font-mono); color: var(--muted); font-size: 0.9rem; }
#roster-count { color: var(--accent); }

.edit-team-btn {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.8rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
}
.edit-team-btn:hover { border-color: var(--accent); color: var(--accent); }
.edit-team-btn.active { border-color: var(--accent); color: #1a1500; background: var(--accent); }

.slot-replace { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; width: 100%; max-width: 100%; }
.slot-replace input {
  flex: 1 1 100%;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
}
.slot-replace button {
  flex: 1 1 100%;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  color: var(--muted);
  font-family: var(--font-display);
  font-size: 0.75rem;
  cursor: pointer;
}
.slot-replace button:hover { border-color: var(--accent); color: var(--accent); }

.roster-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
@media (min-width: 768px) {
  .roster-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.slot {
  position: relative;
  z-index: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 0.9rem 0.9rem;
  min-height: 150px;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
/* :hover applica un transform, che crea un nuovo stacking context: senza
   z-index esplicito la card finisce comunque dietro le successive nel DOM
   quando il suo tooltip (popup) trabocca sopra di loro. */
.slot:hover,
.slot:has(.tap-tooltip) {
  z-index: 5;
}
.slot:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.45), 0 3px 6px rgba(0, 0, 0, 0.35);
}
.slot:active {
  transform: translateY(-1px);
}

.slot-index {
  position: absolute;
  top: 0.6rem;
  left: 0.7rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
}

.slot.empty {
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.85rem;
  border: 2px dashed rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.03);
  box-shadow: none;
}

.slot-add-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--accent);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.slot-add-btn:hover { border-color: var(--accent); }

.slot-remove {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem;
}
.slot-remove:hover { color: var(--danger); }

.slot-body { margin-top: 1.1rem; display: flex; gap: 0.7rem; align-items: center; max-width: 100%; }
.slot-body img { flex: none; width: 56px; height: 56px; max-width: 100%; object-fit: contain; image-rendering: pixelated; }
.slot-info { min-width: 0; }
.slot-name { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; text-transform: capitalize; overflow-wrap: break-word; }

.type-row { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-top: 0.3rem; }
.type-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  padding: 2px 10px;
  border-radius: 20px;
  color: #14151a;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, auto);
  grid-auto-flow: column;
  gap: 2px 8px;
  width: 100%;
  overflow: hidden;
  margin-top: 0.8rem;
  font-family: var(--font-mono);
  color: var(--muted);
}
.stat-row span {
  /* Colonne fisse (non flex/space-between): la larghezza dell'etichetta
     variava con la sua lunghezza (HP vs SpA), spostando il valore di una
     quantità diversa riga per riga e disallineando i numeri tra le card. */
  display: grid;
  grid-template-columns: 2.2rem 1fr;
  white-space: nowrap;
  font-size: 0.8rem;
}
.stat-row strong { color: var(--text); text-align: right; }

.page-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 2rem 1rem 2.5rem;
}

/* --- Fase 2: card roster estesa --- */

.item-line {
  margin-top: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: capitalize;
  text-align: left;
  align-self: flex-start;
}

.moves-row { display: flex; flex-direction: column; gap: 0.25rem; margin-top: 0.5rem; }
.move-chip {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text);
  background: var(--surface-raised);
  border: none;
  border-left: 3px solid var(--muted);
  border-radius: 4px;
  padding: 0.2rem 0.45rem;
  text-transform: capitalize;
  text-align: left;
  cursor: pointer;
  width: 100%;
}
.move-chip:hover { outline: 1px solid var(--accent); }
.move-chip.empty-move { color: var(--muted); font-style: italic; }

.stats-btn {
  margin-top: 0.8rem;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}
.stats-btn:hover { border-color: var(--accent); color: var(--accent); }

.mega-toggle {
  position: absolute;
  top: 0.55rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.mega-icon { font-size: 0.75rem; color: #a259ff; line-height: 1; }
.mega-switch {
  position: relative;
  width: 28px;
  height: 15px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-raised);
  cursor: pointer;
}
.mega-switch::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.mega-switch.on { border-color: #a259ff; background: rgba(162, 89, 255, 0.25); }
.mega-switch.on::after { transform: translateX(13px); background: #a259ff; }

/* --- Tooltip hover, solo desktop (punto 3): CSS puro via [data-tooltip],
   :hover non scatta in modo affidabile su touch quindi non serve rilevare
   il device. --- */
/* Senza questo, tenere premuto su un elemento con tooltip fa scattare la
   selezione testo/menu contestuale nativo del telefono, che interrompe il
   touch e chiude il tooltip prima del previsto. */
[data-tooltip], .move-chip {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after,
[data-tooltip].tap-tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 30;
  width: max-content;
  max-width: 260px;
  white-space: pre-line;
  background: var(--surface-raised);
  border: 1px solid var(--accent-dim);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
@media (hover: none) {
  [data-tooltip]:hover::after { display: none; }
}

/* --- Modal statistiche --- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 12, 0.7);
  z-index: 20;
}
.modal-backdrop.hidden { display: none; }

.stats-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.6rem;
  z-index: 21;
}
.stats-modal.hidden { display: none; }

.modal-close {
  position: sticky;
  top: 0;
  float: right;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--danger); }

.stats-modal-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.2rem; }
.stats-modal-header img { width: 64px; height: 64px; image-rendering: pixelated; }
.stats-modal-header h3 { font-family: var(--font-display); font-size: 1.3rem; margin: 0 0 0.3rem; text-transform: capitalize; }

.stats-modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.4rem; }
@media (max-width: 560px) { .stats-modal-grid { grid-template-columns: 1fr; } }

.stats-modal-section h4 {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1rem 0 0.5rem;
}
.stats-modal-section h4:first-child { margin-top: 0; }

.moves-edit-grid { display: flex; flex-direction: column; gap: 0.5rem; }
.stats-modal-section input[type="text"],
.stats-modal-section select {
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
}

.sp-iv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.sp-iv-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--muted);
}
.sp-iv-grid input {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 0.4rem;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  width: 100%;
}

.sp-total { font-family: var(--font-mono); color: var(--muted); }
.sp-total.error { color: var(--danger); }

.final-stats-table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 0.8rem; }
.final-stats-table th, .final-stats-table td { padding: 0.4rem 0.5rem; text-align: center; border-top: 1px solid var(--line); }
.final-stats-table th:first-child, .final-stats-table td:first-child { text-align: left; color: var(--muted); font-weight: 500; }
.final-stats-table .final-row td { color: var(--accent); font-weight: 600; }

/* --- Analisi matchup --- */

.matchup { margin-top: 2.5rem; }
.matchup-intro { margin-bottom: 1.4rem; }

.matchup-defense { margin-bottom: 1.8rem; }

/* Tabella tipi attaccanti (righe) x Pokémon del roster (colonne). Riga e
   colonna d'intestazione restano fisse (sticky) durante lo scroll dentro
   .matchup-table-wrap, che è l'unico contenitore scrollabile. */
.matchup-table-wrap {
  overflow: auto;
  max-height: 70vh;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.matchup-table { width: 100%; border-collapse: collapse; }
.matchup-table th, .matchup-table td {
  padding: 0.45rem 0.6rem;
  text-align: center;
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: nowrap;
}
.matchup-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  border-top: none;
  background: var(--surface-raised);
}

.matchup-mon-col { min-width: 74px; }
.matchup-mon-col img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto 0.25rem;
}
.matchup-mon-col span {
  display: block;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: capitalize;
}

.matchup-type-col {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #14151a;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* Angolo in alto a sinistra: sticky su entrambi gli assi, sopra riga e
   colonna fisse (z-index più alto di entrambe). Selettore composto per
   battere in specificità ".matchup-table thead th". */
.matchup-table thead th.matchup-corner {
  left: 0;
  z-index: 3;
}

.matchup-table td.eff-weak { color: var(--danger); font-weight: 700; background: rgba(230, 88, 79, 0.12); }
.matchup-table td.eff-resist { color: #7ac74c; font-weight: 700; background: rgba(122, 199, 76, 0.1); }
.matchup-table td.eff-immune { color: var(--muted); background: rgba(255, 255, 255, 0.05); }
.matchup-table td.eff-neutral { color: var(--muted); }

.matchup-table-legend { margin: 0.5rem 0 0; font-family: var(--font-mono); font-size: 0.72rem; }

.matchup-group { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; font-size: 0.85rem; }
.matchup-group-label { font-family: var(--font-mono); font-size: 0.7rem; color: var(--muted); min-width: 5.5rem; }
.matchup-group-weak .matchup-group-label { color: var(--danger); }
.matchup-group-resist .matchup-group-label { color: #7ac74c; }
.matchup-group-immune .matchup-group-label { color: var(--muted); }
.muted-note { color: var(--muted); font-size: 0.8rem; }

.matchup-coverage { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.2rem 1.4rem; margin-bottom: 1.5rem; }
.matchup-coverage h3, .damage-calc h3 { font-family: var(--font-display); font-size: 1.05rem; margin: 0 0 0.8rem; }
.matchup-group-list { margin-top: 0.6rem; }
.matchup-note { color: var(--muted); font-size: 0.8rem; margin: 0 0 0.8rem; }

.damage-calc { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.2rem 1.4rem; }

/* Riga di input: ogni campo ha una micro-label sopra, in stile con .sp-iv-grid label */
.damage-calc-row { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: flex-end; }
.dmg-field { display: flex; flex-direction: column; gap: 0.3rem; }
.dmg-field-grow { flex: 1; min-width: 160px; }
.dmg-field-label {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.damage-calc-row select, .damage-calc-row input {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.85rem;
}
.damage-calc-row input { width: 100%; min-width: 160px; }
.damage-calc-vs { font-family: var(--font-mono); color: var(--muted); font-size: 0.8rem; padding-bottom: 0.55rem; }
#dmg-calc-btn {
  background: var(--accent);
  color: #1a1500;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.1rem;
  font-family: var(--font-display);
  font-weight: 600;
  cursor: pointer;
}
#dmg-calc-btn:hover { background: #ffd85c; }

#dmg-calc-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Toggle segmentato: sostituisce i radio nudi con due "tab" ben distinte */
.dmg-defender-mode {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: 0.3rem;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.dmg-defender-mode label {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.5rem 0.7rem;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
}
.dmg-defender-mode input[type="radio"] { accent-color: var(--accent); margin: 0; }
.dmg-defender-mode label span { display: flex; align-items: baseline; gap: 0.4rem; flex-wrap: wrap; }
.dmg-defender-mode label small { font-family: var(--font-mono); font-size: 0.68rem; color: inherit; opacity: 0.75; }
.dmg-defender-mode label:has(input:checked) {
  background: var(--surface);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--accent-dim);
}
.dmg-defender-mode label:has(input:checked) span { color: var(--accent); font-weight: 600; }

.dmg-defender-custom { margin-top: 0.8rem; padding: 0.9rem 1rem; border: 1px solid var(--line); border-radius: 10px; }
.dmg-defender-custom.hidden { display: none; }
.dmg-defender-custom select { max-width: 260px; }

/* Box risultato: readout enfatizzato invece di una riga di testo piatta */
.dmg-result {
  min-height: 0;
  margin: 1rem 0 0;
  padding: 0.8rem 1rem;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent-dim);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
  transition: border-color 0.15s ease;
}
.dmg-result:empty { display: none; }
.dmg-result.error { border-left: 3px solid var(--danger); color: var(--danger); }

/* Overlay Solana: stili in scout.css */
