/* Mafia (member request, henry: "Copy mafia from FAM chat", ported from the Fam room). public/mafia.js.
   A red felt card table seen from above (the letterboard's felt), seats round its rim (yours at the bottom), the clock
   in board letters in the middle. Day is the wall; at night the room goes almost black and the felt deep oxblood.
   Picks get a hard ring (red by day, white by night). The dead get an ink-black stamp over their head. Your role is a
   paper card you hold to peek at; its back is a little letterboard like gin's cards. No blue, no yellow. */
.mf, .mf-invite {
  --mf-night: #1a0507;
  --mf-night-2: #120304;
  --mf-night-felt: #5e0a10;
  --mf-dead: #2e0b0f;
  --mf-pick: var(--red);
  --mf-paper: #ffffff;
  --mf-paper-ink: #2e0b0f;
  --mf-back: #8e0c14;
}
.mf.night { --mf-pick: #ffffff; }

/* ---------- the overlay ---------- */
.mf { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); 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: #d9b3b6; --room-rule: #ffffff1f; }
.mf :focus-visible { outline: 3px solid var(--mf-pick); 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; display: grid; place-items: center; border: 0; background: #ffffff26; 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 { background-color: var(--mf-night-felt); background-image: repeating-linear-gradient(to bottom, transparent 0 7px, #00000033 7px 9px); box-shadow: inset 0 0 0 2px #f5f5f222, 0 0 0 7px #3a0509, 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-mid .board { background: none; } /* board letters straight on the felt */
.mf-clock { font-size: 46px; line-height: 1; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.mf-clock.low { animation: mf-low 1s steps(2, jump-none) infinite; }
@keyframes mf-low { 50% { opacity: .45; } }
.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; background: var(--red); color: var(--red-ink); font-weight: 700; font-size: 16px; }
.mf-btn:active { transform: translateY(1px); }
.mf-btn.quiet { background: var(--note); color: var(--note-ink); }
.mf-mid .mf-btn { background: var(--letter); color: var(--felt); }
.mf-none { min-height: 40px; padding: 6px 16px; border: 0; background: #ffffff1f; 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-family: var(--font); font-size: 13px; }
.mf-none.on { background: var(--letter); color: var(--felt); }

/* ---------- 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(--paper); color: var(--felt); box-shadow: inset 0 0 0 1.5px var(--felt); }
.mf.night .mf-seat.you .mf-plate { background: var(--letter); color: var(--mf-night-felt); }
.mf-seat.picked .mf-head { outline: 3px solid var(--mf-pick); 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: var(--red); color: #fff; font-size: 13.5px; font-weight: 700; box-shadow: 0 0 0 1.5px #fff; }

/* the dead: dimmed, their card stamped across the head in ink */
.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-dead); }
.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-pick); }
.mf-pk { display: flex; gap: 2px; }
.mf-pk i { display: grid; place-items: center; width: 18px; height: 18px; background: var(--red); 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(--paper); 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: #d9b3b6; }
.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(--red); 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: #ff8a90; }
.mf-lb a { color: inherit; }
.mf-line.whisper .mf-lb { padding-left: 10px; border-left: 3px solid #ff8a90; }

/* 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 0 0 1.5px var(--rule); }
.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 #2e0b0f1a; }
.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(--mf-dead); }
.mf-fate { flex: none; width: 34%; font-size: 13px; color: #7d4a4f; 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(4, 1fr); gap: 8px; }
.mf-reg { min-height: 44px; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px 7px; border: 0; background: var(--note); color: var(--ink); font-size: 13px; font-weight: 700; line-height: 1.2; }
.mf-reg .mf-bot { width: 40px; height: 40px; }
.mf-reg.on { background: var(--felt); color: var(--letter); }
.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 + var(--sab)) 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 { position: relative; flex: none; width: 40px; height: 56px; padding: 0; border: 0; display: grid; place-items: center; touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
  background-color: var(--mf-back); background-image: repeating-linear-gradient(to bottom, transparent 0 4px, #0000002e 4px 5px); }
.mf-card::before { content: ""; position: absolute; inset: 3px; border: 1.5px solid #ffffffb0; pointer-events: none; }
.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); }
.mf.peeking .mf-card::before { border-color: #fff; border-width: 3px; }
.mf-card.flash { animation: mf-flash 1.2s ease-out 2; }
@keyframes mf-flash { 0%, 100% { transform: none; } 15% { transform: translateY(-6px) rotate(-6deg); } 30% { transform: translateY(-6px) rotate(5deg); } 45% { transform: none; } }
.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(--red); }
.mf-say input:focus-visible { outline: none; }
.mf.night .mf-say input { background: #2a0a0d; border-color: #ffffff2e; color: var(--letter); }
.mf.night .mf-say input::placeholder { color: #c79a9e; }
.mf-send { flex: none; width: 44px; height: 44px; padding: 0; border: 0; display: grid; place-items: center; background: var(--red); color: var(--red-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 + var(--sab)); width: min(310px, calc(100% - 24px)); pointer-events: none; transform: translateY(calc(100% + 90px)) rotate(-4deg); transform-origin: 10% 100%; visibility: hidden; transition: transform .22s cubic-bezier(.2, .8, .2, 1), visibility 0s .22s; }
.mf.peeking .mf-peek { transform: none; visibility: visible; transition: transform .22s cubic-bezier(.2, .8, .2, 1), visibility 0s; }
.mf-pcard { padding: 18px 18px 16px; border-radius: 4px; background: var(--mf-paper); color: var(--mf-paper-ink); box-shadow: 0 0 0 3px var(--felt), 0 4px 0 #0000004d; }
.mf-pc-i { display: block; width: 46px; height: 46px; color: var(--felt); 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: #5a2a2f; }
.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 #2e0b0f1a; }

/* ---------- the card in the chat ---------- */
.mf-invite { margin: 16px 0 8px; }
.mf-icard { display: block; width: min(100%, 330px); padding: 0; border: 0; overflow: hidden; background: #fff; color: #2e0b0f; text-align: left; }
.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; border: 1.5px solid #ecd2d4; border-top: 0; }
.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: #d3121c; }
.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; }
}
