[hidden] { display: none !important; }

:root {
  --alcali: #ff8a80;
  --alcalinoterri: #ffcc80;
  --transicio: #fff59d;
  --lantanid: #f8bbd0;
  --actinid: #e1bee7;
  --altre-metall: #b0bec5;
  --metal-loide: #a5d6a7;
  --no-metall: #80deea;
  --halogen: #90caf9;
  --gas-noble: #b39ddb;
  --correcte: #2e7d32;
  --incorrecte: #c62828;
  --revelat: #ef6c00;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 1rem 1.5rem 2rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f5f6fa;
  color: #222;
}

header { text-align: center; }
h1 { margin: 0.2rem 0; }
.subtitol { margin: 0 0 1rem; color: #555; }

.controls, .marcador {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  justify-content: center;
  align-items: center;
  margin-bottom: 0.75rem;
}

select, button {
  font: inherit;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  border: 1px solid #888;
}
button {
  background: #3949ab;
  color: white;
  border-color: #3949ab;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: 0.5; cursor: default; filter: none; }
button.secundari { background: white; color: #3949ab; }

.marcador { font-size: 1.05rem; }

.missatge {
  text-align: center;
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--correcte);
}

.contenidor-taula { overflow-x: auto; padding-bottom: 0.5rem; }

.taula {
  display: grid;
  grid-template-columns: repeat(18, minmax(62px, 1fr));
  grid-template-rows: repeat(7, auto);
  gap: 3px;
  min-width: 1170px;
  max-width: 1400px;
  margin: 0 auto;
}

.casella {
  position: relative;
  aspect-ratio: 1 / 1.1;
  border: 1px solid rgba(0, 0, 0, 0.25);
  border-radius: 4px;
  padding: 2px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.casella .z {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 0.7rem;
  color: #333;
}
.casella .simbol { font-size: 1.35rem; font-weight: bold; margin-top: 0.5rem; }
.casella .nom {
  font-size: 0.6rem;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.casella input {
  width: 90%;
  font: inherit;
  font-weight: bold;
  text-align: center;
  padding: 1px 0;
  border: 2px dashed #555;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.85);
}
.casella input.camp-simbol { margin-top: 0.7rem; font-size: 1rem; }
.casella input.camp-nom { margin-top: 2px; font-size: 0.6rem; font-weight: normal; }
.casella input::placeholder { color: #999; font-weight: normal; }
.casella input:focus { outline: none; border-style: solid; border-color: #3949ab; }

.casella.buida { background-image: repeating-linear-gradient(45deg, rgba(255,255,255,0.35) 0 6px, transparent 6px 12px); }

.casella.correcte { box-shadow: inset 0 0 0 3px var(--correcte); }
.casella input.correcte { border: 2px solid var(--correcte); color: var(--correcte); background: white; }
.casella input.incorrecte { border: 2px solid var(--incorrecte); color: var(--incorrecte); }
.casella input.revelat { border: 2px solid var(--revelat); color: var(--revelat); background: white; }

.alcali { background-color: var(--alcali); }
.alcalinoterri { background-color: var(--alcalinoterri); }
.transicio { background-color: var(--transicio); }
.lantanid { background-color: var(--lantanid); }
.actinid { background-color: var(--actinid); }
.altre-metall { background-color: var(--altre-metall); }
.metal-loide { background-color: var(--metal-loide); }
.no-metall { background-color: var(--no-metall); }
.halogen { background-color: var(--halogen); }
.gas-noble { background-color: var(--gas-noble); }

.llegenda {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem 1rem;
  margin-top: 1rem;
  font-size: 0.9rem;
}
.llegenda span { display: inline-flex; align-items: center; gap: 0.35rem; }
.llegenda i {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

/* ---- Desar partida ---- */
.desar-partida {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  justify-content: center;
  align-items: center;
  max-width: 700px;
  margin: 0 auto 1rem;
  padding: 0.75rem 1rem;
  background: white;
  border: 2px solid #3949ab;
  border-radius: 8px;
}
.desar-partida p { margin: 0; width: 100%; text-align: center; font-weight: bold; }
.desar-partida input {
  font: inherit;
  padding: 0.4rem 0.6rem;
  border: 1px solid #888;
  border-radius: 6px;
}

/* ---- Rànquing i històric ---- */
.resultats {
  max-width: 800px;
  margin: 2rem auto 0;
}
.resultats h2 { text-align: center; margin-bottom: 0.75rem; }

.pestanyes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}
.pestanyes button { background: white; color: #3949ab; }
.pestanyes button.activa { background: #3949ab; color: white; }

.contenidor-resultats { overflow-x: auto; }

.resultats table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  font-size: 0.95rem;
}
.resultats th, .resultats td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid #ddd;
  text-align: left;
  white-space: nowrap;
}
.resultats th { background: #e8eaf6; }
.resultats tr.destacat td { background: #fff59d; font-weight: bold; }
.resultats td.buit { text-align: center; color: #777; font-style: italic; }

.etiqueta-abandonada {
  font-size: 0.75rem;
  font-weight: normal;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: #ffe0b2;
  color: #a04000;
}

.historic { margin-top: 1rem; }
.historic summary { cursor: pointer; font-weight: bold; margin-bottom: 0.5rem; }

.accions-historic {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
}
button.perill { background: white; color: #c62828; border-color: #c62828; }

.avis { text-align: center; color: #555; min-height: 1.2em; }

/* ---- Panell d'edició (només mòbil) ---- */
.panell-mobil {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: grid;
  gap: 0.6rem;
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: white;
  border-top: 2px solid #3949ab;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.15);
}
.panell-capcalera { display: flex; justify-content: space-between; align-items: center; }
.panell-element {
  font-weight: bold;
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.panell-cos { display: grid; grid-template-columns: auto 1fr; gap: 0.75rem; align-items: center; }
.panell-camps { display: grid; gap: 0.5rem; }

.mini-taula {
  display: grid;
  grid-template-columns: repeat(18, 10px);
  grid-template-rows: repeat(7, 10px);
  gap: 1px;
}
.mini-taula span { border-radius: 1px; opacity: 0.55; }
.mini-taula span.mini-buida {
  opacity: 1;
  background: white;
  outline: 1px solid #777;
  outline-offset: -1px;
  cursor: pointer;
}
.mini-taula span.mini-feta { background: var(--correcte); outline-color: var(--correcte); }
.mini-taula span.mini-activa {
  position: relative;
  z-index: 1;
  background: #3949ab;
  outline: 2px solid #3949ab;
  outline-offset: 0;
  transform: scale(1.6);
  animation: parpelleig 1.2s ease-in-out infinite;
}
@keyframes parpelleig {
  50% { opacity: 0.35; }
}
@media (prefers-reduced-motion: reduce) {
  .mini-taula span.mini-activa { animation: none; }
}
.panell-camps input {
  min-width: 0;
  font: inherit;
  font-size: 1.15rem;
  padding: 0.5rem;
  border: 2px solid #888;
  border-radius: 6px;
}
.panell-camps input:focus { outline: none; border-color: #3949ab; }
.panell-camps input.correcte { border-color: var(--correcte); color: var(--correcte); }
.panell-camps input.incorrecte { border-color: var(--incorrecte); color: var(--incorrecte); }
.panell-accions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.panell-accions button { padding: 0.6rem; }

@media (max-width: 760px) {
  body { padding: 0.75rem 1rem 2rem; }
  body.amb-panell { padding-bottom: 12rem; }
  h1 { font-size: 1.5rem; }

  .taula {
    grid-template-columns: repeat(18, minmax(30px, 1fr));
    gap: 2px;
    min-width: 574px;
  }
  .casella { aspect-ratio: 1; padding: 1px; border-radius: 3px; }
  .casella .z { font-size: 0.5rem; top: 1px; left: 2px; }
  .casella .simbol { font-size: 0.85rem; margin-top: 0.35rem; }
  .casella .nom, .casella input.camp-nom { display: none; }

  /* Els inputs de la graella només mostren l'estat: s'escriu al panell. */
  .casella.buida { cursor: pointer; }
  .casella input.camp-simbol {
    pointer-events: none;
    width: 100%;
    margin-top: 0.45rem;
    padding: 0;
    font-size: 0.75rem;
    border-width: 1px;
  }
  .casella input::placeholder { color: transparent; }
  .casella.activa { outline: 3px solid #3949ab; outline-offset: 1px; z-index: 1; }
}
