:root {
  --bg: #140d1f;
  --bg2: #1f1530;
  --panel: #271b3b;
  --line: #3a2a55;
  --text: #f6f0ff;
  --muted: #a99bc2;
  --beer: #ffb81c;
  --pink: #ff3d7f;
  --cyan: #2fd3e6;
  --lime: #9be14a;
  --violet: #9b6bff;
  --paper: #fff8ec;
  --ink: #17121f;
  --display: 'Bungee', 'Arial Black', sans-serif;
  --radius: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: radial-gradient(120% 70% at 50% -10%, #3b1d52 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 700 17px/1.4 'Nunito', system-ui, sans-serif;
  min-height: 100dvh;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--display); font-weight: 400; margin: 0; line-height: 1.05; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

.wrap { max-width: 520px; margin: 0 auto; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); min-height: 100dvh; display: flex; flex-direction: column; gap: 14px; }

/* ---------- buttons & inputs ---------- */
.btn { border: 0; border-radius: 16px; padding: 15px 18px; font-weight: 900; font-size: 18px; background: var(--panel); color: var(--text); box-shadow: 0 4px 0 #0c0714; transition: transform .08s; width: 100%; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #0c0714; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.beer { background: var(--beer); color: var(--ink); box-shadow: 0 4px 0 #a86f00; }
.btn.pink { background: var(--pink); color: #fff; box-shadow: 0 4px 0 #a01b4a; }
.btn.ghost { background: transparent; border: 2px solid var(--line); box-shadow: none; }
.btn.small { padding: 9px 12px; font-size: 15px; width: auto; border-radius: 12px; }
.input { width: 100%; background: #0d0816; border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; font-size: 19px; outline: none; }
.input:focus { border-color: var(--beer); }
.code-in { text-transform: uppercase; letter-spacing: .4em; text-align: center; font-family: var(--display); font-size: 30px; padding-left: calc(16px + .4em); }
.lbl { display: block; font-size: 13px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); margin: 0 0 6px 4px; }
.err { color: #ff8aa8; text-align: center; min-height: 1.4em; font-size: 15px; }

/* ---------- home ---------- */
.logo { text-align: center; padding: 18px 0 4px; }
.logo .fan { position: relative; height: 128px; margin: 0 auto 6px; width: 200px; }
.logo .fan .fc { position: absolute; left: 50%; top: 8px; width: 78px; height: 108px; margin-left: -39px; border-radius: 12px; transform-origin: 50% 120%; }
.logo h1 { font-size: 40px; letter-spacing: .02em; text-shadow: 0 4px 0 #0c0714; }
.logo h1 { font-size: 46px; }
.logo h1 .rest { color: var(--text); display: block; }
.logo h1 .with { display: block; font: 900 italic 22px/1 'Nunito', sans-serif; color: var(--pink); margin: 2px 0 4px; text-shadow: none; }
.logo h1 .josh { color: var(--beer); display: block; font-size: 1.3em; }
.logo p { color: var(--muted); margin: 8px 0 0; }
.card-panel { background: rgba(39, 27, 59, .7); border: 2px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; backdrop-filter: blur(6px); }
/* Home fits on one screen (even with Safari's bars showing): everything scales with the visible height */
.wrap.home { --fh: clamp(54px, 12.5dvh, 128px); height: 100dvh; min-height: 0; justify-content: center; gap: clamp(8px, 1.8dvh, 16px); padding-top: max(10px, env(safe-area-inset-top)); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.home .logo { padding: 0; }
.home .logo .fan { height: calc(var(--fh) * 1.1); width: calc(var(--fh) * 1.6); margin-bottom: clamp(4px, 1dvh, 8px); }
.home .logo .fan .fc { top: calc(var(--fh) * .06); width: calc(var(--fh) * .64); height: calc(var(--fh) * .88); margin-left: calc(var(--fh) * -.32); border-width: 3px; border-radius: calc(var(--fh) * .1); }
.home .logo .fan .fc::after { font-size: calc(var(--fh) * .12); }
.home .logo h1 { font-size: clamp(30px, 5.6dvh, 46px); }
.home .logo h1 .with { font-size: clamp(15px, 2.6dvh, 22px); }
.home .logo p { font-size: clamp(14px, 2dvh, 17px); margin-top: clamp(4px, 1dvh, 8px); }
.home .card-panel { padding: clamp(12px, 2dvh, 18px); gap: clamp(7px, 1.3dvh, 12px); }
.home .input { padding-top: clamp(9px, 1.5dvh, 14px); padding-bottom: clamp(9px, 1.5dvh, 14px); }
.home .code-in { font-size: clamp(24px, 3.8dvh, 30px); }
.home .btn { padding-top: clamp(10px, 1.7dvh, 15px); padding-bottom: clamp(10px, 1.7dvh, 15px); }
.home .err:empty { display: none; }
.home .small-print { margin-top: 0; padding-top: 0; font-size: 12px; }
.or { text-align: center; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 10px; }
.or::before, .or::after { content: ''; flex: 1; height: 2px; background: var(--line); }
.small-print { text-align: center; font-size: 13px; color: var(--muted); margin-top: auto; padding-top: 8px; }

/* ---------- card back & face ---------- */
.back {
  background:
    radial-gradient(circle at 50% 50%, var(--bg) 0 22%, transparent 23%),
    repeating-linear-gradient(45deg, var(--pink) 0 10px, #d92a68 10px 20px);
  border: 4px solid var(--paper);
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
  display: grid; place-items: center;
}
.back::after { content: 'JOSH'; font-family: var(--display); color: var(--beer); font-size: 15px; letter-spacing: .02em; }
.back.big::after { font-size: 26px; }

.face {
  background: var(--paper); color: var(--ink); border-radius: 22px; padding: 16px 16px 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px;
  position: relative;
}
.face .frame { width: 100%; height: 150px; border: 4px solid var(--ink); border-radius: 22px; display: flex; padding: 14px; background: #fff; overflow: hidden; }
.face .frame img { width: 100%; height: 100%; min-height: 0; object-fit: contain; display: block; }
.face h2 { font-size: 26px; color: var(--ink); }
.face p { margin: 0; font-size: 18px; line-height: 1.38; font-weight: 800; color: #2b2236; }
.tag { display: inline-block; font-family: var(--display); font-size: 13px; letter-spacing: .04em; padding: 5px 11px 4px; border-radius: 99px; color: var(--ink); background: var(--beer); }
.tag.you { background: var(--beer); }
.tag.all { background: var(--pink); color: #fff; }
.tag.pick { background: var(--cyan); }
.tag.versus { background: var(--lime); }
.tag.left, .tag.right { background: #ff8a3d; }
.tag.hold { background: var(--violet); color: #fff; }
.face.hold { background: linear-gradient(#fff8ec, #f3eaff); }
.face.hold .frame { border-color: #4b2b8f; }

/* flip-in */
.flip { perspective: 1200px; }
.flip .inner { position: relative; transform-style: preserve-3d; animation: flip .7s cubic-bezier(.2,.8,.2,1.05) both; }
.flip .inner > .side-back { position: absolute; inset: 0; border-radius: 22px; transform: rotateY(180deg); backface-visibility: hidden; }
.flip .inner > .face { backface-visibility: hidden; }
@keyframes flip { from { transform: rotateY(180deg) scale(.85); } to { transform: rotateY(0) scale(1); } }

/* ---------- game layout ---------- */
.topbar { display: flex; align-items: center; gap: 8px; }
.chip { background: var(--panel); border: 2px solid var(--line); border-radius: 99px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
.chip.code { font-family: var(--display); letter-spacing: .12em; color: var(--beer); }
.topbar .grow { flex: 1; }
.iconbtn { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; width: 42px; height: 42px; display: grid; place-items: center; font-size: 20px; padding: 0; }

.seats { display: flex; gap: 8px; overflow-x: auto; padding: 12px 2px 8px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.seats::-webkit-scrollbar { display: none; }
.seat { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px; position: relative; }
.seat .av { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-size: 19px; color: var(--ink); border: 3px solid transparent; position: relative; }
.seat.turn .av { border-color: var(--text); box-shadow: 0 0 0 4px var(--beer), 0 0 22px var(--beer); animation: pulse 1.4s ease-in-out infinite; }
.seat.off .av { filter: grayscale(1) brightness(.6); }
.seat .nm { font-size: 13px; max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat.me .nm { color: var(--beer); }
.seat .badges { position: absolute; top: -8px; right: 2px; display: flex; gap: 2px; }
.badge { background: var(--violet); color: #fff; font-size: 11px; font-weight: 900; border-radius: 99px; min-width: 20px; height: 20px; display: grid; place-items: center; padding: 0 5px; border: 2px solid var(--bg); }
.badge.jail { background: #555; }
.badge.trap { background: var(--pink); }
.dir { align-self: center; color: var(--muted); font-size: 18px; flex: 0 0 auto; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px var(--beer), 0 0 30px var(--beer); } }

.rules { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: -4px -16px 0; padding: 0 16px; }
.rules::-webkit-scrollbar { display: none; }
.rule { flex: 0 0 auto; white-space: nowrap; background: #2b1840; border: 2px dashed var(--pink); border-radius: 12px; padding: 5px 10px; font-size: 14px; text-align: left; }
.rule b { color: var(--pink); }

.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 12px; min-height: 340px; }
.who { text-align: center; font-size: 18px; }
.who b { color: var(--beer); }
.deck-btn { border: 0; background: none; padding: 0; margin: 0 auto; display: block; position: relative; width: 200px; height: 270px; }
.deck-btn .back { position: absolute; inset: 0; border-radius: 22px; }
.deck-btn .back:nth-child(1) { transform: rotate(-6deg) translate(-6px, 6px); opacity: .7; }
.deck-btn .back:nth-child(2) { transform: rotate(4deg) translate(5px, 3px); opacity: .85; }
.deck-btn.go .back:nth-child(3) { animation: bob 1.6s ease-in-out infinite; }
.deck-btn .cta { position: absolute; left: 50%; bottom: -14px; transform: translateX(-50%); white-space: nowrap; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-1deg); } }
.waiting .deck-btn { opacity: .75; pointer-events: none; }

.actions { display: flex; flex-direction: column; gap: 10px; }
.note { text-align: center; color: var(--muted); font-size: 15px; }
.picker { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.pbtn { border: 2px solid var(--line); background: var(--panel); border-radius: 99px; padding: 9px 14px; font-weight: 800; display: inline-flex; align-items: center; gap: 6px; }
.pbtn.on { border-color: var(--beer); background: #3b2a12; color: var(--beer); }
.pbtn .n { background: var(--beer); color: var(--ink); border-radius: 99px; width: 22px; height: 22px; display: inline-grid; place-items: center; font-size: 13px; }
.pbtn:disabled { opacity: .35; }

/* ---------- hand ---------- */
.hand { background: rgba(39, 27, 59, .75); border: 2px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; }
.hand h3 { font-size: 14px; color: var(--muted); font-family: 'Nunito'; font-weight: 900; text-transform: uppercase; letter-spacing: .12em; margin-bottom: 8px; display: flex; justify-content: space-between; }
.hand-row { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.hand-row::-webkit-scrollbar { display: none; }
.mini { flex: 0 0 auto; width: 92px; background: var(--paper); color: var(--ink); border: 0; border-radius: 14px; padding: 8px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: 0 4px 0 #0c0714; }
.mini img { height: 40px; max-width: 76px; object-fit: contain; }
.mini span { font-size: 12px; font-weight: 900; line-height: 1.1; text-align: center; }
.mini.trap { background: repeating-linear-gradient(45deg, var(--pink) 0 8px, #d92a68 8px 16px); color: #fff; }
.mini.new { animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(.4) rotate(-10deg); } 70% { transform: scale(1.1); } }
.hand .empty { color: var(--muted); font-size: 14px; padding: 6px 2px; }

/* ---------- sheets & overlays ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(8, 4, 14, .72); display: flex; align-items: flex-end; justify-content: center; z-index: 50; animation: fade .2s; backdrop-filter: blur(3px); }
.sheet { background: var(--bg2); width: 100%; max-width: 520px; max-height: 92dvh; overflow-y: auto; border-radius: 24px 24px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; animation: up .25s cubic-bezier(.2,.8,.2,1); border-top: 2px solid var(--line); }
.sheet h2 { font-size: 22px; }
.sheet .face { box-shadow: none; }
.sheet .face .frame { height: 120px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40%); } }

.announce { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px; background: rgba(8, 4, 14, .8); animation: fade .2s; backdrop-filter: blur(4px); }
.announce .box { background: var(--paper); color: var(--ink); border-radius: 24px; padding: 22px 20px; max-width: 420px; width: 100%; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; animation: pop .45s ease; box-shadow: 0 0 0 4px var(--beer), 0 20px 60px rgba(0,0,0,.6); }
.announce img { max-height: 90px; max-width: 70%; }
.announce .reveal { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.announce .reveal p { font-size: 18px; }
.announce p { margin: 0; font-size: 20px; font-weight: 900; line-height: 1.3; }
.announce .tap { font-size: 13px; color: #7b6d8f; }

.brk { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; text-align: center; background: radial-gradient(circle at 50% 30%, #3d2160, var(--bg)); }
.brk h1 { font-size: 46px; color: var(--beer); }
.brk .big { font-size: 90px; }
.brk p { font-size: 20px; max-width: 360px; }

.toast { width: max-content; position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translateX(-50%); background: var(--beer); color: var(--ink); padding: 10px 16px; border-radius: 14px; font-weight: 900; z-index: 99; box-shadow: 0 6px 20px rgba(0,0,0,.4); max-width: 92vw; text-align: center; animation: fade .2s; }

.lobby-code { text-align: center; }
.lobby-code .big { font-family: var(--display); font-size: 68px; letter-spacing: .12em; color: var(--beer); line-height: 1; text-shadow: 0 5px 0 #0c0714; }
.plist { display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; align-items: center; gap: 12px; background: var(--panel); border-radius: 14px; padding: 8px 12px; }
.prow .av { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); color: var(--ink); font-size: 15px; flex: 0 0 auto; }
.prow .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .x { background: none; border: 0; color: var(--muted); font-size: 14px; padding: 6px; }
.prow.off .nm { color: var(--muted); }

.log { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.log div { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); }
.log div:last-child { color: var(--text); border-color: var(--beer); }
.how p { margin: 0 0 10px; color: var(--muted); }
.how b { color: var(--text); }
textarea.input { min-height: 90px; resize: vertical; font-size: 17px; }

@media (min-width: 700px) {
  .stage .face { max-width: 440px; margin: 0 auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
@media (max-height: 600px) {
  .home .logo p { display: none; }
}
