/*
 * Player profile (js/perfil.js): level ring, rank, records, categories and
 * medals, on the same black parchment as the main screen.
 */

/* ---------- The level ring: avatar, a ring that fills with XP, and the level ---------- */
.pf-ring {
  --size: 44px;
  position: relative; display: inline-grid; place-items: center; flex: none;
  width: var(--size); height: var(--size); border-radius: 50%;
  padding: calc(var(--size) * .075);
  background: conic-gradient(#f2b705 var(--p), rgba(120, 90, 50, .35) 0);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .28);
}
.pf-ring.small { --size: 72px; }
.pf-ring.big { --size: 132px; }
.pf-face {
  display: block; width: 100%; height: 100%; border-radius: 50%; overflow: hidden;
  background: var(--av); box-shadow: 0 0 0 calc(var(--size) * .03) #2b1a0e;
}
.pf-face svg { display: block; width: 100%; height: 100%; }
.pf-lvl {
  position: absolute; right: -4%; bottom: -4%;
  min-width: 42%; height: 42%; padding: 0 .3em; border-radius: 999px;
  display: grid; place-items: center;
  background: #c8102e; color: #efe1c9; border: calc(var(--size) * .035) solid #2b1a0e;
  font-family: var(--display); font-weight: 900; font-size: calc(var(--size) * .24); line-height: 1;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .3);
}
.pf-ring.mini .pf-lvl { font-size: 11px; min-width: 20px; height: 20px; border-width: 2px; right: -6px; bottom: -5px; }

/* Top bar button */
.pf-btn { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; background: none; cursor: pointer; }
.pf-btn:active .pf-ring { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .28); }

/* ---------- The screen ---------- */
.pf {
  position: fixed; inset: 0; z-index: 85;
  overflow-y: auto; overscroll-behavior: contain;
  color: var(--text);
  /* The black parchment of the page, on the scroller itself so it covers it all the way down. */
  background-color: var(--bg);
  background-image: var(--paper-edge), var(--paper-stains), var(--paper-grain), var(--paper-base);
  background-size: 100% 100%, 700px 700px, 260px 260px, 100% 100%;
  animation: pf-fade .3s ease-out both;
}
.pf .pf-inner { animation: pf-in .32s cubic-bezier(.2, .8, .2, 1) both; }
.pf.out { animation: pf-fade .26s ease-in reverse both; }
.pf:focus { outline: none; }
html.pf-open body { overflow: hidden; }
.pf-inner {
  display: grid; gap: 16px; max-width: 560px; margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}
.pf-head { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.pf-head h1 { font-family: var(--serif); font-size: 1.6rem; line-height: 1.1; }
.pf-back { display: grid; place-items: center; width: 44px; min-width: 44px; height: 44px; padding: 0; }
.pf-back svg { width: 22px; height: 22px; }

.pf-hero { display: grid; justify-items: center; text-align: center; gap: 6px; padding-top: 22px; }
.pf-hero .pf-ring { margin-bottom: 8px; animation: pf-pop .6s cubic-bezier(.3, 1.5, .5, 1) .1s both; }
.pf-name { font-family: var(--serif); font-size: 1.9rem; line-height: 1.1; overflow-wrap: anywhere; }
.pf-where { color: var(--muted); font-size: .95rem; }
.pf-rank { display: inline-flex; align-items: center; gap: 8px; margin: 6px 0 4px; }
.pf-rank span { color: var(--muted); font-weight: 750; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; }
.pf-rank b {
  padding: 4px 12px; border-radius: 999px; background: #f2b705; color: #3a2408;
  font-family: var(--display); font-weight: 900; font-size: 1rem; box-shadow: 0 3px 0 #b88a00;
}
.pf-next { color: var(--muted); font-size: .9rem; }

/* XP bar */
.pf-bar {
  position: relative; width: 100%; height: 16px; border-radius: 999px; overflow: hidden;
  background: rgba(60, 40, 20, .18); box-shadow: inset 0 2px 0 rgba(0, 0, 0, .15);
  border: 2px solid var(--sheet-line, var(--border));
}
.pf-bar i {
  position: absolute; inset: 0 auto 0 0; width: var(--to); border-radius: inherit;
  background: repeating-linear-gradient(90deg, #f2b705 0 14px, #e3a800 14px 28px);
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .15);
  animation: pf-fill 1.1s cubic-bezier(.3, .8, .3, 1) .35s both;
}
.pf-bar.thin { height: 10px; margin-top: 8px; }
.pf-bar-text { width: 100%; display: flex; justify-content: center; gap: 6px; font-size: .9rem; font-variant-numeric: tabular-nums; }
.pf-bar-text span { color: var(--muted); }

.pf-block .label { display: flex; justify-content: space-between; align-items: baseline; }
.pf-count { letter-spacing: 0; text-transform: none; font-size: .85rem; }
.pf-muted { color: var(--muted); font-size: .92rem; margin-bottom: 8px; }

/* Records */
.pf-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pf-stat {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center;
  padding: 10px 12px; border-radius: 14px;
  background: var(--btn-face, var(--surface)); border: 2px solid var(--btn-line, var(--border)); box-shadow: 0 3px 0 var(--btn-depth, var(--border));
  animation: pf-rise .4s cubic-bezier(.2, .8, .2, 1) calc(.15s + var(--i) * 40ms) both;
}
.pf-stat i { grid-row: span 2; display: block; width: 34px; height: 34px; }
.pf-stat i svg, .pf-chip i svg, .pf-mini svg, .pf-game-ico svg { display: block; width: 100%; height: 100%; overflow: visible; }
.pf-stat b { font-family: var(--display); font-size: 1.3rem; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.pf-stat span { color: var(--muted); font-size: .78rem; line-height: 1.2; }

/* Categories */
.pf-best { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; padding: 10px 12px; border-radius: 14px; background: rgba(242, 183, 5, .18); border: 2px dashed rgba(184, 138, 0, .6); }
.pf-best .rajola { width: 34px; height: 34px; flex: none; }

/* Medals */
.pf-medals { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 12px 8px; }
.pf-medal {
  display: grid; justify-items: center; gap: 6px; padding: 0; border: 0; background: none;
  font: inherit; color: inherit; cursor: pointer;
  animation: pf-pop .45s cubic-bezier(.3, 1.5, .5, 1) calc(.2s + var(--i) * 30ms) both;
}
.pf-coin {
  position: relative; display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe27a, #f2b705 55%, #c98f00);
  border: 3px solid #2b1a0e; box-shadow: 0 3px 0 rgba(0, 0, 0, .3), inset 0 0 0 3px rgba(255, 255, 255, .35);
}
.pf-coin svg { width: 34px; height: 34px; overflow: visible; }
.pf-mname { font-size: .72rem; font-weight: 700; line-height: 1.15; text-align: center; }
.pf-medal:not(.got) .pf-coin { background: rgba(110, 90, 70, .35); filter: grayscale(1); opacity: .55; }
.pf-medal:not(.got) .pf-coin::after {
  content: "🔒"; position: absolute; right: -4px; bottom: -4px; font-size: .9rem; filter: none;
}
.pf-medal:not(.got) .pf-coin svg { width: 34px; height: 34px; overflow: visible; }
.pf-mname { color: var(--muted); }
.pf-medal.on .pf-coin { outline: 3px solid #c8102e; outline-offset: 3px; }
.pf-medal.got .pf-coin { animation: pf-shine 3.2s ease-in-out infinite; animation-delay: calc(var(--i) * 170ms); }
.pf-medal-info { margin-top: 14px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: .9rem; min-height: 2.6em; }

.pf-seen { font-size: .95rem; }
.pf-seen b { font-family: var(--display); font-size: 1.3rem; }

/* ---------- After a game ---------- */
.pf-gain { display: grid; gap: 10px; }
.pf-gain-top { display: flex; align-items: center; gap: 14px; }
.pf-plus { font-family: var(--display); font-weight: 900; font-size: 1.7rem; color: #c8102e; line-height: 1.1; animation: pf-pop .5s cubic-bezier(.3, 1.6, .5, 1) .2s both; }
.pf-sub { color: var(--muted); font-weight: 700; }
.pf-up { font-weight: 800; padding: 8px 12px; border-radius: 12px; background: rgba(242, 183, 5, .22); animation: pf-pop .5s cubic-bezier(.3, 1.6, .5, 1) 1.2s both; }
.pf-gain.up .pf-ring { animation: pf-pop .6s cubic-bezier(.3, 1.6, .5, 1) 1.2s both; }
.pf-new .label { margin-bottom: 6px; }
.pf-chip { display: inline-flex; align-items: center; gap: 6px; margin: 0 6px 6px 0; padding: 5px 10px 5px 6px; border-radius: 999px; background: #f2b705; color: #3a2408; font-weight: 800; font-size: .88rem; box-shadow: 0 2px 0 #b88a00; }
.pf-chip i { display: block; width: 22px; height: 22px; }

/* Medal info: the drawing beside the name */
.pf-medal-info b { display: inline-flex; align-items: center; gap: 6px; vertical-align: middle; }
.pf-mini { display: inline-block; width: 22px; height: 22px; }

/* Change the avatar: tap the face or the button under the name */
.pf-face-btn { position: relative; padding: 0; border: 0; background: none; cursor: pointer; border-radius: 50%; }
.pf-face-btn:active .pf-ring { transform: scale(.97); }
.pf-pencil {
  position: absolute; left: -2px; bottom: 6px; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  background: #efe1c9; border: 3px solid #2b1a0e; box-shadow: 0 2px 0 rgba(0, 0, 0, .3);
}
.pf-pencil svg { width: 22px; height: 22px; }
.pf-change { margin-top: -2px; }

.pf-sheet {
  position: fixed; inset: 0; z-index: 2; display: grid; align-items: end; justify-items: center;
  background: rgba(10, 6, 3, .6); animation: pf-fade .2s ease-out both;
  padding: 16px 12px calc(12px + env(safe-area-inset-bottom));
}
.pf-sheet-in { width: 100%; max-width: 520px; max-height: calc(100% - env(safe-area-inset-top) - 20px); overflow-y: auto; animation: pf-in .28s cubic-bezier(.2, .8, .2, 1) both; }
.pf-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.pf-sheet-head h2 { font-family: var(--serif); font-size: 1.35rem; line-height: 1.1; }
.pf-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 10px; }
.pf-pick-av { padding: 0; border: 0; background: none; cursor: pointer; border-radius: 50%; aspect-ratio: 1; }
.pf-pick-av span {
  display: block; width: 100%; height: 100%; border-radius: 50%; overflow: hidden;
  background: var(--av); border: 3px solid #2b1a0e; box-shadow: 0 3px 0 rgba(0, 0, 0, .3);
}
.pf-pick-av svg { display: block; width: 100%; height: 100%; }
.pf-pick-av.on span { outline: 4px solid #f2b705; outline-offset: 2px; }
.pf-pick-av:active span { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
.pf.repaint .pf-inner { animation: none; }

/* El teu castell: the ranks as floors, the pinya wide at the bottom */
.pf-castell { list-style: none; margin: 4px 0 0; padding: 0; display: grid; justify-items: center; gap: 5px; }
.pf-floor {
  position: relative; width: var(--w); min-height: 38px; padding: 6px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-radius: 10px; border: 2px solid #2b1a0e;
  background: #f2b705; color: #3a2408; box-shadow: 0 3px 0 #b88a00;
  animation: pf-rise .4s cubic-bezier(.2, .8, .2, 1) calc(.15s + (8 - var(--i)) * 45ms) both;
}
.pf-floor b { font-family: var(--display); font-weight: 900; font-size: .92rem; line-height: 1.1; }
.pf-floor span { font-size: .72rem; font-weight: 750; opacity: .75; white-space: nowrap; }
.pf-floor.here { background: #c8102e; color: #efe1c9; box-shadow: 0 3px 0 #8e0b20; padding-left: 50px; }
.pf-floor.locked { background: rgba(110, 90, 70, .22); color: var(--muted); border-style: dashed; border-color: rgba(110, 90, 70, .55); box-shadow: none; }
.pf-floor-av {
  position: absolute; left: 4px; top: 50%; translate: 0 -50%;
  width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
  background: var(--av); border: 3px solid #2b1a0e; box-shadow: 0 2px 0 rgba(0, 0, 0, .35);
  animation: pf-pop .5s cubic-bezier(.3, 1.6, .5, 1) .7s both;
}
.pf-floor-av svg { display: block; width: 100%; height: 100%; }
.pf-castell-tip { margin: 12px 0 0; text-align: center; }

/* Últimes partides */
.pf-history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pf-game {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 14px;
  background: var(--btn-face, var(--surface)); border: 2px solid var(--btn-line, var(--border)); box-shadow: 0 3px 0 var(--btn-depth, var(--border));
  animation: pf-rise .4s cubic-bezier(.2, .8, .2, 1) calc(.15s + var(--i) * 50ms) both;
}
.pf-game.won { border-color: #b88a00; background: rgba(242, 183, 5, .22); }
.pf-game-ico { width: 34px; height: 34px; }
.pf-game-main, .pf-game-num { display: grid; line-height: 1.2; }
.pf-game-main b { font-weight: 800; }
.pf-game small { color: var(--muted); font-size: .78rem; }
.pf-game-num { text-align: right; }
.pf-game-num b { font-family: var(--display); font-weight: 900; font-size: 1.15rem; font-variant-numeric: tabular-nums; }

@keyframes pf-in { from { opacity: 0; transform: translateY(18px); } }
@keyframes pf-fade { from { opacity: 0; } }
@keyframes pf-pop { from { opacity: 0; transform: scale(.6); } }
@keyframes pf-rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes pf-fill { from { width: var(--from); } }
@keyframes pf-shine { 0%, 80%, 100% { transform: rotate(0); } 86% { transform: rotate(-10deg) scale(1.06); } 93% { transform: rotate(8deg) scale(1.06); } }

@media (prefers-reduced-motion: reduce) {
  .pf, .pf *, .pf-gain * { animation: none !important; }
}
