/**
 * Kart Reflex Semafori - stili pubblici
 */

.krs-game {
  --krs-red: #e10600;
  --krs-yellow: #ffd84d;
  --krs-letterbox: #cfcfcf;
  position: relative;
  max-width: 1280px;
  margin: 0 auto 1.5em;
  container-type: inline-size;
  outline: none;
  color: #1a1a1a;
  line-height: 1.3;
}

.krs-game *,
.krs-game *::before,
.krs-game *::after {
  box-sizing: border-box;
}

/* ------------------------------------------------------------------ */
/* Area di gioco                                                       */
/* ------------------------------------------------------------------ */

.krs-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 12px;
  background: var(--krs-letterbox);
  container-type: inline-size;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Fuori dallo schermo intero l'immagine non è cliccabile: si entra con il pulsante "Gioca" */
.krs-game:not(.is-fullscreen) .krs-frame {
  cursor: default;
}

/* Le immagini sono sovrapposte: il cambio luce è istantaneo (nessun caricamento) */
.krs-game .krs-light {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
}

.krs-game .krs-light.is-active {
  opacity: 1;
}

/* Fascia testi in basso, sotto le luci */
.krs-band {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 1.4cqw 3cqw 1.6cqw;
  text-align: center;
  color: #fff;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.75), rgba(0, 0, 0, 0.5) 70%, rgba(0, 0, 0, 0));
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.krs-game[data-state="loading"] .krs-band,
.krs-game[data-state="form"] .krs-band,
.krs-game[data-state="lights"] .krs-band,
.krs-game[data-state="green"] .krs-band {
  display: none;
}

.krs-main {
  font-size: max(16px, 4.2cqw);
  font-weight: 800;
  letter-spacing: 0.01em;
}

.krs-game[data-state="result"] .krs-main {
  font-size: max(22px, 6cqw);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.krs-game[data-state="falsestart"] .krs-main {
  color: var(--krs-yellow);
  text-transform: uppercase;
}

.krs-sub {
  font-size: max(13px, 2.2cqw);
  font-weight: 700;
}

.krs-game.is-record .krs-sub {
  color: var(--krs-yellow);
}

.krs-meta {
  font-size: max(12px, 1.8cqw);
  font-variant-numeric: tabular-nums;
}

.krs-hint {
  margin-top: 0.3em;
  font-size: max(11px, 1.5cqw);
  opacity: 0.85;
}

.krs-sub:empty,
.krs-meta:empty,
.krs-hint:empty {
  display: none;
}

/* Pulsante "Gioca" e link "Non sei tu?" (fuori dallo schermo intero) */
.krs-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6em 1.2em;
  margin-top: 0.5em;
}

.krs-game .krs-band .krs-play {
  pointer-events: auto;
  margin: 0;
  padding: 0.55em 2.2em;
  border: 0;
  border-radius: 999px;
  background: var(--krs-red) !important;
  color: #fff !important;
  font-size: max(15px, 2.2cqw);
  font-weight: 800;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-shadow: none;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  touch-action: manipulation;
}

.krs-game .krs-band .krs-play:hover {
  background: #b80500 !important;
}

.krs-game .krs-band .krs-play:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.krs-game .krs-link {
  all: unset;
  pointer-events: auto;
  cursor: pointer;
  font-size: max(12px, 1.6cqw);
  font-weight: 400;
  text-decoration: underline;
}

.krs-game .krs-link:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Pulsante chiusura schermo intero */
.krs-game .krs-close {
  display: none;
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 2;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font: 700 28px/44px sans-serif;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.krs-game .krs-close:hover,
.krs-game .krs-close:focus-visible {
  background: var(--krs-red);
}

/* ------------------------------------------------------------------ */
/* Schermo intero (nativo o, su iPhone, a tutta pagina via CSS)        */
/* ------------------------------------------------------------------ */

html.krs-noscroll,
html.krs-noscroll body {
  overflow: hidden !important;
}

.krs-game.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  margin: 0;
  background: var(--krs-letterbox);
}

.krs-game.is-fullscreen::backdrop {
  background: var(--krs-letterbox);
}

.krs-game.is-fullscreen .krs-frame {
  width: min(100vw, calc(100vh * 16 / 9));
  width: min(100vw, calc(100dvh * 16 / 9));
  border-radius: 0;
  touch-action: none;
}

.krs-game.is-fullscreen .krs-close {
  display: block;
}

/* Smartphone in verticale: i testi vanno nello spazio libero sotto l'immagine, più grandi */
@media (orientation: portrait) {
  .krs-game.is-fullscreen .krs-frame {
    overflow: visible;
  }

  .krs-game.is-fullscreen .krs-band {
    top: 100%;
    bottom: auto;
    padding: 6cqw 5cqw 0;
    background: none;
    color: #1a1a1a;
    text-shadow: none;
  }

  .krs-game.is-fullscreen .krs-main {
    font-size: 8cqw;
  }

  .krs-game.is-fullscreen[data-state="result"] .krs-main {
    font-size: 14cqw;
  }

  .krs-game.is-fullscreen[data-state="falsestart"] .krs-main,
  .krs-game.is-fullscreen.is-record .krs-sub {
    color: var(--krs-red);
  }

  .krs-game.is-fullscreen .krs-sub {
    font-size: 5cqw;
  }

  .krs-game.is-fullscreen .krs-meta {
    font-size: 4.2cqw;
  }

  .krs-game.is-fullscreen .krs-hint {
    margin-top: 1.2em;
    font-size: 3.6cqw;
  }
}

.krs-game.is-fullscreen .krs-form {
  display: none;
}

/* ------------------------------------------------------------------ */
/* Form di registrazione                                               */
/* ------------------------------------------------------------------ */

.krs-form {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
  padding: 18px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
}

.krs-game:not([data-state="form"]) .krs-form {
  display: none;
}

/*
 * Colori forzati: molti temi (soprattutto scuri) impostano testo bianco su label, p e input
 * con selettori più specifici, rendendo il form illeggibile sullo sfondo chiaro.
 */
.krs-game .krs-form,
.krs-game .krs-form .krs-form-title,
.krs-game .krs-form .krs-field,
.krs-game .krs-form .krs-field span {
  color: #1a1a1a !important;
}

.krs-game .krs-form .krs-form-note {
  color: #555 !important;
}

.krs-game .krs-form .krs-form-error {
  color: #c00500 !important;
}

.krs-game .krs-form .krs-field input {
  border: 1px solid #b5b5b5 !important;
  background: #fff !important;
  color: #1a1a1a !important;
  -webkit-text-fill-color: #1a1a1a;
  caret-color: #1a1a1a;
  box-shadow: none;
}

.krs-game .krs-form .krs-field input::placeholder {
  color: #777 !important;
  -webkit-text-fill-color: #777;
  opacity: 1;
}

/* Autocompilazione del browser (Chrome la colora di azzurro/giallo) */
.krs-game .krs-form .krs-field input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px #fff inset;
  -webkit-text-fill-color: #1a1a1a;
}

.krs-game .krs-form .krs-field input:focus,
.krs-game .krs-form .krs-field input[aria-invalid="true"] {
  border-color: var(--krs-red) !important;
}

.krs-game .krs-form .krs-button {
  background: var(--krs-red) !important;
  color: #fff !important;
}

.krs-game .krs-form .krs-button:hover {
  background: #b80500 !important;
}

/* Su schermi larghi il form sta sopra le luci grigie */
@container (min-width: 820px) {
  .krs-form {
    position: absolute;
    top: 57%;
    left: 50%;
    width: min(420px, 50%);
    margin: 0;
    transform: translate(-50%, -50%);
    background: #fff;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  }
}

.krs-form-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

.krs-field {
  display: grid;
  gap: 4px;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.krs-game .krs-field input {
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #b5b5b5;
  border-radius: 8px;
  background: #fff;
  color: #1a1a1a;
  font-size: 16px; /* evita lo zoom automatico su iPhone */
  line-height: 1.3;
}

.krs-game .krs-field input:focus {
  border-color: var(--krs-red);
  outline: 2px solid rgba(225, 6, 0, 0.25);
}

.krs-game .krs-field input[aria-invalid="true"] {
  border-color: var(--krs-red);
}

.krs-form-error {
  margin: 0;
  color: var(--krs-red);
  font-size: 14px;
  font-weight: 600;
}

.krs-form-error:empty {
  display: none;
}

.krs-game .krs-button {
  width: 100%;
  margin: 0;
  padding: 12px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--krs-red);
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
}

.krs-game .krs-button:hover {
  background: #b80500;
}

.krs-game .krs-button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.krs-form-note {
  margin: 0;
  font-size: 12px;
  color: #555;
  text-align: center;
}

/* ------------------------------------------------------------------ */
/* Classifica                                                          */
/* ------------------------------------------------------------------ */

.krs-leaderboard {
  margin: 0 0 1.5em;
}

.krs-leaderboard-title {
  margin: 0 0 0.6em;
}

.krs-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.krs-leaderboard .krs-tab {
  margin: 0;
  padding: 8px 14px;
  border: 1px solid rgba(127, 127, 127, 0.4);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.krs-leaderboard .krs-tab[aria-selected="true"] {
  border-color: #e10600;
  background: #e10600;
  color: #fff;
}

.krs-leaderboard-table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.krs-leaderboard-table th,
.krs-leaderboard-table td {
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid rgba(127, 127, 127, 0.25);
  text-align: left;
}

.krs-leaderboard-table th {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

.krs-leaderboard-table .krs-col-pos {
  width: 3em;
  text-align: center;
  font-weight: 700;
}

.krs-leaderboard-table .krs-col-time,
.krs-leaderboard-table .krs-col-attempts {
  text-align: right;
  white-space: nowrap;
}

.krs-leaderboard-table .krs-col-time {
  font-weight: 700;
}

.krs-leaderboard-table .krs-podium-1 .krs-col-pos {
  color: #c99a00;
}

.krs-leaderboard-table .krs-podium-2 .krs-col-pos {
  color: #8a8a8a;
}

.krs-leaderboard-table .krs-podium-3 .krs-col-pos {
  color: #a0643c;
}

.krs-leaderboard-table .krs-me td {
  background: rgba(225, 6, 0, 0.08);
  font-weight: 700;
}

.krs-leaderboard-table .krs-empty {
  padding: 18px 10px;
  text-align: center;
  opacity: 0.7;
}

@media (max-width: 420px) {
  .krs-leaderboard-table .krs-col-attempts {
    display: none;
  }
}

/* ------------------------------------------------------------------ */
/* Regole                                                              */
/* ------------------------------------------------------------------ */

.krs-rules {
  display: grid;
  gap: 1.2em;
  margin: 0 0 1.5em;
}

.krs-rules-title {
  margin: 0 0 0.4em;
}

.krs-rules-keys {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 0.6em;
}

.krs-key {
  display: inline-block;
  min-width: 3.5em;
  padding: 4px 10px;
  border: 1px solid rgba(127, 127, 127, 0.5);
  border-bottom-width: 3px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.krs-rules-list {
  margin: 0;
  padding-left: 1.3em;
}

.krs-rules-list li {
  margin-bottom: 0.3em;
}
