@import url("https://fonts.googleapis.com/css2?family=Montserrat:wght@600;700&family=Roboto:wght@400;500;700&display=swap");

:root {
  --paper: #fbf8f1;
  --card: #ffffff;
  --ink: #2b2a27;
  --muted: #6d6a62;
  --line: #e6e0d2;
  --green: #5f8f3e;
  --green-soft: #dfe9cf;
  --orange: #d9772b;
  --orange-soft: #fbe2cf;
  --red: #b54434;
  --radius: 14px;
  --hand: "Montserrat", system-ui, sans-serif;
  --body: "Roboto", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.5;
}
h1, h2, h3 { font-family: var(--hand); font-weight: 700; margin: 0; line-height: 1.15; letter-spacing: -0.01em; }
button, select, textarea, input { font: inherit; color: inherit; }

.btn {
  border: 1.5px solid var(--ink);
  background: var(--card);
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  font-weight: 700;
  transition: transform .08s ease, background .15s;
}
.btn:hover { background: #f3efe4; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primari { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primari:hover { background: #527d35; }
.btn.suau { border-color: var(--line); color: var(--muted); font-weight: 600; }
.btn.perill { border-color: var(--red); color: var(--red); }
.btn.petit { padding: 5px 12px; font-size: 14px; }

.xip {
  display: inline-block;
  background: var(--orange-soft);
  color: #8a4614;
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 14px;
  font-weight: 600;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 20px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 50; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.avis-demo {
  background: #fff4c2; border-bottom: 1px solid #e8d77a; text-align: center;
  font-size: 14px; padding: 6px 16px;
}

/* ───────── Pàgina alumnes ───────── */
.alumne { max-width: 640px; margin: 0 auto; padding: 24px 16px 60px; }
.alumne header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 18px; }
.alumne header h1 { font-size: 24px; }
.comptador { color: var(--muted); font-size: 15px; white-space: nowrap; }

.tarja {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-top: 8px solid var(--green);
  border-radius: var(--radius);
  padding: 26px 24px 22px;
  box-shadow: 0 6px 20px rgba(60, 50, 20, .06);
  animation: entra .3s ease;
}
@keyframes entra { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.tarja .nom { font-size: 32px; color: var(--green); }
.tarja .def { color: var(--muted); margin: 6px 0 18px; font-size: 16px; }
.tarja label { font-weight: 700; display: block; margin-bottom: 6px; }
.tarja textarea {
  width: 100%; min-height: 140px; resize: vertical;
  border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fffdf8;
}
.tarja textarea:focus, .tarja select:focus { outline: 2px solid var(--green); outline-offset: 1px; border-color: transparent; }
.ajuda { font-size: 14px; color: var(--muted); margin-top: 4px; min-height: 1.4em; }
.ajuda.alerta { color: var(--orange); }
.bloc-nec { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.bloc-nec select { width: 100%; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: #fffdf8; }
.def-nec { font-size: 14px; color: #8a4614; margin-top: 6px; min-height: 1.4em; }
.accions { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin-top: 20px; }

.recordatori { font-size: 14px; color: var(--muted); text-align: center; margin-top: 18px; }

.pantalla-msg { text-align: center; padding: 60px 16px; }
.pantalla-msg .icona { font-size: 56px; }
.pantalla-msg h2 { font-size: 28px; margin: 10px 0; }
.pantalla-msg p { color: var(--muted); max-width: 440px; margin: 0 auto; }

.banner-tancat {
  background: var(--orange-soft); color: #8a4614; border-radius: 10px;
  padding: 10px 14px; margin-bottom: 14px; font-weight: 600; text-align: center;
}

/* ───────── Panell ───────── */
.panell { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.barra { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.barra h1 { font-size: 24px; }
.usuari { color: var(--muted); font-size: 14px; display: flex; gap: 10px; align-items: center; }

.controls {
  display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 20px;
}
.control h3 { font-family: var(--body); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; font-weight: 700; }
.fila { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.fila input, .fila select { border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fffdf8; min-width: 0; flex: 1; }
.estat { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.estat::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.estat.obert { color: var(--green); } .estat.obert::before { background: var(--green); }
.estat.tancat { color: var(--red); } .estat.tancat::before { background: var(--red); }

.resum { color: var(--muted); margin-bottom: 12px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }

.graella { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.rajola { min-width: 0; overflow: hidden; }
.rajola {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px 14px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 4px;
  transition: border-color .15s, transform .08s;
}
.rajola:hover { border-color: var(--green); }
.rajola .n { font-size: 13px; color: var(--muted); }
.rajola .t { font-family: var(--hand); font-weight: 600; font-size: 15px; line-height: 1.1; overflow-wrap: anywhere; hyphens: auto; }
.rajola .t { word-break: break-word; }
.rajola .c { font-size: 14px; font-weight: 700; color: var(--green); }
.rajola.buida { opacity: .55; }
.rajola.buida .c { color: var(--muted); font-weight: 600; }

.detall-cap { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.detall-cap h2 { font-size: 40px; color: var(--green); flex: 1; min-width: 200px; }
.detall-def { color: var(--muted); font-size: 18px; margin-bottom: 14px; }
.necs-resum { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; align-items: center; }
.necs-resum span.et { font-size: 14px; color: var(--muted); margin-right: 4px; }

/* Respostes com a bambolles de diàleg */
.respostes { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 34px 24px; align-items: start; padding-top: 34px; }
.resposta {
  position: relative; outline: none;
  --bub: #eef4e6; --bub-vora: #cfe0bb;
}
.resposta:nth-child(4n+2) { --bub: #fdf0e3; --bub-vora: #f3d3b3; }
.resposta:nth-child(4n+3) { --bub: #e8f1f6; --bub-vora: #c3d9e6; }
.resposta:nth-child(4n+4) { --bub: #f6ecf4; --bub-vora: #e2c8dc; }
.bambolla {
  position: relative; background: var(--bub); border: 2px solid var(--bub-vora);
  border-radius: 26px; padding: 20px 24px; margin-bottom: 14px;
  box-shadow: 0 4px 14px rgba(60, 50, 20, .06); transition: transform .15s ease, box-shadow .15s ease;
}
/* cua de la bambolla */
.bambolla::after, .bambolla::before {
  content: ""; position: absolute; left: 30px; border-style: solid; border-color: transparent;
}
.bambolla::before { bottom: -16px; border-width: 16px 14px 0 0; border-top-color: var(--bub-vora); }
.bambolla::after  { bottom: -12px; left: 32px; border-width: 13px 11px 0 0; border-top-color: var(--bub); }
.resposta:hover .bambolla, .resposta:focus-visible .bambolla, .resposta.obert .bambolla {
  transform: translateY(-2px); box-shadow: 0 10px 24px rgba(60, 50, 20, .12);
}
.bambolla p { margin: 0; font-size: 20px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }

/* indicador que té necessitat + etiqueta que apareix en passar per sobre */
.te-nec { position: absolute; right: 14px; bottom: 8px; font-size: 16px; opacity: .55; }
.nec-hover {
  position: absolute; left: 50%; top: 0; z-index: 5;
  transform: translate(-50%, -90%); opacity: 0; pointer-events: none;
  background: var(--orange); color: #fff; border-radius: 999px; padding: 6px 16px;
  font-size: 16px; white-space: nowrap; box-shadow: 0 6px 16px rgba(217, 119, 43, .3);
  transition: opacity .15s ease, transform .15s ease;
}
.resposta:hover .nec-hover, .resposta:focus-visible .nec-hover, .resposta.obert .nec-hover {
  opacity: 1; transform: translate(-50%, -125%);
}

/* botó d'esborrar a la cantonada, visible en passar per sobre */
.btn-esborrar {
  position: absolute; top: -12px; right: -10px; z-index: 6;
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--red);
  background: #fff; color: var(--red); font-size: 16px; line-height: 1; cursor: pointer;
  opacity: 0; transform: scale(.8); transition: opacity .15s, transform .15s;
}
.resposta:hover .btn-esborrar, .resposta:focus-within .btn-esborrar, .resposta.obert .btn-esborrar { opacity: 1; transform: scale(1); }
.btn-esborrar:hover { background: var(--red); color: #fff; }

.resposta .peu { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding-left: 12px; }
.grup-tag { font-size: 13px; color: var(--muted); }
.resposta.amagada .bambolla { opacity: .45; border-style: dashed; }
.resposta.amagada .bambolla p { text-decoration: line-through; }
.buit { color: var(--muted); padding: 30px 0; text-align: center; }

/* Mode projector: lletra gran, sense controls, només respostes visibles */
body.projector .controls, body.projector .barra, body.projector .nomes-revisio,
body.projector .resposta .peu, body.projector .resposta.amagada, body.projector .avis-demo { display: none !important; }
body.projector .panell { max-width: none; padding: 28px 40px; }
body.projector .detall-cap h2 { font-size: 64px; }
body.projector .detall-def { font-size: 24px; }
body.projector .bambolla { padding: 24px 28px; }
body.projector .bambolla p { font-size: 28px; }
body.projector .nec-hover { font-size: 20px; }
body.projector .respostes { grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 44px 32px; }
body.projector .necs-resum { display: none; }
.sortir-proj { display: none; }
body.projector .sortir-proj { display: inline-block; position: fixed; top: 12px; right: 12px; opacity: .3; z-index: 10; }
body.projector .sortir-proj:hover { opacity: 1; }

/* Overlay enllaç + QR */
.overlay {
  position: fixed; inset: 0; background: rgba(251, 248, 241, .98); z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 24px; text-align: center;
}
.overlay[hidden] { display: none; }
.overlay h2 { font-size: 40px; }
.overlay .url { font-size: clamp(20px, 3.5vw, 40px); font-weight: 700; color: var(--green); word-break: break-all; }
.overlay #qr { background: #fff; padding: 16px; border-radius: 16px; border: 1.5px solid var(--line); }
.overlay #qr img, .overlay #qr canvas { display: block; }
.overlay .grup-gran { font-size: 22px; color: var(--muted); }

.login { text-align: center; padding: 80px 16px; }
.login h1 { font-size: 32px; margin-bottom: 10px; }
.login p { color: var(--muted); margin-bottom: 24px; }
.error { color: var(--red); margin-top: 12px; }

@media (max-width: 560px) {
  .tarja { padding: 22px 18px 18px; }
  .tarja .nom { font-size: 26px; }
  .accions .btn { flex: 1; }
  .detall-cap h2 { font-size: 30px; }
}
