:root {
  --fondo: #f6f2ea;          /* the warm paper behind everything */
  --carta: #fffdf8;          /* the sample page */
  --inchiostro: #4a4540;     /* the sample text before high contrast */
  --tenue: #8a837a;          /* secondary text */
  --nero: #16140f;           /* panel text */
  --accento: #2f5bd6;        /* the only accent: knobs, fills, labels */
  --linea: rgba(22, 20, 15, 0.1);
  --ombra: 0 1px 0 rgba(255, 255, 255, 0.9) inset, 0 18px 40px -22px rgba(40, 30, 10, 0.35), 0 2px 6px -2px rgba(40, 30, 10, 0.12);
  --scala: 1;                /* text size multiplier, set by the script */
  --spazio-lettere: 0em;
  --interlinea: 1.5;
  --spazio-parole: 0em;
}

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

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

body {
  background: var(--fondo);
  color: var(--nero);
  font-family: 'Instrument Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.scena {
  height: min(100vh, 520px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 300px);
  gap: clamp(14px, 2.4vw, 28px);
  align-items: stretch;
  justify-content: center;
  align-content: center;
  width: min(860px, 92vw);
  margin: 0 auto;
  padding: clamp(14px, 4vh, 40px) 0;
}

/* the sample page */
.foglio {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  background: var(--carta);
  box-shadow: var(--ombra);
  padding: clamp(16px, 3.4vh, 32px) clamp(16px, 3vw, 34px);
  color: var(--inchiostro);
  min-height: 0;
}

.foglio.leggibile { font-family: 'Atkinson Hyperlegible Next Variable', system-ui, sans-serif; }

.marca {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 clamp(8px, 2vh, 18px);
  font: 500 11px/1 'Geist Mono Variable', ui-monospace, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tenue);
}
.marca svg { width: 16px; height: 16px; color: var(--accento); }

.titolo {
  margin: 0 0 clamp(6px, 1.6vh, 14px);
  font-size: calc(clamp(17px, min(2.6vw, 4.2vh), 26px) * var(--scala));
  line-height: 1.15;
  font-weight: 600;
  font-variation-settings: 'wdth' 92;
  letter-spacing: calc(-0.015em + var(--spazio-lettere));
  word-spacing: var(--spazio-parole);
  color: var(--nero);
}

.testo {
  margin: 0;
  font-size: calc(clamp(12px, min(1.55vw, 2.6vh), 16px) * var(--scala));
  line-height: var(--interlinea);
  letter-spacing: var(--spazio-lettere);
  word-spacing: var(--spazio-parole);
  font-variation-settings: 'wdth' 92;
}
.foglio.leggibile .titolo, .foglio.leggibile .testo { font-variation-settings: normal; }

.parola { display: inline-block; transform-origin: 0 70%; will-change: transform; }

/* the bottom fade when the text grows past the page */
.velo {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 22%;
  background: linear-gradient(to bottom, transparent, var(--carta) 80%);
  pointer-events: none;
}

/* the panel */
.pannello {
  display: flex;
  flex-direction: column;
  gap: clamp(4px, 1.2vh, 10px);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--ombra);
  padding: clamp(12px, 2.6vh, 22px) clamp(14px, 2vw, 20px);
  min-height: 0;
}

.pannello__testa {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: clamp(2px, 1vh, 8px);
}
.pannello__icona { width: 20px; height: 20px; color: var(--accento); }

.riga {
  display: grid;
  gap: 8px;
  padding: clamp(5px, 1.2vh, 9px) 0;
  border-top: 1px solid var(--linea);
}
.riga__nome { font-size: 12.5px; color: #3c3833; font-weight: 500; }
.riga__nome small { font: 500 10px/1 'Geist Mono Variable', ui-monospace, monospace; color: var(--tenue); margin-left: 6px; letter-spacing: 0.04em; }

.riga--interruttore { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }

/* the stepped slider */
.binario {
  position: relative;
  height: 26px;
  margin: 18px 22px 0;
  cursor: pointer;
  outline: none;
  touch-action: none;
}
.binario::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 50%;
  height: 4px;
  margin-top: -2px;
  border-radius: 4px;
  background: #ece7df;
}
.binario__pieno {
  position: absolute;
  left: 0; top: 50%;
  height: 4px;
  margin-top: -2px;
  width: 100%;
  border-radius: 4px;
  background: var(--accento);
  transform-origin: 0 50%;
}
.tacca {
  position: absolute;
  top: 50%;
  width: 2px;
  height: 8px;
  margin: -4px 0 0 -1px;
  border-radius: 2px;
  background: #cfc8bd;
}
.manopola {
  position: absolute;
  left: 0; top: 50%;
  width: 22px; height: 22px;
  margin: -11px 0 0 -11px;
}
.manopola__disco {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1px rgba(22, 20, 15, 0.12), 0 2px 6px rgba(22, 20, 15, 0.18);
}
.manopola__disco::after {
  content: '';
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--accento);
}
.binario:focus-visible .manopola__disco { box-shadow: 0 0 0 3px rgba(47, 91, 214, 0.28), 0 2px 6px rgba(22, 20, 15, 0.18); }

/* the small label over the knob */
.valore {
  position: absolute;
  left: 0; bottom: 100%;
  margin-bottom: 1px;
  height: 18px;
  pointer-events: none;
}
.valore__testo {
  position: absolute;
  left: 0; top: 0;
  height: 18px;
  padding: 0 7px;
  border-radius: 9px;
  background: var(--nero);
  color: #fff;
  font: 500 10px/18px 'Geist Mono Variable', ui-monospace, monospace;
  white-space: nowrap;
}

/* the switch */
.interruttore {
  position: relative;
  width: 44px; height: 26px;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: #e3ddd3;
  cursor: pointer;
  outline: none;
}
.interruttore:focus-visible { box-shadow: 0 0 0 3px rgba(47, 91, 214, 0.28); }
.interruttore__manopola {
  position: absolute;
  left: 3px; top: 3px;
  width: 20px; height: 20px;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(22, 20, 15, 0.22);
}

/* reset */
.reimposta {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding: 8px 14px;
  border: 1px solid var(--linea);
  border-radius: 999px;
  background: #fff;
  color: #3c3833;
  font: 500 12.5px/1 'Instrument Sans Variable', system-ui, sans-serif;
  cursor: pointer;
}
.reimposta svg { width: 14px; height: 14px; }
.reimposta:focus-visible { box-shadow: 0 0 0 3px rgba(47, 91, 214, 0.28); outline: none; }
@media (hover: hover) {
  .reimposta:hover { border-color: rgba(22, 20, 15, 0.22); }
}

/* phone and small boxes: the panel goes under the page */
@media (max-width: 620px) {
  .scena {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    width: calc(100vw - 24px);
    height: 100vh;
    padding: 12px 0;
    gap: 10px;
  }
  .foglio { padding: 12px 14px; border-radius: 14px; }
  .marca { margin-bottom: 6px; font-size: 10px; }
  .titolo { font-size: calc(clamp(14px, 4.4vw, 18px) * var(--scala)); margin-bottom: 4px; }
  .testo { font-size: calc(clamp(11px, 3.4vw, 13px) * var(--scala)); }
  .pannello {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 14px;
    row-gap: 2px;
    padding: 8px 12px 10px;
    border-radius: 14px;
  }
  .pannello__testa { display: none; }
  .riga { padding: 4px 0; border-top: 0; gap: 2px; }
  .riga__nome { font-size: 11px; }
  .riga__nome small { display: none; }
  .binario { margin-top: 14px; height: 22px; }
  .reimposta { display: none; }
}
@media (max-width: 620px) and (max-height: 330px) {
  .marca { display: none; }
}
