/* css/style.css — Fase 2 (PokéDle).
   Identità visiva: console/Pokédex — guscio rosso, schermo LCD verde-oliva con
   scanline. La griglia+tastiera della vecchia Wordle sono sparite: al centro
   c'è una barra di ricerca stile terminale e una tabella di confronto attributi.
   Solo font di sistema (nessuna dipendenza runtime esterna oltre PokéAPI,
   usata solo in fase di build). */

:root {
  /* Palette */
  --paper: #eef1e3;
  --paper-dot: #dfe4cf;
  --ink: #202a1a;
  --shell: #d8342a;
  --shell-dark: #9c2019;
  --shell-highlight: #f0584c;
  --screen-bg: #c8d9a4;
  --screen-ink: #33421f;
  --screen-dim: #a9bd82;
  --screen-border: #5c6b52;
  --gold: #f2b632; /* accento UI: focus, suggerimento attivo, badge vittoria */

  /* Stato di confronto (compareGuess): verde / giallo (tipo nell'altra colonna) / grigio */
  --fb-correct: #4c9a3c;
  --fb-correct-ink: #eef7e6;
  --fb-present: #e0a92e;
  --fb-present-ink: #33260a;
  --fb-absent: #8a9a7c;
  --fb-absent-ink: #263118;

  /* Tipografia: niente webfont, solo stack di sistema */
  --font-mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --radius-shell: 26px;
  --radius-screen: 12px;
  --radius-key: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--paper);
  background-image: radial-gradient(var(--paper-dot) 1.5px, transparent 1.5px);
  background-size: 22px 22px;
}

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

.page {
  min-height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(12px, 3vw, 40px);
}

/* -------------------------------------------------------------------------
   Guscio della console
   ------------------------------------------------------------------------- */

.console {
  width: 100%;
  max-width: 640px;
  background: linear-gradient(180deg, var(--shell-highlight) 0%, var(--shell) 12%, var(--shell) 88%, var(--shell-dark) 100%);
  border-radius: var(--radius-shell);
  padding: clamp(14px, 3vw, 22px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 18px 40px -14px rgba(32, 42, 26, 0.45);
  position: relative;
}

.console::before,
.console::after {
  content: "";
  position: absolute;
  top: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffffaa, var(--shell-dark) 70%);
}
.console::before {
  left: 12px;
}
.console::after {
  right: 12px;
}

.console__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 6px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--screen-dim);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.15) inset;
}
.led[data-on="true"] {
  background: #79e06a;
  box-shadow: 0 0 6px 1px #79e06a, 0 0 0 2px rgba(0, 0, 0, 0.15) inset;
}

.brand__title {
  margin: 0;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(15px, 4vw, 19px);
  letter-spacing: 0.06em;
  color: #fdece9;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.field {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--shell-dark);
  padding: 5px 9px;
  border-radius: var(--radius-key);
}

.field__label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: #fdece9;
  letter-spacing: 0.03em;
}

.select {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--screen-ink);
  background: var(--screen-bg);
  border: none;
  border-radius: 5px;
  padding: 3px 6px;
  cursor: pointer;
}
.select:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.btn {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.03em;
  border: none;
  border-radius: var(--radius-key);
  padding: 8px 12px;
  cursor: pointer;
  color: #fdece9;
  background: var(--shell-dark);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.btn:hover {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
.btn:active {
  transform: translateY(2px);
  box-shadow: none;
}
.btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.btn--new {
  background: var(--gold);
  color: #3a2a06;
}

/* -------------------------------------------------------------------------
   Schermo LCD
   ------------------------------------------------------------------------- */

.screen {
  position: relative;
  background: var(--screen-bg);
  border: 3px solid var(--screen-border);
  border-radius: var(--radius-screen);
  padding: 14px 12px;
  overflow: hidden;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25) inset;
}

.scanlines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    180deg,
    rgba(51, 66, 31, 0.06) 0px,
    rgba(51, 66, 31, 0.06) 1px,
    transparent 1px,
    transparent 3px
  );
}

/* -------------------------------------------------------------------------
   Barra di ricerca + suggerimenti
   ------------------------------------------------------------------------- */

.search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ink);
  border: 2px solid var(--screen-border);
  border-radius: var(--radius-key);
  padding: 6px 8px;
}

.search__prompt {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  color: var(--gold);
  line-height: 1;
}

.search__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 14px;
  color: #f4f6ec;
  padding: 6px 2px;
}
.search__input::placeholder {
  color: #f4f6ec99;
}
.search__input:focus {
  outline: none;
}
.search:focus-within {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.search__submit {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: var(--gold);
  color: #3a2a06;
  font-weight: 700;
  cursor: pointer;
}
.search__submit:focus-visible {
  outline: 2px solid var(--screen-ink);
  outline-offset: 2px;
}
.search__submit:disabled,
.search__input:disabled {
  opacity: 0.5;
  cursor: default;
}

.suggestions {
  position: relative;
  z-index: 5;
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  background: var(--ink);
  border: 2px solid var(--screen-border);
  border-radius: var(--radius-key);
  max-height: 220px;
  overflow-y: auto;
}

.suggestions__item {
  font-family: var(--font-mono);
  font-size: 13px;
  color: #f4f6ec;
  padding: 7px 8px;
  border-radius: 5px;
  cursor: pointer;
}
.suggestions__item:hover,
.suggestions__item[aria-selected="true"] {
  background: var(--gold);
  color: #3a2a06;
}

/* -------------------------------------------------------------------------
   Stato / contatore tentativi
   ------------------------------------------------------------------------- */

.status {
  min-height: 1.4em;
  margin: 10px 0 0;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--screen-ink);
}
.status[data-tone="error"] {
  color: var(--shell-dark);
  font-weight: 700;
}

/* Indizio (Tipo 1 del target) mostrato dopo il 4° tentativo sbagliato. */
.hint {
  margin: 8px 2px 0;
  padding: 6px 10px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--screen-ink);
  background: rgba(224, 169, 46, 0.22);
  border: 1px dashed var(--fb-present);
  border-radius: 6px;
}
.hint .type-dot {
  margin: 0 6px 0 2px;
}

.results {
  display: flex;
  justify-content: flex-end;
  margin: 10px 0 6px;
}

.readout {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--screen-bg);
  background: var(--screen-ink);
  padding: 3px 9px;
  border-radius: 999px;
}

/* -------------------------------------------------------------------------
   Tabella dei tentativi
   ------------------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 2px solid var(--screen-border);
  border-radius: 8px;
}
.table-wrap:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.attempts {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.attempts thead th {
  position: sticky;
  top: 0;
  background: var(--screen-ink);
  color: var(--screen-bg);
  text-align: left;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 8px 10px;
  white-space: nowrap;
}

.attempts tbody td {
  padding: 7px 10px;
  border-top: 1px solid var(--screen-border);
  white-space: nowrap;
  color: var(--ink);
}

.attempts tbody th[scope="row"],
.attempts tbody td:first-child {
  position: sticky;
  left: 0;
  background: var(--screen-bg);
  z-index: 1;
}

.attempts .row-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.row-sprite {
  width: 26px;
  height: 26px;
  object-fit: contain;
  flex-shrink: 0;
}

.type-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  border: 1px solid rgba(0, 0, 0, 0.25);
  vertical-align: middle;
}

.attempts td[data-state="green"] {
  background: var(--fb-correct);
  color: var(--fb-correct-ink);
}
.attempts td[data-state="yellow"] {
  background: var(--fb-present);
  color: var(--fb-present-ink);
}
.attempts td[data-state="gray"] {
  background: var(--fb-absent);
  color: var(--fb-absent-ink);
}

.arrow {
  margin-left: 5px;
  font-weight: 700;
}

.attempts tbody tr {
  animation: row-in 220ms ease;
}
@keyframes row-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.empty-hint {
  margin: 10px 2px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--screen-ink);
  opacity: 0.8;
  text-align: center;
}

/* -------------------------------------------------------------------------
   Pannello di fine partita
   ------------------------------------------------------------------------- */

.reveal {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 2px dashed var(--screen-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}

.reveal__sprite {
  width: 96px;
  height: 96px;
  filter: drop-shadow(0 4px 3px rgba(51, 66, 31, 0.35));
}

.reveal__result {
  margin: 2px 0 0;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.03em;
  color: var(--screen-ink);
}

.reveal__name {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
}

/* -------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------- */

@media (max-width: 420px) {
  .console__header {
    justify-content: center;
    text-align: center;
  }
  .results {
    justify-content: center;
  }
}

/* -------------------------------------------------------------------------
   Accessibilità: rispetta prefers-reduced-motion
   ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .attempts tbody tr,
  .btn {
    animation: none !important;
    transition: none !important;
  }
}
