/*
  Compteur d'électricité (type Schlumberger / Contigea, 1986).
  Toutes les tailles sont en cqw (1 % de la largeur du compteur) :
  le compteur garde ses proportions quelle que soit la taille de la fenêtre.
  Maquette de référence : 700 px de large  ->  1cqw = 7 px.
*/

:root { color-scheme: dark; }
* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  place-items: center;
  background: radial-gradient(120% 90% at 50% 40%, #5b574a 0%, #2d2b26 58%, #151412 100%);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

/* ---------- la scène : fixe la taille du compteur et sert de référence aux cqw ---------- */
.scene {
  container-type: inline-size;
  position: relative;
  width: min(94vw, calc(94vh * 700 / 640), 900px);
  aspect-ratio: 700 / 640;
}

/* ---------- boîtier noir ---------- */
.boitier {
  --cell: 6.6cqw;               /* hauteur d'un chiffre du totalisateur */
  position: absolute;
  inset: 0;
  border-radius: 3.4cqw;
  background: linear-gradient(145deg, #3a3a3d 0%, #151516 35%, #0b0b0c 62%, #1c1c1e 100%);
  box-shadow:
    inset 0 0 0 .25cqw #050505,
    inset .5cqw .5cqw 1cqw rgba(255, 255, 255, .12),
    inset -.5cqw -.5cqw 1cqw rgba(0, 0, 0, .8),
    0 3cqw 6cqw rgba(0, 0, 0, .65);
}

/* ---------- lunette métallique autour de la vitre ---------- */
.lunette {
  position: absolute;
  left: 11.4cqw;
  top: 10.7cqw;
  width: 77.9cqw;
  height: 70cqw;
  border-radius: 2.6cqw;
  background: linear-gradient(135deg, #d6d8dc 0%, #9a9da3 30%, #c8cacf 55%, #8a8d93 100%);
  box-shadow: inset 0 0 0 .3cqw #6d7075, 0 0 1cqw rgba(0, 0, 0, .6);
}

/* reflet sur la vitre, par-dessus tout le reste */
.lunette::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(118deg,
              rgba(255, 255, 255, .34) 0%,
              rgba(255, 255, 255, .08) 30%,
              rgba(255, 255, 255, 0) 48%);
}

/* ---------- cadran blanc cassé ---------- */
.cadran {
  position: absolute;
  inset: 3.6cqw;                /* donne 70,7 x 62,8 cqw = 495 x 440 px de la maquette */
  border-radius: 1.2cqw;
  overflow: hidden;
  background: radial-gradient(120% 110% at 40% 35%, #f3f3f0 0%, #e6e6e2 60%, #d3d3ce 100%);
  box-shadow: inset 0 0 1.4cqw rgba(0, 0, 0, .35);
}

/* ---------- gravure (texte et dessins du cadran) ---------- */
.gravure {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.gravure .t {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 17px;
  fill: #3d3d3d;
}
.gravure .fin   { font-size: 14px; letter-spacing: 1px; fill: #666; }
.gravure .gras  { font-weight: 700; fill: #262626; }
.gravure .grand { font-size: 21px; letter-spacing: .5px; }
.gravure .kwh   { font-size: 30px; font-weight: 800; fill: #1a1a1a; }
.gravure .plus  { font-size: 18px; font-weight: 700; fill: #111; }
.gravure .logo-haut { font-size: 9.5px; font-weight: 800; fill: #111; letter-spacing: .3px; }
.gravure .logo-bas  { font-size: 12.5px; font-weight: 800; fill: #fff; }

/* ---------- vis en laiton ---------- */
.vis {
  position: absolute;
  width: 2.3cqw;
  height: 2.3cqw;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #e6c768, #8a6a1c 70%, #4a3608);
  box-shadow: 0 0 .3cqw rgba(0, 0, 0, .6);
}

/* ---------- totalisateur à tambours ---------- */
.fenetre {
  position: absolute;
  left: 24.6%;
  top: 8.2%;
  width: 57.2%;
  height: var(--cell);
  border-radius: .5cqw;
  /* 6 tambours noirs, puis la zone rouge du tambour des dixièmes */
  background: linear-gradient(90deg, #0d0d0d 0 79.5%, #c3241d 79.5% 100%);
  box-shadow: 0 0 0 .3cqw #1b1b1b, inset 0 0 .6cqw rgba(0, 0, 0, .7);
}

.tambours {
  display: flex;
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
}

.tambour {
  position: relative;
  flex: 0 0 13.25%;
  height: 100%;
  overflow: hidden;
  border-left: .1cqw solid rgba(255, 255, 255, .08);
}
.tambour:first-child { border-left: 0; }

/* ombre en haut et en bas : donne l'effet de cylindre */
.tambour::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom,
              rgba(0, 0, 0, .7) 0%, rgba(0, 0, 0, 0) 24%,
              rgba(0, 0, 0, 0) 76%, rgba(0, 0, 0, .7) 100%);
}

/* la bande des chiffres 0-9-0 défile : --pos va de 0 à 10 (réglé par script.js) */
.bande {
  transform: translateY(calc(var(--pos, 0) * var(--cell) * -1));
  will-change: transform;
}
.bande span {
  display: block;
  height: var(--cell);
  line-height: var(--cell);
  text-align: center;
  font-size: 5.3cqw;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #f4f4f2;
}

/* petit repère blanc sous la fenêtre, avant le tambour rouge */
.repere {
  position: absolute;
  left: 79.5%;
  bottom: -1.5cqw;
  width: 1.7cqw;
  height: 1.7cqw;
  background: #f2f2f0;
  border: .15cqw solid #8a8a8a;
  transform: translateX(-50%) rotate(45deg);
}

/* ---------- ligne de contrôle (ajoute ?debug à l'adresse) ---------- */
.debug {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 1.2rem;
  margin: 0;
  text-align: center;
  font: 14px/1.4 ui-monospace, Menlo, monospace;
  color: #cfcab8;
}

/* ---------- le compteur n'apparaît qu'une fois la valeur reçue du serveur ---------- */
body:not(.pret) .fenetre { visibility: hidden; }

/* ---------- panneau d'accélération du temps (ajoute ?admin à l'adresse) ---------- */
.admin {
  position: fixed;
  top: .8rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  max-width: 94vw;
  padding: .6rem .9rem;
  background: rgba(20, 20, 18, .92);
  border: 1px solid #4a473d;
  border-radius: 10px;
  color: #e6e2d3;
  font: 14px/1.3 "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.admin button {
  padding: .3rem .7rem;
  border: 1px solid #5d594b;
  border-radius: 6px;
  background: #2b2a25;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.admin button:hover { background: #3a382f; }
.admin button.actif { background: #c3241d; border-color: #c3241d; color: #fff; }
.admin input {
  width: 6.5rem;
  padding: .3rem .5rem;
  border: 1px solid #5d594b;
  border-radius: 6px;
  background: #151412;
  color: inherit;
  font: inherit;
}
.admin .msg { flex-basis: 100%; text-align: center; color: #cfcab8; min-height: 1.2em; }
