
:root {
  --bg: #f6f8fc;
  --card: #ffffff;
  --text: #243042;
  --muted: #607086;
  --primary: #3b82f6;
  --primary-dark: #1d4ed8;
  --accent: #10b981;
  --danger: #ef4444;
  --shadow: 0 14px 40px rgba(27, 54, 93, 0.12);
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: linear-gradient(180deg, #eff4ff 0%, var(--bg) 100%); color: var(--text); }
body { min-height: 100vh; }
button, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

#app { max-width: 1320px; margin: 0 auto; padding: 24px; }

#pantalla-inicial, #pantalla-joc { background: rgba(255,255,255,0.72); backdrop-filter: blur(8px); border: 1px solid rgba(255,255,255,0.6); box-shadow: var(--shadow); border-radius: 28px; }
#pantalla-inicial { padding: 36px; text-align: center; }
#pantalla-joc { display: none; grid-template-columns: 1fr 340px; gap: 22px; padding: 24px; align-items: start; }

.hero-emoji { font-size: 4rem; line-height: 1; margin-bottom: 8px; }
h1 { margin: 0; font-size: clamp(2rem, 3vw, 3rem); }
.subtitol { color: var(--muted); max-width: 760px; margin: 12px auto 0; font-size: 1.05rem; }

.config-box { margin: 28px auto 18px; max-width: 700px; background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); text-align: left; }
.config-box label { display: block; font-weight: 700; margin-bottom: 10px; }
#selector-tema { width: 100%; border-radius: 14px; border: 1px solid #dce6f4; padding: 14px 16px; background: #fbfdff; }
.preview-card { margin-top: 16px; display: flex; gap: 14px; align-items: center; padding: 16px; background: linear-gradient(180deg, #f8fbff 0%, #eef5ff 100%); border-radius: 18px; min-height: 96px; }
.preview-mini, .emoji-modal { width: 64px; height: 64px; display: grid; place-items: center; font-size: 2rem; border-radius: 18px; background: #ffffff; box-shadow: inset 0 0 0 1px #d9e7fb; flex: 0 0 auto; }
.preview-mini-title { font-weight: 800; }
.preview-mini-text { color: var(--muted); margin-top: 4px; }
.pregunta-jugadors { margin-top: 18px; font-weight: 700; }
.selector-jugadors { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; }
.btn-jugadors { background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%); color: white; border: none; border-radius: 18px; padding: 14px 20px; min-width: 170px; box-shadow: var(--shadow); }
.btn-jugadors:hover { transform: translateY(-1px); }
.btn-jugadors .num { font-size: 1.4rem; font-weight: 800; }
.nota { color: var(--muted); margin-top: 18px; }

#taulell-container { background: var(--card); border-radius: 24px; box-shadow: var(--shadow); padding: 18px; min-height: 640px; }
#taulell { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 12px; }
.casella { min-height: 108px; border-radius: 18px; background: linear-gradient(180deg, #ffffff 0%, #f5f8ff 100%); border: 1px solid #dfe8f6; padding: 10px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.casella.start { border-color: #86efac; background: linear-gradient(180deg, #f0fdf4 0%, #dcfce7 100%); }
.casella.end { border-color: #fca5a5; background: linear-gradient(180deg, #fff1f2 0%, #ffe4e6 100%); }
.casella.current { outline: 3px solid rgba(59,130,246,0.35); transform: translateY(-1px); }
.casella-top { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.casella-num { font-weight: 800; color: #526174; }
.casella-label { font-size: 0.82rem; color: var(--muted); }
.token-stack { display: flex; flex-wrap: wrap; gap: 6px; min-height: 18px; }
.token { width: 16px; height: 16px; border-radius: 999px; border: 2px solid white; box-shadow: 0 2px 4px rgba(0,0,0,0.18); }
.casella-points { font-size: 0.78rem; color: var(--muted); }

#panell { background: var(--card); border-radius: 24px; box-shadow: var(--shadow); padding: 20px; position: sticky; top: 18px; }
#game-title { margin-top: 0; margin-bottom: 10px; }
.game-theme-line { display: flex; align-items: center; gap: 10px; margin-top: 0; color: var(--muted); }
#game-emoji { font-size: 1.6rem; }
#info-torn { margin: 18px 0; padding: 14px 16px; background: #f8fbff; border-radius: 18px; border: 1px solid #e3ecfb; }
.torn-label { display: block; color: var(--muted); margin-bottom: 6px; }
.torn-jugador { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.torn-color { width: 16px; height: 16px; border-radius: 999px; display: inline-block; }

#dau-container { text-align: center; display: grid; gap: 12px; margin: 18px 0; }
#dau { width: 90px; height: 90px; margin: 0 auto; background: linear-gradient(180deg, #ffffff 0%, #f3f7ff 100%); border: 1px solid #dce6f4; border-radius: 22px; display: grid; place-items: center; font-size: 2rem; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.8); }
#btn-tirar, .btn-reiniciar, .answer-btn, #btn-seguent { border: none; border-radius: 16px; padding: 12px 16px; }
#btn-tirar { background: linear-gradient(180deg, var(--accent) 0%, #059669 100%); color: white; font-weight: 800; }
#btn-tirar[disabled] { opacity: 0.55; cursor: not-allowed; }
.btn-reiniciar { width: 100%; margin-top: 16px; background: #eef4ff; color: var(--primary-dark); font-weight: 700; }

#classificacio h3 { margin: 10px 0 8px; }
#scoreboard { display: grid; gap: 10px; }
.score-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: #f8fbff; border: 1px solid #e3ecfb; border-radius: 16px; padding: 10px 12px; }
.score-left { display: flex; align-items: center; gap: 10px; }
.score-chip { width: 14px; height: 14px; border-radius: 999px; }
.score-meta { color: var(--muted); font-size: 0.9rem; }
.score-value { font-weight: 800; }

#registre { margin-top: 16px; max-height: 310px; overflow: auto; display: grid; gap: 10px; }
.entry { padding: 10px 12px; border-radius: 14px; background: #f8fbff; border: 1px solid #e3ecfb; font-size: 0.95rem; }
.entry-muted { color: var(--muted); }
.entry-good { background: #f0fdf4; border-color: #bbf7d0; }
.entry-bad { background: #fff1f2; border-color: #fecdd3; }
.entry-info { background: #eff6ff; border-color: #bfdbfe; }

#modal-overlay { position: fixed; inset: 0; background: rgba(18, 32, 52, 0.48); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
#modal-overlay.open { display: flex; }
#modal { width: min(760px, 96vw); background: #ffffff; border-radius: 26px; box-shadow: 0 28px 80px rgba(0,0,0,0.22); padding: 24px; position: relative; }
#modal-close { position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 999px; border: none; background: #eef4ff; color: var(--primary-dark); font-weight: 900; }
.modal-image { width: 100%; max-height: 260px; object-fit: contain; background: #f7f9fc; border: 1px solid #e3ecfb; border-radius: 18px; margin: 14px 0 10px; }
.pregunta-text { font-size: 1.1rem; line-height: 1.55; }
.opcions { display: grid; gap: 10px; margin-top: 18px; }
.answer-btn { background: #f8fbff; color: var(--text); border: 1px solid #dfe8f6; text-align: left; font-weight: 600; }
.answer-btn:hover { border-color: #93c5fd; background: #eff6ff; }
.answer-btn.correct { background: #ecfdf5; border-color: #86efac; }
.answer-btn.wrong { background: #fff1f2; border-color: #fda4af; }
.resultat-text { min-height: 24px; margin-top: 16px; font-weight: 700; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
#btn-seguent { background: var(--primary); color: white; font-weight: 800; }

@media (max-width: 980px) {
  #pantalla-joc { grid-template-columns: 1fr; }
  #panell { position: static; }
}

@media (max-width: 640px) {
  #app { padding: 14px; }
  #pantalla-inicial { padding: 22px; }
  #pantalla-joc { padding: 14px; }
  #taulell { grid-template-columns: repeat(auto-fit, minmax(74px, 1fr)); gap: 10px; }
  .casella { min-height: 94px; padding: 8px; }
  .selector-jugadors { flex-direction: column; }
  .btn-jugadors { width: 100%; }
}
