:root {
  --bg: #F7F1E3;
  --paper: #FFFCF5;
  --ink: #3B2412;
  --ink-2: #6B4F36;
  --muted: #9A8268;
  --line: #E8DCC4;
  --brown: #8E602E;
  --groc: #EDB61C;
  --groc-ink: #6A4E00;
  --groc-soft: #FCEFC4;
  --lila: #6C4C9E;
  --lila-ink: #4E3478;
  --lila-soft: #EAE2F5;
  --ok: #2F7D4F;
  --danger: #B3402F;
  --radius: 18px;
  --shadow: 0 1px 0 rgba(59,36,18,.04), 0 6px 18px -10px rgba(59,36,18,.25);
  --display: 'Fraunces', Georgia, serif;
  --body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body);
  font-size: 15px; line-height: 1.4; -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(84px + var(--safe-b));
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- capçalera ---------- */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: var(--ink); color: #FBEFD6;
}
.top-logo { width: 40px; height: 40px; border-radius: 50%; background: #fff; object-fit: cover; }
.top-title { display: flex; flex-direction: column; line-height: 1; flex: 1; }
.top-kicker { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; opacity: .7; }
.top-name { font-family: var(--display); font-weight: 800; font-size: 22px; letter-spacing: .01em; }
.top-me {
  border: 0; border-radius: 999px; padding: 6px 12px; background: rgba(255,255,255,.12);
  color: #FBEFD6; font-size: 13px; font-weight: 600; max-width: 45vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-me.groc { box-shadow: inset 0 0 0 2px var(--groc); }
.top-me.lila { box-shadow: inset 0 0 0 2px #A98BD6; }

main { max-width: 640px; margin: 0 auto; padding: 16px; }

/* ---------- navegació ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--paper); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b));
}
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; font-size: 11px; color: var(--muted); padding: 4px 0; }
.tabs a .ti { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--ink); font-weight: 700; }
.tabs a.on .ti { filter: none; opacity: 1; }
.tabs .tab-add .ti {
  width: 46px; height: 46px; margin-top: -22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--ink); color: #FBEFD6; font-size: 26px; filter: none; opacity: 1; box-shadow: 0 6px 14px -4px rgba(59,36,18,.5);
}

/* ---------- elements comuns ---------- */
.card { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.h { font-family: var(--display); font-weight: 800; font-size: 20px; margin: 22px 2px 10px; }
.h:first-child { margin-top: 4px; }
.sub { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.groc { background: var(--groc); } .dot.lila { background: var(--lila); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--bg); color: var(--ink-2); }
.pill.groc { background: var(--groc-soft); color: var(--groc-ink); }
.pill.lila { background: var(--lila-soft); color: var(--lila-ink); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 14px;
  padding: 13px 18px; font-weight: 700; background: var(--ink); color: #FBEFD6; cursor: pointer; width: 100%;
}
.btn:disabled { opacity: .5; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.small { width: auto; padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1.5px #E9C3BB; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- marcador ---------- */
.score { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: stretch; }
.team-card { border-radius: var(--radius); padding: 16px 14px; text-align: center; position: relative; overflow: hidden; }
.team-card.groc { background: var(--groc); color: #3B2A00; }
.team-card.lila { background: var(--lila); color: #fff; }
.team-card .tn { font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; opacity: .85; }
.team-card .tp { font-family: var(--display); font-weight: 800; font-size: 44px; line-height: 1.05; margin: 4px 0 2px; }
.team-card .te { font-size: 18px; letter-spacing: 2px; }
.team-card .crown { position: absolute; top: 8px; right: 10px; font-size: 18px; }
.vs { align-self: center; font-family: var(--display); font-weight: 800; color: var(--muted); font-size: 14px; }
.tug { height: 10px; border-radius: 999px; background: var(--lila); overflow: hidden; margin: 14px 0 6px; }
.tug > i { display: block; height: 100%; background: var(--groc); border-right: 2px solid var(--paper); transition: width .6s; }
.breakdown { width: 100%; border-collapse: collapse; font-size: 13px; }
.breakdown td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.breakdown tr:last-child td { border-bottom: 0; font-weight: 800; }
.breakdown td:nth-child(2), .breakdown td:nth-child(3) { text-align: right; width: 28%; }
.breakdown th { font-size: 11px; color: var(--muted); text-align: right; font-weight: 600; padding-bottom: 4px; }
.breakdown th:first-child { text-align: left; }

/* comparació disciplines */
.cmp { margin: 10px 0; }
.cmp-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.cmp-head b { font-weight: 700; }
.cmp-bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--line); }
.cmp-bar .g { background: var(--groc); } .cmp-bar .l { background: var(--lila); }

/* gràfic */
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 6px; }

/* ---------- activitats ---------- */
.act { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.act:last-child { border-bottom: 0; }
.act-ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: var(--bg); flex: none; }
.act-title { font-weight: 700; font-size: 14px; }
.act-meta { color: var(--ink-2); font-size: 13px; margin-top: 1px; }
.act-who { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.act-pts { text-align: right; flex: none; }
.act-pts b { font-family: var(--display); font-size: 20px; display: block; line-height: 1.1; }
.act-pts span { font-size: 11px; color: var(--muted); }

/* ---------- formulari ---------- */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.seg button {
  border: 0; border-radius: 14px; background: var(--paper); box-shadow: var(--shadow); padding: 12px 4px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.seg button .e { font-size: 26px; }
.seg button.on { background: var(--ink); color: #FBEFD6; }
.field { margin-bottom: 14px; }
.field label, .lbl { display: block; font-size: 12px; font-weight: 700; color: var(--ink-2); margin: 0 0 6px 2px; letter-spacing: .02em; }
.input {
  width: 100%; min-width: 0; max-width: 100%; border: 1.5px solid var(--line); background: var(--paper); border-radius: 12px; padding: 12px; font-size: 16px; outline: none;
}
.input:focus { border-color: var(--brown); }
.input-wrap { position: relative; }
.input-wrap .unit { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 14px; pointer-events: none; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.grid2 > * { min-width: 0; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.toggle { display: flex; align-items: center; justify-content: space-between; padding: 12px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper); }
.toggle input { width: 22px; height: 22px; accent-color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  border: 1.5px solid var(--line); background: var(--paper); border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 600; color: var(--ink-2);
}
.chip.groc.on { background: var(--groc); border-color: var(--groc); color: #3B2A00; }
.chip.lila.on { background: var(--lila); border-color: var(--lila); color: #fff; }
.preview { background: var(--ink); color: #FBEFD6; border-radius: var(--radius); padding: 14px 16px; margin: 6px 0 14px; }
.preview .big { font-family: var(--display); font-size: 30px; font-weight: 800; }
.preview .small { font-size: 13px; opacity: .8; }
.preview .lines { margin-top: 8px; font-size: 13px; display: grid; gap: 3px; }

/* ---------- rànquing ---------- */
.filters { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters button { flex: none; border: 0; border-radius: 999px; padding: 7px 13px; background: var(--paper); box-shadow: var(--shadow); font-size: 13px; font-weight: 600; color: var(--ink-2); }
.filters button.on { background: var(--ink); color: #FBEFD6; }
.rank { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; }
.rank:last-child { border-bottom: 0; }
.rank .pos { width: 26px; text-align: center; font-family: var(--display); font-weight: 800; color: var(--muted); }
.rank .pos.m { font-size: 18px; }
.rank .nm { font-weight: 600; font-size: 14px; }
.rank .bar { height: 5px; border-radius: 999px; margin-top: 5px; background: var(--line); overflow: hidden; }
.rank .bar i { display: block; height: 100%; }
.rank .bar i.groc { background: var(--groc); } .rank .bar i.lila { background: var(--lila); }
.rank .val { font-weight: 800; font-size: 15px; text-align: right; }
.rank.me .nm::after { content: ' · tu'; color: var(--muted); font-weight: 500; }

/* ---------- setmana ---------- */
.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.weeknav button { border: 0; background: var(--paper); box-shadow: var(--shadow); width: 40px; height: 40px; border-radius: 12px; font-size: 18px; }
.weeknav button:disabled { opacity: .3; }
.weeknav .wl { text-align: center; }
.weeknav .wl b { font-family: var(--display); font-size: 18px; display: block; }
.awards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.award { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.award .ae { font-size: 26px; }
.award .an { font-weight: 800; font-size: 14px; margin-top: 4px; }
.award .ad { font-size: 11px; color: var(--muted); min-height: 28px; }
.award .aw { margin-top: 8px; font-size: 13px; font-weight: 700; }
.award .av { font-size: 12px; color: var(--ink-2); }
.award .apts { float: right; font-size: 11px; font-weight: 800; background: var(--bg); padding: 2px 7px; border-radius: 999px; }

/* ---------- perfil ---------- */
.prof-head { display: flex; align-items: center; gap: 14px; }
.avatar { width: 58px; height: 58px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 22px; flex: none; }
.avatar.groc { background: var(--groc); color: #3B2A00; } .avatar.lila { background: var(--lila); color: #fff; }
.prof-name { font-family: var(--display); font-weight: 800; font-size: 22px; line-height: 1.1; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.tile { background: var(--bg); border-radius: 14px; padding: 10px; }
.tile b { font-family: var(--display); font-size: 20px; font-weight: 800; display: block; line-height: 1.15; }
.tile span { font-size: 11px; color: var(--muted); }
.dtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.dtable th { font-size: 11px; color: var(--muted); font-weight: 600; text-align: right; padding: 0 0 6px; }
.dtable th:first-child, .dtable td:first-child { text-align: left; }
.dtable td { padding: 9px 0; border-top: 1px solid var(--line); text-align: right; }
.wbars { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin-top: 8px; }
.wbar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.wbar i { display: block; width: 100%; border-radius: 6px 6px 2px 2px; min-height: 2px; }
.wbar i.groc { background: var(--groc); } .wbar i.lila { background: var(--lila); }
.wbar span { font-size: 10px; color: var(--muted); }
.wbar em { font-size: 10px; font-style: normal; font-weight: 700; color: var(--ink-2); }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }

/* ---------- benvinguda ---------- */
.welcome { text-align: center; padding-top: 10px; }
.welcome img { width: 150px; height: 150px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); }
.welcome h1 { font-family: var(--display); font-weight: 800; font-size: 26px; margin: 14px 0 4px; }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; margin-top: 8px; }
.pick button { border: 0; background: var(--paper); box-shadow: var(--shadow); border-radius: 12px; padding: 12px; display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }

/* ---------- toast i modal ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #FBEFD6; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; transition: .25s; z-index: 50; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); color: #fff; }
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(40,24,10,.45); display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.sheet { background: var(--paper); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0; padding: 18px 18px calc(22px + var(--safe-b)); max-height: 88vh; overflow: auto; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: -6px auto 12px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.loading { text-align: center; padding: 60px 0; color: var(--muted); }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--ink); animation: s 1s linear infinite; margin: 0 auto 10px; }
@keyframes s { to { transform: rotate(360deg); } }
.note { font-size: 12px; color: var(--muted); margin-top: 8px; }

input[type=date].input { -webkit-appearance: none; appearance: none; display: block; min-height: 48px; text-align: left; }
input[type=date].input::-webkit-date-and-time-value { text-align: left; }
.input-wrap .input { padding-right: 44px; }
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }
