/* Abaco h da u. Font: Andika (SIL International, SIL Open Font License 1.1, vedi /fonts/OFL.txt) */
@font-face {
  font-family: 'Andika';
  src: url('/fonts/andika-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Andika';
  src: url('/fonts/andika-700.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --font: 'Andika', 'Segoe UI', system-ui, sans-serif;
  --bg: #e7ebef;
  --carta: #ffffff;
  --ink: #17212b;
  --muted: #56626e;
  --linea: #d2d9e0;
  --r: 14px;
  --ombra: 0 1px 0 rgba(23, 33, 43, .05), 0 10px 26px -14px rgba(23, 33, 43, .28);

  --u: #1f5fd1;
  --u-testo: #1d57c2;
  --da: #d42a2a;
  --da-testo: #c02222;
  --h: #22a04d;
  --h-testo: #17803d;

  --avviso-sfondo: #fff3dd;
  --avviso-bordo: #f0b35a;
  --avviso-testo: #773800;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input { font-family: inherit; }

.solo-lettori {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.c-h { color: var(--h-testo); }
.c-da { color: var(--da-testo); }
.c-u { color: var(--u-testo); }
/* il verde delle palline (#22a04d) col bianco sopra arriva a 3,4:1: sotto le scritte si usa quello scuro */
.sfondo-h { background: var(--h-testo); color: #fff; }
.sfondo-da { background: var(--da); color: #fff; }
.sfondo-u { background: var(--u); color: #fff; }

/* ---------- Impaginazione ---------- */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-columns: minmax(0, 1fr) clamp(300px, 31vw, 470px);
  grid-template-rows: minmax(0, 1fr) auto auto;
  grid-template-areas:
    "abaco numero"
    "abaco comandi"
    "abaco firma";
  gap: clamp(10px, 1.6vh, 18px);
  height: 100vh;
  height: 100dvh;
  padding: clamp(10px, 1.6vh, 18px);
  -webkit-user-select: none;
  user-select: none;
}

.abaco {
  grid-area: abaco;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.scena {
  position: relative;
  min-height: 0;
}

.numero,
.comandi {
  background: var(--carta);
  border-radius: var(--r);
  box-shadow: var(--ombra);
  padding: clamp(12px, 2vh, 22px);
}

.numero {
  grid-area: numero;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  gap: clamp(4px, 1vh, 12px);
  min-height: 0;
  overflow: auto;
}

.numero > * { flex-shrink: 0; }

.comandi {
  grid-area: comandi;
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 14px);
}

/* ---------- Scritta del cambio ---------- */

.banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: clamp(54px, 8.8vh, 90px);
  padding: 0 6px clamp(4px, .8vh, 10px);
}

.banner__testo {
  margin: 0;
  padding: .32em .9em;
  font-size: clamp(19px, 3.3vh, 36px);
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  background: var(--carta);
  border-radius: var(--r);
  box-shadow: var(--ombra);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .22s ease, transform .22s ease;
}

.banner__testo.acceso {
  opacity: 1;
  transform: none;
}

.banner--avviso .banner__testo {
  background: var(--avviso-sfondo);
  color: var(--avviso-testo);
  box-shadow: inset 0 0 0 3px var(--avviso-bordo);
}

.banner__avanti {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: clamp(50px, 7.4vh, 72px);
  padding: 0 .7em 0 .9em;
  border: 0;
  border-radius: var(--r);
  background: var(--ink);
  color: #fff;
  font-size: clamp(19px, 3.1vh, 32px);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--ombra);
  touch-action: manipulation;
}

.banner__avanti[hidden] { display: none; }

.banner__avanti svg {
  width: 1.1em;
  height: 1.1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.banner__avanti:focus-visible { outline: 4px solid var(--u); outline-offset: 3px; }

/* ---------- Palco dell'abaco (unità fisse 760 x 930, scalate dal JS) ---------- */

.palco {
  position: absolute;
  left: 0;
  top: 0;
  width: 760px;
  height: 930px;
  transform-origin: 0 0;
}

.asta {
  position: absolute;
  top: 150px;
  width: 14px;
  height: 580px;
  margin-left: -7px;
  border-radius: 7px 7px 0 0;
  z-index: 1;
  background: linear-gradient(90deg, #5f6872 0%, #aab3bb 22%, #f3f5f7 45%, #c3cad0 62%, #7b848d 85%, #59626b 100%);
  box-shadow: 3px 0 4px -1px rgba(20, 28, 38, .18);
}

.asta--h { left: 150px; }
.asta--da { left: 380px; }
.asta--u { left: 610px; }

.base {
  position: absolute;
  left: 40px;
  top: 724px;
  width: 680px;
  height: 80px;
  border-radius: var(--r);
  z-index: 2;
  background-color: #c68d55;
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, .34) 0, rgba(255, 255, 255, .1) 12%, rgba(0, 0, 0, 0) 55%, rgba(60, 30, 10, .28) 100%),
    url('/legno.svg');
  background-size: 100% 100%, 100% 100%;
  box-shadow:
    0 18px 26px -14px rgba(23, 33, 43, .5),
    inset 0 2px 0 rgba(255, 255, 255, .35),
    inset 0 -4px 0 rgba(60, 30, 10, .25);
}

.foro {
  position: absolute;
  top: -4px;
  width: 30px;
  height: 11px;
  margin-left: -15px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 60%, rgba(40, 20, 5, .6), rgba(40, 20, 5, 0) 72%);
}

.foro--h { left: 110px; }
.foro--da { left: 340px; }
.foro--u { left: 570px; }

.etichetta {
  position: absolute;
  top: 15px;
  width: 86px;
  height: 50px;
  margin-left: -43px;
  border-radius: var(--r);
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  line-height: 50px;
  text-align: center;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .2), 0 1px 0 rgba(255, 255, 255, .25);
}

.etichetta--h { left: 110px; background: var(--h-testo); }
.etichetta--da { left: 340px; background: var(--da); }
.etichetta--u { left: 570px; background: var(--u); }

/* palline, mazzetto, lampo, numerini: create dal JS e posizionate col transform */

.pallina,
.elastico,
.anello,
.numerino {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform, opacity;
  pointer-events: none;
}

.pallina {
  width: 86px;
  height: 52px;
  margin: -26px 0 0 -43px;
  border-radius: 50%;
  z-index: 3;
  background:
    radial-gradient(ellipse 34% 26% at 36% 28%, rgba(255, 255, 255, .72), rgba(255, 255, 255, 0) 100%),
    radial-gradient(ellipse 78% 82% at 50% 36%, var(--chiaro) 0%, var(--pieno) 50%, var(--scuro) 100%);
  box-shadow: 0 4px 5px -2px rgba(20, 28, 38, .35);
}

.pallina--u, .anello--u { --chiaro: #6f9bf0; --pieno: #1f5fd1; --scuro: #0b2f73; }
.pallina--da, .anello--da { --chiaro: #f5857a; --pieno: #d42a2a; --scuro: #6e0d0d; }
.pallina--h, .anello--h { --chiaro: #7fdc9c; --pieno: #22a04d; --scuro: #0a5224; }

.elastico {
  width: 292px;
  height: 94px;
  margin: -47px 0 0 -146px;
  border: 7px solid #eea400;
  border-radius: 26px;
  z-index: 4;
  box-shadow: 0 2px 0 rgba(90, 55, 0, .25);
}

.anello {
  width: 90px;
  height: 90px;
  margin: -45px 0 0 -45px;
  border-radius: 50%;
  border: 7px solid var(--pieno);
  z-index: 5;
}

.numerino {
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 23px;
  font-weight: 700;
  line-height: 40px;
  text-align: center;
  z-index: 6;
  box-shadow: 0 1px 4px rgba(20, 28, 38, .28);
}

/* tasti + e − sotto le aste */

.tasti {
  position: absolute;
  top: 822px;
  width: 212px;
  margin-left: -106px;
  display: flex;
  gap: 12px;
}

.tasti--h { left: 150px; }
.tasti--da { left: 380px; }
.tasti--u { left: 610px; }

.tasto {
  flex: 1 1 0;
  height: 100px;
  padding: 0;
  border-radius: var(--r);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease;
}

.tasto svg {
  width: 46px;
  height: 46px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3.4;
  stroke-linecap: round;
}

.tasto--piu {
  border: 0;
  color: #fff;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .22), 0 4px 8px -2px rgba(20, 28, 38, .3);
}

.tasto--meno {
  background: #fff;
  border: 4px solid currentColor;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .07), 0 4px 8px -2px rgba(20, 28, 38, .2);
}

.tasti--h .tasto--piu { background: var(--h-testo); }
.tasti--da .tasto--piu { background: var(--da); }
.tasti--u .tasto--piu { background: var(--u); }
.tasti--h .tasto--meno { color: var(--h-testo); }
.tasti--da .tasto--meno { color: var(--da-testo); }
.tasti--u .tasto--meno { color: var(--u-testo); }

.tasto:active { transform: translateY(3px); }
.tasto:focus-visible { outline: 4px solid var(--ink); outline-offset: 3px; }

/* passo passo: durante il cambio i tasti delle aste aspettano */
.tasto:disabled {
  opacity: .35;
  cursor: default;
  transform: none;
}

.scuoti { animation: scuoti .42s ease; }

@keyframes scuoti {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(4px); }
}

/* ---------- Pannello del numero ---------- */

.numero__testa {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.numero__titolo {
  margin: 0;
  font-size: clamp(16px, 2.3vh, 23px);
  color: var(--muted);
}

.numero__grande {
  margin: 0;
  text-align: center;
  font-size: 120px;
  font-size: clamp(56px, 16vh, 200px);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.numero__grande.coperto { color: var(--muted); }

.numero__lettere {
  margin: 0;
  min-height: 1.25em;
  text-align: center;
  font-size: clamp(19px, 3.1vh, 34px);
  line-height: 1.25;
}

.tabella {
  width: 100%;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: clamp(6px, 1vh, 10px) 0;
}

.tabella th {
  padding: .16em 0;
  font-size: clamp(17px, 2.6vh, 28px);
  font-weight: 700;
  border-radius: var(--r) var(--r) 0 0;
}

.tabella td {
  height: 1.3em;
  font-size: clamp(32px, 6.2vh, 66px);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  background: #fff;
  border: 3px solid var(--linea);
  border-top: 0;
  border-radius: 0 0 var(--r) var(--r);
}

.tabella td.troppe {
  background: var(--avviso-sfondo);
  border-color: var(--avviso-bordo);
  animation: scuoti .45s ease;
}

.numero__riga {
  margin: 0;
  min-height: 1.3em;
  text-align: center;
  font-size: clamp(16px, 2.5vh, 27px);
  line-height: 1.3;
  text-wrap: balance;
}

.numero__riga--somma { font-weight: 700; }

/* ---------- Comandi ---------- */

.scrivi__etichetta {
  display: block;
  font-size: clamp(15px, 2.1vh, 20px);
  font-weight: 700;
}

.scrivi__riga {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.scrivi__campo {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  padding: 4px 10px;
  font-size: clamp(26px, 4.4vh, 44px);
  font-weight: 700;
  color: var(--ink);
  text-align: center;
  background: #fff;
  border: 3px solid var(--linea);
  border-radius: var(--r);
  -webkit-user-select: text;
  user-select: text;
}

.scrivi__campo:focus { outline: none; border-color: var(--ink); }
.scrivi__campo::placeholder { color: #aab3bc; }

.bottone {
  min-height: clamp(46px, 6.6vh, 62px);
  padding: 0 14px;
  white-space: nowrap;
  font-size: clamp(15px, 2.2vh, 21px);
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--linea);
  border-radius: var(--r);
  cursor: pointer;
  touch-action: manipulation;
}

.bottone--pieno {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

.bottone:focus-visible,
.chip:focus-visible { outline: 3px solid var(--u); outline-offset: 2px; }

.impostazioni,
.azioni {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.azioni .bottone { flex: 1 1 auto; }

.impostazioni {
  padding-top: clamp(8px, 1.2vh, 12px);
  border-top: 2px solid var(--linea);
}

.impostazioni .chip {
  flex: 1 1 auto;
  justify-content: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 10px;
  white-space: nowrap;
  font-size: clamp(14px, 1.9vh, 18px);
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--linea);
  border-radius: var(--r);
  cursor: pointer;
  touch-action: manipulation;
}

.chip svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chip[aria-pressed="true"] {
  background: #dce4ed;
  border-color: var(--ink);
}

.impostazioni .chip--icona {
  flex: 0 0 auto;
  padding: 0 12px;
}

.chip--icona svg {
  width: 24px;
  height: 24px;
}

#nascondi[aria-pressed="false"] .icona-occhio,
#nascondi[aria-pressed="true"] .icona-occhio-chiuso,
#suoni[aria-pressed="false"] .onda,
#suoni[aria-pressed="true"] .muto { display: none; }

/* ---------- Firma e contatti: chiusi durante la lezione ---------- */

.firma {
  grid-area: firma;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 0 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.firma__credito {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  white-space: nowrap;
}

.firma a {
  min-height: 44px;
  color: inherit;
  text-underline-offset: 3px;
  touch-action: manipulation;
}

.firma__credito a {
  display: inline-flex;
  align-items: center;
  min-width: 44px;
  font-weight: 700;
}

.firma__contatti { position: relative; }

.firma summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 8px;
  list-style: none;
  cursor: pointer;
  touch-action: manipulation;
}

.firma summary::-webkit-details-marker { display: none; }
.firma summary::after { content: '+'; font-size: 18px; }
.firma details[open] summary::after { content: '−'; }

.firma a:hover,
.firma summary:hover { color: var(--ink); }

.firma a:focus-visible,
.firma summary:focus-visible {
  outline: 3px solid var(--u);
  outline-offset: 2px;
  border-radius: var(--r);
}

.firma__scheda {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 20;
  width: min(320px, calc(100vw - 28px));
  max-height: calc(100vh - 96px);
  max-height: calc(100dvh - 96px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px;
  color: var(--ink);
  background: var(--carta);
  border: 1px solid var(--linea);
  border-radius: var(--r);
  box-shadow: var(--ombra);
  -webkit-user-select: text;
  user-select: text;
}

.firma__nome {
  margin: 4px 8px 8px;
  font-size: 16px;
  font-weight: 700;
}

.firma__scheda nav { display: grid; }

.firma__scheda a {
  display: flex;
  align-items: center;
  padding: 8px;
  overflow-wrap: anywhere;
  border-radius: var(--r);
}

.firma__scheda a:hover { background: var(--bg); }

/* ---------- Schermi verticali (tablet in piedi, telefono) ---------- */

@media (max-aspect-ratio: 5/6), (max-width: 700px) {
  body { overflow: auto; }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "numero"
      "abaco"
      "comandi"
      "firma";
    height: auto;
    min-height: 100vh;
  }

  .abaco { height: 110vw; height: min(132vw, 84vh); }

  .numero__grande { font-size: clamp(56px, 18vw, 130px); }
  .tabella td { font-size: clamp(30px, 9vw, 60px); }
}

@media (prefers-reduced-motion: reduce) {
  .banner__testo { transition: none; }
}
