:root {
  --bg: #0b0d12;
  --panel: rgba(14, 17, 24, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --text: #eef0f3;
  --dim: #9aa3b2;
  --accent: #ffb020;
  --red: #ff4d4f;
  --cyan: #5fd8f5;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 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-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
canvas { position: fixed; inset: 0; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hudTL {
  position: absolute; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l));
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 10px; font-size: 12px; min-width: 128px;
}
#roleTag { font-weight: 800; letter-spacing: 2px; font-size: 11px; color: var(--cyan); margin-bottom: 3px; }
#roleTag.traitor { color: var(--red); }
.hudRow { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; font-weight: 700; }
.hudRow .lbl { color: var(--dim); font-weight: 600; font-size: 10px; letter-spacing: 1px; align-self: center; }
#storm.warn { color: var(--red); }
#lift.on { color: #6dff9a; }
#hpWrap { height: 6px; background: rgba(255,255,255,0.12); border-radius: 3px; margin-top: 5px; overflow: hidden; position: relative; }
#shBar { position: absolute; left: 0; top: 0; height: 2px; width: 0; background: #7ff3ff; }
#mats { display: grid; grid-template-columns: repeat(3, auto); gap: 1px 8px; margin-top: 5px; font-size: 9px; font-weight: 700; letter-spacing: .5px; }
#mats b { color: var(--text); }
#bWeapon, #bCraft {
  position: absolute; top: calc(122px + var(--safe-t)); pointer-events: auto; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); font-weight: 800; font-size: 11px; letter-spacing: 1px; padding: 0 10px;
}
#bCraft { right: calc(8px + var(--safe-r)); color: var(--accent); }
#bCraft.ping { border-color: var(--accent); box-shadow: 0 0 12px rgba(255,176,32,.5); animation: ping 1.4s infinite; }
@keyframes ping { 50% { box-shadow: 0 0 2px rgba(255,176,32,.2); } }
#bWeapon { right: calc(84px + var(--safe-r)); max-width: 150px; }
#craft {
  position: fixed; top: calc(160px + var(--safe-t)); right: calc(8px + var(--safe-r)); width: min(330px, 70vw);
  bottom: calc(8px + var(--safe-b)); background: rgba(14,17,24,.95); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; z-index: 5;
}
.crHead { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; font-weight: 900; letter-spacing: 2px; font-size: 12px; color: var(--accent); border-bottom: 1px solid var(--line); }
.crHead button { background: none; border: 0; font-size: 16px; }
#craftList { overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.recipe { text-align: left; background: rgba(255,255,255,.05); border: 1px solid transparent; border-radius: 9px; padding: 7px 9px; opacity: .55; }
.recipe.ok { opacity: 1; border-color: rgba(255,176,32,.5); background: rgba(255,176,32,.08); }
.recipe.weapon .rName { color: var(--accent); }
.rTop { display: flex; justify-content: space-between; }
.rName { font-weight: 800; font-size: 13px; }
.rKind { font-size: 9px; font-weight: 800; letter-spacing: 1px; color: var(--dim); }
.rDesc { font-size: 11px; color: var(--dim); margin: 2px 0 4px; }
.rCost { display: flex; flex-wrap: wrap; gap: 4px; }
.cost { font-size: 10px; font-weight: 700; color: var(--c); border: 1px solid var(--c); border-radius: 5px; padding: 1px 5px; }
.cost.short { opacity: .45; text-decoration: line-through; }
#hpBar { height: 100%; width: 100%; background: linear-gradient(90deg, #ff4d4f, #ffb020 40%, #6dff9a); background-size: 300px 100%; transition: width .15s; }
#objective {
  position: absolute; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 14px; font-size: 12px; font-weight: 700; white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis;
}
#toasts { position: absolute; top: calc(42px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.toast { background: rgba(0,0,0,.7); border-radius: 8px; padding: 4px 10px; font-size: 12px; font-weight: 700; animation: toastIn .25s ease-out; }
.toast.good { color: #6dff9a; } .toast.bad { color: var(--red); } .toast.gold { color: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }
#ghostBanner {
  position: absolute; bottom: calc(14px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 8px 6px 14px;
  font-size: 12px; font-weight: 800; letter-spacing: 1px; pointer-events: auto; display: flex; gap: 10px; align-items: center;
}
#ghostBanner button { background: rgba(255,255,255,.12); border: 0; border-radius: 999px; padding: 4px 10px; font-weight: 800; }
#bPause {
  position: absolute; top: calc(8px + var(--safe-t)); right: calc(170px + var(--safe-r));
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  font-weight: 900; pointer-events: auto;
}

/* ---------- Controls ---------- */
#controls { position: fixed; inset: 0; pointer-events: none; }
#stickZone { position: absolute; left: 0; bottom: 0; width: 45%; height: 75%; pointer-events: auto; }
#stickBase {
  position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%;
  background: rgba(255,255,255,0.06); border: 2px solid rgba(255,255,255,0.18);
  left: calc(110px + var(--safe-l)); top: calc(100% - 110px - var(--safe-b)); opacity: .55; transition: opacity .15s;
}
#stickBase.active { opacity: 1; transition: none; }
#stickKnob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255,255,255,0.35); }
.btn {
  position: absolute; pointer-events: auto; border-radius: 50%; border: 2px solid rgba(255,255,255,.25);
  background: rgba(20,24,32,.72); font-weight: 900; font-size: 12px; letter-spacing: 1px;
  width: 66px; height: 66px; display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.1;
  touch-action: none;
}
.btn.small { font-size: 10px; }
.btn.off { opacity: .35; }
.btn:active, .btn.down { transform: scale(.94); }
.btn .cd { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; background: rgba(0,0,0,.55); border-radius: 50%; }
.btn .cd:empty { display: none; }
#bFire { width: 92px; height: 92px; right: calc(24px + var(--safe-r)); bottom: calc(24px + var(--safe-b)); background: rgba(255,176,32,.25); border-color: var(--accent); font-size: 15px; }
#bUse { right: calc(128px + var(--safe-r)); bottom: calc(20px + var(--safe-b)); }
#bUse.ready { background: rgba(95,216,245,.3); border-color: var(--cyan); }
#bReport { background: rgba(255,176,32,.35); border-color: var(--accent); }
#bReport { right: calc(206px + var(--safe-r)); bottom: calc(24px + var(--safe-b)); }
#bKill { right: calc(128px + var(--safe-r)); bottom: calc(96px + var(--safe-b)); background: rgba(255,77,79,.3); border-color: var(--red); }
#bSab { right: calc(206px + var(--safe-r)); bottom: calc(100px + var(--safe-b)); width: 52px; height: 52px; background: rgba(255,77,79,.18); border-color: rgba(255,77,79,.6); }
#bGadget { right: calc(40px + var(--safe-r)); bottom: calc(126px + var(--safe-b)); width: 58px; height: 58px; background: rgba(109,255,154,.14); border-color: rgba(109,255,154,.6); font-size: 11px; }
#bGadget .cnt { position: absolute; right: -2px; top: -2px; background: #6dff9a; color: #062; border-radius: 9px; font-size: 10px; min-width: 18px; height: 18px; display: flex; align-items: center; justify-content: center; }
#bGSwap { right: calc(14px + var(--safe-r)); bottom: calc(176px + var(--safe-b)); width: 30px; height: 30px; font-size: 13px; }
#bKill.off, #bSab.off { opacity: .45; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(40,30,20,.85), rgba(6,7,10,.96));
  padding: calc(12px + var(--safe-t)) calc(16px + var(--safe-r)) calc(12px + var(--safe-b)) calc(16px + var(--safe-l));
}
.menuInner { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 560px; width: 100%; max-height: 100%; overflow-y: auto; }
.logo { font-size: 44px; font-weight: 900; letter-spacing: 3px; line-height: .95; text-align: center; color: var(--red); text-shadow: 0 0 24px rgba(255,77,79,.35); }
.logo span { display: block; color: var(--accent); font-size: .8em; letter-spacing: 8px; text-shadow: 0 0 24px rgba(255,176,32,.3); }
.logo.small { font-size: 30px; color: var(--text); text-shadow: none; }
.tag { color: var(--dim); font-size: 13px; letter-spacing: 2px; }
.roleSel { display: flex; background: rgba(255,255,255,.06); border-radius: 999px; padding: 3px; }
.roleSel button { border: 0; background: none; padding: 7px 16px; border-radius: 999px; font-weight: 700; font-size: 13px; color: var(--dim); }
.roleSel button.sel { background: rgba(255,255,255,.14); color: var(--text); }
button.big {
  border: 0; border-radius: 12px; padding: 12px 40px; font-size: 18px; font-weight: 900; letter-spacing: 3px;
  background: linear-gradient(180deg, #ffbf3d, #e08a00); color: #1a1205; box-shadow: 0 6px 24px rgba(255,160,0,.3);
}
.menuInner > button:not(.big) { border: 1px solid var(--line); background: none; border-radius: 10px; padding: 8px 20px; font-weight: 700; color: var(--dim); }
#best { color: var(--dim); font-size: 12px; min-height: 14px; }
.how { max-width: 480px; font-size: 12px; color: var(--dim); background: rgba(255,255,255,.04); border-radius: 10px; padding: 6px 12px; }
.how summary { font-weight: 700; color: var(--text); cursor: pointer; }
.how p { margin: 6px 0; line-height: 1.4; }
.how b { color: var(--text); }

#roleScreen { flex-direction: column; gap: 6px; background: #000; }
#roleShh { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: 4px; }
#roleTitle { font-size: 52px; font-weight: 900; letter-spacing: 6px; }
#roleTitle.raider { color: var(--cyan); text-shadow: 0 0 30px rgba(95,216,245,.5); }
#roleTitle.traitor { color: var(--red); text-shadow: 0 0 30px rgba(255,77,79,.6); }
#roleBeans { display: flex; gap: 6px; height: 64px; align-items: flex-end; }
#roleBeans svg { animation: beanIn .5s ease-out backwards; }
#roleDesc { color: var(--dim); font-size: 14px; text-align: center; max-width: 440px; }
@keyframes beanIn { from { opacity: 0; transform: translateY(14px); } }

/* Meeting */
#meeting { flex-direction: column; justify-content: flex-start; gap: 8px; background: repeating-linear-gradient(0deg, rgba(255,255,255,.015) 0 2px, transparent 2px 4px), linear-gradient(180deg, #1b1712, #0d0c0a); }
.mtHead { display: flex; justify-content: space-between; align-items: center; width: 100%; max-width: 900px; }
#mtTitle { font-weight: 900; letter-spacing: 3px; font-size: 16px; color: var(--accent); font-family: ui-monospace, Menlo, monospace; }
#mtTimer { font-weight: 800; font-variant-numeric: tabular-nums; color: #ff5a5a; font-size: 13px; font-family: ui-monospace, Menlo, monospace; }
.mtBody { display: flex; gap: 10px; width: 100%; max-width: 900px; flex: 1; min-height: 0; }
#mtCards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; flex: 1.1; align-content: start; overflow-y: auto; }
.card {
  display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.06); border: 2px solid transparent;
  border-radius: 10px; padding: 4px 8px; min-height: 48px; position: relative; text-align: left;
}
.card svg { flex: none; }
.card .nm { font-weight: 800; font-size: 14px; }
.card .st { font-size: 10px; color: var(--dim); }
.card.dead { opacity: .4; }
.card.sel { border-color: var(--accent); background: rgba(255,176,32,.12); }
.card .voted { position: absolute; top: 4px; right: 6px; font-size: 9px; font-weight: 800; color: #6dff9a; letter-spacing: 1px; }
.card .chips { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; max-width: 60px; }
.chip { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.4); }
#mtChat { flex: 1; background: rgba(0,0,0,.45); border: 1px solid rgba(255,176,32,.2); font-family: ui-monospace, Menlo, monospace; font-size: 12px !important; border-radius: 10px; padding: 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.msg { display: flex; gap: 6px; align-items: flex-start; animation: toastIn .25s ease-out; }
.msg .who { font-weight: 800; flex: none; }
.msg.sys { color: var(--dim); font-style: italic; }
.mtFoot { display: flex; justify-content: space-between; align-items: center; width: 100%; max-width: 900px; gap: 10px; }
#mtHint { color: var(--dim); font-size: 12px; }
#bSkip { border: 1px solid var(--line); background: rgba(255,255,255,.08); border-radius: 10px; padding: 8px 18px; font-weight: 800; letter-spacing: 1px; }
#bSkip.sel { border-color: var(--accent); background: rgba(255,176,32,.15); }

#eject { flex-direction: column; gap: 10px; background: #000; }
#ejBean { height: 70px; }
#ejBean svg { animation: static 3.2s steps(24) forwards; }
@keyframes static { 0% { filter: none; opacity: 1; } 40% { filter: grayscale(.5) contrast(1.6); transform: translateX(2px); } 60% { transform: translateX(-3px); opacity: .7; } 100% { filter: grayscale(1) brightness(.4); opacity: .15; transform: none; } }
#ejSub.good { color: #6dff9a; } #ejSub.bad { color: var(--red); }
#ejText { font-size: 22px; font-weight: 800; text-align: center; }
#ejSub { font-size: 15px; color: var(--dim); text-align: center; }

#endTitle.win { color: #6dff9a; text-shadow: 0 0 24px rgba(109,255,154,.35); }
#endReason { font-size: 15px; text-align: center; }
#endTraitor { display: flex; align-items: center; gap: 8px; color: var(--dim); font-size: 13px; }
#endStats { display: flex; gap: 18px; font-size: 12px; color: var(--dim); }
#endStats b { display: block; color: var(--text); font-size: 18px; text-align: center; }
#endStash, #wsCredits { color: var(--accent); font-weight: 800; letter-spacing: 1px; }
.row { display: flex; gap: 8px; }
.row button, #bWorkshop, #bWsBack { border: 1px solid var(--line); background: rgba(255,255,255,.05); border-radius: 10px; padding: 8px 20px; font-weight: 800; letter-spacing: 1px; color: var(--text); }
#wsList { display: flex; flex-direction: column; gap: 6px; width: 100%; }
.bp { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: rgba(255,255,255,.05); border-radius: 10px; padding: 8px 12px; }
.bp.owned { border: 1px solid rgba(255,176,32,.35); }
.bp .stats { font-size: 10px; color: var(--dim); font-family: ui-monospace, Menlo, monospace; }
.bp button { border: 0; border-radius: 8px; padding: 7px 12px; font-weight: 800; background: var(--accent); color: #1a1205; white-space: nowrap; }
.bp button:disabled { opacity: .35; }
.bp .eq { font-size: 10px; font-weight: 800; color: #6dff9a; letter-spacing: 1px; }

@media (orientation: portrait) {
  .mtBody { flex-direction: column; }
  #mtChat { min-height: 30vh; }
  #objective { top: calc(150px + var(--safe-t)); max-width: 90vw; }
  #toasts { top: calc(184px + var(--safe-t)); }
  #bPause { right: calc(8px + var(--safe-r)); top: calc(120px + var(--safe-t)); }
}
@media (max-height: 420px) {
  .logo { font-size: 34px; }
  #roleTitle { font-size: 40px; }
  .menuInner { gap: 7px; }
}

#bossBar { position: absolute; top: calc(40px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(320px, 40vw); text-align: center; font-size: 10px; font-weight: 900; letter-spacing: 4px; color: #ffb020; }
#bossTrack { height: 7px; background: rgba(0,0,0,.6); border: 1px solid rgba(255,176,32,.5); border-radius: 4px; overflow: hidden; margin-top: 2px; }
#bossFill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff4d4f, #ffb020); transition: width .15s; }
#bossBar:not(.hidden) ~ #toasts { top: calc(66px + var(--safe-t)); }

/* ---------- small phones: short landscape screens (Safari bars showing) ---------- */
@media (orientation: landscape) and (max-height: 430px) {
  #hudTL { padding: 4px 8px; min-width: 112px; font-size: 11px; }
  #roleTag { font-size: 10px; margin-bottom: 1px; }
  .hudRow .lbl { font-size: 9px; }
  #mats { font-size: 8px; gap: 0 6px; margin-top: 3px; }
  #objective { font-size: 11px; padding: 4px 12px; max-width: 40vw; }
  #bPause { right: calc(132px + var(--safe-r)); width: 30px; height: 30px; }
  #bWeapon, #bCraft { top: calc(98px + var(--safe-t)); height: 26px; font-size: 10px; padding: 0 8px; }
  #bWeapon { right: calc(74px + var(--safe-r)); max-width: 120px; }
  #craft { top: calc(132px + var(--safe-t)); }
  .btn { width: 54px; height: 54px; font-size: 10px; }
  #bFire { width: 74px; height: 74px; right: calc(14px + var(--safe-r)); bottom: calc(12px + var(--safe-b)); font-size: 13px; }
  #bUse { right: calc(98px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); }
  #bReport { right: calc(160px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); }
  #bKill { right: calc(98px + var(--safe-r)); bottom: calc(72px + var(--safe-b)); }
  #bSab { right: calc(160px + var(--safe-r)); bottom: calc(72px + var(--safe-b)); width: 46px; height: 46px; }
  #bGadget { width: 48px; height: 48px; right: calc(26px + var(--safe-r)); bottom: calc(96px + var(--safe-b)); font-size: 10px; }
  #bGSwap { width: 26px; height: 26px; right: calc(4px + var(--safe-r)); bottom: calc(150px + var(--safe-b)); font-size: 11px; }
  #stickZone { height: 62%; }
  #stickBase { width: 100px; height: 100px; margin: -50px 0 0 -50px; left: calc(84px + var(--safe-l)); top: calc(100% - 84px - var(--safe-b)); }
  #stickKnob { width: 44px; height: 44px; margin: -22px 0 0 -22px; }
}

/* ---------- portrait phones ---------- */
@media (orientation: portrait) {
  #hudTL { font-size: 11px; min-width: 112px; }
  #mats { font-size: 8px; }
  #bWeapon, #bCraft { top: calc(98px + var(--safe-t)); height: 28px; font-size: 10px; }
  #bWeapon { right: calc(74px + var(--safe-r)); max-width: 120px; }
  #bPause { right: calc(8px + var(--safe-r)); top: calc(134px + var(--safe-t)); }
  #objective { top: calc(176px + var(--safe-t)); }
  #toasts { top: calc(208px + var(--safe-t)); }
  #bossBar { top: calc(206px + var(--safe-t)); }
  #craft { top: calc(176px + var(--safe-t)); width: calc(100vw - 16px); }
}
