/* Pepita — carta, inchiostro, un po' d'oro.
   ===========================================================================

   Cosa si e' evitato di proposito, perche' e' la firma involontaria di
   un'interfaccia generata invece che disegnata:

   - il blu-viola d'ordinanza. Qui la scala e' carta e inchiostro, e l'unico
     colore vivo e' un ocra ossidato che compare SOLO sulle pepite trovate.
     Un accento che appare dappertutto non accenta piu' niente.
   - il raggio d'angolo uguale su tutto. Ogni foglio ha quattro raggi diversi
     fra loro e diversi da quelli del foglio accanto: e' carta tagliata, non
     un rettangolo generato.
   - la superficie perfettamente piatta. Tre punti percentuali di grana.
   - le emoji al posto delle icone. I segni sono tracciati, con un filtro di
     turbolenza che li fa tremare come una penna vera.
   - il fade-in-up identico su ogni cosa, con ritardi a passo regolare. Qui
     l'entrata scavalca il punto d'arrivo e poi rientra, e i ritardi sono
     sfasati (0, 90, 230 ms): un ritmo che nessuno conta.
   - hover: scale(1.05). Sul telefono l'hover non esiste nemmeno; i bottoni
     si comportano da timbro, si premono in dentro.
=========================================================================== */

@font-face {
  font-family: 'Fraunces';
  src: url('../fonts/fraunces-var-latin.woff2') format('woff2');
  font-weight: 300 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Space Mono';
  src: url('../fonts/spacemono-400-latin.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Space Mono';
  src: url('../fonts/spacemono-700-latin.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --carta: #efe8db;
  --foglio: #f8f4ec;
  --inchiostro: #221d17;
  --tenue: #6d6154;
  --tratto: #cdc2ae;
  --oro: #96651a;
  --oro-velo: #e8d7b0;
  --terra: #97381f;

  --grazia: 'Fraunces', ui-serif, Georgia, 'Times New Roman', serif;
  --mono: 'Space Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --corpo: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  /* Scavalca il punto d'arrivo, poi rientra. E' il modo in cui si posa un
     oggetto appoggiato, non il modo in cui compare un div. */
  --posa: cubic-bezier(0.2, 1.42, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --carta: #15120f;
    --foglio: #1e1a15;
    --inchiostro: #ece3d4;
    --tenue: #9a8d7c;
    --tratto: #3a332a;
    --oro: #d9a441;
    --oro-velo: #443519;
    --terra: #e0795c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 max(18px, env(safe-area-inset-left)) calc(48px + env(safe-area-inset-bottom));
  background: var(--carta);
  color: var(--inchiostro);
  font: 16px/1.62 var(--corpo);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

/* La grana: rumore generato dal browser, zero byte di rete. */
.grana {
  position: fixed;
  inset: -50%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.032;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.82' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) { .grana { opacity: 0.055; } }

.definizioni { position: absolute; width: 0; height: 0; overflow: hidden; }

header, main { position: relative; z-index: 1; max-width: 680px; margin: 0 auto; }

/* --- il marchio ---------------------------------------------------------
   Fraunces ha un asse WONK che storce davvero le lettere. All'apertura il
   titolo entra dritto e si storce in un secondo: l'irregolarita' non e' un
   filtro appiccicato sopra, e' la forma che il disegnatore ha previsto. */
header { padding: 46px 0 10px; }

#marchio {
  margin: 0;
  font-family: var(--grazia);
  font-size: clamp(2.9rem, 13vw, 4.2rem);
  font-weight: 600;
  line-height: 0.94;
  letter-spacing: -0.035em;
  font-variation-settings: 'opsz' 120, 'SOFT' 58, 'WONK' 1;
  animation: si-storce 1.15s var(--posa) 0.15s both;
}
@keyframes si-storce {
  from { font-variation-settings: 'opsz' 9, 'SOFT' 0, 'WONK' 0; opacity: 0; }
  40%  { opacity: 1; }
  to   { font-variation-settings: 'opsz' 120, 'SOFT' 58, 'WONK' 1; opacity: 1; }
}

.occhiello {
  margin: 8px 0 0 2px;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--tenue);
  animation: affiora 0.7s ease-out 0.55s both;
}

/* Il filo si disegna da solo, da sinistra, come un tratto di penna. */
.filo { display: block; width: 100%; height: 13px; margin-top: 16px; color: var(--tratto); }
.filo path {
  stroke-dasharray: 340;
  stroke-dashoffset: 340;
  animation: traccia 1.1s cubic-bezier(0.65, 0, 0.35, 1) 0.4s both;
}
/* La ripassata parte dopo e corre piu' veloce: due gesti, non uno duplicato. */
.filo .ripassata { animation-duration: 0.85s; animation-delay: 0.72s; }
@keyframes traccia { to { stroke-dashoffset: 0; } }
@keyframes affiora { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* --- i fogli ------------------------------------------------------------
   Angoli tutti diversi e una rotazione minima e alternata: fogli appoggiati
   sul tavolo, non riquadri allineati al pixel. */
.foglio {
  position: relative;
  background: var(--foglio);
  border: 1px solid var(--tratto);
  border-radius: 15px 4px 13px 6px;
  padding: 20px 18px 22px;
  margin: 22px 0;
  transform: rotate(-0.22deg);
  box-shadow: 0 1px 0 var(--tratto), 0 14px 26px -22px rgba(34, 24, 10, 0.55);
  animation: si-posa 0.62s var(--posa) var(--ritardo, 0ms) both;
}
.foglio:nth-of-type(2n) { border-radius: 5px 14px 5px 12px; transform: rotate(0.28deg); }
.foglio:nth-of-type(3n) { border-radius: 12px 7px 4px 15px; transform: rotate(-0.12deg); }

@keyframes si-posa {
  from { opacity: 0; transform: translateY(16px) rotate(-1.4deg) scale(0.985); }
  to   { opacity: 1; }
}

h2 {
  margin: 0 0 16px;
  font-family: var(--grazia);
  font-size: 1.18rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  font-variation-settings: 'opsz' 40, 'SOFT' 40, 'WONK' 1;
}
.testata { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.testata h2 { margin-bottom: 12px; }

/* --- campi --------------------------------------------------------------
   Sottolineati come su un modulo di carta, non incassati in una scatola. */
label {
  display: block;
  margin-bottom: 7px;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tenue);
}

input {
  width: 100%;
  padding: 9px 2px;
  font-family: var(--corpo);
  font-size: 16px;            /* sotto i 16px iOS zooma da solo al fuoco */
  color: var(--inchiostro);
  background: transparent;
  border: 0;
  border-bottom: 1.5px solid var(--tratto);
  border-radius: 0;
  transition: border-color 0.25s ease;
}
input::placeholder { color: var(--tenue); opacity: 0.65; }
input:focus { outline: 0; border-bottom-color: var(--oro); }
input:focus-visible { outline: 2px solid var(--oro); outline-offset: 3px; }

.fila { display: flex; gap: 18px; margin-top: 18px; }
.campetto { flex: 1; margin: 0; }
.campetto input { margin-top: 5px; font-family: var(--mono); }

/* --- il timbro ----------------------------------------------------------
   Si preme in dentro e lascia un alone che si allarga, come inchiostro che
   entra nella carta. Niente ingrandimenti al passaggio del mouse. */
.timbro {
  position: relative;
  display: block;
  width: 100%;
  margin-top: 24px;
  padding: 14px;
  overflow: hidden;
  font-family: var(--grazia);
  font-size: 1.02rem;
  font-weight: 600;
  font-variation-settings: 'opsz' 30, 'SOFT' 30, 'WONK' 1;
  color: var(--foglio);
  background: var(--inchiostro);
  border: 0;
  border-radius: 11px 3px 10px 4px;
  cursor: pointer;
  transition: transform 0.12s var(--posa), opacity 0.2s ease;
}
.timbro::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  transform: translate(-50%, -50%) scale(0);
  opacity: 0;
}
.timbro:active { transform: translateY(2px) scale(0.988); }
.timbro:active::after { animation: alone 0.55s ease-out; }
@keyframes alone {
  from { transform: translate(-50%, -50%) scale(0); opacity: 0.7; }
  to   { transform: translate(-50%, -50%) scale(46); opacity: 0; }
}
.timbro:disabled { opacity: 0.45; cursor: default; }

.minimo {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  padding: 0;
  color: var(--tenue);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.minimo svg { width: 19px; height: 19px; }
.minimo:active svg { animation: gira 0.6s cubic-bezier(0.4, 0, 0.2, 1); }
@keyframes gira { to { transform: rotate(360deg); } }

/* --- note --------------------------------------------------------------- */
.nota { margin: 12px 0 0; font-size: 0.83rem; line-height: 1.5; color: var(--tenue); }
.nota.male { color: var(--terra); }
.nota.bene { color: var(--oro); }

/* --- i conteggi ---------------------------------------------------------
   Numeri in monospaziato, ciascuno appena fuori squadra. Le pepite trovate
   sono l'unica cosa in oro, e portano un cerchio tracciato attorno. */
.conteggi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 16px 10px;
  margin: 8px 0 6px;
}
.dato { position: relative; padding: 6px 2px; text-align: center; }
.dato b {
  display: block;
  font-family: var(--mono);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}
.dato span {
  display: block;
  margin-top: 7px;
  font-family: var(--mono);
  font-size: 0.6rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--tenue);
}
.dato:nth-child(3n)   { transform: rotate(-0.9deg); }
.dato:nth-child(3n+1) { transform: rotate(0.6deg); }

.dato.trovate b { color: var(--oro); }
.dato.trovate .cerchio {
  position: absolute;
  top: -8px; left: 50%;
  width: 76px; height: 52px;
  margin-left: -38px;
  color: var(--oro);
  pointer-events: none;
}
.dato.trovate .cerchio path {
  stroke-dasharray: 220;
  stroke-dashoffset: 220;
  animation: traccia 1.05s cubic-bezier(0.55, 0.1, 0.3, 1) 0.55s both;
}

/* --- voci in elenco ------------------------------------------------------ */
.voce {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-top: 2px;
  padding: 13px 4px;
  font: inherit;
  color: inherit;
  text-align: left;
  text-decoration: none;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--tratto);
  cursor: pointer;
  transition: padding-left 0.22s var(--posa), background-color 0.22s ease;
}
.voce:last-child { border-bottom: 0; }
.voce:active { padding-left: 12px; background: rgba(150, 101, 26, 0.07); }
.voce .titolo { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voce .quando { font-family: var(--mono); font-size: 0.66rem; color: var(--tenue); white-space: nowrap; }
.voce svg { flex: none; width: 17px; height: 17px; }
.voce .si { color: var(--oro); }
.voce .no { color: var(--tenue); opacity: 0.7; }
.voce .freccia { width: 13px; color: var(--tenue); }

/* --- il setaccio --------------------------------------------------------
   Sei sassi cadono nel vaglio: cinque passano, uno resta. Il telaio si
   scuote con un ritmo asimmetrico, perche' una mano non oscilla a metronomo. */
.setaccio { display: grid; place-items: center; padding: 22px 0; color: var(--tenue); }
.setaccio svg { width: 84px; height: 63px; overflow: visible; }
.setaccio .scuote { animation: scuoti 1.9s ease-in-out infinite; transform-origin: 32px 26px; }
@keyframes scuoti {
  0%, 100% { transform: rotate(-2.6deg) translateX(-0.6px); }
  38%      { transform: rotate(2.1deg) translateX(1px); }
  61%      { transform: rotate(-1.1deg) translateX(0); }
}
.setaccio .sasso {
  fill: var(--tenue);
  opacity: 0;
  animation: cade 2.6s cubic-bezier(0.45, 0.02, 0.7, 0.4) infinite;
  animation-delay: calc(var(--i) * 260ms + 60ms);
}
@keyframes cade {
  0%        { opacity: 0;    transform: translateY(-6px); }
  12%       { opacity: 0.85; }
  46%       { opacity: 0.85; transform: translateY(20px); }  /* dentro il vaglio */
  70%       { opacity: 0.35; transform: translateY(40px); }  /* passa la rete */
  86%, 100% { opacity: 0;    transform: translateY(54px); }
}
.setaccio .pepita {
  fill: var(--oro);
  animation: resta 2.6s cubic-bezier(0.4, 0, 0.3, 1) infinite;
}
@keyframes resta {
  0%        { opacity: 0; transform: translateY(-6px) scale(0.7); }
  14%       { opacity: 1; }
  44%       { transform: translateY(20px) scale(1); }        /* si ferma sulla rete */
  56%       { transform: translateY(18px) scale(1.14); }     /* rimbalza appena */
  72%, 88%  { transform: translateY(19px) scale(1); opacity: 1; }
  100%      { opacity: 0; transform: translateY(19px) scale(1); }
}

/* --- il lettore --------------------------------------------------------- */
dialog {
  width: min(100%, 720px);
  max-height: 88vh;
  padding: 26px 22px 30px;
  color: var(--inchiostro);
  background: var(--foglio);
  border: 1px solid var(--tratto);
  border-radius: 16px 5px 14px 6px;
}
dialog[open] { animation: si-posa 0.4s var(--posa) both; }
dialog::backdrop { background: rgba(26, 18, 8, 0.62); backdrop-filter: blur(2px); }
#chiudi { position: sticky; top: 0; float: right; margin: -8px -6px 0 0; }

article { overflow-wrap: anywhere; }
article h1, article h2, article h3 {
  font-family: var(--grazia);
  font-variation-settings: 'opsz' 60, 'SOFT' 45, 'WONK' 1;
  letter-spacing: -0.015em;
}
article h1 { margin: 0 0 4px; font-size: 1.5rem; line-height: 1.18; }
article h2 { margin: 30px 0 8px; font-size: 1.1rem; }
article h3 { margin: 22px 0 6px; font-size: 0.98rem; }
article p { margin: 0 0 12px; }

/* Il verdetto: barra d'oro a sinistra, come un segno di matita a margine. */
article blockquote {
  margin: 20px 0;
  padding: 14px 16px;
  background: transparent;
  border-left: 3px solid var(--oro);
  border-radius: 0;
}
article blockquote p:first-child {
  font-family: var(--grazia);
  font-size: 1.14rem;
  font-weight: 600;
  font-variation-settings: 'opsz' 40, 'SOFT' 40, 'WONK' 1;
}
article blockquote p:last-child { margin-bottom: 0; }

article code {
  padding: 1px 5px;
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--oro-velo);
  border-radius: 4px 2px 4px 2px;
}
article pre {
  padding: 14px;
  overflow-x: auto;          /* i comandi lunghi scorrono, non allargano la pagina */
  font-size: 0.82rem;
  background: var(--carta);
  border: 1px solid var(--tratto);
  border-radius: 10px 3px 9px 4px;
}
article pre code { padding: 0; background: none; }
article ul { padding-left: 20px; }
article li { margin-bottom: 5px; }
article hr { height: 0; margin: 26px 0; border: 0; border-top: 1px solid var(--tratto); }
article a { color: var(--oro); text-decoration-thickness: 1px; text-underline-offset: 2px; }
article sub { font-size: 0.72rem; line-height: 1.5; color: var(--tenue); }
article details { margin: 18px 0; }
article summary {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tenue);
  cursor: pointer;
}

/* --- chi non vuole movimento -------------------------------------------
   Non e' una spunta di conformita': su un telefono tenuto in mano, per chi
   soffre di cinetosi, un vaglio che oscilla in continuazione da' davvero
   fastidio. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  #marchio { font-variation-settings: 'opsz' 120, 'SOFT' 58, 'WONK' 1; }
  .filo path, .dato.trovate .cerchio path { stroke-dashoffset: 0; }
  .setaccio .sasso { opacity: 0.85; }
  .setaccio .pepita { opacity: 1; }
}
