:root {
  --bg: #0b0a14; --panel: rgba(22, 18, 38, 0.92); --line: rgba(255, 255, 255, 0.12);
  --text: #f3f0ff; --dim: #a9a3c4; --pink: #ff3d81; --teal: #38d6c4; --gold: #ffd76a; --red: #e5484d; --green: #2faa5a;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 15px/1.35 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; overscroll-behavior: none; touch-action: manipulation; }
[hidden] { display: none !important; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.screen { position: fixed; inset: 0; pointer-events: none; }
.screen > * { pointer-events: auto; }

button, input, select { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); border-radius: 12px; padding: 10px 14px; cursor: pointer; font-weight: 600; }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; }
button.primary { background: linear-gradient(135deg, var(--pink), #ff7a3d); border: 0; color: #fff; box-shadow: 0 6px 18px rgba(255, 61, 129, 0.35); }
button.round { width: 42px; height: 42px; border-radius: 50%; padding: 0; font-size: 22px; flex: none; }
button.icon { width: 40px; height: 40px; padding: 0; border-radius: 12px; font-size: 18px; position: relative; flex: none; }
button.danger { background: rgba(229, 72, 77, 0.2); border-color: rgba(229, 72, 77, 0.5); }
button.small { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
input, select { width: 100%; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 16px; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--teal); outline-offset: 1px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--dim); font-weight: 600; margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.sp { flex: 1; }
.hint { color: var(--dim); font-size: 12px; margin: 0 0 10px; }
.err { color: #ff8f93; min-height: 18px; margin: 8px 0 0; font-size: 13px; }

/* ---------- lobby ---------- */
.brand { position: absolute; top: calc(var(--sat) + 14px); left: 0; right: 0; text-align: center; pointer-events: none; }
.brand h1 { margin: 0; font: italic 700 38px Georgia, serif; color: #ffd6e6; text-shadow: 0 0 18px var(--pink), 0 0 40px rgba(255, 61, 129, 0.6); }
.brand p { margin: 2px 0 0; color: var(--teal); font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 62%; overflow-y: auto; padding: 14px 16px calc(var(--sab) + 16px);
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 22px 22px 0 0; backdrop-filter: blur(10px); }
.char-pick { display: flex; align-items: center; gap: 10px; }
.char-id { flex: 1; text-align: center; display: flex; flex-direction: column; }
.char-id strong { font-size: 20px; }
.char-id span { color: var(--dim); font-size: 12px; }
.char-try { display: flex; gap: 6px; justify-content: center; margin: 8px 0 12px; }
.char-try button { padding: 5px 10px; font-size: 12px; border-radius: 999px; }
.tabs, .presets { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button, .presets button { flex: 1; padding: 9px 6px; }
.tabs button.on, .presets button.on { background: rgba(56, 214, 196, 0.2); border-color: var(--teal); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
input.code { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-weight: 700; font-size: 22px; }
#joinBtn, #hostBtn { width: 100%; padding: 14px; font-size: 17px; margin-top: 4px; }
.pen-head { display: flex; flex-direction: column; margin: 6px 0 8px; }
.pen-head .hint { margin: 0; }
.pen-row { display: grid; grid-template-columns: 1fr 112px 36px; gap: 6px; margin-bottom: 6px; }
.pen-row input, .pen-row select { padding: 8px; font-size: 14px; }
.pen-row button { padding: 0; }
#tab-host .row { margin-bottom: 12px; }
#tab-host .row button { flex: 1; font-size: 13px; }

@media (min-width: 760px) {
  .sheet { left: auto; right: 24px; bottom: 24px; top: 24px; width: 400px; max-height: none; border-radius: 22px; border: 1px solid var(--line); }
  .brand { right: 424px; }
}

/* ---------- game chrome ---------- */
#topbar { position: absolute; top: calc(var(--sat) + 8px); left: 10px; right: 10px; display: flex; gap: 8px; align-items: center; }
.pill { border-radius: 999px; padding: 8px 14px; font-weight: 800; letter-spacing: 0.14em; background: rgba(0, 0, 0, 0.5); }
#blindsLbl { font-size: 12px; color: var(--dim); text-shadow: 0 1px 3px #000; }
#chatDot { position: absolute; top: 5px; right: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--pink); }
#banner { position: absolute; top: calc(var(--sat) + 60px); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.banner { background: rgba(0, 0, 0, 0.72); border: 1px solid var(--line); padding: 8px 16px; border-radius: 999px; font-weight: 700; max-width: 92%; text-align: center;
  animation: bannerIn 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
.banner.big { font-size: 26px; padding: 10px 26px; color: var(--gold); border-color: var(--gold); text-shadow: 0 0 14px rgba(255, 215, 106, 0.7); }
.banner.red { color: #fff; background: rgba(229, 72, 77, 0.85); border-color: #ff9a9d; }
.banner.out { opacity: 0; transition: opacity 0.4s; }
@keyframes bannerIn { from { transform: scale(0.5); opacity: 0; } }

#hud { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px calc(var(--sab) + 10px); display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(to top, rgba(8, 6, 16, 0.95) 55%, rgba(8, 6, 16, 0)); pointer-events: none; }
#hud > * { pointer-events: auto; }
#status { text-align: center; color: var(--dim); font-size: 13px; min-height: 18px; text-shadow: 0 1px 3px #000; pointer-events: none; }
#mine { display: flex; align-items: center; gap: 10px; }
#myCards { display: flex; gap: 5px; min-width: 96px; min-height: 62px; }
.card { width: 44px; height: 62px; border-radius: 7px; background: #fbfaf5; color: #15151d; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font: 700 21px/1 Georgia, serif; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5); }
.card.red { color: #d3243b; }
.card span { font-size: 19px; }
.card.folded { opacity: 0.4; }
.card.back { background: repeating-linear-gradient(45deg, #7a1730 0 6px, #5d1024 6px 12px); border: 3px solid #f4efe2; }
#myInfo { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#myHand { color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#myChips { color: var(--dim); font-size: 13px; }
#actions { display: flex; gap: 8px; }
#actions button { flex: 1; padding: 15px 6px; font-size: 16px; border-radius: 14px; min-width: 0; }
#actions .fold { background: rgba(229, 72, 77, 0.25); border-color: rgba(229, 72, 77, 0.6); }
#actions .call { background: rgba(47, 170, 90, 0.3); border-color: rgba(47, 170, 90, 0.7); }
#actions .raise { background: rgba(255, 215, 106, 0.22); border-color: rgba(255, 215, 106, 0.7); }
#actions small { display: block; font-weight: 500; font-size: 12px; opacity: 0.85; }
#turnBar { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.1); overflow: hidden; visibility: hidden; }
#turnBar.on { visibility: visible; }
#turnBar i { display: block; height: 100%; width: 100%; background: var(--gold); transform-origin: left; }
#raiseBox { background: rgba(0, 0, 0, 0.55); border: 1px solid var(--line); border-radius: 14px; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
#raiseBox .presets { margin: 0; }
#raiseBox .presets button { padding: 7px 2px; font-size: 13px; }
#raiseRange { flex: 1; padding: 0; height: 36px; accent-color: var(--gold); border: 0; background: none; }
#emotes { display: flex; gap: 6px; justify-content: flex-end; }
#emotes button { width: 44px; height: 44px; padding: 0; font-size: 22px; border-radius: 50%; background: rgba(0, 0, 0, 0.6); }

@media (min-width: 760px) {
  #hud { left: 50%; right: auto; width: 520px; transform: translateX(-50%); background: none; }
}

/* ---------- things pinned to the 3D scene ---------- */
.plate { position: absolute; transform: translate(-50%, -100%); background: rgba(10, 8, 20, 0.82); border: 1px solid var(--line); border-radius: 10px; padding: 3px 8px 5px;
  text-align: center; min-width: 74px; max-width: 124px; font-size: 12px; line-height: 1.25; transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s; }
.plate b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate .chips { color: var(--gold); font-weight: 700; }
.plate .tag { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--teal); min-height: 12px; }
.plate.acting { border-color: var(--gold); box-shadow: 0 0 14px rgba(255, 215, 106, 0.6); }
.plate.folded { opacity: 0.5; }
.plate.out .chips { color: var(--red); }
.plate.allin .tag { color: #ff8f93; font-weight: 800; }
.plate.winner { border-color: var(--teal); box-shadow: 0 0 16px rgba(56, 214, 196, 0.7); }
.plate .bar { height: 3px; border-radius: 3px; background: var(--gold); margin-top: 3px; transform-origin: left; }
.plate .badges { position: absolute; top: -9px; right: -6px; display: flex; gap: 2px; }
.plate .badges i { font-style: normal; font-size: 9px; font-weight: 800; background: #f4f4f0; color: #15151d; border-radius: 999px; padding: 1px 5px; }
.plate .badges i.host { background: var(--pink); color: #fff; }
.betlbl, .potlbl { position: absolute; transform: translate(-50%, -50%); font-weight: 800; font-size: 12px; background: rgba(0, 0, 0, 0.7); border-radius: 999px; padding: 2px 8px; color: var(--gold); white-space: nowrap; }
.potlbl { font-size: 15px; padding: 4px 12px; border: 1px solid rgba(255, 215, 106, 0.5); }
.bubble { position: absolute; transform: translate(-50%, -100%); margin-top: -62px; z-index: 2; background: #fff; color: #15151d; border-radius: 14px; padding: 6px 10px; font-size: 12px; font-weight: 600;
  max-width: 190px; text-align: center; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5); animation: bubbleIn 0.25s cubic-bezier(0.2, 1.5, 0.4, 1); }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-top-color: #fff; border-bottom: 0; }
.bubble.emoji { background: none; box-shadow: none; font-size: 40px; padding: 0; animation: emojiUp 1.8s ease-out forwards; }
.bubble.emoji::after { display: none; }
.bubble.chat { background: #d9fffb; }
.bubble.chat::after { border-top-color: #d9fffb; }
@keyframes bubbleIn { from { transform: translate(-50%, -100%) scale(0.3); opacity: 0; } }
@keyframes emojiUp { from { transform: translate(-50%, -60%) scale(0.3); opacity: 0; } 20% { transform: translate(-50%, -100%) scale(1.2); opacity: 1; } to { transform: translate(-50%, -190%) scale(1); opacity: 0; } }

/* ---------- panels ---------- */
.panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(380px, 100%); background: var(--panel); border-left: 1px solid var(--line); backdrop-filter: blur(12px);
  padding: calc(var(--sat) + 12px) 14px calc(var(--sab) + 14px); overflow-y: auto; display: flex; flex-direction: column; gap: 10px; z-index: 5; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head strong { font-size: 18px; }
.panel h3 { margin: 8px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--teal); }
.panel table { width: 100%; border-collapse: collapse; font-size: 13px; }
.panel td, .panel th { padding: 5px 4px; text-align: right; border-bottom: 1px solid var(--line); }
.panel td:first-child, .panel th:first-child { text-align: left; }
.panel th { color: var(--dim); font-weight: 600; font-size: 11px; }
.pos { color: #6fe39a; } .neg { color: #ff8f93; }
.rules { color: var(--dim); font-size: 13px; margin: 0; }
.plist { display: flex; flex-direction: column; gap: 6px; }
.plist > div { display: flex; align-items: center; gap: 6px; background: rgba(255, 255, 255, 0.05); border-radius: 10px; padding: 6px 8px; }
.plist span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.penlog { margin: 0; padding-left: 18px; font-size: 13px; color: var(--dim); }
.penlog b { color: var(--text); }
.stack { display: flex; flex-direction: column; gap: 8px; }
#chatLog { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
#chatLog b { color: var(--teal); }
#chatForm { display: flex; gap: 6px; }
#chatForm button { padding: 10px 14px; }

/* ---------- penalty wheel ---------- */
#wheel { position: fixed; inset: 0; background: rgba(5, 3, 12, 0.82); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.wheel-card { text-align: center; width: min(380px, 100%); }
#wheelWho { font-size: 20px; font-weight: 800; margin: 0 0 10px; color: var(--pink); text-shadow: 0 0 14px rgba(255, 61, 129, 0.7); }
.wheel-wrap { position: relative; width: 100%; aspect-ratio: 1; }
#wheelCanvas { width: 100%; height: 100%; display: block; }
.wheel-pin { position: absolute; top: -4px; left: 50%; margin-left: -12px; border: 12px solid transparent; border-top: 22px solid #fff; filter: drop-shadow(0 2px 4px #000); }
#wheelText { font-size: 22px; font-weight: 800; min-height: 60px; margin: 12px 0; color: var(--gold); }
#wheelOk { padding: 12px 30px; }

#toasts { position: fixed; left: 0; right: 0; top: calc(var(--sat) + 56px); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 30; }
.toast { background: rgba(20, 16, 34, 0.96); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-size: 13px; max-width: 90%; animation: bannerIn 0.25s; }
.toast.bad { border-color: var(--red); color: #ffc2c4; }

/* ---------- character select ---------- */
button.wide { width: 100%; margin-top: 8px; padding: 8px; font-size: 13px; }
#picker { position: fixed; inset: 0; z-index: 15; background: rgba(5, 3, 12, 0.9); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center;
  padding: calc(var(--sat) + 12px) 12px calc(var(--sab) + 12px); }
.picker-card { width: min(560px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 10px; }
#pickGrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; overflow-y: auto; }
@media (min-width: 560px) { #pickGrid { grid-template-columns: repeat(4, 1fr); } }
.pick { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 6px 10px; background: rgba(255, 255, 255, 0.06); }
.pick img { width: 100%; max-width: 120px; aspect-ratio: 1; object-fit: contain; }
.pick strong { font-size: 14px; }
.pick span { font-size: 11px; color: var(--dim); font-weight: 500; line-height: 1.2; }
.pick.on { border-color: var(--teal); background: rgba(56, 214, 196, 0.16); }
.pick.taken { opacity: 0.4; }
