/* ============================================================
   J-hoot — identitat visual
   Tinta fosca + 4 colors de resposta inspirats en les fitxes
   de tota la vida a classe: cada opció té la seva forma I el seu
   color, perquè es reconeguin també sense necessitat de llegir.
   Els botons, xips i files tenen un relleu tipus "fitxa de joc de
   taula" (ombra sòlida inferior que es "prem" en fer clic).
   ============================================================ */

:root {
  --ink: #14142B;
  --ink-soft: #1E1E40;
  --paper: #F4F1EA;
  --accent: #6C5CE7;
  --accent-soft: #8B7EF0;

  --opt-red: #E84142;
  --opt-blue: #1A6DFF;
  --opt-yellow: #FFC700;
  --opt-green: #2BB673;

  --gold: #FFC700;
  --silver: #C9CEDB;
  --bronze: #D98A4E;

  --ok: #2BB673;
  --ko: #E84142;

  --radius: 18px;
  --radius-sm: 12px;
  --bevel: rgba(0, 0, 0, 0.28);

  --space-1: 6px;
  --space-2: 10px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;

  /* Fredoka: rodona i contundent, per a titulars, botons, números i xifres grans.
     Nunito: també rodona però més neutra, per a text corregut i llegibilitat. */
  --font-display: 'Fredoka', sans-serif;
  --font-body: 'Nunito', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  min-height: 100vh;
  line-height: 1.6;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-image:  linear-gradient(180deg, rgba(20, 20, 43, 0.55) 0%, rgba(20, 20, 43, 0.88) 100%), url("../background1.png");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 700; letter-spacing: -0.01em; margin: 0; }
section { text-align: center; }

.screen {
  width: 100%;
  max-width: 1280px;
  padding: var(--space-5) var(--space-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  flex: 1;
}
#screen-setup { align-items: center; text-align: center; }
#quiz-list { justify-content: center; }
#screen-join { margin-top: var(--space-4); }
#quiz-list button { margin: var(--space-3) 0; }

.hidden { display: none !important; }

/* --- Marca --- */
.brand {
  font-family: var(--font-display);
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  font-size: 64px;
}
.brand .j { text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25); color: var(--opt-yellow); }
.brand .hoot { text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25); color: var(--paper); }

/* --- Codi de sala: fitxa tipus "etiqueta de pupitre" --- */
.room-code {
  display: flex;
  gap: 10px;
  margin: 8px 0;
  align-content: center;
  justify-content: center;
}
.room-code .tile {
  width: 64px;
  height: 80px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--ink);
  box-shadow: 0 6px 0 var(--bevel);
}
.room-code .tile:nth-child(1) { background: var(--opt-red); color: white; }
.room-code .tile:nth-child(2) { background: var(--opt-blue); color: white; }
.room-code .tile:nth-child(3) { background: var(--opt-yellow); }
.room-code .tile:nth-child(4) { background: var(--opt-green); color: white; }

.subtle { opacity: 0.75; font-size: 15px; }

/* --- Formularis --- */
input[type="text"] {
  font-family: var(--font-body);
  font-size: 20px;
  font-weight: 700;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: none;
  outline: none;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
}
input[type="text"]:focus-visible { box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 0 0 3px var(--accent-soft); }
button {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  padding: 14px 28px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  background: var(--accent);
  color: white;
  box-shadow: 0 5px 0 var(--bevel);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--bevel); }
button:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
button.secondary { background: var(--ink-soft); }
button.big { font-size: 24px; padding: 18px 40px; margin: 5vw; }
button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--paper);
  outline-offset: 2px;
}

/* --- Barra de temps: degradat verd→groc→vermell fix a l'amplada
   màxima de la pista, ancorat a la dreta. Com que l'element de
   progrés s'estreny des de la dreta, ensenya cada cop més "vermell"
   sense necessitat de cap càlcul des de JS. --- */
.timer-bar {
  width: 100%;
  max-width: 600px;
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
  margin: 10px auto;
}
.timer-bar > div {
  height: 100%;
  border-radius: 999px;
  background-image: linear-gradient(to right, var(--opt-green), var(--opt-yellow), var(--opt-red));
  background-size: 600px 100%;
  background-position: right center;
  background-repeat: no-repeat;
  transition: width 0.2s linear;
}

/* --- Pregunta --- */
.question-text {
  font-size: clamp(22px, 4vw, 38px);
  font-weight: 700;
  text-align: center;
  max-width: 900px;
  line-height: 1.4;
  margin-bottom: 25px;
}
.question-image {
  max-width: 100%;
  max-height: 250px;
  margin: var(--space-3); 
  width: auto;
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  object-fit: contain;
}
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  width: 100%;
  max-width: 800px;
}
@media (max-width: 560px) {
  .options-grid { grid-template-columns: 1fr; }
}
.option-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 22px 20px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 20px;
  font-weight: 700;
  color: white;
  text-align: left;
  min-height: 70px;
  box-shadow: 0 5px 0 var(--bevel);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.15s ease, opacity 0.2s ease;
}
.option-btn:hover:not(:disabled) { filter: brightness(1.06); }
.option-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--bevel); }
.option-btn .shape { font-size: 26px; line-height: 1; }
.option-btn:nth-child(1) { background: var(--opt-red); }
.option-btn:nth-child(2) { background: var(--opt-blue); }
.option-btn:nth-child(3) { background: var(--opt-yellow); color: var(--ink); }
.option-btn:nth-child(4) { background: var(--opt-green); }
.option-btn.dimmed { opacity: 0.35; box-shadow: none; }
.option-btn.correct-pulse { outline: 4px solid white; }

/* --- Lobby / llista de jugadors --- */
.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 400px;
  margin-top: var(--space-3);
}
.player-chip {
  background: var(--ink-soft);
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 3px 0 var(--bevel);
}

/* --- Classificació --- */
.leaderboard-list {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--ink-soft);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  font-size: 18px;
  font-weight: 600;
  box-shadow: 0 3px 0 var(--bevel);
}
.leaderboard-row .rank {
  font-family: var(--font-display);
  font-weight: 700;
  width: 28px;
  color: var(--opt-yellow);
}
.leaderboard-row .name { flex: 1; }
.leaderboard-row .score { font-weight: 700; }
.leaderboard-row.me { outline: 2px solid var(--accent); }

/* Medalles pel top 3: és un rànquing real, no decoració. */
.leaderboard-row:nth-child(1) { background: linear-gradient(135deg, #FFE8A3, var(--gold)); color: var(--ink); }
.leaderboard-row:nth-child(1) .rank { color: var(--ink); }
.leaderboard-row:nth-child(2) { background: linear-gradient(135deg, #EDEFF5, var(--silver)); color: var(--ink); }
.leaderboard-row:nth-child(2) .rank { color: var(--ink); }
.leaderboard-row:nth-child(3) { background: linear-gradient(135deg, #F0BD8C, var(--bronze)); color: var(--ink); }
.leaderboard-row:nth-child(3) .rank { color: var(--ink); }

/* --- Resultat individual (alumne) --- */
.result-banner {
  width: 100%;
  max-width: 420px;
  padding: 28px;
  border-radius: var(--radius);
  text-align: center;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  box-shadow: 0 6px 0 var(--bevel);
}
.result-banner.ok { background: var(--ok); }
.result-banner.ko { background: var(--ko); }
.result-points { font-family: var(--font-body); font-size: 16px; font-weight: 700; opacity: 0.9; margin-top: 6px; }

/* --- Barres de recompte de respostes (revelar, host) --- */
.bars {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bar-row { display: flex; align-items: center; gap: 12px; }
.bar-row .label { width: 220px; font-weight: 700; font-size: 15px; text-align: left; }
.bar-track { flex: 1; background: rgba(255, 255, 255, 0.1); border-radius: 8px; height: 26px; overflow: hidden; }
.bar-fill { height: 100%; transition: width 0.5s ease; }
.bar-row .count { width: 36px; text-align: right; font-weight: 700; }

footer.foot {padding: 16px; font-size: 13px; opacity: 0.55;  text-align: center;}
footer.foot a { color: var(--paper); }

.error-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ko);
  color: white;
  padding: 12px 22px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.text-answer-input {width: 100%; max-width: 420px;}

#btn-reveal {margin-top: var(--space-6);}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
