/* SimQuímica — laboratori. Botons ≥ 48 px (≥ 64 px a les pantalles 4K de l'aula). */

:root {
  --fons: #eef2f6; --superficie: #ffffff; --text: #1b2733; --suau: #5b6b7c; --vora: #d3dce6;
  --accent: #1f6feb; --accent-text: #fff; --be: #1a7f37; --avis: #9a6700; --perill: #c62828;
  --paret: #e6edf3; --taulell: #4a5866; --radi: 10px; --boto: 48px;
  font-size: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fons: #0f1720; --superficie: #17212c; --text: #e6edf3; --suau: #9fb0c2; --vora: #2b3a4a;
    --accent: #4c9aff; --accent-text: #0b1520; --be: #3fb950; --avis: #e3b341; --perill: #ff7b72;
    --paret: #1d2a36; --taulell: #39424c;
  }
}
@media (min-width: 2400px) { :root { font-size: 22px; --boto: 64px; } }

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--fons); color: var(--text); overflow: hidden; }
button { font: inherit; min-height: var(--boto); padding: 0 0.9rem; border-radius: 8px; border: 1px solid var(--vora); background: var(--superficie); color: var(--text); cursor: pointer; touch-action: manipulation; }
button:hover { border-color: var(--accent); }
button[aria-pressed="true"], button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primari { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.secundari { color: var(--suau); }
button.mini { min-height: 32px; padding: 0 0.5rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--fons); border: 1px solid var(--vora); border-radius: 8px; padding: 0.4rem 0.6rem; }
input[type="range"] { width: 100%; min-height: var(--boto); padding: 0; background: none; border: 0; accent-color: var(--accent); }

/* ── Barra superior ─────────────────────────────────────────── */
.barra { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1.2rem; padding: 0.5rem 1rem; background: var(--superficie); border-bottom: 1px solid var(--vora); }
.marca { font-size: 1.1rem; flex: 1 1 220px; }
.marca span { color: var(--suau); margin-left: 0.4rem; }
.temps, .epi, .accions-barra { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
#rellotge { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 5.5em; }

/* ── Cos: prestatge | banc | lateral ────────────────────────── */
.lab-cos { display: grid; grid-template-columns: 15.5rem 1fr 22.5rem; height: calc(100vh - 66px); }
@media (min-width: 2400px) { .lab-cos { height: calc(100vh - 88px); } }
#prestatge, #lateral { background: var(--superficie); overflow: auto; display: flex; flex-direction: column; }
#prestatge { border-right: 1px solid var(--vora); }
#lateral { border-left: 1px solid var(--vora); }
.pestanyes { display: flex; gap: 0.3rem; padding: 0.5rem; position: sticky; top: 0; background: var(--superficie); z-index: 1; border-bottom: 1px solid var(--vora); }
.pestanyes button { flex: 1; }
.contingut-prestatge { padding: 0.5rem 0.7rem 1.5rem; }
.seccio-prestatge h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--suau); margin: 0.9rem 0 0.4rem; }
.llista-prestatge { display: grid; gap: 0.3rem; }
.item-prestatge { text-align: left; min-height: 44px; font-size: 0.92rem; }
.item-prestatge.destacat { border-color: var(--accent); }

#banc-contenidor { overflow: auto; background: var(--paret); touch-action: pan-x pan-y; }
#banc { display: block; user-select: none; -webkit-user-select: none; touch-action: none; }
#banc .paret { fill: var(--paret); }
#banc .taulell { fill: var(--taulell); }
#banc .vora-taulell { stroke: #2d3640; stroke-width: 3; }
#banc .obj { cursor: grab; }
#banc .zona { fill: transparent; stroke: none; }
#banc .seleccionat .zona { fill: rgba(31, 111, 235, 0.08); stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; }
#banc .objectiu .zona { fill: rgba(26, 127, 55, 0.12); stroke: var(--be); stroke-width: 3; }
#banc .etiqueta-banc { fill: #e6edf3; font-size: 12px; }

.panell-lateral { padding: 0.8rem 1rem 2rem; }
.panell-lateral h2 { margin: 0.2rem 0 0.6rem; font-size: 1.15rem; }
.panell-lateral button { margin: 0.2rem 0.2rem 0.2rem 0; }
.panell-buit, .buit, .ajuda, .nota { color: var(--suau); font-size: 0.9rem; }
.observacio { background: var(--fons); border-radius: 8px; padding: 0.6rem 0.8rem; }
.pantalla { background: #13221a; color: #7dff8a; font-family: ui-monospace, Consolas, monospace; border-radius: 8px; padding: 0.6rem 0.8rem; margin: 0.4rem 0; }
.pantalla.gran { font-size: 1.6rem; }
.pantalla strong { font-weight: 700; }
.pantalla .estable { font-size: 0.75rem; opacity: 0.8; margin-left: 0.4rem; }
details.diari { margin-top: 0.7rem; font-size: 0.85rem; }
details.diari summary { cursor: pointer; font-weight: 600; }
details.diari ol { list-style: none; padding: 0; margin: 0.3rem 0; max-height: 14rem; overflow: auto; }
details.diari li { padding: 0.25rem 0; border-bottom: 1px solid rgba(120, 140, 160, 0.25); }
.hora { font-family: ui-monospace, Consolas, monospace; opacity: 0.7; margin-right: 0.3rem; }
ul.canals { list-style: none; padding: 0; margin: 0.4rem 0; }
ul.canals li { display: flex; align-items: center; gap: 0.35rem; padding: 0.15rem 0; }
.marca-canal { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 50%; flex: none; }
button.petit { min-height: 0; padding: 0.1rem 0.45rem; font-size: 0.8rem; margin-left: auto; }
.grafica-viva svg, .grafica-canals { width: 100%; height: auto; display: block; margin: 0.4rem 0; }
.camp-poe { display: block; margin: 0.5rem 0; font-weight: 600; }
.camp-poe textarea, input.equacio { display: block; width: 100%; box-sizing: border-box; margin-top: 0.2rem; font: inherit; font-weight: 400; padding: 0.4rem; }
.bloquejat { padding: 0.5rem 0.7rem; border-radius: 8px; background: rgba(127, 127, 127, 0.12); }
.resultat-equacio { font-weight: 600; }
.lupa-particules { width: 100%; max-width: 420px; height: auto; display: block; }
.llegenda-lupa { list-style: none; padding: 0; margin: 0.4rem 0; display: flex; flex-wrap: wrap; gap: 0.3rem 0.9rem; font-size: 0.9rem; }
.llegenda-lupa li { display: flex; align-items: center; gap: 0.3rem; }
.barres-log { display: grid; gap: 0.2rem; margin: 0.4rem 0; }
.barra-log { display: grid; grid-template-columns: 8.5rem 1fr 6.5rem; align-items: center; gap: 0.4rem; font-size: 0.85rem; }
.barra-log .barra { height: 0.7rem; background: #457b9d; border-radius: 3px; }
.barra-log .nom { font-family: ui-monospace, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; }
details.veritat { margin-top: 0.6rem; padding: 0.4rem 0.6rem; border-radius: 8px; background: rgba(233, 196, 106, 0.15); }
details.veritat summary { cursor: pointer; font-weight: 600; }
table.veritat td { padding: 0.1rem 0.5rem; }
body.mode-professor #professor-btn { background: #e9c46a; color: #222; }
.targeta-practica.repte { border-color: #e9c46a; box-shadow: inset 4px 0 0 #e9c46a; }
.nivell-prestatge { margin: 0.4rem 0.6rem; font-size: 0.9rem; }
#banc-contenidor { position: relative; }
#obs-gran { position: absolute; top: 0.5rem; left: 0.5rem; right: 0.5rem; z-index: 2; padding: 0.6rem 1rem; border-radius: 10px; pointer-events: none;
  background: rgba(255, 255, 255, 0.92); color: #123; font-size: 1.6rem; font-weight: 600; line-height: 1.3; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15); }
body.mode-demo { font-size: 120%; }
body.mode-demo .toast { font-size: 1.3rem; }
body.mode-demo #demo-btn { background: #2a9d8f; color: #fff; }
.opcions-repte { display: flex; gap: 1rem; flex-wrap: wrap; margin: 0.4rem 0; }
.resposta-repte { margin: 0.6rem 0; }
.resultat-repte { font-weight: 600; }
.grup-botons { display: flex; flex-wrap: wrap; gap: 0.2rem; margin: 0.4rem 0; }
.control { display: block; margin: 0.6rem 0; }
.ghs-fila { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.4rem 0; }
.sense-perill { color: var(--suau); font-size: 0.9rem; }
.frases-h { padding-left: 1.1rem; font-size: 0.9rem; }
.frases-h li { margin: 0.2rem 0; }
.peu-panell { margin-top: 1.2rem; border-top: 1px solid var(--vora); padding-top: 0.6rem; }

.passos { padding-left: 1.3rem; }
.passos li { margin: 0.45rem 0; color: var(--suau); }
.passos li.actual { color: var(--text); font-weight: 600; }
.passos li.fet { color: var(--be); text-decoration: line-through; text-decoration-color: rgba(26, 127, 55, 0.4); }
.passos li.fet::marker { content: "✓ "; }
.nivell { color: var(--suau); font-size: 0.85rem; }
.nota-seguretat { background: rgba(198, 40, 40, 0.08); border-left: 4px solid var(--perill); padding: 0.5rem 0.7rem; border-radius: 6px; margin: 0.8rem 0; }
.comprova { margin-top: 1rem; padding: 0.7rem; background: var(--fons); border-radius: 8px; }
.comprova input { width: 9em; min-height: var(--boto); }
.be { color: var(--be); }

.taula { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.taula th, .taula td { text-align: left; padding: 0.3rem 0.35rem; border-bottom: 1px solid var(--vora); vertical-align: top; }
.taula .num { text-align: right; }
.nota-quadern { display: flex; flex-direction: column; gap: 0.2rem; margin-top: 0.8rem; }
.fila-botons { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.4rem; }

/* ── Inici ──────────────────────────────────────────────────── */
.inici { position: fixed; inset: 0; background: var(--fons); overflow: auto; z-index: 20; }
.inici[hidden] { display: none; }
.inici-cos { max-width: 1100px; margin: 0 auto; padding: 2rem 1.2rem 4rem; }
.inici h1 { font-size: 2.2rem; margin: 0 0 0.5rem; }
.intro { font-size: 1.1rem; color: var(--suau); max-width: 60ch; }
.inici-botons { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin: 1.2rem 0 2rem; }
button.gran { min-height: 64px; font-size: 1.15rem; padding: 0 1.6rem; }
.enllac { color: var(--accent); }
.filtre { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.graella-practiques { display: grid; gap: 0.8rem; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.targeta-practica { display: flex; flex-direction: column; align-items: flex-start; gap: 0.3rem; text-align: left; padding: 1rem; min-height: 150px; }
.targeta-practica .icona { font-size: 1.8rem; }
.targeta-practica .desc { color: var(--suau); font-size: 0.92rem; }
.targeta-practica[hidden] { display: none; }

/* ── Diàlegs i avisos ───────────────────────────────────────── */
.dialeg { border: 1px solid var(--vora); border-radius: 14px; background: var(--superficie); color: var(--text); padding: 1.2rem 1.4rem; max-width: min(560px, 94vw); }
.dialeg::backdrop { background: rgba(10, 20, 30, 0.45); }
.dialeg h2 { margin: 0 0 0.8rem; font-size: 1.2rem; }
.dialeg-botons { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 1rem; }
.dialeg-botons .tanca { color: var(--suau); }
.camp-nombre input { width: 8em; min-height: var(--boto); font-size: 1.2rem; }
.rapids { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.6rem; }
.boto-camp { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; padding: 0.4rem 0.6rem; border: 1px dashed var(--vora); border-radius: 8px; }
.boto-camp label { flex: 1; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.boto-camp input { width: 6.5em; min-height: var(--boto); font-size: 1.1rem; }
.boto-camp input:invalid { border-color: var(--perill); }
.lupa { width: 100%; max-width: 260px; display: block; margin: 0 auto; border-radius: 8px; }
.toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: 0.4rem; z-index: 50; width: min(420px, 94vw); pointer-events: none; }
body.amb-informe .toasts { display: none; }
.toast { background: var(--superficie); border: 1px solid var(--vora); border-left: 5px solid var(--accent); border-radius: 8px; padding: 0.6rem 0.9rem; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); transition: opacity 0.4s; }
.toast-be { border-left-color: var(--be); }
.toast-avis { border-left-color: var(--avis); }
.toast-perill { border-left-color: var(--perill); font-weight: 600; }
.toast.fora { opacity: 0; }

/* ── Informe (pantalla i impressió) ─────────────────────────── */
#informe { position: fixed; inset: 0; z-index: 30; background: #e9edf2; overflow: auto; color: #111; }
#informe[hidden] { display: none; }
.informe-barra { position: sticky; top: 0; display: flex; gap: 0.5rem; padding: 0.6rem; background: #fff; border-bottom: 1px solid #ccc; }
.informe-paper { max-width: 800px; margin: 1rem auto 3rem; background: #fff; padding: 2rem 2.4rem; border-radius: 6px; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1); }
.informe-paper h1 { margin: 0 0 0.2rem; }
.informe-paper h2 { font-size: 1.1rem; border-bottom: 2px solid #1f6feb; padding-bottom: 0.2rem; margin-top: 1.6rem; }
.informe-paper input, .informe-paper textarea { width: 100%; background: #fff; color: #111; border: 1px solid #bbb; }
.informe-paper .taula th, .informe-paper .taula td { border-bottom: 1px solid #ddd; }
.grafica-informe { width: 100%; height: auto; }
@media print {
  @page { size: A4; margin: 15mm; }
  body { overflow: visible; background: #fff; }
  body.amb-informe > *:not(#informe) { display: none !important; }
  #informe { position: static; background: #fff; overflow: visible; }
  .no-imprimir { display: none !important; }
  .informe-paper { box-shadow: none; margin: 0; padding: 0; max-width: none; }
  .informe-paper textarea { border: none; border-bottom: 1px solid #999; resize: none; }
}

/* ── Mòbil i tauleta vertical ───────────────────────────────── */
@media (max-width: 900px) {
  body { overflow: auto; }
  .lab-cos { display: flex; flex-direction: column; height: auto; }
  #banc-contenidor { order: 1; height: 55vh; }
  /* Al mòbil, el prestatge just davall del banc (amb desplaçament propi) i el panell després */
  #prestatge { order: 2; border: 0; border-top: 1px solid var(--vora); max-height: 38vh; overflow: auto; }
  #lateral { order: 3; border: 0; border-top: 1px solid var(--vora); max-height: none; }
  #obs-gran { font-size: 1.1rem; }
  .barra { gap: 0.4rem; }
  .accions-barra button, .epi button { padding: 0 0.6rem; }
}
