/* Layout: one-screen card table. Players on top, one large card in the middle, actions below.
   Single deliberate look: indigo velvet with brass, ivory cards. */
:root {
  --table: #1d1b3a;
  --table-2: #2a2758;
  --brass: #d9b25f;
  --brass-dk: #8c6a2a;
  --ink: #f3efe4;
  --muted: #a9a5cc;
  --card: #fbf8f1;
  --card-ink: #1c1b22;
  --card-muted: #5b5870;
  --rose: #e0566f;
  --display: "DM Serif Display", Georgia, "Times New Roman", serif;
  --body: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(ellipse at 50% 30%, var(--table-2), var(--table) 70%) fixed;
  background-color: var(--table);
  color: var(--ink);
  font: 15px/1.45 var(--body);
  -webkit-tap-highlight-color: transparent;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }
button { font-family: var(--body); color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.wrap {
  max-width: 620px; margin: 0 auto; min-height: 100%;
  padding-inline: 16px; padding-block: 14px 22px;
  display: flex; flex-direction: column; gap: 14px;
}

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
h1 { font: 400 1.5rem var(--display); margin: 0; color: var(--brass); }
.menu { display: flex; gap: 6px; }
.icon-btn {
  background: transparent; border: 0; cursor: pointer; font-weight: 600; font-size: .85rem;
  color: var(--muted); padding: .45em .8em; border-radius: 999px; box-shadow: inset 0 0 0 1.5px rgba(169,165,204,.45);
}
.icon-btn:hover { color: var(--ink); }

/* Players */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.player {
  border-radius: 14px; padding: 10px 12px; background: rgba(255,255,255,.04);
  box-shadow: inset 0 0 0 1.5px rgba(169,165,204,.25); display: flex; flex-direction: column; gap: 4px; min-width: 0;
  transition: box-shadow .2s, background .2s;
}
.player.active { background: rgba(217,178,95,.12); box-shadow: inset 0 0 0 2px var(--brass); }
.player .name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .meta { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; gap: 8px; }
.passes { display: flex; gap: 4px; }
.passes i { width: 9px; height: 9px; border-radius: 50%; background: var(--brass); display: block; }
.passes i.used { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
.label { text-transform: uppercase; letter-spacing: .12em; font-size: .7rem; font-weight: 600; color: var(--muted); }

/* Card */
.stage { flex: 1; display: grid; place-items: center; perspective: 1400px; min-height: 360px; }
.card {
  width: min(100%, 360px); aspect-ratio: 5 / 7; max-height: 62vh; position: relative;
  transform-style: preserve-3d; transition: transform .6s cubic-bezier(.3,.7,.3,1);
}
.card.flipped { transform: rotateY(180deg); }
.card.out { animation: out .28s ease-in forwards; }
@keyframes out { to { transform: rotateY(180deg) translateX(-40px) rotate(-6deg); opacity: 0; } }
.face {
  position: absolute; inset: 0; border-radius: 20px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 14px 34px rgba(0,0,0,.45);
}
.back {
  background:
    radial-gradient(circle at 50% 50%, var(--table) 0 32%, transparent 32.5%),
    repeating-linear-gradient(45deg, var(--brass) 0 7px, var(--brass-dk) 7px 14px);
  border: 7px solid var(--card); display: grid; place-items: center;
}
.back-mark, .logo span { font: 400 2.4rem var(--display); color: var(--brass); }
.back-mark i, .logo i { font-style: italic; color: var(--ink); padding-inline: .05em; }
.front {
  transform: rotateY(180deg); background: var(--card); color: var(--card-ink);
  padding: 22px 22px 18px; display: flex; flex-direction: column; justify-content: space-between; gap: 12px;
}
.front-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.cat { font: 700 .72rem var(--body); text-transform: uppercase; letter-spacing: .14em; color: var(--brass-dk); }
.q { font: 400 clamp(1.3rem, 5.4vw, 1.8rem)/1.25 var(--display); margin: 0; text-wrap: balance; overflow-wrap: anywhere; }
.who { font-size: .9rem; color: var(--card-muted); border-top: 1px solid #e3ddcf; padding-top: 12px; }
.who b { color: var(--card-ink); }
.fav { background: transparent; border: 0; padding: 6px; margin: -6px; cursor: pointer; line-height: 0; }
.fav svg { width: 26px; height: 26px; fill: transparent; stroke: var(--card-muted); stroke-width: 1.8; transition: fill .15s, stroke .15s, transform .15s; }
.fav[aria-pressed="true"] svg { fill: var(--rose); stroke: var(--rose); transform: scale(1.1); }
.fav:focus-visible { outline-color: var(--card-ink); }

.left { text-align: center; color: var(--muted); font-size: .85rem; margin: 0; font-variant-numeric: tabular-nums; }

/* Buttons */
.actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.btn {
  font-weight: 700; font-size: 1.05rem; border: 0; border-radius: 999px; padding: .85em 1.6em; cursor: pointer;
  background: var(--brass); color: #22190a; transition: transform .1s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--muted); }
.btn.small { font-size: .9rem; padding: .6em 1.1em; }
.btn.danger { background: transparent; color: #ff8a9b; box-shadow: inset 0 0 0 1.5px #ff8a9b; }
.btn:disabled { opacity: .35; cursor: not-allowed; }

/* Setup */
.overlay { position: fixed; inset: 0; background: var(--table); display: grid; place-items: center; padding: 16px; z-index: 5; overflow-y: auto; }
.panel { max-width: 400px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.panel h2 { font: 400 2.2rem var(--display); margin: 0; color: var(--brass); text-wrap: balance; }
.panel p { margin: 0; color: var(--muted); line-height: 1.55; }
.logo { width: 96px; height: 134px; border-radius: 12px; border: 5px solid var(--card); display: grid; place-items: center;
  background: radial-gradient(circle, var(--table) 0 34%, transparent 34.5%), repeating-linear-gradient(45deg, var(--brass) 0 5px, var(--brass-dk) 5px 10px);
  transform: rotate(-6deg); box-shadow: 0 10px 24px rgba(0,0,0,.4); }
.logo span { font-size: 1.5rem; }
.fields { display: flex; flex-direction: column; gap: 6px; width: 100%; text-align: left; }
.fields label { font-size: .8rem; color: var(--muted); font-weight: 600; margin-top: 6px; }
input, textarea {
  font: inherit; font-size: 1rem; padding: .7em 1em; border-radius: 10px; border: 1.5px solid rgba(169,165,204,.5);
  background: var(--table-2); color: var(--ink); width: 100%;
}
textarea { resize: vertical; min-height: 90px; }

/* Bottom sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.scrim { position: absolute; inset: 0; background: rgba(10,9,25,.6); }
.sheet {
  position: relative; width: 100%; max-width: 620px; max-height: 86vh; display: flex; flex-direction: column;
  background: var(--table); border-radius: 20px 20px 0 0; box-shadow: 0 -10px 30px rgba(0,0,0,.4);
  padding-bottom: env(safe-area-inset-bottom, 0px); animation: up .25s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 8px; gap: 12px; }
.sheet-head h2 { font: 400 1.5rem var(--display); margin: 0; color: var(--brass); }
.sheet-body { overflow-y: auto; padding: 8px 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.sheet-body p { margin: 0; color: var(--muted); }
.sheet-body h3 { margin: 8px 0 0; font-size: .75rem; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }

.deck-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
  background: rgba(255,255,255,.04); cursor: pointer; border: 0; width: 100%; text-align: left;
}
.deck-row .info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.deck-row .info b { font-size: 1rem; }
.deck-row .info span { font-size: .82rem; color: var(--muted); }
.deck-row .count { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.switch { width: 42px; height: 24px; border-radius: 999px; background: rgba(169,165,204,.3); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); transition: transform .15s; }
[aria-checked="true"] .switch { background: var(--brass); }
[aria-checked="true"] .switch::after { transform: translateX(18px); }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list li { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--card); color: var(--card-ink); }
.list li div { flex: 1; min-width: 0; }
.list li small { display: block; font-size: .7rem; text-transform: uppercase; letter-spacing: .12em; color: var(--brass-dk); font-weight: 700; margin-bottom: 2px; }
.list li span { font-family: var(--display); font-size: 1.08rem; line-height: 1.3; overflow-wrap: anywhere; }
.list li button { background: transparent; border: 0; color: var(--card-muted); cursor: pointer; font-size: .8rem; font-weight: 600; padding: 4px; }
.empty { text-align: center; padding: 20px 8px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: rgba(255,255,255,.05); border-radius: 12px; padding: 12px; text-align: center; }
.stat b { display: block; font: 400 2rem var(--display); color: var(--brass); font-variant-numeric: tabular-nums; }
.stat span { font-size: .85rem; color: var(--muted); }

/* Two phones */
.link-pill {
  margin-right: auto; border: 0; cursor: pointer; font-weight: 600; font-size: .78rem; padding: .4em .8em .4em .7em;
  border-radius: 999px; background: rgba(255,255,255,.06); color: var(--muted); display: inline-flex; align-items: center; gap: .45em;
  max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.link-pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1.5px var(--muted); }
.link-pill.on { color: var(--ink); }
.link-pill.on::before { background: #6fd39b; box-shadow: none; }
.or { display: flex; align-items: center; gap: 12px; width: 100%; font-size: .85rem; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: rgba(169,165,204,.3); }
.row.center { justify-content: center; }
.logo.small { width: 64px; height: 90px; border-width: 4px; }
.logo.small span { font-size: .78rem; }
.code-box { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 18px; border-radius: 14px; background: rgba(255,255,255,.05); width: 100%; }
.code { font: 700 2.2rem/1.1 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .18em; color: var(--brass); padding-left: .18em; }
.qr { width: min(220px, 64vw); aspect-ratio: 1; border-radius: 14px; overflow: hidden; background: var(--card); flex: none; align-self: center; }
.qr svg { display: block; width: 100%; height: 100%; fill: var(--card-ink); }
.qr:empty { opacity: .25; }
.scanner { width: min(300px, 78vw); aspect-ratio: 1; border-radius: 16px; overflow: hidden; background: #000; position: relative; flex: none; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner::after { content: ""; position: absolute; inset: 14%; border-radius: 12px; box-shadow: 0 0 0 2px var(--brass), 0 0 0 999px rgba(0,0,0,.35); pointer-events: none; }
.steps { margin: 0; padding-left: 1.3em; text-align: left; color: var(--muted); display: flex; flex-direction: column; gap: 4px; width: 100%; }
.steps b, .panel p b { color: var(--ink); }
.text-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: var(--brass); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.code-input { text-transform: uppercase; letter-spacing: .2em; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.wait { margin: 0; color: var(--muted); text-align: center; padding: .85em 0; }
.wait b { color: var(--ink); }
.dots::after { content: "…"; display: inline-block; animation: dots 1.4s steps(4, end) infinite; overflow: hidden; vertical-align: bottom; width: 0; }
@keyframes dots { to { width: 1.1em; } }
.panel .fine { font-size: .82rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px);
  background: var(--card); color: var(--card-ink); padding: .6em 1.1em; border-radius: 999px; font-weight: 600; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .stage { min-height: 300px; }
  .front { padding: 18px 18px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .card, .sheet, .toast, .switch::after { transition: none; animation: none; }
  .card.out { animation: none; }
  .dots::after { animation: none; width: auto; }
}
