:root {
  --bg: #09090c;
  --bg-elevated: #121217;
  --bg-card: #17171e;
  --bg-input: #0e0e13;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #f3f1ed;
  --text-muted: #9b99a3;
  --text-dim: #6e6c75;
  --crimson: #b91c1c;
  --crimson-bright: #dc2626;
  --crimson-glow: rgba(185, 28, 28, 0.28);
  --gold: #d4af37;
  --gold-soft: rgba(212, 175, 55, 0.16);
  --emerald: #22c55e;
  --amber: #f59e0b;
  --radius: 14px;
  --radius-sm: 10px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Vazirmatn', 'Tahoma', sans-serif;
  --font-display: Georgia, 'Times New Roman', serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, #1c1014 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

/* Shared Status & Buttons */
.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.conn-pill.is-online .conn-dot {
  background: var(--emerald);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
}

.conn-pill.is-offline .conn-dot {
  background: var(--amber);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.1s ease, opacity 0.16s ease;
}

.btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-strong);
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, var(--crimson-bright), var(--crimson));
  border-color: rgba(255, 255, 255, 0.14);
  color: #fff;
  box-shadow: 0 8px 24px var(--crimson-glow);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #e03131, #c51d1d);
  border-color: rgba(255, 255, 255, 0.24);
}

.btn-ghost-danger {
  background: transparent;
  border-color: rgba(220, 38, 38, 0.35);
  color: #f87171;
}

.btn-ghost-danger:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.14);
  border-color: rgba(248, 113, 113, 0.6);
}

.btn-subtle {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
  color: var(--text-muted);
}

/* ==================== DESKTOP ==================== */
.desktop-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.desktop-shell {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 22px 28px 28px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.desktop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(145deg, #231115, #121217);
  border: 1px solid rgba(220, 38, 38, 0.45);
  display: grid;
  place-items: center;
  color: var(--crimson-bright);
  box-shadow: 0 4px 16px var(--crimson-glow);
}

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
}

.brand-sub {
  font-size: 0.84rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.round-badge {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--gold-soft);
  border: 1px solid rgba(212, 175, 55, 0.3);
  color: #f3d778;
  font-size: 0.82rem;
  font-weight: 600;
}

.lobby-grid {
  display: grid;
  grid-template-columns: 330px minmax(300px, 1fr) minmax(320px, 1fr);
  gap: 20px;
  flex: 1;
  align-items: stretch;
}

@media (max-width: 1120px) {
  .lobby-grid {
    grid-template-columns: 1fr 1fr;
  }
  .panel-qr {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .lobby-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 480px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}

.count-chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* QR Panel */
.panel-qr {
  align-items: center;
  text-align: center;
  justify-content: space-between;
}

.qr-frame {
  background: #ffffff;
  padding: 14px;
  border-radius: 16px;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.55);
  width: 248px;
  height: 248px;
  display: grid;
  place-items: center;
}

.qr-frame img {
  width: 100%;
  height: 100%;
  display: block;
}

.qr-url {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

.qr-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.qr-counter-num {
  font-size: 2.35rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text);
}

.qr-counter-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Participants List */
.list-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 4px;
}

.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-dim);
  padding: 28px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.participant-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.25s ease;
}

.participant-row.is-god {
  border-color: rgba(212, 175, 55, 0.55);
  background: linear-gradient(90deg, rgba(212, 175, 55, 0.1), var(--bg-card));
}

.participant-row.is-highlighted {
  border-color: var(--crimson-bright);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.45), 0 0 24px var(--crimson-glow);
  background: rgba(185, 28, 28, 0.16);
}

.participant-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #52525b;
}

.status-dot.online {
  background: var(--emerald);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.55);
}

.participant-name {
  font-size: 1.08rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  unicode-bidi: plaintext;
}

.participant-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.god-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.god-toggle:hover {
  border-color: rgba(212, 175, 55, 0.5);
  color: var(--text);
}

.god-toggle.active {
  background: var(--gold-soft);
  border-color: rgba(212, 175, 55, 0.7);
  color: #f6dc82;
}

.god-box {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1.5px solid currentColor;
  display: grid;
  place-items: center;
  font-size: 10px;
  line-height: 1;
}

.icon-btn {
  padding: 6px 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.icon-btn.danger:hover {
  background: rgba(220, 38, 38, 0.2);
  border-color: rgba(248, 113, 113, 0.5);
  color: #fca5a5;
}

/* Role Config */
.role-add-form {
  display: flex;
  gap: 8px;
}

.text-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  transition: border-color 0.16s ease;
}

.text-input:focus {
  border-color: rgba(220, 38, 38, 0.7);
}

.role-add-form .text-input {
  flex: 1;
  min-width: 0;
}

.qty-input {
  width: 64px;
  text-align: center;
}

.role-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.role-name-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 1rem;
  font-weight: 600;
  outline: none;
  unicode-bidi: plaintext;
}

.role-name-input:hover {
  border-color: var(--border);
}

.role-name-input:focus {
  background: var(--bg-input);
  border-color: rgba(220, 38, 38, 0.6);
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.stepper-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 700;
}

.stepper-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
}

.stepper-val {
  min-width: 28px;
  text-align: center;
  font-weight: 700;
  font-size: 0.98rem;
}

.validation-box {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.stat-cell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}

.stat-val {
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-lbl {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.validation-msg {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: 8px;
  text-align: center;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.28);
  color: #fcd34d;
}

.validation-msg.is-valid {
  background: rgba(34, 197, 94, 0.1);
  border-color: rgba(34, 197, 94, 0.3);
  color: #86efac;
}

.start-btn {
  width: 100%;
  padding: 14px 20px;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
}

/* Desktop Game Started Screen */
.started-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  position: relative;
}

.cards-emblem {
  position: relative;
  width: 170px;
  height: 140px;
  margin-bottom: 26px;
}

.cards-emblem svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 18px 34px rgba(185, 28, 28, 0.32));
  animation: floatSlow 5.5s ease-in-out infinite;
}

@keyframes floatSlow {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-7px); }
}

.started-title {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 5vw, 4.2rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.started-subtitle {
  margin: 0 0 24px;
  font-size: clamp(1.05rem, 2vw, 1.35rem);
  color: var(--text-muted);
}

.started-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.95rem;
}

.started-footer {
  position: fixed;
  bottom: 22px;
  right: 26px;
  display: flex;
  gap: 10px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.modal-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-body {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.desktop-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f1f27;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 60;
}

/* ==================== MOBILE ==================== */
.mobile-body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.mobile-shell {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: 16px 18px 28px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.mobile-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-brand .brand-mark {
  width: 32px;
  height: 32px;
}

.mobile-brand-name {
  font-family: var(--font-display);
  font-size: 1.2rem;
  letter-spacing: 0.14em;
  font-weight: 700;
}

.mobile-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px 0;
}

.mobile-card-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.mobile-heading {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
}

.mobile-subtext {
  margin: 0;
  color: var(--text-muted);
  text-align: center;
  font-size: 0.95rem;
}

.mobile-input {
  width: 100%;
  min-height: 52px;
  font-size: 1.08rem;
  padding: 12px 14px;
  text-align: start;
  unicode-bidi: plaintext;
}

.mobile-btn-lg {
  width: 100%;
  min-height: 52px;
  font-size: 1.05rem;
}

.mobile-alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(220, 38, 38, 0.14);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  font-size: 0.9rem;
  text-align: center;
}

/* Waiting */
.waiting-box {
  text-align: center;
  align-items: center;
}

.waiting-box.is-identified {
  border-color: var(--crimson-bright);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.45), 0 0 36px var(--crimson-glow);
}

.pulse-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid rgba(220, 38, 38, 0.5);
  display: grid;
  place-items: center;
  position: relative;
  margin: 6px 0;
}

.pulse-ring::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px solid rgba(220, 38, 38, 0.25);
  animation: pulseOut 2.2s ease-out infinite;
}

@keyframes pulseOut {
  0% { transform: scale(0.92); opacity: 0.9; }
  100% { transform: scale(1.3); opacity: 0; }
}

.player-tag {
  font-size: 1.3rem;
  font-weight: 700;
  unicode-bidi: plaintext;
}

/* 3D Role Flip Card */
.role-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
}

.player-header-chip {
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  font-size: 0.95rem;
  font-weight: 600;
  unicode-bidi: plaintext;
}

.flip-scene {
  width: 100%;
  max-width: 310px;
  aspect-ratio: 3 / 4.25;
  perspective: 1200px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.flip-card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.62s cubic-bezier(0.22, 1, 0.36, 1);
}

.flip-scene.is-flipped .flip-card {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.card-back-face {
  background: radial-gradient(circle at 50% 35%, #231116 0%, #121217 72%);
  border: 1.5px solid rgba(220, 38, 38, 0.45);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.65), inset 0 0 0 8px rgba(255, 255, 255, 0.02);
}

.card-back-inner {
  width: 100%;
  height: 100%;
  border: 1px solid rgba(220, 38, 38, 0.28);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 18px;
}

.card-hint {
  font-size: 0.95rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.card-front-face {
  transform: rotateY(180deg);
  background: radial-gradient(circle at 50% 25%, #241519 0%, #14141a 75%);
  border: 1.5px solid rgba(212, 175, 55, 0.55);
  box-shadow: 0 24px 55px rgba(0, 0, 0, 0.72);
  justify-content: space-between;
}

.card-role-kicker {
  font-size: 0.78rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #e2be53;
  font-weight: 700;
}

.card-role-name {
  font-size: clamp(1.9rem, 7vw, 2.55rem);
  font-weight: 800;
  line-height: 1.25;
  word-break: break-word;
  unicode-bidi: plaintext;
}

/* God Screen */
.god-view {
  justify-content: flex-start;
}

.god-banner {
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.16), rgba(185, 28, 28, 0.14));
  border: 1px solid rgba(212, 175, 55, 0.45);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 14px;
  text-align: center;
}

.god-title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.55rem;
  color: #f6dc82;
}

.god-meta {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.god-table-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.god-table {
  width: 100%;
  border-collapse: collapse;
}

.god-table th,
.god-table td {
  padding: 13px 16px;
  text-align: start;
  border-bottom: 1px solid var(--border);
}

.god-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
}

.god-table tr:last-child td {
  border-bottom: none;
}

.god-player-cell {
  font-weight: 600;
  font-size: 1.02rem;
  unicode-bidi: plaintext;
}

.god-role-cell {
  font-weight: 700;
  color: #fca5a5;
  font-size: 1.02rem;
  unicode-bidi: plaintext;
}
