:root {
  --bg: #120d1c;
  --bg2: #1c1530;
  --panel: #241b3d;
  --panel2: #2e2350;
  --ink: #f3ecff;
  --dim: #a99cc9;
  --line: #0a0713;
  --gold: #ffd23f;
  --gold2: #c9a24a;
  --good: #3c8ee8;
  --evil: #d83a3a;
  --ok: #2f9e57;
  --purple: #9b6bff;
  --font: Vazirmatn, "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { min-height: 100dvh; font-size: 15px; line-height: 1.6; overscroll-behavior-y: contain; }
.hidden { display: none !important; }
button, input, select { font: inherit; color: inherit; }

.screen { max-width: 560px; margin: 0 auto; padding: max(10px, env(safe-area-inset-top)) 12px max(18px, env(safe-area-inset-bottom)); }

/* ---------- pixel UI kit ---------- */
.card, #panel, #sheet, .overlay-card {
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: inset 3px 3px 0 rgba(255,255,255,.10), inset -3px -3px 0 rgba(0,0,0,.35), 0 4px 0 var(--line);
}
.card { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.btn {
  border: 3px solid var(--line);
  background: var(--panel2);
  box-shadow: inset 3px 3px 0 rgba(255,255,255,.22), inset -3px -3px 0 rgba(0,0,0,.35), 0 3px 0 var(--line);
  padding: 8px 14px; cursor: pointer; font-weight: 700; min-height: 44px;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: inset 3px 3px 0 rgba(0,0,0,.25), 0 1px 0 var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: #5a35c8; }
.btn.good { background: #1f6fd0; }
.btn.evil { background: #b22a2a; }
.btn.ok { background: #1f8a48; }
.btn.gold { background: #b8860b; color: #fff8dc; }
.btn.big { min-height: 52px; font-size: 17px; }
.btn.small { min-height: 34px; padding: 3px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }
.icon-btn { width: 40px; height: 40px; border: 3px solid var(--line); background: var(--panel2); font-size: 20px; cursor: pointer; box-shadow: inset 2px 2px 0 rgba(255,255,255,.2), inset -2px -2px 0 rgba(0,0,0,.3); }
.field { display: flex; flex-direction: column; gap: 4px; color: var(--dim); font-size: 13px; }
input, select {
  background: #0f0a1c; border: 3px solid var(--line); padding: 8px 10px; min-height: 44px; font-size: 16px;
  box-shadow: inset 2px 2px 0 rgba(0,0,0,.5);
}
input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.code-input { text-align: center; letter-spacing: .5em; font-size: 24px; font-weight: 800; text-transform: uppercase; }
.err { color: #ff8b8b; margin: 0; min-height: 1.4em; font-size: 13px; }
.hint { color: var(--dim); font-size: 13px; text-align: center; margin: 14px 4px; }
.or { text-align: center; color: var(--dim); font-size: 13px; }

/* ---------- home ---------- */
#home { padding-top: 6vh; }
.logo { text-align: center; margin-bottom: 18px; }
.logo-title { font-size: 56px; font-weight: 900; color: var(--gold); letter-spacing: 2px; text-shadow: 3px 3px 0 #6b3d00, 6px 6px 0 var(--line); }
.logo-sub { color: var(--dim); font-size: 14px; }

/* ---------- room HUD ---------- */
#hud { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.quests { display: flex; gap: 6px; flex: 1; justify-content: center; }
.q {
  width: 38px; height: 38px; display: grid; place-items: center; font-weight: 900; font-size: 16px;
  border: 3px solid var(--line); background: #3a3358; color: #cfc6ee; position: relative;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.18), inset -2px -2px 0 rgba(0,0,0,.35);
}
.q.cur { background: #7a5b10; color: var(--gold); animation: pulse 1.2s steps(2) infinite; }
.q.success { background: #1f6fd0; color: #fff; }
.q.fail { background: #b22a2a; color: #fff; }
.q small { position: absolute; bottom: -9px; right: -4px; font-size: 9px; background: var(--line); color: var(--gold); padding: 0 3px; }
@keyframes pulse { 50% { filter: brightness(1.5); } }
.rejects { display: flex; gap: 3px; align-items: center; }
.rejects i { width: 8px; height: 8px; background: #3a3358; border: 1px solid var(--line); }
.rejects i.on { background: var(--evil); }
.net { width: 12px; height: 12px; background: #888; border: 2px solid var(--line); }
.net.online { background: #3ddc84; }
.net.connecting { background: #ffd23f; }
.net.offline { background: #ff5252; }

/* ---------- table stage ---------- */
#stage { position: relative; width: 100%; line-height: 0; border: 3px solid var(--line); box-shadow: 0 4px 0 var(--line); background: #1d1730; }
#table { width: 100%; height: auto; image-rendering: pixelated; image-rendering: crisp-edges; image-rendering: pixelated; display: block; touch-action: manipulation; }
#seats { position: absolute; inset: 0; pointer-events: none; }
.seat {
  position: absolute; transform: translate(-50%, 0); pointer-events: auto; border: 0; background: none; padding: 0;
  display: flex; flex-direction: column; align-items: center; gap: 1px; cursor: default; line-height: 1.25; max-width: 28%;
}
.seat.above { transform: translate(-50%, -100%); flex-direction: column-reverse; }
.seat.above::before { bottom: auto; top: 100%; height: 40px; }
.seat::before { content: ""; position: absolute; left: 50%; bottom: 100%; width: 54px; height: 46px; transform: translateX(-50%); }
.seat .nm {
  background: rgba(10,7,19,.82); border: 2px solid var(--line); padding: 0 5px; font-size: 11px; font-weight: 800;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #fff;
}
.seat.me .nm { border-color: var(--gold); color: var(--gold); }
.seat.away .nm { opacity: .6; }
.seat.tap { cursor: pointer; }
.seat.tap .nm { border-color: #fff; animation: pulse 1s steps(2) infinite; }
.seat.sel .nm { background: #1f6fd0; border-color: #bfe1ff; }
.seat .rl { font-size: 10px; font-weight: 800; padding: 0 4px; border: 2px solid var(--line); white-space: nowrap; }
.rl.evil { background: #b22a2a; color: #fff; }
.rl.good { background: #1f6fd0; color: #fff; }
.rl.wizard { background: #6b3fd0; color: #fff; }
.rl.info { background: #3a3358; color: #ddd; }
.rl.vote-yes { background: #1f8a48; color: #fff; }
.rl.vote-no { background: #b22a2a; color: #fff; }
.banner { position: absolute; top: 46%; left: 50%; transform: translate(-50%, -50%); line-height: 1.4; background: rgba(10,7,19,.9); border: 3px solid var(--gold2); padding: 4px 12px; font-weight: 900; color: var(--gold); white-space: nowrap; }
.banner.good { color: #8fc8ff; border-color: var(--good); }
.banner.evil { color: #ff9a9a; border-color: var(--evil); }
#toasts { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); top: max(6px, env(safe-area-inset-top)); width: min(540px, calc(100% - 24px)); display: flex; flex-direction: column; gap: 4px; pointer-events: none; line-height: 1.4; }
.toast { background: rgba(10,7,19,.92); border: 2px solid var(--gold2); padding: 3px 8px; font-size: 12px; animation: toast 5s forwards; }
@keyframes toast { 0%, 85% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- panel ---------- */
#panel { margin-top: 12px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
#panel h2 { margin: 0; font-size: 18px; color: var(--gold); }
#panel p { margin: 0; color: var(--dim); }
#panel .sub { font-size: 13px; color: var(--dim); }
.code-big { font-size: 40px; font-weight: 900; letter-spacing: .3em; color: var(--gold); text-align: center; direction: ltr; text-shadow: 3px 3px 0 #6b3d00; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 2px solid var(--line); background: #3a3358; padding: 1px 8px; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.chip.yes { background: #1f8a48; }
.chip.no { background: #b22a2a; }
.chip.away { opacity: .6; }
.chip button { border: 0; background: none; color: #ff8b8b; cursor: pointer; padding: 0 2px; font-weight: 900; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toggle { display: flex; align-items: center; gap: 8px; border: 3px solid var(--line); background: #1a1230; padding: 6px 8px; cursor: pointer; font-size: 13px; font-weight: 700; user-select: none; }
.toggle input { width: 18px; height: 18px; min-height: 0; accent-color: var(--gold); }
.toggle.disabled { opacity: .5; }
.rolecard { border: 3px solid var(--line); padding: 12px; display: flex; flex-direction: column; gap: 8px; background: #1a1230; }
.rolecard.good { border-color: var(--good); }
.rolecard.evil { border-color: var(--evil); }
.rolecard .rname { font-size: 24px; font-weight: 900; }
.rolecard .team { font-size: 12px; font-weight: 800; padding: 0 8px; align-self: flex-start; border: 2px solid var(--line); }
.rolecard.good .team { background: var(--good); }
.rolecard.evil .team { background: var(--evil); }
.hidden-role { text-align: center; padding: 18px; color: var(--dim); border: 3px dashed #4a3f78; }
.progress { height: 10px; background: #0f0a1c; border: 2px solid var(--line); }
.progress i { display: block; height: 100%; background: var(--gold2); }
.cd { font-variant-numeric: tabular-nums; color: var(--gold); font-weight: 800; }
.vote-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.vote-btns .btn { min-height: 64px; font-size: 20px; }
.vote-btns .btn.chosen { outline: 4px solid var(--gold); outline-offset: 2px; }
.waiting { display: flex; align-items: center; gap: 10px; }
.dots::after { content: ""; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.row-item { border: 2px solid var(--line); background: #1a1230; padding: 6px 8px; font-size: 13px; }
.row-item b { color: var(--gold); }
.proxy { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }

/* ---------- sheet ---------- */
#sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; }
#sheet { position: fixed; z-index: 21; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; max-height: 78dvh; display: flex; flex-direction: column; border-bottom: 0; }
.tabs { display: flex; border-bottom: 3px solid var(--line); }
.tab { flex: 1; border: 0; background: var(--panel2); padding: 10px 2px; font-weight: 800; font-size: 13px; cursor: pointer; border-left: 2px solid var(--line); }
.tab.on { background: var(--panel); color: var(--gold); }
.tab.close { flex: 0 0 48px; }
#sheet-body { padding: 14px; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: max(14px, env(safe-area-inset-bottom)); }
#sheet-body h3 { margin: 0; color: var(--gold); font-size: 15px; }
#sheet-body p, #sheet-body li { color: var(--dim); margin: 0; font-size: 13px; }
#sheet-body ul { margin: 0; padding-inline-start: 18px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(8,5,16,.78); display: grid; place-items: center; padding: 20px; }
.overlay-card { padding: 20px; text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: stretch; max-width: 360px; }
.overlay-card h2 { margin: 0; color: var(--gold); }
.overlay-card p { margin: 0; color: var(--dim); }
.spinner { width: 28px; height: 28px; margin: 0 auto; background: var(--gold); animation: spin 1s steps(8) infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }

/* ---------- legal ---------- */
.legal { margin: 18px 4px 0; padding-top: 12px; border-top: 2px solid #2e2350; color: var(--dim); font-size: 12px; line-height: 1.7; }
.legal p { margin: 0 0 8px; }
.legal a { color: var(--gold2); }
