:root {
  --verd: #6aaa64;
  --groc: #c9b458;
  --gris: #787c7e;
  --vora: #d3d6da;
  --vora-plena: #878a8c;
  --tecla: #d3d6da;
  --text: #1a1a1b;
  --fons: #ffffff;
  --capa: rgba(0, 0, 0, 0.5);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--fons);
  color: var(--text);
  font-family: "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
header {
  width: 100%;
  max-width: 500px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-bottom: 1px solid var(--vora);
}
header h1 { margin: 0; font-size: 26px; letter-spacing: 1px; font-weight: 800; }
header button {
  background: none; border: 0; cursor: pointer; padding: 6px;
  font-size: 20px; line-height: 1; color: var(--text); border-radius: 50%;
  width: 38px; height: 38px;
}
header button:hover { background: #f0f0f0; }
main {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  padding: 8px 0;
}
#tauler {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  width: min(330px, 90vw);
  aspect-ratio: 5 / 6;
  max-height: 100%;
}
.fila { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.fila.sacseja { animation: sacseja 0.5s; }
.casella {
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--vora);
  font-size: clamp(22px, 7vw, 32px); font-weight: 700; text-transform: uppercase;
  user-select: none;
}
.casella.plena { border-color: var(--vora-plena); animation: pica 0.1s; }
.casella.verd, .casella.groc, .casella.gris { color: #fff; border-color: transparent; animation: gira 0.5s ease both; }
.casella.verd { background: var(--verd); }
.casella.groc { background: var(--groc); }
.casella.gris { background: var(--gris); }
#teclat { width: 100%; max-width: 500px; padding: 0 6px 8px; }
.fila-teclat { display: flex; justify-content: center; gap: 5px; margin-bottom: 7px; }
.fila-teclat button {
  flex: 1 1 0; height: 54px; border: 0; border-radius: 4px; cursor: pointer;
  background: var(--tecla); color: var(--text);
  font-size: 15px; font-weight: 700; text-transform: uppercase; padding: 0;
  font-family: inherit;
}
.fila-teclat button.ampla { flex: 1.5 1 0; font-size: 12px; }
.fila-teclat button.verd { background: var(--verd); color: #fff; }
.fila-teclat button.groc { background: var(--groc); color: #fff; }
.fila-teclat button.gris { background: var(--gris); color: #fff; }
#avis {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 12px 16px; border-radius: 4px;
  font-weight: 700; font-size: 14px; opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 20;
}
#avis.visible { opacity: 1; }
.capa {
  position: fixed; inset: 0; background: var(--capa);
  display: none; align-items: center; justify-content: center; z-index: 10; padding: 16px;
}
.capa.oberta { display: flex; }
.finestra {
  background: var(--fons); border-radius: 8px; padding: 20px; width: 100%; max-width: 420px;
  max-height: 100%; overflow-y: auto; position: relative; box-shadow: 0 4px 23px rgba(0, 0, 0, 0.2);
}
.finestra h2 { margin: 0 0 12px; font-size: 18px; text-align: center; text-transform: uppercase; letter-spacing: 0.5px; }
.finestra p { margin: 8px 0; font-size: 15px; line-height: 1.4; }
.tanca { position: absolute; top: 8px; right: 10px; background: none; border: 0; font-size: 26px; cursor: pointer; color: var(--text); }
.exemple { display: flex; gap: 4px; margin: 10px 0 4px; }
.exemple .casella { width: 36px; height: 36px; font-size: 20px; animation: none; }
.peu { font-size: 12px; color: #6b6b6b; border-top: 1px solid var(--vora); padding-top: 10px; margin-top: 14px; }
.peu a { color: inherit; }
.solucio { text-align: center; font-size: 15px; margin-bottom: 14px; }
.solucio strong { display: block; font-size: 26px; letter-spacing: 3px; text-transform: uppercase; margin-top: 4px; }
.xifres { display: flex; justify-content: space-around; text-align: center; margin-bottom: 14px; }
.xifres div { font-size: 30px; font-weight: 400; }
.xifres span { display: block; font-size: 11px; }
.barres { margin-bottom: 14px; }
.barra { display: flex; align-items: center; gap: 6px; font-size: 14px; margin: 3px 0; }
.barra i { font-style: normal; background: var(--gris); color: #fff; padding: 2px 8px; font-weight: 700; min-width: 22px; text-align: right; }
.barra i.actual { background: var(--verd); }
.final { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.final .compte { text-align: center; flex: 1; font-size: 13px; }
.final .compte b { display: block; font-size: 26px; letter-spacing: 1px; }
.comparteix {
  flex: 1; background: var(--verd); color: #fff; border: 0; border-radius: 4px; height: 48px;
  font-size: 17px; font-weight: 700; cursor: pointer; text-transform: uppercase;
}
@keyframes pica { 50% { transform: scale(1.1); } }
@keyframes gira { 0% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes sacseja {
  10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); }
}
@media (max-height: 600px) {
  .fila-teclat button { height: 44px; }
  header h1 { font-size: 22px; }
}
.nomes-infinit { display: none; }
.infinit .nomes-infinit { display: block; }
.infinit .nomes-diari { display: none; }
