/* =========================================================================
   FANTA F1 — foglio di stile
   Estetica da pit-wall: fondo asfalto, tipografia tecnica, semaforo, mescole.
   ========================================================================= */

:root {
  --asphalt: #0a0b0d;
  --panel: #14161a;
  --panel-2: #1b1e24;
  --line: #2a2f38;
  --line-soft: #21252c;

  --text: #e8eaed;
  --text-dim: #9aa3af;
  --text-faint: #6b7280;

  --red: #e10600;
  --red-dark: #9c0400;
  --green: #00d26a;
  --yellow: #ffd21e;
  --blue: #3671c6;

  --soft: #f5333f;
  --medium: #ffd12e;
  --hard: #f0f0f0;
  --inter: #43b02a;
  --wet: #0067ad;

  --radius: 4px;
  --shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 50% -200px, #1a1d23 0%, transparent 70%),
    var(--asphalt);
  color: var(--text);
  font-family: 'Titillium Web', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

h1, h2, h3 {
  font-family: 'Titillium Web', system-ui, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 900;
  margin: 0 0 12px;
}
h1 { font-size: 26px; }
h2 { font-size: 17px; color: var(--text-dim); letter-spacing: 0.12em; }
h3 { font-size: 14px; letter-spacing: 0.1em; color: var(--text-dim); }

.mono {
  font-family: 'Chakra Petch', 'Consolas', monospace;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  height: 60px;
  background: linear-gradient(180deg, #16181d 0%, #101216 100%);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 6px; height: 26px;
  background: var(--red);
  box-shadow: 10px 0 0 -2px var(--red-dark);
  transform: skewX(-15deg);
}
.brand-name {
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.brand-name em { color: var(--red); font-style: normal; }

.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav-link {
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-radius: var(--radius);
  border: 1px solid transparent;
}
.nav-link:hover { color: var(--text); background: var(--panel-2); }
.nav-link.is-active {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line);
  box-shadow: inset 0 -2px 0 var(--red);
}

.user-chip { display: flex; align-items: center; gap: 12px; }
.user-name {
  font-size: 13px; font-weight: 600; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-dim);
}
.link-button {
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); font: inherit; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.08em; padding: 0;
}
.link-button:hover { color: var(--red); }

/* ------------------------------------------------------------------ page */

.page { max-width: 1180px; margin: 0 auto; padding: 26px 20px 60px; }

.flash {
  max-width: 1180px; margin: 16px auto -6px; padding: 11px 16px;
  border-radius: var(--radius); font-size: 14px; font-weight: 600;
  border-left: 4px solid;
}
.flash-ok { background: rgba(0, 210, 106, 0.1); border-color: var(--green); }
.flash-error { background: rgba(225, 6, 0, 0.12); border-color: var(--red); }

.footer {
  text-align: center; padding: 24px; color: var(--text-faint);
  font-size: 12px; letter-spacing: 0.05em; border-top: 1px solid var(--line-soft);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.panel-head h2, .panel-head h1 { margin: 0; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
/* Senza questo una colonna con contenuto largo (carosello, griglia piloti)
   allarga la propria traccia e schiaccia l'altra. */
.grid > * { min-width: 0; }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); font-size: 13px; }
.right { text-align: right; }
.center { text-align: center; }

/* ----------------------------------------------------------------- gauge */

.gauge { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.gauge-head { display: flex; justify-content: space-between; align-items: baseline; }
.gauge-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.16em; color: var(--text-faint); display: flex; align-items: center; }
.gauge-label .coin { width: 22px; height: 22px; vertical-align: 0; }
.gauge-value {
  font-family: 'Chakra Petch', monospace; font-size: 30px; font-weight: 700;
  font-variant-numeric: tabular-nums; line-height: 1;
}
.gauge-track { height: 6px; background: #0c0e11; border-radius: 3px; margin-top: 10px; overflow: hidden; }
.gauge-fill { height: 100%; background: linear-gradient(90deg, var(--green), #7ee787); transition: width .4s ease; }
.gauge.is-mid .gauge-fill { background: linear-gradient(90deg, var(--yellow), #ffe680); }
.gauge.is-low .gauge-fill { background: linear-gradient(90deg, var(--red), #ff6b63); }
.gauge.is-low .gauge-value { color: var(--red); }

/* ---------------------------------------------------------------- lights */

.lights { display: inline-flex; gap: 7px; }
.lights span {
  width: 17px; height: 17px; border-radius: 50%;
  background: #23262c; border: 1px solid #31353d;
}
.lights span.is-lit { background: var(--red); border-color: #ff5a52; box-shadow: 0 0 12px rgba(225, 6, 0, .75); }
.lights.is-green span { background: var(--green); border-color: #7ee7b0; box-shadow: 0 0 12px rgba(0, 210, 106, .6); }

.closed { color: var(--red); font-weight: 700; letter-spacing: .1em; }

/* ---------------------------------------------------------------- tyres */

.tyre {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid var(--text-faint); background: #17191d;
  font-family: 'Chakra Petch', monospace; font-size: 11px; font-weight: 700;
  vertical-align: middle;
}
.tyre-soft { border-color: var(--soft); color: var(--soft); }
.tyre-medium { border-color: var(--medium); color: var(--medium); }
.tyre-hard { border-color: var(--hard); color: var(--hard); }
.tyre-intermediate { border-color: var(--inter); color: var(--inter); }
.tyre-wet { border-color: var(--wet); color: #4da3dd; }
.tyre-none { border-style: dashed; color: var(--text-faint); }
.tyre-name { font-size: 11px; letter-spacing: .1em; color: var(--text-dim); }

/* -------------------------------------------------------- timing tower */

.tower { display: flex; flex-direction: column; gap: 3px; }
.tower-row {
  display: grid;
  grid-template-columns: 42px 4px 1fr auto auto;
  align-items: center;
  gap: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 9px 14px 9px 0;
  transition: transform .15s ease, border-color .15s ease;
}
.tower-row:hover { transform: translateX(3px); border-color: var(--line); }
.tower-row.is-me { border-color: var(--red); background: linear-gradient(90deg, rgba(225,6,0,.14), var(--panel-2) 40%); }
.tower-pos {
  font-family: 'Chakra Petch', monospace; font-weight: 700; font-size: 17px;
  text-align: center; color: var(--text); background: #0e1013;
  padding: 8px 0; border-radius: var(--radius) 0 0 var(--radius);
}
.tower-row:nth-child(1) .tower-pos { color: var(--yellow); }
.tower-bar { width: 4px; height: 26px; border-radius: 2px; background: var(--text-faint); }
.tower-name { font-weight: 600; letter-spacing: .03em; }
.tower-sub { font-size: 12px; color: var(--text-faint); letter-spacing: .04em; }
.tower-gap { font-family: 'Chakra Petch', monospace; color: var(--text-dim); font-size: 14px; }
.tower-delta { font-family: 'Chakra Petch', monospace; font-size: 13px; min-width: 46px; text-align: right; }
.delta-up { color: var(--green); }
.delta-down { color: var(--red); }
.delta-flat { color: var(--text-faint); }

/* ---------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase;
  letter-spacing: .12em; color: var(--text-faint); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }
td.num, th.num { text-align: right; font-family: 'Chakra Petch', monospace; font-variant-numeric: tabular-nums; }

.team-dot { display: inline-block; width: 3px; height: 15px; border-radius: 2px; margin-right: 8px; vertical-align: -2px; }

.octanes { font-family: 'Chakra Petch', monospace; font-weight: 700; }
.octanes.is-pos { color: var(--green); }
.octanes.is-neg { color: var(--red); }
.octanes.is-zero { color: var(--text-faint); }

/* ----------------------------------------------------------------- form */

label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--text-faint); margin-bottom: 5px; }

select, input[type='text'], input[type='password'], input[type='number'] {
  width: 100%; padding: 9px 11px;
  background: #0e1013; color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  font-family: 'Titillium Web', sans-serif; font-size: 14px;
}
select:focus, input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 2px rgba(225, 6, 0, .18); }

.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }

button, .button {
  display: inline-block; cursor: pointer;
  padding: 10px 20px;
  background: var(--red); color: #fff; border: none; border-radius: var(--radius);
  font-family: 'Titillium Web', sans-serif; font-weight: 700; font-size: 13px;
  text-transform: uppercase; letter-spacing: .1em;
}
button:hover, .button:hover { background: #ff1a12; }
button:disabled { background: #3a3d44; color: var(--text-faint); cursor: not-allowed; }
.button-ghost { background: transparent; border: 1px solid var(--line); color: var(--text-dim); }
.button-ghost:hover { background: var(--panel-2); color: var(--text); }
.button-small { padding: 6px 12px; font-size: 11px; }

/* ----------------------------------------------------------------- login */

.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand-name { font-size: 30px; }
.login-head { text-align: center; margin-bottom: 22px; }
.login-lights { justify-content: center; display: flex; margin-bottom: 18px; }

/* ----------------------------------------------------------------- misc */

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  border: 1px solid var(--line); color: var(--text-dim);
}
.badge-sprint { border-color: var(--yellow); color: var(--yellow); }
.badge-locked { border-color: var(--red); color: var(--red); }
.badge-open { border-color: var(--green); color: var(--green); }

.stat-row { display: flex; gap: 26px; flex-wrap: wrap; }
.stat { min-width: 76px; }
.stat-value { font-family: 'Chakra Petch', monospace; font-size: 22px; font-weight: 700; }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .14em; color: var(--text-faint); }

.pick-line {
  display: grid; grid-template-columns: 150px 1fr auto; gap: 14px;
  align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line-soft);
}
.pick-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--text-faint); }
.pick-cost { font-family: 'Chakra Petch', monospace; color: var(--text-dim); font-size: 13px; white-space: nowrap; }

.hint { font-size: 12px; color: var(--text-faint); margin-top: 4px; }

.empty { text-align: center; padding: 34px 16px; color: var(--text-faint); }

/* La barra ha bisogno di piu' spazio del resto: con sei voci piu' la direzione
   gara smette di stare su una riga ben prima che la pagina diventi stretta. */
@media (max-width: 1000px) {
  /* Su schermo stretto la barra si divide in due righe: logo e nome utente
     sopra, le voci sotto. Prima la nav restava schiacciata fra i due e ogni
     voce andava a capo per conto suo, finendo sopra il logo. */
  .topbar { height: auto; padding: 10px 14px 0; flex-wrap: wrap; gap: 10px 12px; }
  .brand { order: 1; }
  .user-chip { order: 2; margin-left: auto; }
  .nav {
    order: 3;
    flex: 1 0 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    /* Le voci arrivano fino al bordo e oltre: si capisce che si scorre. */
    margin: 0 -14px;
    padding: 0 14px 8px;
  }
  .nav::-webkit-scrollbar { display: none; }
  /* Voci piu' alte: un dito non e' un puntatore del mouse. */
  .nav-link { flex: none; white-space: nowrap; padding: 10px 14px; }
  /* Anche "Esci" va colpito col pollice, non con la punta di un mouse. */
  .link-button { padding: 8px 4px; }
}

@media (max-width: 820px) {
  .grid-2, .grid-side { grid-template-columns: 1fr; }
  .page { padding: 18px 14px 50px; }

  .pick-line { grid-template-columns: 1fr; gap: 6px; }
  .tower-row { grid-template-columns: 34px 4px 1fr auto; }
  .tower-gap { display: none; }
}

/* ------------------------------------------------------- pagina pilota */

.driver-hero { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.driver-hero-main { display: flex; align-items: center; gap: 18px; }
.driver-number {
  font-size: 52px; font-weight: 700; line-height: 1;
  letter-spacing: -0.02em; opacity: .9;
}
.driver-price { text-align: right; }
.driver-price-value { font-size: 34px; font-weight: 700; line-height: 1; }

.pos-badge {
  display: inline-block; min-width: 26px; padding: 2px 7px;
  background: #0e1013; border: 1px solid var(--line); border-radius: var(--radius);
  font-family: 'Chakra Petch', monospace; font-weight: 700;
}
.pos-badge.is-podium { border-color: var(--yellow); color: var(--yellow); }

tr.is-next td { background: rgba(255, 210, 30, .07); }
tr.is-next .badge { margin-left: 8px; }

/* ------------------------------------------------------ pagina circuito */

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 7px;
  padding: 7px 13px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-weight: 600; font-size: 14px;
}
.chip em {
  font-style: normal; font-size: 10px; text-transform: uppercase;
  letter-spacing: .12em; color: var(--text-faint);
}
.chip.is-team { border-color: rgba(225, 6, 0, .5); }
.chip.is-driver { border-color: rgba(0, 210, 106, .35); }

/* Registrazione e cambio password */
.login-alt { margin: 16px 0 0; text-align: center; font-size: 13px; color: var(--text-faint); }
.login-alt a { color: var(--red); text-decoration: none; font-weight: 600; }
.login-alt a:hover { text-decoration: underline; }

.narrow-panel { max-width: 460px; }
.stack-form { display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.stack-form button { align-self: flex-start; }

a.user-name { color: inherit; text-decoration: none; }
a.user-name:hover { color: var(--red); }

/* ------------------------------------------------- accesso a tutto schermo

   Le pagine di accesso e registrazione non hanno barra in alto ne' contenuti da
   scorrere: sono una fotografia con sopra un modulo. Lo sfondo sta sul body con
   position:fixed, cosi' non si sposta se la tastiera del telefono restringe la
   pagina.

   L'immagine puo' non esserci: sotto resta il fondo scuro del gioco, e la
   schermata funziona lo stesso invece di diventare un rettangolo bianco.        */

body.on-track { background: var(--asphalt); }

body.on-track::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("/img/login-bg.jpg");
  background-size: cover;
  background-position: center;
  z-index: -2;
}

/* Velo scuro: da sinistra copre quasi del tutto, cosi' il modulo si legge
   sempre, e verso destra si apre per lasciar vedere le macchine. */
body.on-track::after {
  content: "";
  position: fixed;
  inset: 0;
  /* Vignettatura appena accennata: scurisce i bordi, lascia stare il centro.
     Non deve piu' fare da fondale al modulo - a quello pensa il vetro - ma solo
     impedire che i bordi illuminati della fotografia tirino via lo sguardo. */
  background:
    radial-gradient(120% 90% at 50% 45%, transparent 35%, rgba(6, 7, 9, .55) 100%),
    linear-gradient(rgba(6, 7, 9, .10), rgba(6, 7, 9, .34));
  z-index: -1;
}

body.on-track .topbar,
body.on-track .footer { display: none; }

body.on-track .page { max-width: none; padding: 0; }

/* Il modulo sta al centro, sopra il logo della Formula 1: e' l'unica parte
   della fotografia che si puo' coprire senza perdere niente, perche' il nome
   del gioco lo ripete gia' il riquadro. Piloti e monoposto restano scoperti. */
body.on-track .login-wrap {
  min-height: 100vh;
  justify-content: center;
  padding: 24px 18px;
}

/* Il riquadro e' vetro, non un pannello: la fotografia si vede attraverso.
   La leggibilita' non la fa l'opacita' ma la sfocatura, che riduce quello che
   sta dietro a una macchia di colore invece che a un'immagine con dei contorni. */
body.on-track .login-card {
  max-width: 440px;
  padding: 16px 22px 18px;
  background: rgba(10, 12, 15, .38);
  border-color: rgba(255, 255, 255, .2);
  backdrop-filter: blur(20px) saturate(130%);
  -webkit-backdrop-filter: blur(20px) saturate(130%);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}

/* Il riquadro deve restare basso quanto la fascia del logo, quindi
   l'intestazione si stringe e i due campi vanno affiancati invece che in
   colonna: e' il modo di guadagnare in larghezza quello che si toglie in
   altezza, e di non salire fino ai volti dei piloti. */
body.on-track .login-head { margin-bottom: 12px; }
body.on-track .login-card .brand-name { font-size: 22px; }
body.on-track .login-lights { margin-bottom: 7px; transform: scale(.6); }
body.on-track .field { margin-bottom: 0; }
body.on-track .login-alt { margin-top: 11px; font-size: 12px; }
body.on-track .login-card button { padding: 10px 16px; }

.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-bottom: 14px; }

/* Sotto i 420px due colonne diventerebbero due campi da toccare col mignolo. */
@media (max-width: 420px) {
  .field-grid { grid-template-columns: 1fr; }
}

/* Il logo della Formula 1 sta poco sotto la meta' dell'immagine: il riquadro
   scende con lui, invece di restare centrato e mordere i volti in alto. */
body.on-track .login-card { margin-top: 12vh; }

/* Anche i campi diventano di vetro, altrimenti resterebbero due rettangoli
   pieni dentro un riquadro trasparente. */
body.on-track .login-card select,
body.on-track .login-card input[type='text'],
body.on-track .login-card input[type='password'] {
  background: rgba(255, 255, 255, .07);
  border-color: rgba(255, 255, 255, .18);
}
body.on-track .login-card input:focus {
  background: rgba(255, 255, 255, .12);
  border-color: var(--red);
}

/* Sul vetro il testo va scritto piu' chiaro: il grigio spento del pannello
   opaco qui si perderebbe sopra le zone illuminate della fotografia. */
body.on-track .login-card label,
body.on-track .login-alt { color: rgba(232, 234, 237, .72); }
body.on-track .login-head .faint { color: rgba(232, 234, 237, .8); }

/* Su schermo stretto la fotografia si vede poco e il modulo va al centro. */
@media (max-width: 760px) {
  body.on-track::after {
    background: linear-gradient(rgba(6, 7, 9, .30), rgba(6, 7, 9, .58));
  }
}

/* La moneta del gioco al posto della parola "ottani" quando fa da unita'. */
.coin { display: inline-block; vertical-align: -.18em; flex: none; }
.coin-sm { width: 15px; height: 15px; }
.coin-md { width: 20px; height: 20px; }
.coin-lg { width: 28px; height: 28px; }
th .coin { vertical-align: -.15em; }
