* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #12151c;
  color: #e8e6e0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#c { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

.hidden { display: none !important; }

/* ---------- HUD ---------- */

#hud { position: fixed; inset: 0; pointer-events: none; display: flex; flex-direction: column; justify-content: space-between; transition: opacity .25s; }
/* while the in-scene book is open, the HUD fades out and stops catching taps */
#hud.dim { opacity: .08; }
#hud.dim button { pointer-events: none; }

#top { display: flex; flex-direction: column; }
#players {
  display: flex; justify-content: center; gap: 8px; flex-wrap: wrap;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 10px 6px;
}
/* who is watching: a slim line under the player cards, never one of them */
#watchers {
  pointer-events: none; align-self: center; flex: none;
  margin: 0 10px 4px; padding: 3px 11px; max-width: min(88vw, 460px);
  font-size: 12px; font-weight: 600; color: #cfd3dc;
  background: rgba(18, 21, 28, 0.7); border: 1px solid rgba(255,255,255,0.08); border-radius: 999px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pcard {
  pointer-events: none;
  background: rgba(18, 21, 28, 0.82);
  border: 1px solid rgba(255,255,255,0.08);
  border-left: 4px solid var(--pc, #888);
  border-radius: 10px;
  padding: 6px 10px;
  min-width: 86px;
  backdrop-filter: blur(6px);
  transition: box-shadow .25s, transform .25s;
}
.pcard.turn { box-shadow: 0 0 0 2px var(--pc), 0 0 18px var(--pc); transform: translateY(2px); }
.pcard .pname { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.pcard .pstats { font-size: 12px; opacity: .85; margin-top: 2px; }
.pcard .off { color: #ff9a6b; font-size: 11px; }
.pcard button {
  pointer-events: auto;
  margin-top: 4px; font-size: 11px; padding: 2px 6px; border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.25); background: rgba(255,255,255,0.08); color: #e8e6e0;
}

#bottomBar {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 6px 10px calc(env(safe-area-inset-bottom, 0px) + 14px);
}
#status {
  pointer-events: none;
  font-size: 15px; font-weight: 600; text-align: center;
  text-shadow: 0 1px 6px rgba(0,0,0,.9);
  min-height: 20px;
}
#status.mine { color: #86efac; }
#controls { display: flex; align-items: center; gap: 14px; pointer-events: none; min-height: 56px; }
#controls button { pointer-events: auto; }

/* ---------- dice ---------- */

#diceRow { display: flex; gap: 6px; }
#diceRow:not(:empty) {
  background: rgba(14, 17, 23, 0.55);
  border-radius: 12px;
  padding: 7px 9px;
  backdrop-filter: blur(4px);
}
.die {
  width: 34px; height: 34px; border-radius: 8px; position: relative;
  background: linear-gradient(145deg, #faf7ee, #ddd8c8);
  box-shadow: 0 3px 8px rgba(0,0,0,.5), inset 0 1px 0 #fff;
  transition: opacity .3s;
}
.die.used { opacity: .28; filter: grayscale(1); }
.die.pop { animation: diePop .45s ease; }
@keyframes diePop { 0% { transform: scale(.4) rotate(-160deg); } 70% { transform: scale(1.15) rotate(8deg); } 100% { transform: scale(1) rotate(0); } }
.die .p { position: absolute; width: 7px; height: 7px; border-radius: 50%; background: #26221a; transform: translate(-50%, -50%); }
/* the roll for first: dice wear their roller's color (like the ones on the table); each player card holds a mini one */
.die.seat {
  background: var(--pc, #ddd);
  background: linear-gradient(145deg, color-mix(in srgb, var(--pc, #ddd) 62%, white), color-mix(in srgb, var(--pc, #ddd) 90%, black));
  box-shadow: 0 3px 8px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.55);
}
.die.seat .p { background: #1a1510; }
.die.mini { width: 20px; height: 20px; border-radius: 5px; box-shadow: 0 1px 3px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.55); }
.die.mini .p { width: 4px; height: 4px; }
.pcard .pstats.roll { display: flex; align-items: center; min-height: 20px; }

/* ---------- buttons ---------- */

button {
  font-family: inherit; font-size: 15px; font-weight: 600; color: #e8e6e0;
  background: rgba(255,255,255,0.10); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px; padding: 10px 18px; cursor: pointer;
}
button:active { transform: scale(.96); }
button.primary { background: #3f8f5f; border-color: #4fb377; box-shadow: 0 4px 14px rgba(63,143,95,.4); }
button:disabled { opacity: .4; pointer-events: none; }
#rollBtn { font-size: 18px; padding: 12px 28px; animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(79,179,119,.55); } 50% { box-shadow: 0 0 0 12px rgba(79,179,119,0); } }

/* ---------- overlays ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 12, 17, 0.72); backdrop-filter: blur(8px);
  padding: 16px;
}
.panel {
  width: 100%; max-width: 400px; max-height: 88vh; overflow-y: auto;
  background: #1a1f2a; border: 1px solid rgba(255,255,255,0.09);
  border-radius: 18px; padding: 22px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,.6);
}
.panel h1 { font-size: 26px; text-align: center; }
.sub { font-size: 13px; opacity: .75; text-align: center; line-height: 1.5; }
.panel input {
  font-family: inherit; font-size: 17px; color: #e8e6e0;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.16);
  border-radius: 12px; padding: 12px 14px; outline: none; user-select: text; -webkit-user-select: text;
}
.panel input:focus { border-color: #4fb377; }
.row { display: flex; gap: 10px; justify-content: center; }
.row button { flex: 1; }

#urls { word-break: break-all; }
#urls b { color: #86efac; font-weight: 600; }

#shareBox { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#qrImg {
  width: 140px; height: 140px;
  background: #fff; padding: 8px; border-radius: 12px;
}
#copyBtn { font-size: 13px; padding: 7px 14px; }

#seatList { display: flex; flex-direction: column; gap: 8px; }
/* flex: none — an overflow:hidden flex item may shrink to nothing when the panel overflows a phone */
#lobbyWatch { flex: none; margin: 8px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.05); border-radius: 12px; padding: 10px 12px;
  border-left: 4px solid var(--pc, #555);
}
.seat .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--pc); flex: none; }
.seat .sname { flex: 1; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat .tag { font-size: 11px; opacity: .7; background: rgba(255,255,255,.09); border-radius: 6px; padding: 2px 7px; flex: none; }
.seat.empty { opacity: .55; border-left-style: dashed; }
.seat.empty .sname { font-weight: 400; font-style: italic; }
.seat .kick { border: none; background: none; font-size: 15px; padding: 4px 6px; opacity: .6; }
.seat.clickable { cursor: pointer; }
.seat.clickable:active { background: rgba(255,255,255,0.12); }
.seat.moving { outline: 2px solid var(--pc); background: rgba(255,255,255,0.12); opacity: 1; }
/* your colour: a row of dots under your own seat (per device, see app.js) */
.seat .pal { flex-basis: 100%; display: flex; gap: 8px; padding: 2px 0 2px 24px; }
.seat .pal button {
  width: 26px; height: 26px; padding: 0; border-radius: 50%; flex: none;
  background: var(--pc); border: 2px solid rgba(0,0,0,.35); box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.seat .pal button.on { border-color: #fff; box-shadow: 0 0 0 2px var(--pc), 0 0 10px var(--pc); }
.seat .pal button.taken { opacity: .2; }

#winTitle { font-size: 30px; }
#winDetail { display: flex; flex-direction: column; gap: 6px; font-size: 15px; text-align: center; }
/* result picture: above the win screen; the image keeps the browser's own
   long-press / right-click menu so it can be saved from here */
#cardOverlay { z-index: 30; }
#cardOverlay .panel { max-width: 440px; align-items: center; }
#cardImg {
  width: 100%; max-height: 62vh; object-fit: contain; border-radius: 12px;
  -webkit-touch-callout: default; user-select: auto; -webkit-user-select: auto;
}
.lvl { font-size: 11px; opacity: .7; font-weight: 600; white-space: nowrap; }
#winStats .lvl { display: block; }

/* ---------- reactions ---------- */

/* the picker sits in the free bottom-left corner, above the win overlay (z 20)
   so the applause can land on the winner; the tray is a 3×3 keypad in the
   order of the desktop keys 1..9 */
#reactBtn {
  position: fixed; left: 10px; bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); z-index: 25;
  pointer-events: auto;
  width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 22px; line-height: 1;
  background: rgba(18, 21, 28, 0.82); border: 1px solid rgba(255,255,255,0.14);
}
#reactTray {
  position: fixed; left: 10px; bottom: calc(env(safe-area-inset-bottom, 0px) + 66px); z-index: 30;
  pointer-events: auto;
  display: grid; grid-template-columns: repeat(3, 48px); gap: 2px; padding: 6px;
  background: rgba(18, 21, 28, 0.92); border: 1px solid rgba(255,255,255,0.14);
  border-radius: 14px; box-shadow: 0 12px 32px rgba(0,0,0,.55);
  transform-origin: bottom left;
  animation: trayIn .15s ease;
}
@keyframes trayIn { from { opacity: 0; transform: translateY(6px) scale(.92); } to { opacity: 1; transform: none; } }
#reactTray button {
  width: 48px; height: 48px; padding: 0; border-radius: 10px; font-size: 28px; line-height: 1;
  background: transparent; border: none;
}
#reactTray button:active { background: rgba(255,255,255,0.14); transform: scale(1.15); }

/* a reaction pops out of the sender's player card and drops onto the table */
#reactions { position: fixed; inset: 0; z-index: 30; pointer-events: none; overflow: hidden; }
.reaction {
  position: absolute; display: flex; flex-direction: column; align-items: center; gap: 1px;
  will-change: transform, opacity;
  animation: reactDrop 2.3s cubic-bezier(.25,.7,.3,1) forwards;
}
.reaction .emo { font-size: 42px; line-height: 1; filter: drop-shadow(0 4px 8px rgba(0,0,0,.6)); }
.reaction .who {
  font-size: 11px; font-weight: 700; color: var(--pc, #ccc);
  text-shadow: 0 1px 4px #000, 0 0 8px #000; max-width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@keyframes reactDrop {
  0%   { opacity: 0; transform: translate(-50%, -10px) scale(.3) rotate(var(--rot, 0deg)); }
  12%  { opacity: 1; transform: translate(-50%, 6px) scale(1.2) rotate(var(--rot, 0deg)); }
  24%  { transform: translate(-50%, 10px) scale(1) rotate(var(--rot, 0deg)); }
  72%  { opacity: 1; transform: translate(-50%, 44px) scale(1) rotate(var(--rot, 0deg)); }
  100% { opacity: 0; transform: translate(-50%, 78px) scale(.85) rotate(var(--rot, 0deg)); }
}

/* ---------- voice notes ---------- */

/* hold-to-talk in the free bottom-right corner (the 😀 has the left), above
   the lobby and win overlays like it; the button owns its touches — no
   scroll, no long-press menu, no selection — or a hold would break */
#voiceBtn {
  position: fixed; right: 10px; bottom: calc(env(safe-area-inset-bottom, 0px) + 14px); z-index: 25;
  pointer-events: auto; touch-action: none; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  width: 44px; height: 44px; padding: 0; border-radius: 50%; font-size: 22px; line-height: 1;
  background: rgba(18, 21, 28, 0.82); border: 1px solid rgba(255,255,255,0.14);
  transition: transform .15s, background .15s, border-color .15s;
}
#voiceBtn.arming { background: rgba(138, 61, 61, 0.55); border-color: #b85c5c; }
#voiceBtn.rec, #voiceBtn.rec:active {
  background: #8a3d3d; border-color: #b85c5c; transform: scale(1.18);
  animation: recPulse 1.2s ease-in-out infinite;
}
#voiceBtn.cancel, #voiceBtn.cancel:active { background: #3a3d45; border-color: #777; transform: scale(1); animation: none; }
#voiceBtn.off { opacity: .45; }
/* the book dims the HUD; the button lives outside it (stacking) and follows */
#hud.dim ~ #voiceBtn, #hud.dim ~ #voiceTime { opacity: .08; pointer-events: none; }
@keyframes recPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(184, 92, 92, .7); }
  50% { box-shadow: 0 0 0 12px rgba(184, 92, 92, 0); }
}
/* the elapsed seconds, left of the button while it records */
#voiceTime {
  position: fixed; right: 62px; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); z-index: 25; pointer-events: none;
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; color: #fff; white-space: nowrap;
  background: rgba(138, 61, 61, 0.92); border: 1px solid #b85c5c;
}
#voiceTime.cancel { background: rgba(58, 61, 69, .92); border-color: #777; }
/* a clip's badge hangs under the speaker's card while it plays */
.vbubble {
  position: absolute; transform: translate(-50%, 0); z-index: 31;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
  color: #fff; background: rgba(18, 21, 28, 0.92); border: 2px solid var(--pc, rgba(255,255,255,0.3));
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
  animation: vbubbleIn .2s ease; transition: opacity .3s;
}
.vbubble.live { box-shadow: 0 0 0 2px rgba(255,255,255,.15), 0 0 16px var(--pc, rgba(255,255,255,.3)); }
.vbubble.out { opacity: 0; }
@keyframes vbubbleIn { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- toast & badges ---------- */

#toast {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 64px); left: 50%; transform: translateX(-50%);
  z-index: 30; pointer-events: none;
  background: rgba(20, 24, 32, 0.94); border: 1px solid rgba(255,255,255,0.14);
  border-radius: 12px; padding: 10px 18px; font-size: 15px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  animation: toastIn .25s ease;
  max-width: 86vw; text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

#connBadge {
  /* left of the ⚙ button */
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 8px); right: 58px; z-index: 40;
  background: #8a3d3d; border-radius: 8px; padding: 4px 10px; font-size: 12px; font-weight: 600;
}

#menuBtn {
  /* above the lobby overlay (z 20) so the book is reachable while waiting */
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 8px); left: 10px; z-index: 25;
  padding: 8px 13px; font-size: 16px; border-radius: 10px;
  background: rgba(18, 21, 28, 0.82); border: 1px solid rgba(255,255,255,0.14);
}
#menuPanel {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 54px); left: 10px; z-index: 30;
  display: flex; flex-direction: column; gap: 6px; min-width: 180px;
  background: #1a1f2a; border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px; padding: 10px;
  box-shadow: 0 12px 32px rgba(0,0,0,.55);
}
#menuRoom { font-size: 12px; opacity: .7; text-align: center; padding: 2px 0 4px; }

/* ⚙ settings: translucent corner panel */
#cfgBtn {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 8px); right: 10px; z-index: 25;
  padding: 8px 12px; font-size: 16px; border-radius: 10px;
  background: rgba(18, 21, 28, 0.55); border: 1px solid rgba(255,255,255,0.14);
}
#cfgPanel {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 54px); right: 10px; z-index: 30;
  display: flex; flex-direction: column; gap: 12px; min-width: 214px;
  background: rgba(18, 21, 28, 0.62); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px; padding: 13px 14px;
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 32px rgba(0,0,0,.45);
}
.cfg-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; font-weight: 600; cursor: pointer; }
.cfg-row input { display: none; }
.cfg-row .sw {
  flex: none; width: 36px; height: 21px; border-radius: 11px;
  background: rgba(255,255,255,0.16); position: relative; transition: background .2s;
}
.cfg-row .sw::after {
  content: ''; position: absolute; top: 2.5px; left: 2.5px; width: 16px; height: 16px;
  border-radius: 50%; background: #b9bec8; transition: transform .2s, background .2s;
}
.cfg-row input:checked + .sw { background: #3f8f5f; }
.cfg-row input:checked + .sw::after { transform: translateX(15px); background: #fff; }
.menu-sep { height: 1px; background: rgba(255,255,255,0.12); margin: 2px 4px; }
.menu-item { text-align: left; font-size: 14px; padding: 10px 12px; background: rgba(255,255,255,0.06); }
.menu-item.armed { background: #8a3d3d; border-color: #b85c5c; }

/* ---------- settings extras, lobby, win stats ---------- */

#cfgPanel { max-height: calc(100vh - 80px); overflow-y: auto; }
.cfg-sep { height: 1px; background: rgba(255,255,255,0.12); margin: 0 2px; }

/* segmented control */
.seg { display: inline-flex; border: 1px solid rgba(255,255,255,0.18); border-radius: 9px; overflow: hidden; flex: none; }
.seg button { font-size: 11px; padding: 4px 9px; border: none; border-radius: 0; background: rgba(255,255,255,0.05); }
.seg button + button { border-left: 1px solid rgba(255,255,255,0.14); }
.seg button.on { background: #3f8f5f; color: #fff; }
.lvlrow { align-items: center; gap: 8px; }
.seat .tag.level { cursor: pointer; }

/* win-screen stats */
#winStats { display: grid; grid-template-columns: auto repeat(4, 1fr); gap: 4px 8px; font-size: 12px; text-align: center; }
#winStats .h { opacity: .6; font-weight: 600; }
#winStats .n { font-weight: 700; }
