/* Système visuel : noir neutre, contraste blanc, aucune couleur d'accent.
   Le haut de gamme vient ici du vide, du contraste et de la matière — pas
   d'une teinte. Tokens sémantiques uniquement. */

@font-face {
  font-family: 'Inter';
  /* Chemin relatif à la feuille de style : servie sous /_v/<empreinte>/, elle
     résout la police à la même URL versionnée que le préchargement de la page.
     Un chemin absolu visait une autre adresse, le préchargement ne servait donc
     à rien et la police partait deux fois. */
  src: url('fonts/inter-latin.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

/* Thème sombre uniquement : un compteur consulté au pouce gagne à ne pas
   changer d'apparence selon l'heure. */
:root {
  color-scheme: dark;

  --color-background: #000000;
  --color-foreground: #fafafa;
  --color-card: #0c0c0c;
  --color-surface: #18181b;
  --color-muted-foreground: #a1a1aa;
  --color-border: #27272a;
  --color-border-strong: #3f3f46;
  /* L'accent est le blanc : l'action principale est l'élément le plus
     contrasté de l'écran, sans qu'aucune couleur n'ait à le signaler. */
  --color-accent: #fafafa;
  --color-on-accent: #0a0a0a;
  --color-ring: #fafafa;
  --color-data: #fafafa;

  --shadow-tap: 0 2px 8px rgb(0 0 0 / 0.6), 0 24px 48px -20px rgb(255 255 255 / 0.12);
  --shadow-tap-hover: 0 2px 8px rgb(0 0 0 / 0.6), 0 32px 64px -20px rgb(255 255 255 / 0.2);
  --shadow-card: 0 1px 2px rgb(0 0 0 / 0.6), 0 16px 40px -24px rgb(0 0 0 / 0.9);

  --radius-card: 14px;
  --radius-control: 10px;

  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.25rem;
  --space-5: 3.5rem;
  --space-6: 5rem;

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--color-background);
  color: var(--color-foreground);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
  font-feature-settings: 'cv05' 1; /* « l » à empattement, plus lisible qu'un I */
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Halo unique, très diffus : donne de la profondeur au noir sans y poser de
   motif. La trame technique précédente signait « outil de dev ». */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(ellipse 70% 55% at 50% 38%, rgb(255 255 255 / 0.055), transparent 70%);
}

/* Une seule vue est montée à la fois, et c'est data-view sur le body qui en
   décide. Le JS n'a plus qu'un attribut à écrire, au lieu de quatre attributs
   hidden à tenir synchronisés. */
#auth,
#app,
#stats,
.topbar {
  display: none;
}

[data-view='auth'] #auth {
  display: block;
}

[data-view='counter'] #app {
  display: grid;
}

[data-view='stats'] #stats {
  display: block;
}

[data-view='counter'] .topbar,
[data-view='stats'] .topbar {
  display: flex;
}

.shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: max(var(--space-2), env(safe-area-inset-top)) var(--space-3)
    max(var(--space-3), env(safe-area-inset-bottom));
}

/* Placement explicite : sans lui, un header masqué (display:none) ne crée plus
   de boîte et main remonterait dans la rangée auto au lieu du 1fr. */
.topbar {
  grid-row: 1;
}

main {
  grid-row: 2;
  display: grid;
  place-items: center;
}

.label {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--color-muted-foreground);
}

/* --- Barre supérieure ---------------------------------------------------- */

.topbar {
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand__mark {
  inline-size: 7px;
  block-size: 7px;
  border-radius: 50%;
  background: var(--color-foreground);
}

.brand__name {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.14em;
}

.account {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}

.account__email {
  font-size: 0.8125rem;
  color: var(--color-muted-foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Boutons ------------------------------------------------------------- */

.btn-ghost {
  /* 44px de haut : cible tactile confortable même pour une action discrète. */
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 var(--space-1);
  border: 0;
  background: none;
  color: var(--color-muted-foreground);
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: color 180ms var(--ease);
}

.btn-ghost:hover {
  color: var(--color-foreground);
}

.tap {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: clamp(10.5rem, 52vw, 14rem);
  aspect-ratio: 1;
  margin-block: var(--space-4) var(--space-3);
  border: 0;
  border-radius: 50%;
  background: var(--color-accent);
  color: var(--color-on-accent);
  box-shadow: var(--shadow-tap);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition:
    transform 220ms var(--ease),
    box-shadow 220ms var(--ease);
}

@media (hover: hover) {
  .tap:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-tap-hover);
  }
}

.tap:active {
  transform: scale(0.97);
  box-shadow: var(--shadow-tap);
  transition-duration: 80ms;
}

/* Halo porté par le bouton, pas un contour : la lumière remplace le trait. */
.tap__ring {
  position: absolute;
  inset: -18%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgb(255 255 255 / 0.09), transparent 78%);
  pointer-events: none;
}

:where(button, a):focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 4px;
}

/* --- Compteur ------------------------------------------------------------ */

.counter {
  justify-items: center;
  text-align: center;
}

.counter__value {
  display: block;
  font-weight: 700;
  font-size: clamp(4rem, 22vw, 7.5rem);
  line-height: 1;
  letter-spacing: -0.045em;
  /* Chiffres de largeur fixe : le compteur ne doit pas frémir en changeant. */
  font-variant-numeric: tabular-nums;
}

.counter__label {
  margin: var(--space-1) 0 0;
}

/* --- État de synchronisation --------------------------------------------- */

/* Aucune teinte n'encode l'état : le libellé le dit, la pastille le nuance.
   Un système monochrome ne peut pas se reposer sur la couleur seule. */
.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.875rem;
  margin: 0;
  padding: 0 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-card);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-muted-foreground);
}

.status__dot {
  inline-size: 6px;
  block-size: 6px;
  border-radius: 50%;
  background: var(--color-foreground);
}

.status[data-state='pending'] .status__dot {
  animation: pulse 1.6s ease-in-out infinite;
}

.status[data-state='offline'] .status__dot {
  background: var(--color-border-strong);
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

/* --- Lien vers les statistiques ------------------------------------------ */

.statslink {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-top: var(--space-2);
  color: var(--color-muted-foreground);
  font-size: 0.8125rem;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 180ms var(--ease), border-color 180ms var(--ease);
}

.statslink:hover {
  color: var(--color-foreground);
  border-bottom-color: var(--color-border-strong);
}

/* --- Écran de connexion --------------------------------------------------- */

.auth {
  inline-size: min(22rem, 100%);
  padding: var(--space-4) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  background: var(--color-card);
  box-shadow: var(--shadow-card);
  text-align: center;
}

.auth .brand {
  justify-content: center;
  margin-bottom: var(--space-3);
}

.auth__title {
  margin: 0 0 var(--space-1);
  font-weight: 600;
  font-size: 1.4375rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.auth__sub {
  margin: 0 0 var(--space-3);
  color: var(--color-muted-foreground);
  font-size: 0.875rem;
  text-wrap: pretty;
}

/* La hauteur est réservée avant le rendu du bouton Google : sans elle, l'iframe
   arrive après coup et pousse la carte au moment où elle apparaît.

   Le recadrage traite un défaut que le CSS ne peut pas atteindre autrement : en
   variante personnalisée, Google peint un liseré blanc à l'intérieur de son
   iframe, et celle-ci déborde son conteneur d'une dizaine de pixels de chaque
   côté. Nos éléments sont tous transparents — mesuré — donc le seul recours est
   de rogner. C'est un contournement, pas une correction : il disparaîtra le jour
   où Google traitera son thème sombre jusqu'au bord. */
.gsi {
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: 100%;
  block-size: 44px;
  overflow: hidden;
  border-radius: var(--radius-control);
}

.gsi iframe {
  /* Le rayon reconstitue les angles que la coupe emporte. */
  clip-path: inset(3px round 8px);
}

/* --- Vue statistiques ----------------------------------------------------- */

.stats {
  inline-size: min(32rem, 100%);
  align-self: start;
  padding-block: var(--space-3);
}

.stats__head {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.iconbtn {
  display: grid;
  place-items: center;
  /* 44px : la flèche de retour est la cible la plus sollicitée de cette vue. */
  inline-size: 44px;
  block-size: 44px;
  margin-inline-start: -0.625rem;
  border: 0;
  border-radius: var(--radius-control);
  background: none;
  color: var(--color-muted-foreground);
  cursor: pointer;
  transition: color 180ms var(--ease), background-color 180ms var(--ease);
}

.iconbtn:hover {
  color: var(--color-foreground);
  background: var(--color-surface);
}

.stats__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.stats__state {
  margin: 0;
  padding: var(--space-4) 0;
  color: var(--color-muted-foreground);
  font-size: 0.875rem;
  text-align: center;
}

.stats__since {
  margin: var(--space-3) 0 0;
  text-align: center;
}

/* --- Tuiles de synthèse --------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 1px;
  margin: 0 0 var(--space-2);
  /* Le fond traverse les gouttières : les filets séparateurs viennent de lui
     plutôt que de bordures, qui se doubleraient entre deux tuiles. */
  background: var(--color-border);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.tile {
  padding: var(--space-2);
  background: var(--color-card);
}

.tile__value {
  margin: 0.375rem 0 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.tile__value small {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--color-muted-foreground);
}

/* --- Graphique ------------------------------------------------------------ */

.chart {
  margin: 0;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  background: var(--color-card);
}

.chart__caption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.chart__plot {
  position: relative;
}

#chart {
  display: block;
  inline-size: 100%;
  block-size: auto;
}

/* Série unique : une seule teinte, et c'est celle du texte. Introduire une
   couleur de données dans un système monochrome la ferait passer pour un état. */
.bar {
  fill: var(--color-data);
  fill-opacity: 0.82;
  transition: fill-opacity 160ms var(--ease);
}

.bar--empty {
  fill: var(--color-border);
  fill-opacity: 1;
}

.bar__hit {
  fill: transparent;
}

.bar__hit:hover + .bar,
.bar__group.is-active .bar {
  fill-opacity: 1;
}

.chart__axis {
  stroke: var(--color-border);
  stroke-width: 1;
}

.chart__value {
  fill: var(--color-foreground);
  font-size: 9px;
  font-weight: 600;
}

.chart__tick {
  fill: var(--color-muted-foreground);
  font-size: 8px;
}

/* Infobulle : le survol seul ne suffirait pas au tactile, elle s'ouvre donc
   aussi au toucher, et le tableau ci-dessous couvre clavier et lecteur d'écran. */
.tip {
  position: absolute;
  z-index: 1;
  transform: translate(-50%, -100%);
  padding: 0.3125rem 0.5rem;
  border: 1px solid var(--color-border-strong);
  border-radius: 8px;
  background: var(--color-surface);
  color: var(--color-foreground);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.chart__data {
  margin-top: var(--space-2);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-2);
}

.chart__data summary {
  color: var(--color-muted-foreground);
  font-size: 0.8125rem;
  cursor: pointer;
}

.chart__data summary:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 4px;
}

.chart__data table {
  inline-size: 100%;
  margin-top: var(--space-2);
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.chart__data th,
.chart__data td {
  padding: 0.375rem 0;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  font-weight: 400;
}

.chart__data th {
  color: var(--color-muted-foreground);
}

.chart__data td:last-child,
.chart__data th:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --- Préférences de mouvement -------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .tap:hover,
  .tap:active {
    transform: none;
  }

  /* La pastille cesse de battre : l'état reste porté par le libellé. */
  .status[data-state='pending'] .status__dot {
    animation: none;
    opacity: 0.5;
  }
}
