:root {
  --bg: #0c0b09;
  --panel: rgba(28, 24, 21, 0.88);
  --panel-alt: rgba(20, 17, 14, 0.9);
  --border: #3d362c;
  --text: #ece5d8;
  --muted: #948b7c;
  --accent: #d98e34;
  --accent-hover: #eaa250;
  --on-accent: #1a1310;
  --danger: #9c3b30;
  --danger-hover: #b8453a;
  --positive: #5c7a4a;
}
/* Tema per gioco: sovrascrive gli accenti globali. Applicata a <body> (pagine intere)
   o a un singolo .game-tile nella home, dove ogni riquadro ha il colore del proprio gioco. */
.theme-acc {
  --accent: #e4020f;
  --accent-hover: #ff3b3f;
  --on-accent: #fff3f1;
  --danger: #7a1015;
  --danger-hover: #9c1c22;
}
.theme-ac {
  --accent: #2b9fe6;
  --accent-hover: #5bb8f0;
  --on-accent: #04121c;
}
* { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  margin: 0;
  padding: 2rem 1rem 4rem;
  line-height: 1.5;
  min-height: 100vh;
  background-size: cover;
  background-position: center;
}
body.with-bg {
  background-image: linear-gradient(rgba(10,9,8,0.82), rgba(10,9,8,0.93)), var(--bg-image);
  background-size: cover;
  background-position: center top;
  background-attachment: fixed;
}
/* "fixed" è costoso sui dispositivi touch (e iOS lo ignora) */
@media (hover: none), (max-width: 768px) {
  body.with-bg { background-attachment: scroll; }
}
.wrap { max-width: 720px; margin: 0 auto; }
h1 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 2.4rem;
  letter-spacing: 0.04em;
  margin: 0 0 0.25rem;
  border-bottom: 3px solid var(--accent);
  padding-bottom: 0.5rem;
}
h2 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.35rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  margin: 2rem 0 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}
h3 {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 1.05rem;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 1.25rem 0 0.5rem;
}
a {
  color: var(--accent);
  text-decoration: none;
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 0.04em;
  font-size: 1.05rem;
}
a:hover { text-decoration: underline; }
.nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.status {
  display: inline-block;
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.6rem;
  border: 1px solid currentColor;
}
.status.on { color: var(--positive); }
.status.off { color: var(--muted); }
.players-info { color: var(--muted); font-size: 0.95rem; margin: 0.5rem 0 0; }
.players-info strong { color: var(--text); }
.flash {
  background: var(--panel-alt);
  border-left: 3px solid var(--accent);
  padding: 0.6rem 1rem;
  margin: 1rem 0 1.25rem;
  font-size: 0.95rem;
  white-space: pre-line;
}
.flash.error { border-left-color: var(--danger); }
.error-text { color: #d9695c; }
.badge {
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0 0.4rem;
  margin-left: 0.5rem;
}
.save-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--border);
  gap: 1rem;
}
.save-row:last-child { border-bottom: none; }
label { font-weight: 600; color: var(--text); font-size: 0.92rem; }
input[type=text], input[type=password], input[type=number], select {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  padding: 0.5rem 0.6rem;
  font-size: 0.95rem;
}
input[type=text]:focus, input[type=password]:focus, input[type=number]:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 1rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.field-row select { grid-column: 2 / span 2; }
.field-row input[type=number] { width: 6rem; text-align: right; }
@media (max-width: 560px) {
  .field-row { grid-template-columns: 1fr auto; gap: 0.5rem 1rem; }
  .field-row > label:first-child, .field-row select { grid-column: 1 / -1; }
}
input[type=range] { width: 100%; accent-color: var(--accent); background: transparent; }
.toggle { position: relative; display: inline-block; width: 3rem; height: 1.6rem; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute; inset: 0;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: 0.15s;
}
.toggle .slider::before {
  content: "";
  position: absolute;
  height: 1.1rem; width: 1.1rem;
  left: 0.18rem; top: 0.18rem;
  background: var(--muted);
  transition: 0.15s;
}
.toggle input:checked + .slider { border-color: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(1.35rem); background: var(--accent); }
.toggle input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 0.06em;
  font-size: 1.05rem;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  padding: 0.65rem 1.4rem;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button.danger { background: var(--danger); color: var(--text); }
button.danger:hover { background: var(--danger-hover); }
button.link {
  background: none;
  color: var(--accent);
  padding: 0;
  letter-spacing: 0.04em;
}
button.link:hover { background: none; text-decoration: underline; }
form { margin: 0; }
.login-box { max-width: 340px; margin: 7rem auto 0; text-align: center; }
.login-box h1 { border: none; }
.login-box input { width: 100%; margin-bottom: 0.75rem; }
.login-box button { width: 100%; }
.game-grid { display: flex; flex-wrap: wrap; gap: 1rem; margin-top: 1.5rem; }
.game-tile {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 1.5rem;
  width: 220px;
  max-width: 100%;
  text-align: center;
}
.game-tile:hover { border-color: var(--accent); text-decoration: none; }
.game-tile img { max-width: 100%; height: auto; }

/* --- Intestazione del gioco con indirizzo di connessione --- */
.nav form { display: flex; align-items: center; gap: 0.6rem; }
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  border-bottom: 3px solid var(--accent);
  padding-bottom: 0.5rem;
  margin-bottom: 0.25rem;
}
.game-header h1 { border-bottom: none; padding-bottom: 0; margin: 0; }
.connect-info { text-align: right; font-size: 0.95rem; color: var(--muted); line-height: 1.4; }
.connect-info strong { color: var(--text); font-weight: 600; user-select: all; }
@media (max-width: 560px) {
  .connect-info { text-align: left; }
}

/* --- Salvataggi e pulsanti --- */
.panel-title { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 0.5rem 1rem; }
.panel-title h2, .panel-title h3 { margin-top: 0; }
.panel-title h2 { border-bottom: none; padding-bottom: 0; margin-bottom: 0.5rem; }
.save-main { display: flex; align-items: center; flex-wrap: wrap; gap: 0.6rem; min-width: 0; }
.save-main .badge { margin-left: 0; }
.save-name { overflow-wrap: anywhere; }
button.start { background: var(--positive); color: var(--text); }
button.start:hover { background: #6f9159; }
button.small, .save-row button { padding: 0.35rem 0.9rem; font-size: 0.95rem; }
button:disabled { opacity: 0.6; cursor: wait; }
.badge.on { color: var(--positive); border-color: var(--positive); }
.badge.admin { color: var(--accent); border-color: var(--accent); }
.muted { color: var(--muted); }

/* --- Impostazioni admin --- */
.admin-panel { border-color: #5a4a30; }
.wide-control {
  grid-column: 2 / span 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
}
.wide-control input { width: 16rem; max-width: 100%; }
.readonly-value { color: var(--muted); }
@media (max-width: 560px) {
  .field-row .wide-control { grid-column: 1 / -1; justify-content: flex-start; }
  .wide-control input { width: 100%; }
}

/* --- Selettore pista (come nel gioco: sagoma del tracciato, non un menu a tendina) --- */
.track-field { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.track-field > label { display: block; margin-bottom: 0.6rem; }
.track-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.6rem;
}
.track-card input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track-card-body {
  display: block;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  padding: 0.6rem 0.5rem 0.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.track-card-body img {
  display: block;
  width: 100%;
  height: 95px;
  object-fit: contain;
  filter: invert(1) brightness(1.05);
  margin-bottom: 0.4rem;
}
.track-card-body b {
  display: block;
  font-family: 'Bebas Neue', sans-serif;
  font-weight: normal;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  color: var(--text);
}
.track-card:hover .track-card-body { border-color: var(--accent); }
.track-card input:checked ~ .track-card-body {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
.track-card input:checked ~ .track-card-body b { color: var(--accent); }
.track-card input:focus-visible ~ .track-card-body { outline: 2px solid var(--accent); outline-offset: 2px; }
.track-credit { font-size: 0.8rem; color: var(--muted); margin: 0.75rem 0 0; }
.track-credit a { font-family: inherit; letter-spacing: normal; font-size: inherit; }

/* --- Scelta multipla da un elenco lungo (auto di Assetto Corsa) --- */
.field-hint { font-size: 0.85rem; color: var(--muted); margin: 0.25rem 0 0.5rem; }
.multi-field { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.multi-field > label { display: block; margin-bottom: 0.4rem; }
.multi-filter { width: 100%; margin-bottom: 0.6rem; }
.multi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.35rem 0.75rem;
  max-height: 22rem;
  overflow-y: auto;
  padding: 0.5rem;
  background: var(--panel-alt);
  border: 1px solid var(--border);
}
.multi-item { display: flex; align-items: flex-start; gap: 0.5rem; cursor: pointer; font-weight: 500; }
.multi-item[hidden] { display: none; }
.multi-item input { margin-top: 0.3rem; accent-color: var(--accent); }
.multi-item small { display: block; color: var(--muted); font-weight: 400; font-size: 0.75rem; }

/* --- Backup --- */
.backup-row { padding: 0.6rem 0; border-top: 1px dashed var(--border); }
.backup-row details { margin-top: 0.35rem; }
.backup-row summary {
  cursor: pointer;
  color: var(--accent);
  font-family: 'Bebas Neue', sans-serif;
  letter-spacing: 0.04em;
}
.restore-form { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; padding: 0.6rem 0 0.2rem 1rem; }
.radio { display: flex; align-items: center; gap: 0.4rem; font-weight: 500; }
