/* Mafia (member request, henry: "Add this https://en.wikipedia.org/wiki/Mafia_(party_game)"). public/mafia.js.
   The Bad Family as a crime family: a felt card table seen from above, seats round its rim (yours at the bottom), the
   clock in board letters in the middle. Night is a midnight room, day the wall. Periwinkle marks picks; one deep blood
   red is spent only on the dead (their card, stamped over their head). Your role is a paper card you hold to peek at. */
.mf, .mf-invite {
  --mf-night: #121a3f;
  --mf-night-2: #0d1331;
  --mf-blood: #8e1b22;
  --mf-peri: #7c8cff;
  --mf-paper: #ffffff;
  --mf-paper-ink: #1d2140;
}
@media (prefers-color-scheme: dark) {
  .mf, .mf-invite { --mf-night: #0a0e26; --mf-night-2: #070a1c; }
}

/* ---------- the overlay ---------- */
.mf { position: fixed; left: 0; right: 0; top: 0; height: var(--app-h); z-index: 30; display: flex; flex-direction: column; background: var(--wall); color: var(--ink); opacity: 0; transition: opacity .18s, background-color .7s; overscroll-behavior: contain; --room-ink: var(--ink); --room-ink-2: var(--ink-2); --room-rule: var(--rule); }
.mf.in { opacity: 1; }
.mf.night { background: var(--mf-night); color: var(--letter); --room-ink: var(--letter); --room-ink-2: #c5cae6; --room-rule: #ffffff1f; }
.mf :focus-visible { outline: 3px solid var(--mf-peri); outline-offset: 2px; }
.mf button { -webkit-user-select: none; user-select: none; }

.mf-top { flex: none; display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px calc(16px + env(safe-area-inset-left)); padding-right: calc(12px + env(safe-area-inset-right)); }
.mf-title { flex: 1; min-width: 0; }
.mf-title .row1 { font-size: 30px; letter-spacing: .2em; }
.mf-title .row2 { margin-top: 5px; }
.mf-x { flex: none; width: 44px; height: 44px; padding: 0; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--letter); background: none; color: var(--letter); }
.mf-x svg { width: 20px; height: 20px; }

/* ---------- the table ---------- */
.mf-room { flex: none; position: relative; height: clamp(250px, 44vh, 390px); width: 100%; max-width: 560px; margin: 0 auto; transition: height .2s; }
html.kb-open .mf-room { height: 0; overflow: hidden; }
.mf-felt { position: absolute; inset: 16% 13%; border-radius: 50%;
  background-color: var(--felt); background-image: repeating-linear-gradient(to bottom, transparent 0 7px, var(--felt-groove) 7px 9px);
  box-shadow: inset 0 0 0 2px #f5f5f222, 0 0 0 7px var(--felt-groove), 0 7px 0 7px #00000038; }
.mf.night .mf-felt { box-shadow: inset 0 0 0 2px #f5f5f222, 0 0 0 7px #05081a, 0 7px 0 7px #00000066; }
.mf-mid { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 54%; max-width: 270px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; color: var(--letter); }
.mf-mid p { margin: 0; }
.mf-clock { font-size: 46px; line-height: 1; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.mf-clock.low { color: var(--mf-peri); }
.mf-big { font-size: 30px; line-height: 1; }
.mf-win { font-size: 28px; line-height: 1.05; letter-spacing: .16em; }
.mf-prompt, .mf-note { font-size: 14.5px; line-height: 1.3; color: #f5f5f2d9; text-wrap: balance; }
.mf-btn { min-height: 44px; padding: 10px 18px; border: 0; border-radius: 10px; background: var(--indigo); color: var(--indigo-ink); font-weight: 700; font-size: 16px; }
.mf-btn:active { transform: translateY(1px); }
.mf-btn.quiet { background: transparent; border: 1.5px solid var(--room-rule); color: var(--room-ink); }
.mf-mid .mf-btn { background: var(--letter); color: var(--felt); }
.mf-none { min-height: 40px; padding: 6px 16px; border-radius: 99px; border: 1.5px solid #f5f5f299; background: none; color: var(--letter); font-weight: 700; font-size: 15px; }
.mf-none b { display: inline-grid; place-items: center; min-width: 20px; height: 20px; margin-left: 6px; padding: 0 4px; background: var(--letter); color: var(--felt); font-size: 13px; }
.mf-none.on { border-color: var(--mf-peri); box-shadow: 0 0 0 2px var(--mf-peri); }

/* ---------- seats ---------- */
.mf-seats { position: absolute; inset: 0; --hs: 52px; }
.mf-seats[data-n="9"], .mf-seats[data-n="10"], .mf-seats[data-n="11"], .mf-seats[data-n="12"], .mf-seats[data-n="13"] { --hs: 42px; }
.mf-seat { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -50%); width: calc(var(--hs) + 30px); min-height: 44px; padding: 0; border: 0; background: none; color: inherit; display: flex; flex-direction: column; align-items: center; gap: 3px; transition: transform .15s; }
.mf-seat[aria-disabled="true"] { cursor: default; }
.mf-head { position: relative; display: block; width: var(--hs); height: var(--hs); border-radius: 50%; }
.mf-head .mface, .mf-head .mf-bot { display: block; width: 100%; height: 100%; }
.mf-head img, .mf-head svg { display: block; width: 100%; height: 100%; }
.mf-head .mface.flat svg { padding: 3px; }
.mf-bot svg { display: block; width: 100%; height: 100%; }
.mf-plate { max-width: 100%; padding: 2px 7px; border-radius: 4px; background: var(--felt); color: var(--letter); font-size: 12.5px; font-weight: 700; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mf-seat.you .mf-plate { background: var(--indigo); color: var(--indigo-ink); }
.mf-seat.picked .mf-head { outline: 3px solid var(--mf-peri); outline-offset: 3px; }
.mf-seat.picked { transform: translate(-50%, calc(-50% - 3px)); }
.mf-seat.empty .mf-head { border: 2px dashed var(--room-ink-2); opacity: .7; }
.mf-seat.empty .mf-plate { background: none; color: var(--room-ink); border: 1.5px dashed var(--room-ink-2); }
.mf-count { position: absolute; top: -4px; left: calc(50% + var(--hs) / 2 - 12px); min-width: 22px; height: 22px; padding: 0 5px; display: grid; place-items: center; background: #fff; color: var(--mf-paper-ink); font-size: 13.5px; font-weight: 700; box-shadow: 0 0 0 1.5px var(--felt); }

/* the dead: dimmed, their card stamped across the head in blood red */
.mf-seat.dead .mf-head { filter: grayscale(1); opacity: .42; }
.mf-seat.dead .mf-plate { opacity: .6; text-decoration: line-through; }
.mf-role { position: absolute; top: calc(var(--hs) / 2 - 10px); left: 50%; transform: translateX(-50%) rotate(-9deg); padding: 2px 7px 1px; border-radius: 3px; background: var(--felt); color: var(--letter); font: 600 13px/1.1 var(--board); letter-spacing: .12em; text-transform: uppercase; white-space: nowrap; box-shadow: 0 0 0 1.5px #f5f5f2cc; }
.mf-seat.dead .mf-role { background: var(--mf-blood); }
.mf-seat.fresh .mf-role { animation: mf-stamp .42s cubic-bezier(.3, 1.5, .5, 1) both; }
@keyframes mf-stamp { from { transform: translateX(-50%) rotate(-24deg) scale(2.2); opacity: 0; } to { transform: translateX(-50%) rotate(-9deg) scale(1); opacity: 1; } }

/* what only you know: shown while you hold your card */
.mf-secret { position: absolute; bottom: calc(100% - 6px); left: 50%; transform: translateX(-50%); display: none; gap: 3px; align-items: center; white-space: nowrap; }
.mf.peeking .mf-secret { display: flex; }
.mf-sec { padding: 1px 6px; border-radius: 3px; background: var(--mf-paper); color: var(--mf-paper-ink); font-size: 11.5px; font-weight: 700; box-shadow: 0 0 0 2px var(--mf-peri); }
.mf-pk { display: flex; gap: 2px; }
.mf-pk i { display: grid; place-items: center; width: 18px; height: 18px; background: var(--mf-peri); color: #fff; font-style: normal; font-size: 11px; font-weight: 700; }

/* ---------- table talk ---------- */
.mf-talk { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px calc(14px + env(safe-area-inset-right)) 14px calc(14px + env(safe-area-inset-left)); border-top: 1px solid var(--room-rule); background: var(--wall-2); color: var(--ink); width: 100%; }
.mf.night .mf-talk { background: var(--mf-night-2); color: var(--letter); }
.mf-talk > * { max-width: 620px; margin-left: auto; margin-right: auto; }
.mf-news { margin: 10px auto; text-align: center; font-size: 14.5px; line-height: 1.35; color: var(--room-ink-2); text-wrap: pretty; }
.mf.night .mf-news { color: #c5cae6; }
.mf-news.phase { font-weight: 700; color: inherit; }
.mf-news.death::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 7px; background: var(--mf-blood); vertical-align: 1px; box-shadow: 0 0 0 1.5px #ffffffaa; }
.mf-line { display: flex; gap: 9px; align-items: flex-start; margin: 9px auto; }
.mf-lh { flex: none; width: 30px; height: 30px; }
.mf-lh .mface, .mf-lh .mf-bot, .mf-lh img, .mf-lh svg { display: block; width: 100%; height: 100%; }
.mf-lb { min-width: 0; font-size: 16px; line-height: 1.38; overflow-wrap: anywhere; }
.mf-lb b { display: block; font-size: 13.5px; color: var(--uc, var(--ink)); }
@media (prefers-color-scheme: dark) { .mf-lb b { color: var(--ink); } }
.mf.night .mf-lb b { color: var(--letter); }
.mf-lb i { display: block; font-size: 12.5px; color: var(--mf-peri); }
.mf-lb a { color: inherit; }
.mf-line.whisper .mf-lb { padding-left: 10px; border-left: 3px solid var(--mf-peri); }

/* the end: every card face up */
.mf-cast { margin-top: 18px; padding: 14px 14px 6px; border-radius: 4px; background: var(--mf-paper); color: var(--mf-paper-ink); box-shadow: 0 2px 0 #1d214026; }
.mf-cast h3 { margin: 0 0 6px; font-size: 16px; }
.mf-cast ul { list-style: none; margin: 0; padding: 0; }
.mf-cast li { display: flex; align-items: center; gap: 9px; padding: 7px 0; border-top: 1px solid #1d21401a; }
.mf-cast li b { flex: 1; min-width: 0; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mf-cast .mf-role { position: static; transform: none; flex: none; }
.mf-cast .mf-role.fam { background: var(--indigo); }
.mf-fate { flex: none; width: 34%; font-size: 13px; color: #5b6079; text-align: right; }

/* ---------- taking seats ---------- */
.mf-open h3 { margin: 6px 0 2px; font-size: 16px; }
.mf-sub { margin: 0 0 10px; font-size: 14.5px; color: var(--ink-2); }
.mf-regs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mf-reg { min-height: 44px; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 7px; border: 1.5px solid var(--rule); border-radius: 10px; background: var(--paper); color: var(--ink); font-size: 13px; font-weight: 700; line-height: 1.2; }
.mf-reg .mf-bot { width: 40px; height: 40px; }
.mf-reg.on { border-color: var(--mf-peri); box-shadow: 0 0 0 2px var(--mf-peri); }
.mf-reg:disabled { opacity: .55; }
.mf-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 4px; }
.mf-past { list-style: none; margin: 0 0 8px; padding: 0; }
.mf-past button { width: 100%; min-height: 44px; display: flex; flex-direction: column; gap: 1px; padding: 9px 0; border: 0; border-bottom: 1px solid var(--rule); background: none; text-align: left; color: inherit; }
.mf-past span { font-size: 14.5px; color: var(--ink-2); }
.mf-rules { margin-top: 14px; font-size: 15px; color: var(--ink-2); }
.mf-rules summary { min-height: 44px; display: flex; align-items: center; font-weight: 700; color: var(--ink); cursor: pointer; }
.mf-rules p { margin: 0 0 10px; }

/* ---------- the dock: your card and the talk box ---------- */
.mf-dock { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px calc(12px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left)); background: var(--wall-2); border-top: 1px solid var(--room-rule); }
.mf.night .mf-dock { background: var(--mf-night-2); }
.mf-card { flex: none; width: 40px; height: 56px; padding: 0; border: 0; border-radius: 5px; display: grid; place-items: center; touch-action: none; -webkit-touch-callout: none;
  background-color: #3340a0; background-image: repeating-linear-gradient(to bottom, transparent 0 4px, #0000002e 4px 5px); box-shadow: inset 0 0 0 3px #3340a0, inset 0 0 0 4px #f5f5f266, 0 2px 0 #0000004d; }
.mf-card span { font: 600 12px/1 var(--board); letter-spacing: .14em; text-transform: uppercase; color: var(--letter); transform: rotate(-90deg); text-shadow: 0 1px 0 #000a; pointer-events: none; }
.mf.peeking .mf-card { transform: translateY(2px); box-shadow: inset 0 0 0 3px #3340a0, inset 0 0 0 4px #f5f5f266, 0 0 0 3px var(--mf-peri); }
.mf-card.flash { animation: mf-flash 1.2s ease-out 2; }
@keyframes mf-flash { 0%, 100% { box-shadow: inset 0 0 0 3px #3340a0, inset 0 0 0 4px #f5f5f266, 0 0 0 0 var(--mf-peri); } 30% { box-shadow: inset 0 0 0 3px #3340a0, inset 0 0 0 4px #f5f5f266, 0 0 0 5px var(--mf-peri); } }
.mf-say { flex: 1; min-width: 0; display: flex; gap: 8px; margin: 0; }
.mf-say input { flex: 1; min-width: 0; height: 44px; padding: 0 14px; font-size: 17px; border-radius: 10px; border: 1.5px solid var(--rule); background: var(--paper); color: var(--ink); outline: none; }
.mf-say input:focus { border-color: var(--indigo); }
.mf.night .mf-say input { background: #1b2350; border-color: #ffffff2e; color: var(--letter); }
.mf.night .mf-say input::placeholder { color: #a9b0d8; }
.mf-send { flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; background: var(--indigo); color: var(--indigo-ink); }
.mf-send svg { width: 20px; height: 20px; }
.mf-walk { display: block; min-height: 44px; margin: 14px auto 0; padding: 0 12px; border: 0; background: none; color: var(--room-ink-2); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.mf-quiet { flex: 1; margin: 0; font-size: 15px; color: var(--room-ink-2); }

/* your card, face up */
.mf-peek { position: absolute; left: calc(12px + env(safe-area-inset-left)); bottom: calc(76px + env(safe-area-inset-bottom)); width: min(310px, calc(100% - 24px)); pointer-events: none; transform: translateY(calc(100% + 90px)) rotate(-4deg); transform-origin: 10% 100%; transition: transform .22s cubic-bezier(.2, .8, .2, 1); }
.mf.peeking .mf-peek { transform: none; }
.mf-pcard { padding: 18px 18px 16px; border-radius: 14px; background: var(--mf-paper); color: var(--mf-paper-ink); box-shadow: 0 0 0 1px #1d214033, 0 4px 0 #0000004d; }
.mf-pc-i { display: block; width: 46px; height: 46px; color: var(--indigo); margin-bottom: 4px; }
.mf-pc-n { margin: 0; font-size: 32px; font-weight: 700; line-height: 1.05; letter-spacing: -.01em; }
.mf-pc-d { margin: 8px 0 0; font-size: 15px; line-height: 1.38; color: #3c415e; }
.mf-pc-x { margin: 10px 0 0; font-size: 15px; font-weight: 700; }
.mf-pc-l { list-style: none; margin: 10px 0 0; padding: 0; font-size: 15px; }
.mf-pc-l li { padding: 3px 0; border-top: 1px solid #1d21401a; }

/* ---------- the card in the chat ---------- */
.mf-invite { margin: 16px 0 8px; }
.mf-icard { display: block; width: min(100%, 330px); padding: 0; border: 0; border-radius: 12px; overflow: hidden; background: var(--paper); color: var(--ink); text-align: left; box-shadow: 0 1px 0 #1d214020; }
.mf-icard:disabled { opacity: .6; cursor: default; }
.mf-iboard { display: block; padding: 14px 16px 13px; }
.mf-iboard .row1 { display: block; font-size: 30px; letter-spacing: .2em; }
.mf-iboard .row2 { display: block; margin-top: 6px; }
.mf-ifoot { display: flex; align-items: center; gap: 10px; padding: 10px 16px 11px; }
.mf-iheads { flex: 1; min-width: 0; display: flex; }
.mf-ih { flex: none; width: 30px; height: 30px; margin-right: -7px; }
.mf-ih .mface, .mf-ih .mf-bot, .mf-ih img, .mf-ih svg { display: block; width: 100%; height: 100%; }
.mf-ih.out { filter: grayscale(1); opacity: .45; }
.mf-icta { flex: none; margin-left: auto; font-weight: 700; font-size: 15px; color: var(--indigo); }
@media (prefers-color-scheme: dark) { .mf-icta { color: var(--ink); } }
.mf-icard:active { transform: translateY(1px); }

@media (prefers-reduced-motion: reduce) {
  .mf, .mf-peek, .mf-seat, .mf-room { transition: none; }
  .mf-seat.fresh .mf-role, .mf-card.flash { animation: none; }
}
