:root {
  --bg: #0d0d0f;
  --bg-2: #16161a;
  --line: #26262c;
  --ink: #f4f4f5;
  --ink-dim: #9a9aa4;
  --ink-faint: #61616b;
  --accent: #ff2d55;
  --accent-ink: #fff;
  --gold: #ffc83d;
  --radius: 14px;
  --pad: clamp(16px, 4vw, 24px);
  --card-face: #fafafa;
  --card-ink: #101014;
}

* { box-sizing: border-box; }

/* L'atribut [hidden] ha de guanyar sempre: moltes classes d'aquí porten
   display:flex/grid i, per especificitat, deixaven l'element visible. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

body {
  background-image:
    radial-gradient(900px 500px at 50% -10%, #1d1d23 0%, transparent 70%),
    radial-gradient(600px 400px at 100% 100%, #1a1116 0%, transparent 70%);
  background-attachment: fixed;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) var(--pad) calc(24px + env(safe-area-inset-bottom));
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.view { display: none; flex: 1; flex-direction: column; gap: 20px; animation: rise .28s ease; }
.view.is-active { display: flex; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ── portada ───────────────────────────────────────────────────────────── */

.brand { text-align: center; padding-top: clamp(12px, 6vh, 48px); }

.brand h1 {
  font-size: clamp(52px, 17vw, 88px);
  line-height: .86;
  margin: 12px 0 0;
  font-weight: 900;
  letter-spacing: -.04em;
  text-transform: uppercase;
}
.brand h1::after { content: ""; display: block; width: 46px; height: 5px; background: var(--accent); margin: 18px auto 0; border-radius: 3px; }

.brand-cards { display: flex; justify-content: center; gap: 6px; }
.mini-card { width: 30px; height: 42px; border-radius: 5px; display: block; }
.mini-card.black { background: #000; border: 1px solid #3a3a44; transform: rotate(-9deg); }
.mini-card.white { background: var(--card-face); transform: rotate(9deg); }

.tagline { color: var(--ink-dim); margin: 16px auto 0; max-width: 30ch; line-height: 1.5; font-size: 15px; }

.foot { text-align: center; color: var(--ink-faint); font-size: 13px; margin: auto 0 0; }

/* ── panells i formularis ──────────────────────────────────────────────── */

.panel {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel-title { font-size: 15px; margin: 0; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-dim); display: flex; align-items: center; gap: 8px; }

.pill { background: var(--line); color: var(--ink-dim); border-radius: 99px; padding: 2px 9px; font-size: 12px; letter-spacing: 0; }

.field { display: flex; flex-direction: column; gap: 7px; }
.field > span { font-size: 13px; color: var(--ink-dim); }

input[type=text] {
  width: 100%;
  background: #0b0b0d;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  padding: 13px 14px;
  outline: none;
  transition: border-color .15s;
}
input[type=text]:focus { border-color: var(--accent); }
input::placeholder { color: #4a4a53; }

.code-input {
  text-align: center;
  font-size: 30px !important;
  font-weight: 800;
  letter-spacing: .34em;
  text-indent: .34em;
  text-transform: uppercase;
  padding: 14px 0 !important;
  font-variant-ligatures: none;
}

.tabs { display: flex; gap: 6px; background: #0b0b0d; padding: 4px; border-radius: 11px; border: 1px solid var(--line); }
.tab {
  flex: 1; background: none; border: 0; color: var(--ink-dim); font: inherit; font-size: 14px;
  padding: 9px; border-radius: 8px; cursor: pointer; transition: .15s;
}
.tab.is-active { background: var(--line); color: var(--ink); font-weight: 600; }

.tab-panel { display: none; flex-direction: column; gap: 14px; }
.tab-panel.is-active { display: flex; }

.stepper { display: flex; align-items: center; gap: 4px; background: #0b0b0d; border: 1px solid var(--line); border-radius: 11px; padding: 5px; width: fit-content; }
.stepper button {
  width: 40px; height: 40px; border-radius: 8px; border: 0; background: var(--line);
  color: var(--ink); font-size: 22px; line-height: 1; cursor: pointer;
}
.stepper button:active { background: #34343d; }
.stepper output { min-width: 52px; text-align: center; font-size: 19px; font-weight: 700; }

/* ── botons ────────────────────────────────────────────────────────────── */

.btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 11px; cursor: pointer;
  padding: 15px 18px; font-size: 16px; transition: transform .08s, opacity .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: default; }

.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 20px -8px var(--accent); }
.btn-ghost { background: transparent; color: var(--ink-dim); border: 1px solid var(--line); }
.btn-sm { padding: 10px 14px; font-size: 14px; }
.btn-xs { padding: 7px 11px; font-size: 12px; font-weight: 600; }
.btn-leave { align-self: center; margin-top: auto; }

.error {
  color: #ff8095; background: rgba(255, 45, 85, .1); border: 1px solid rgba(255, 45, 85, .3);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 0;
}
.error.floating { position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(560px, calc(100vw - 32px)); background: #2a0f16; z-index: 30; }

.hint { color: var(--ink-faint); font-size: 13px; margin: 0; line-height: 1.5; }

/* ── sala d'espera ─────────────────────────────────────────────────────── */

.lobby-code { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: clamp(8px, 3vh, 24px); }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: .16em; color: var(--ink-faint); }

/* El QR mana: és un joc de taula, s'escaneja el mòbil del del costat.
   Fons blanc i marge propi — un QR sobre fons fosc no l'agafa cap càmera. */
.qr {
  width: clamp(180px, 52vw, 232px);
  aspect-ratio: 1;
  background: #fff;
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 14px 34px -18px #000;
  animation: rise .3s ease;
}
.qr svg { display: block; border-radius: 6px; }

.code-line { margin: 0; font-size: 13px; color: var(--ink-faint); display: flex; align-items: baseline; gap: 10px; }
.code-line strong { font-size: clamp(30px, 9vw, 40px); font-weight: 900; letter-spacing: .12em; text-indent: .12em; line-height: 1; color: var(--ink); }

/* ── full del QR a mig joc ─────────────────────────────────────────────── */

.sheet {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: var(--pad);
  background: rgba(6, 6, 8, .72); backdrop-filter: blur(3px); animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; align-items: center; gap: 12px;
}

/* Qui arriba escanejant el QR només ha de fer una cosa: dir com es diu. */
#join-sheet .sheet-card { align-items: stretch; text-align: center; width: min(360px, 100%); }
.sheet-code { font-size: clamp(38px, 12vw, 52px); font-weight: 900; letter-spacing: .12em; text-indent: .12em; line-height: 1; }
#join-sheet .field { gap: 10px; margin-top: 4px; }
#join-sheet [data-join-cancel] { border: 0; color: var(--ink-faint); font-size: 13px; padding: 4px; }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.players li { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.players li:last-child { border-bottom: 0; }
.players .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .tag { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-faint); border: 1px solid var(--line); border-radius: 99px; padding: 2px 7px; }
.players .tag.judge { color: var(--gold); border-color: rgba(255,200,61,.4); }
.players .tag.you { color: var(--accent); border-color: rgba(255,45,85,.4); }
.players .sc { font-weight: 800; font-variant-numeric: tabular-nums; min-width: 22px; text-align: right; }
.players .dot { width: 7px; height: 7px; border-radius: 50%; background: #3ddc84; flex: none; }
.players .dot.off { background: #4a4a53; }
.players li.done .nm::after { content: " ✓"; color: #3ddc84; }
.players .kick { background: none; border: 0; color: var(--ink-faint); font-size: 16px; cursor: pointer; padding: 0 4px; }

/* ── partida ───────────────────────────────────────────────────────────── */

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.topbar-left { display: flex; gap: 8px; align-items: center; }
.room-tag, .round-tag { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.room-tag {
  font-family: inherit; font-weight: 800; color: var(--ink-dim); cursor: pointer;
  background: none; border: 1px solid var(--line); border-radius: 99px; padding: 5px 11px;
  display: inline-flex; align-items: center; gap: 6px; -webkit-tap-highlight-color: transparent;
}
.room-tag::before { content: "▦"; font-size: 13px; line-height: 1; letter-spacing: 0; }
.room-tag:active { background: var(--line); }

.scoreboard { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }

.stage { display: flex; flex-direction: column; gap: 16px; flex: 1; }

.status { text-align: center; font-size: 14px; color: var(--ink-dim); min-height: 20px; line-height: 1.45; }
.status b { color: var(--ink); }

/* Qui fa de jutge ho ha de veure sense llegir res: barra d'or a dalt de tot. */
.rolebar {
  display: flex; align-items: center; gap: 12px;
  border-radius: 12px; padding: 12px 14px;
  border: 1px solid rgba(255, 200, 61, .45);
  background: linear-gradient(90deg, rgba(255, 200, 61, .18), rgba(255, 200, 61, .04));
  animation: rise .3s ease;
}
.rolebar .icon { font-size: 24px; line-height: 1; flex: none; }
.rolebar .txt { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.rolebar .ttl { color: var(--gold); text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 800; }
.rolebar .dsc { font-size: 13px; color: var(--ink-dim); line-height: 1.4; }

.rolebar.other { border-color: var(--line); background: var(--bg-2); }
.rolebar.other .ttl { color: var(--ink-dim); }

/* i, per si de cas, la carta negra també es tenyeix d'or quan jutges */
.card.black.judging { border-color: rgba(255, 200, 61, .5); box-shadow: 0 0 0 1px rgba(255, 200, 61, .18), 0 18px 40px -22px #000; }

/* cartes */
.card {
  border-radius: 16px;
  padding: 20px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -.01em;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card p { margin: 0; }
.card footer { margin-top: auto; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; opacity: .45; }

.card.black {
  background: #000;
  border: 1px solid #2e2e36;
  color: #fff;
  font-size: clamp(19px, 5.2vw, 25px);
  min-height: clamp(132px, 20vh, 168px);
  box-shadow: 0 18px 40px -22px #000;
}
.card.black .gap { color: var(--accent); }
.card.black .fill { color: var(--gold); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }

.card.white { background: var(--card-face); color: var(--card-ink); font-size: 15px; }

/* taula del jutge */
.table { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }

.sub {
  position: relative; border-radius: 16px; min-height: 128px; padding: 16px; text-align: left;
  font: inherit; font-weight: 700; font-size: 15px; line-height: 1.3; cursor: default;
  border: 1px solid transparent; transition: transform .12s, box-shadow .12s;
  display: flex; flex-direction: column; gap: 8px;
  animation: rise .3s ease;
}
.sub.hidden-card {
  background: repeating-linear-gradient(45deg, #17171c 0 8px, #1c1c22 8px 16px);
  border-color: var(--line); color: var(--ink-faint); align-items: center; justify-content: center;
  font-size: 13px; text-transform: uppercase; letter-spacing: .1em;
}
.sub.hidden-card.done { border-color: rgba(61, 220, 132, .45); color: #3ddc84; }
.sub.face { background: var(--card-face); color: var(--card-ink); }
.sub.tappable { cursor: pointer; }
.sub.tappable:active { transform: scale(.97); }
.sub.face.tappable:hover { box-shadow: 0 0 0 3px var(--accent); }
/* Les cartes blanques es guarden en minúscula (van dins la frase de la carta
   negra); soltes, es mostren amb majúscula inicial. */
.sub.face p::first-letter, .hand button::first-letter { text-transform: uppercase; }

.sub .who { margin-top: auto; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; }
.sub.win { box-shadow: 0 0 0 3px var(--gold), 0 14px 34px -16px var(--gold); }
.sub.win .who { opacity: 1; color: #8a6b00; font-weight: 800; }
.sub .mine-tag { position: absolute; top: -7px; right: 10px; background: var(--accent); color: #fff; font-size: 10px; letter-spacing: .08em; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; }

/* mà */
/* espai perquè l'últim rengle de cartes no quedi sota la barra d'acció */
.hand-wrap { margin-top: auto; padding-bottom: 76px; }
.hand { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 10px; }

.hand button {
  position: relative; text-align: left; font: inherit; font-weight: 700; font-size: 15px; line-height: 1.3;
  background: var(--card-face); color: var(--card-ink); border: 0; border-radius: 14px; padding: 16px;
  min-height: 104px; cursor: pointer; transition: transform .12s, box-shadow .12s, opacity .12s;
  -webkit-tap-highlight-color: transparent;
}
.hand button:active { transform: scale(.97); }
.hand button.sel { box-shadow: 0 0 0 3px var(--accent), 0 12px 28px -14px var(--accent); transform: translateY(-3px); }
.hand button .ord {
  position: absolute; top: -8px; right: -6px; background: var(--accent); color: #fff;
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 800;
}
.hand.locked button { opacity: .45; pointer-events: none; }

.actionbar {
  position: sticky; bottom: 0; padding: 12px 0 calc(4px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
  display: flex; z-index: 20;
}
.actionbar .btn { flex: 1; }

/* ── final ─────────────────────────────────────────────────────────────── */

.trophy { font-size: 72px; text-align: center; margin-top: clamp(12px, 8vh, 60px); animation: pop .55s cubic-bezier(.16, 1, .3, 1); }
@keyframes pop { from { transform: scale(.3) rotate(-20deg); opacity: 0; } }
.winner-name { text-align: center; font-size: clamp(32px, 10vw, 46px); font-weight: 900; margin: 6px 0 0; letter-spacing: -.03em; }
.view[data-view=over] .tagline { margin-top: 4px; }

/* ── connexió ──────────────────────────────────────────────────────────── */

.conn {
  position: fixed; top: 0; left: 0; right: 0; text-align: center; font-size: 12px;
  padding: 6px; background: #3a2a00; color: var(--gold); z-index: 50; letter-spacing: .04em;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
