/* ================================================
   CB PALLEJÀ — TIRS LLIURES  ·  game.css  v4
   iOS + Android + Responsive
   ================================================ */
@import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&family=Barlow+Condensed:wght@400;600;700&display=swap');

:root {
  --bg      : #07091a;
  --bg2     : #0f1530;
  --cbblue  : #002B6B;
  --cbblue2 : #1a4a9a;
  --orange  : #f05a1a;
  --orange2 : #ff7a3a;
  --white   : #f5f0e8;
  --gray    : #7a8faa;
  --gold    : #f0c040;
  --success : #00cc55;
  --danger  : #ff3344;
  --p1:#f05a1a; --p2:#1a8aff; --p3:#00cc66; --p4:#cc44ff;
  --uni-red : #7d1e2a;
  --uni-navy: #1a1535;
  --uni-gold: #c8a060;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── iOS + Android base fix ───────────────── */
html {
  height: 100%;
  height: -webkit-fill-available; /* iOS Safari */
}

html, body {
  background: var(--bg);
  color: var(--white);
  font-family: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

body {
  min-height: 100vh;
  min-height: -webkit-fill-available; /* iOS Safari no talla la pantalla */
  min-height: 100dvh;                 /* navegadors moderns */
}

/* ─── SCREENS ─────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease;
  overflow-y: auto; overflow-x: hidden;
  /* Safe area per iPhone notch/Dynamic Island */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-overflow-scrolling: touch; /* iOS momentum scroll */
}
.screen.active { opacity: 1; pointer-events: all; }

/* ─── MODAL INSTRUCCIONS ─────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.82);
  z-index: 999;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .3s;
  padding: 16px;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal-box {
  background: #0f1530;
  border: 1.5px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 24px 22px 20px;
  max-width: 400px; width: 100%;
  position: relative;
  display: flex; flex-direction: column; gap: 14px;
}
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: transparent; border: none;
  color: var(--gray); font-size: 1.1rem; cursor: pointer;
  transition: color .2s;
}
.modal-close:hover { color: var(--white); }
.modal-title {
  font-family: 'Bebas Neue', serif;
  font-size: 1.8rem; letter-spacing: 3px; text-align: center;
}
.modal-steps { display: flex; flex-direction: column; gap: 10px; }
.m-step {
  display: flex; gap: 12px; align-items: flex-start;
  background: rgba(255,255,255,.04); border-radius: 10px; padding: 10px 12px;
}
.m-num {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--orange); color: #fff;
  font-family: 'Bebas Neue', serif; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.m-txt { font-size: .95rem; line-height: 1.5; color: var(--white); }
.m-txt strong { color: var(--gold); }
.m-txt em { color: var(--gray); font-style: normal; }

.modal-zones { display: flex; flex-direction: column; gap: 6px; }
.zone-pill {
  padding: 6px 12px; border-radius: 8px; font-size: .85rem; letter-spacing: .5px;
}
.z-green  { background: rgba(0,200,80,.12); border: 1px solid rgba(0,200,80,.4); color: #44ee88; }
.z-yellow { background: rgba(240,192,64,.12); border: 1px solid rgba(240,192,64,.4); color: #f0c040; }
.z-out    { background: rgba(255,50,50,.08); border: 1px solid rgba(255,50,50,.25); color: #ff7777; }

.modal-note { font-size: .85rem; color: var(--white); background: rgba(240,90,26,.08); border-radius: 8px; padding: 8px 12px; border-left: 3px solid var(--orange); }
.modal-note-sub { font-size: .78rem; color: var(--gray); text-align: center; line-height: 1.5; }

.modal-ok { width: 100%; max-width: 100%; margin-top: 4px; }

/* ─── BUTTONS ────────────────────────────── */
.btn-primary {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 28px;
  background: var(--orange); border: none; border-radius: 12px;
  color: var(--white); font-family: 'Bebas Neue', serif;
  font-size: 1.5rem; letter-spacing: 4px; cursor: pointer;
  transition: background .2s, transform .15s, box-shadow .2s;
  box-shadow: 0 4px 22px rgba(240,90,26,.4);
  text-shadow: 0 2px 4px rgba(0,0,0,.3);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}
.btn-primary:hover:not(:disabled) { background: var(--orange2); transform: translateY(-2px); box-shadow: 0 6px 30px rgba(240,90,26,.5); }
.btn-primary:active:not(:disabled) { transform: scale(0.97); }
.btn-primary:disabled { opacity: .28; cursor: not-allowed; box-shadow: none; transform: none; }

.btn-secondary {
  padding: 11px 22px; background: transparent;
  border: 2px solid var(--gray); border-radius: 9px; color: var(--gray);
  font-family: 'Bebas Neue', serif; font-size: 1rem; letter-spacing: 2px;
  cursor: pointer; transition: all .2s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.btn-secondary:hover { border-color: var(--white); color: var(--white); }
.btn-secondary:active { border-color: var(--white); color: var(--white); }

/* ════════════════════════════════════════════
   SCREEN 1: SELECTION
   ════════════════════════════════════════════ */
#screen-select { justify-content: flex-start; }

.select-wrap {
  width: 100%; max-width: 540px;
  padding: 14px 18px 28px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.select-header { text-align: center; }
.club-badge {
  width: 62px; height: 62px; border-radius: 50%;
  background: linear-gradient(135deg, var(--uni-red), #5a1525);
  border: 3px solid var(--uni-gold);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 10px;
  box-shadow: 0 0 26px rgba(200,160,96,.35);
}
.badge-txt { font-family: 'Bebas Neue', serif; font-size: 24px; letter-spacing: 2px; color: var(--uni-gold); }
.game-title {
  font-family: 'Bebas Neue', serif;
  font-size: clamp(2rem, 9vw, 3.5rem); letter-spacing: 5px;
  text-shadow: 0 0 28px rgba(200,160,96,.4); line-height: 1;
}
.game-sub { font-size: .9rem; letter-spacing: 6px; color: var(--uni-gold); margin-top: 4px; }

.setup-section { width: 100%; }
.section-lbl { font-family: 'Bebas Neue', serif; font-size: 1.2rem; letter-spacing: 3px; color: var(--gray); margin-bottom: 12px; text-align: center; }

.count-row { display: flex; gap: 10px; justify-content: center; }
.count-btn {
  width: 56px; height: 56px; border-radius: 12px;
  background: rgba(255,255,255,.04); border: 2px solid rgba(255,255,255,.12);
  color: var(--white); font-family: 'Bebas Neue', serif; font-size: 1.8rem;
  cursor: pointer; transition: all .2s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.count-btn:hover { border-color: var(--uni-gold); background: rgba(200,160,96,.08); }
.count-btn.active { border-color: var(--uni-gold); background: rgba(200,160,96,.18); color: var(--uni-gold); box-shadow: 0 0 14px rgba(200,160,96,.3); }

/* Player rows */
.players-setup { display: flex; flex-direction: column; gap: 10px; width: 100%; }

.player-row {
  background: rgba(255,255,255,.04);
  border: 1.5px solid rgba(255,255,255,.1);
  border-radius: 12px; padding: 12px 14px;
  border-left: 4px solid var(--p1);
}
.player-row[data-idx="0"] { border-left-color: var(--p1); }
.player-row[data-idx="1"] { border-left-color: var(--p2); }
.player-row[data-idx="2"] { border-left-color: var(--p3); }
.player-row[data-idx="3"] { border-left-color: var(--p4); }

.player-row-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.player-num-badge {
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Bebas Neue', serif; font-size: 1rem;
  flex-shrink: 0;
}
.player-num-badge[data-idx="0"] { background: var(--p1); color: #fff; }
.player-num-badge[data-idx="1"] { background: var(--p2); color: #fff; }
.player-num-badge[data-idx="2"] { background: var(--p3); color: #000; }
.player-num-badge[data-idx="3"] { background: var(--p4); color: #fff; }

.player-name-input {
  flex: 1;
  background: rgba(255,255,255,.07); border: 1.5px solid rgba(255,255,255,.15);
  border-radius: 7px; color: var(--white);
  font-family: 'Barlow Condensed', sans-serif; font-size: 1rem; font-weight: 600;
  padding: 6px 10px; outline: none;
}
.player-name-input::placeholder { color: rgba(255,255,255,.25); }
.player-name-input:focus { border-color: var(--uni-gold); background: rgba(200,160,96,.06); }
.player-name-input.error {
  border-color: var(--danger) !important;
  animation: shake .35s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-5px); }
  75%      { transform: translateX(5px); }
}

.player-row-check { font-size: 1rem; flex-shrink: 0; opacity: 0; transition: opacity .2s; }
.player-row.ready .player-row-check { opacity: 1; }

.gender-btns { display: flex; gap: 8px; margin-bottom: 8px; }
.gen-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: rgba(255,255,255,.04); border: 2px solid rgba(255,255,255,.1);
  border-radius: 10px; padding: 6px 8px;
  cursor: pointer; color: var(--white);
  font-family: 'Bebas Neue', serif; font-size: .9rem; letter-spacing: 1px;
  transition: all .2s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.gen-btn canvas { border-radius: 6px; background: rgba(20,15,40,.5); display: block; }
.gen-btn:hover { border-color: var(--uni-gold); }
.gen-btn.selected { border-color: var(--uni-gold); background: rgba(200,160,96,.1); box-shadow: 0 0 14px rgba(200,160,96,.2); }

.cat-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-btn {
  background: rgba(255,255,255,.04); border: 1.5px solid rgba(255,255,255,.12);
  border-radius: 7px; padding: 5px 10px;
  cursor: pointer; color: var(--white);
  font-family: 'Barlow Condensed', sans-serif; font-size: .8rem; font-weight: 600;
  transition: all .2s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; min-height: 34px;
}
.cat-btn:hover { border-color: var(--uni-gold); }
.cat-btn.selected { border-color: var(--gold); background: rgba(240,192,64,.12); color: var(--gold); }

/* Footer */
.select-footer { width: 100%; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn-instr {
  padding: 10px 14px; background: transparent;
  border: 1.5px solid rgba(255,255,255,.15); border-radius: 9px;
  color: var(--white); font-size: .85rem; cursor: pointer; transition: all .2s; white-space: nowrap;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; min-height: 44px;
}
.btn-instr:hover { border-color: var(--white); }
.btn-hof {
  padding: 10px 14px; background: rgba(240,192,64,.08);
  border: 1.5px solid rgba(240,192,64,.3); border-radius: 9px;
  color: var(--gold); font-family: 'Bebas Neue', serif;
  font-size: .95rem; letter-spacing: 2px; cursor: pointer; transition: all .2s; white-space: nowrap;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; min-height: 44px;
}
.btn-hof:hover { background: rgba(240,192,64,.18); border-color: var(--gold); }
.select-footer .btn-primary { flex: 1; min-width: 130px; max-width: 200px; }

/* ════════════════════════════════════════════
   SCREEN 2: HOF
   ════════════════════════════════════════════ */
#screen-hof { justify-content: flex-start; }
.hof-wrap { width: 100%; max-width: 520px; padding: 22px 18px 32px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.hof-header { text-align: center; }
.hof-title { font-family: 'Bebas Neue', serif; font-size: clamp(1.8rem, 7vw, 3rem); letter-spacing: 4px; }
.hof-month-badge { display: inline-block; margin-top: 8px; padding: 3px 12px; border-radius: 20px; background: rgba(240,192,64,.12); border: 1px solid rgba(240,192,64,.4); color: var(--gold); font-size: .9rem; letter-spacing: 2px; font-family: 'Bebas Neue', serif; }
.hof-reset-note, .hof-tie-note { font-size: .78rem; color: var(--gray); margin-top: 5px; }
.hof-list { width: 100%; display: flex; flex-direction: column; gap: 5px; }
.hof-list-compact .hof-entry { padding: 8px 12px; }
.hof-entry { display: grid; grid-template-columns: 32px 1fr 48px 58px; align-items: center; gap: 8px; padding: 10px 14px; background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.07); border-radius: 9px; }
.hof-entry:first-child { background: rgba(240,192,64,.08); border-color: rgba(240,192,64,.3); }
.hof-entry:nth-child(2) { background: rgba(184,192,204,.05); border-color: rgba(184,192,204,.2); }
.hof-entry:nth-child(3) { background: rgba(205,128,64,.05); border-color: rgba(205,128,64,.2); }
.hof-pos { font-family: 'Bebas Neue', serif; font-size: 1.2rem; text-align: center; }
.hof-name-cell { display: flex; flex-direction: column; min-width: 0; }
.hof-pname { font-weight: 700; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hof-pcat { font-size: .7rem; color: var(--gray); }
.hof-score { font-family: 'Bebas Neue', serif; font-size: 1.4rem; text-align: right; color: var(--gold); }
.hof-time { font-size: .75rem; color: var(--gray); text-align: right; }
.hof-empty { text-align: center; color: var(--gray); padding: 24px; font-size: .9rem; }
.hof-back-btn { margin-top: 6px; }

/* ════════════════════════════════════════════
   SCREEN 3: TRANSITION
   ════════════════════════════════════════════ */
#screen-transition { justify-content: center; }
.transition-wrap { max-width: 340px; width: 100%; padding: 24px 18px; display: flex; flex-direction: column; align-items: center; gap: 9px; text-align: center; }
.tr-badge { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--p1); color: #fff; font-family: 'Bebas Neue', serif; font-size: 1rem; letter-spacing: 1px; }
.tr-label { font-size: .72rem; letter-spacing: 5px; color: var(--gray); }
.tr-name { font-family: 'Bebas Neue', serif; font-size: clamp(2rem, 9vw, 3.5rem); letter-spacing: 3px; line-height: 1.1; }
#tr-avatar { border-radius: 10px; background: rgba(20,15,40,.5); margin: 3px 0; }
.tr-cat { font-size: .88rem; letter-spacing: 2px; color: var(--gray); }
.tr-prev-scores { width: 100%; background: rgba(0,0,0,.3); border-radius: 8px; padding: 8px 12px; font-size: .82rem; color: var(--gray); }
.tr-prev-scores:empty { display: none; }
.tr-prev-row { display: flex; justify-content: space-between; }
.tr-prev-row .tr-pname { font-weight: 700; color: var(--white); }
.tr-prev-row .tr-pscore { color: var(--gold); font-family: 'Bebas Neue', serif; font-size: 1rem; }
.tr-hint { font-size: .78rem; color: var(--orange); letter-spacing: 1px; }
.tr-go-btn { margin-top: 6px; width: 100%; max-width: 250px; }

/* ════════════════════════════════════════════
   SCREEN 4: GAME
   ════════════════════════════════════════════ */
#screen-game {
  flex-direction: column; justify-content: flex-start;
  height: 100vh; height: 100dvh;
  padding-top: env(safe-area-inset-top, 0px);
}
.game-hud { width: 100%; max-width: 800px; display: flex; justify-content: space-between; padding: 7px 14px; background: rgba(0,0,0,.45); border-bottom: 1px solid rgba(255,255,255,.06); flex-shrink: 0; }
.hud-box { display: flex; flex-direction: column; align-items: center; min-width: 60px; }
.hud-main { align-items: center; }
.hud-lbl { font-size: .57rem; letter-spacing: 3px; color: var(--gray); text-transform: uppercase; }
.hud-val { font-family: 'Bebas Neue', serif; font-size: 1.25rem; letter-spacing: 2px; }
.hud-timer { color: var(--gold); }
.canvas-area { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; position: relative; overflow: hidden; min-height: 0; }
#gameCanvas { width: 100%; max-width: 800px; height: auto; display: block; cursor: pointer; touch-action: none; -webkit-user-select:none; user-select:none; }
.feedback { position: absolute; top: 42%; left: 50%; transform: translate(-50%,-50%); font-family: 'Bebas Neue', serif; font-size: clamp(1.8rem,7vw,3.8rem); letter-spacing: 4px; text-shadow: 0 3px 18px rgba(0,0,0,.85); pointer-events: none; transition: opacity .35s; white-space: nowrap; }
.feedback.success { color: var(--success); }
.feedback.swish   { color: var(--gold); }
.feedback.miss    { color: var(--danger); }
.feedback.hidden  { opacity: 0; }
.game-foot { width: 100%; max-width: 800px; display: flex; align-items: center; gap: 9px; padding: 8px 14px max(11px, env(safe-area-inset-bottom, 11px)); background: rgba(0,0,0,.45); border-top: 1px solid rgba(255,255,255,.06); flex-shrink: 0; }
.tirs-left { flex: 1; font-size: .78rem; letter-spacing: .5px; color: var(--gray); }
.btn-shoot { flex: 2; padding: 12px 18px; background: var(--uni-navy); border: 2px solid #2a2060; border-radius: 10px; color: var(--white); font-family: 'Bebas Neue', serif; font-size: 1.15rem; letter-spacing: 2px; cursor: pointer; transition: all .15s; touch-action: manipulation; -webkit-tap-highlight-color: transparent; min-height: 48px; }
.btn-shoot:hover { background: #2a2060; }
.btn-shoot.primed { background: var(--uni-red); border-color: #aa2838; box-shadow: 0 2px 22px rgba(125,30,42,.6); animation: pulse-btn .5s infinite alternate; }
@keyframes pulse-btn { from { box-shadow: 0 2px 22px rgba(125,30,42,.6); } to { box-shadow: 0 2px 36px rgba(125,30,42,.9); } }
.btn-exit { padding: 11px 13px; background: transparent; border: 1.5px solid rgba(255,255,255,.14); border-radius: 8px; color: var(--gray); font-size: 1.1rem; cursor: pointer; transition: all .2s; touch-action: manipulation; -webkit-tap-highlight-color: transparent; min-height: 44px; min-width: 44px; }
.btn-exit:hover { border-color: var(--white); color: var(--white); }

/* ════════════════════════════════════════════
   SCREEN 5: RESULTS
   ════════════════════════════════════════════ */
#screen-results { justify-content: flex-start; }
.results-wrap { width: 100%; max-width: 520px; padding: 20px 18px 30px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.res-title { font-family: 'Bebas Neue', serif; font-size: clamp(2rem, 8vw, 3.5rem); letter-spacing: 6px; text-align: center; }
.res-section { width: 100%; }
.res-section-title { font-family: 'Bebas Neue', serif; font-size: 1.2rem; letter-spacing: 3px; color: var(--gray); margin-bottom: 8px; text-align: center; }
.res-hof-header { display: flex; flex-direction: column; align-items: center; gap: 3px; margin-bottom: 5px; }
.res-hof-sub { font-family: 'Bebas Neue', serif; font-size: .9rem; color: var(--gold); letter-spacing: 2px; }
.res-reset-note { font-size: .74rem; color: var(--gray); margin-bottom: 7px; text-align: center; }
.session-ranking { display: flex; flex-direction: column; gap: 7px; }
.session-entry { display: grid; grid-template-columns: 40px 1fr 58px 68px; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 10px; border: 1.5px solid rgba(255,255,255,.08); background: rgba(255,255,255,.04); }
.session-entry.winner { background: rgba(240,192,64,.09); border-color: rgba(240,192,64,.35); }
.sess-medal { font-size: 1.4rem; text-align: center; }
.sess-name-cell { display: flex; flex-direction: column; min-width: 0; }
.sess-name { font-weight: 700; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess-cat { font-size: .7rem; color: var(--gray); }
.sess-tie { font-size: .66rem; color: var(--orange); }
.sess-score { font-family: 'Bebas Neue', serif; font-size: 1.5rem; text-align: right; color: var(--gold); }
.sess-time { font-size: .76rem; color: var(--gray); text-align: right; }
.res-btns { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 270px; }
.res-btns .btn-primary { width: 100%; max-width: 100%; }

/* ─── RESPONSIVE ─────────────────────────── */
@media (max-width: 460px) {
  .hof-entry { grid-template-columns: 28px 1fr 42px 50px; }
  .session-entry { grid-template-columns: 34px 1fr 50px 60px; }
  .count-btn { width: 48px; height: 48px; font-size: 1.5rem; }
}
@media (max-height: 600px) {
  .club-badge { display: none; }
  .game-title { font-size: 2rem; }
  .select-wrap { gap: 10px; }
}

.ceb-logo-panel {
  display: block;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 8px;
  border: 2px solid #CDA470;
}
